|  | @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
	
		
			
				|  |  |  //import com.usky.backend.client.DeviceDataClient;
 | 
	
		
			
				|  |  | -import com.usky.backend.domain.request.DeviceDataInfoVO;
 | 
	
		
			
				|  |  | +import com.usky.iot.service.vo.DeviceDataInfoVO;
 | 
	
		
			
				|  |  |  import com.usky.common.core.exception.BusinessException;
 | 
	
		
			
				|  |  |  import com.usky.common.mybatis.core.AbstractCrudService;
 | 
	
		
			
				|  |  |  import com.usky.common.security.utils.SecurityUtils;
 | 
	
	
		
			
				|  | @@ -15,12 +15,11 @@ import com.usky.backend.domain.request.DmpDeviceDataRequestVO;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  |  import java.time.Instant;
 | 
	
		
			
				|  |  |  import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  import java.time.ZoneId;
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * <p>
 | 
	
	
		
			
				|  | @@ -44,6 +43,9 @@ public class DmpDataInfoServiceImpl extends AbstractCrudService<DmpDataInfoMappe
 | 
	
		
			
				|  |  |  //    @Autowired
 | 
	
		
			
				|  |  |  //    private DeviceDataClient deviceDataClient;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private MqttOutConfig.MqttGateway mqttGateway;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private DmpDeviceTypeService dmpDeviceTypeService;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -87,20 +89,27 @@ public class DmpDataInfoServiceImpl extends AbstractCrudService<DmpDataInfoMappe
 | 
	
		
			
				|  |  |                  for(int i=0;i<list1.size();i++){
 | 
	
		
			
				|  |  |                      Map<String,Float> metrics = dmpDeviceDataRequestVO.getMetrics();
 | 
	
		
			
				|  |  |                      if(metrics.size()>0){
 | 
	
		
			
				|  |  | +                        DeviceDataInfoVO deviceDataInfoVO = new DeviceDataInfoVO();
 | 
	
		
			
				|  |  | +                        Map<String,Object> mp = new HashMap<>();
 | 
	
		
			
				|  |  | +                        List<Map<String,Object>> list2 = new ArrayList<>();
 | 
	
		
			
				|  |  |                          for(Map.Entry<String,Float> map:metrics.entrySet()){
 | 
	
		
			
				|  |  |                              String key = map.getKey();
 | 
	
		
			
				|  |  |                              float value = map.getValue();
 | 
	
		
			
				|  |  |                              if(key.equals(list1.get(i).getAttributeCode())){   //属性名需和产品注册信息一致
 | 
	
		
			
				|  |  | -                                DeviceDataInfoVO deviceDataInfoVO = new DeviceDataInfoVO();
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setDeviceId(dmpDeviceDataRequestVO.getDeviceId());
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setDeviceType(list.get(0).getDeviceType());
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setTypeAbbrevia(shortName);
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setName(key);
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setValue(value);
 | 
	
		
			
				|  |  | -                                deviceDataInfoVO.setTimestamp(LocalDateTime.ofInstant(Instant.ofEpochSecond(dmpDeviceDataRequestVO.getTimestamp()), ZoneId.systemDefault()));
 | 
	
		
			
				|  |  | -                                dataInfo.add(deviceDataInfoVO);
 | 
	
		
			
				|  |  | +                                mp.put(key,value);
 | 
	
		
			
				|  |  | +                                list2.add(mp);
 | 
	
		
			
				|  |  | +                            }else{
 | 
	
		
			
				|  |  | +                                throw new BusinessException("设备属性"+key+" 在产品属性表中不存在");
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | +                        deviceDataInfoVO.setMetrics(list2);
 | 
	
		
			
				|  |  | +                        deviceDataInfoVO.setDevice_id(dmpDeviceDataRequestVO.getDeviceId());
 | 
	
		
			
				|  |  | +                        deviceDataInfoVO.setProduct_id(list.get(0).getId().toString());
 | 
	
		
			
				|  |  | +                        Calendar calendar = Calendar.getInstance();
 | 
	
		
			
				|  |  | +                        long timestamp = calendar.getTimeInMillis() / 1000;
 | 
	
		
			
				|  |  | +                        deviceDataInfoVO.setTimestamp(timestamp);
 | 
	
		
			
				|  |  | +                        deviceDataInfoVO.setDevice_type(list.get(0).getDeviceType()+"-"+shortName);
 | 
	
		
			
				|  |  | +                        dataInfo.add(deviceDataInfoVO);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -108,7 +117,7 @@ public class DmpDataInfoServiceImpl extends AbstractCrudService<DmpDataInfoMappe
 | 
	
		
			
				|  |  |              throw new BusinessException("查找产品信息失败,"+dmpDeviceDataRequestVO.getProductCode()+" 在产品信息表中不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if(CollectionUtils.isNotEmpty(dataInfo)){
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            mqttGateway.sendToMqtt("data-collector",dataInfo);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |