yangys
2024-11-03 d187cd0fa46d01ec293e2aba1a1e54fdfab2ec80
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;
@@ -27,6 +28,7 @@
   private PackedDataService packedDataService;
   @Autowired
    private WorkstationDatapointsService dpService;
   /**
    * 处理收到的消息,对应TelemetryDataPostingConsumer
    * @param payload
@@ -54,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);
@@ -86,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));//使用原始配置点保持保存数据
              });