yangys
2025-11-24 11d4be720620abf502d35000e2ed40d30c4023bf
collect/src/main/java/com/qianwen/mdc/collect/service/IOTMqttReceiveService.java
@@ -19,6 +19,7 @@
@Service
public class IOTMqttReceiveService {
   public static final String NEWDP_SUFFIX = "_n";//计算规则使用之后新数据点的结尾
   private static final Logger log = LoggerFactory.getLogger(IOTMqttReceiveService.class);
   @Autowired
   private CollectDataService collectDataService;
@@ -26,12 +27,11 @@
   @Autowired
   private PackedDataService packedDataService;
   @Autowired
   private RedisUtil redisUtil;
   @Autowired
    private WorkstationDatapointsService dpService;
   /**
    * 处理收到的消息,对应TelemetryDataPostingConsumer
    * @param payload
    * @param payload 数据,json格式
    */
   public void handle(String payload) {
        //解析消息
@@ -56,15 +56,13 @@
        Set<String> keySet = jsonObj.keySet();
        String[] keys = keySet.toArray(new String[] {});
        
        //WorkstationDatapointsVO dpVo;
        
        final String NEWDP_SUFFIX = "_n";//计算规则使用之后新数据点的结尾
        for(String key : keys) {
           String appId = key;//iot系统中的应用id,本应用中应该用表去对应
           
           //TODO 获取工位数据点配置,只保存配置好的数据点,没有配置的采集数据抛弃。
           //获取工位数据点配置,只保存配置好的数据点,没有配置的采集数据抛弃。
           final WorkstationDatapointsVO dpVo = dpService.getDatapointsByAppIdFromCache(appId);
           //final WorkstationDatapointsVO dpVo = dpService.getDataPointByAppId(appId);
           if(dpVo == null) {
              //工位没有定义过数据点或者appId不匹配
              log.warn("appId={}未找到数据点定义记录,丢弃数据",appId);
@@ -88,14 +86,16 @@
              
              Set<String> valueKeySet = values.keySet();
              valueKeySet.forEach(valueKey ->{
                 String oriValueKey = valueKey;;//由于使用计算规则的采集点名称会后面增加一个"_n",所以这个oriValueKey代表没有增加"_n"的
                 if(StringUtils.endsWith(valueKey, NEWDP_SUFFIX)) {
                    oriValueKey = StringUtils.removeEnd(valueKey, NEWDP_SUFFIX);
                 }
                 if(!dpVo.containsDataPoint(oriValueKey)) {
                 if(!dpVo.containsDataPoint(valueKey)) {
                   //如果不存在该数据点配置,该数据直接忽略
                   return;
                }
                 String oriValueKey = valueKey;//由于使用计算规则的采集点名称会后面增加一个"_n",所以这个oriValueKey代表没有增加"_n"的
                 if(StringUtils.endsWith(valueKey, NEWDP_SUFFIX)) {
                    oriValueKey = StringUtils.removeEnd(valueKey, NEWDP_SUFFIX);
                 }
                 tdataItem.addPoint(oriValueKey,values.getString(valueKey));//使用原始配置点保持保存数据
              });
              
@@ -108,21 +108,4 @@
        return dtList;
   }
   
   /**
    * 根据对应表缓存,获取appId对应的id
    * @param appId
    * @return
    */
   /*
   public Long getWorkstationIdByAppId(String appId) {
      Object wid = redisUtil.hget("workstation-appid-map", appId);
      String workstationId = String.valueOf(Optional.ofNullable(wid).orElse(StringUtils.EMPTY));
      if(ObjectUtil.isEmpty(workstationId)) {
         return null;
      }
      return Long.parseLong(workstationId);
   }
   */
}