Browse Source

Merge branch 'master' of http://221.182.8.141:2300/linzhiwei/tf_snws

linzhiwei 2 years ago
parent
commit
2d5faaa40b

+ 66 - 213
snws-monitor/snws-monitor-boot/src/main/java/com/tofly/monitor/mqtt/HangZhengTopicHandler.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.tofly.monitor.screenDisplay.entity.dto.WisdomDisplayDto;
 import com.tofly.monitor.screenDisplay.mapper.CustomDisplayMapper;
 import com.tofly.pojo.IndexVal;
+import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.messaging.Message;
@@ -19,238 +20,90 @@ import java.util.Map;
 
 @Service("hangZhengTopicHandler")
 @Slf4j
+@AllArgsConstructor
 public class HangZhengTopicHandler implements TopicHandler {
 
-    @Autowired
-    private CustomDisplayMapper customDisplayMapper;
+    private final CustomDisplayMapper customDisplayMapper;
 
     @Override
     public void handler(Message<?> message) {
         String payload = String.valueOf(message.getPayload());
         Map<String,Object> payloads = JSON.parseObject(payload);
+        // 历史指标数据列表
         List<IndexVal> indexValList = new ArrayList<>();
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
-        //航征微型内涝一体机
-        if (payloads!=null&&payloads.get("device_id")!=null&&payloads.get("device_id").equals("7e7e0071200366")) {
-            IndexVal indexVal = new IndexVal();
-            Long id = SnowFlake.nextId();
-            indexVal.setId(id);
-            indexVal.setDeviceCode("wxnlytj");
-            indexVal.setItCd("ss");
-            indexVal.setItVal(String.valueOf(payloads.get("depth_of_water")));
-            Date collectTime;
-            try {
-                collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
-                indexVal.setScadaTime(collectTime);
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            WisdomDisplayDto wis = new WisdomDisplayDto();
-            wis.setIndexCode("ss");
-            wis.setDeviceCode("wxnlytj");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal1 == null || indexVal1.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(indexVal);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                indexVal.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
-                customDisplayMapper.updateTemp(indexVal);
-            }
-            indexVal.setId(id);
+        // 航征微型内涝一体机
+        if (payloads != null && payloads.get("device_id") != null && payloads.get("device_id").equals("7e7e0071200366")) {
+            IndexVal indexVal = getIndexInfo(payloads,"ss","wxnlytj","depth_of_water");
             indexValList.add(indexVal);
         }
+        // 雷达水位计一体机1
+        if (payloads != null && payloads.get("device_model") != null && payloads.get("device_model").equals("HZ-RLS-60L-50Pi")) {
+            IndexVal swIndexVal = getIndexInfo(payloads,"sw","ldswytj1","water_levels");
+            indexValList.add(swIndexVal);
 
-        //雷达水位计一体机1
-        if (payloads!=null&&payloads.get("device_model")!=null&&payloads.get("device_model").equals("HZ-RLS-60L-50Pi")) {
-            IndexVal swIndex = new IndexVal();
-            Long id = SnowFlake.nextId();
-            swIndex.setId(id);
-            swIndex.setDeviceCode("ldswytj1");
-            swIndex.setItCd("sw");
-            swIndex.setItVal(String.valueOf(payloads.get("water_levels")));
-            Date collectTime;
-            try {
-                collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
-                swIndex.setScadaTime(collectTime);
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            WisdomDisplayDto wis = new WisdomDisplayDto();
-            wis.setIndexCode("sw");
-            wis.setDeviceCode("ldswytj1");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal1 == null || indexVal1.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(swIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                swIndex.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
-                customDisplayMapper.updateTemp(swIndex);
-            }
-            swIndex.setId(id);
-            indexValList.add(swIndex);
-
-            IndexVal kgIndex = new IndexVal();
-            id = SnowFlake.nextId();
-            kgIndex.setId(id);
-            kgIndex.setItCd("kg");
-            kgIndex.setItVal(String.valueOf(payloads.get("ullage")));
-            wis.setIndexCode("kg");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal2 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal2 == null || indexVal2.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(kgIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                kgIndex.setId(Long.parseLong(String.valueOf(indexVal2.get(0).get("id"))));
-                customDisplayMapper.updateTemp(kgIndex);
-            }
-            kgIndex.setId(id);
-            indexValList.add(kgIndex);
+            IndexVal kgIndexVal = getIndexInfo(payloads,"kg","ldswytj1","ullage");
+            indexValList.add(kgIndexVal);
         }
+        // 雷达水位计一体机2
+        if (payloads != null && payloads.get("device_model") != null && payloads.get("device_model").equals("HZ-RLS-60L-50")) {
+            IndexVal swIndexVal = getIndexInfo(payloads,"sw","ldswytj2","water_levels");
+            indexValList.add(swIndexVal);
 
-        //雷达水位计一体机2
-        if (payloads!=null&&payloads.get("device_model")!=null&&payloads.get("device_model").equals("HZ-RLS-60L-50")) {
-            IndexVal swIndex = new IndexVal();
-            Long id = SnowFlake.nextId();
-            swIndex.setId(id);
-            swIndex.setDeviceCode("ldswytj2");
-            swIndex.setItCd("sw");
-            swIndex.setItVal(String.valueOf(payloads.get("water_levels")));
-            Date collectTime;
-            try {
-                collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
-                swIndex.setScadaTime(collectTime);
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            WisdomDisplayDto wis = new WisdomDisplayDto();
-            wis.setIndexCode("sw");
-            wis.setDeviceCode("ldswytj2");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal1 == null || indexVal1.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(swIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                swIndex.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
-                customDisplayMapper.updateTemp(swIndex);
-            }
-            swIndex.setId(id);
-            indexValList.add(swIndex);
-
-            IndexVal kgIndex = new IndexVal();
-            id = SnowFlake.nextId();
-            kgIndex.setId(id);
-            kgIndex.setItCd("kg");
-            kgIndex.setItVal(String.valueOf(payloads.get("ullage")));
-            wis.setIndexCode("kg");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal2 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal2 == null || indexVal2.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(kgIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                kgIndex.setId(Long.parseLong(String.valueOf(indexVal2.get(0).get("id"))));
-                customDisplayMapper.updateTemp(kgIndex);
-            }
-            kgIndex.setId(id);
-            indexValList.add(kgIndex);
+            IndexVal kgIndexVal = getIndexInfo(payloads,"kg","ldswytj2","ullage");
+            indexValList.add(kgIndexVal);
         }
+        // 雷达流量计
+        if (payloads != null && payloads.get("device_model") != null && payloads.get("device_model").equals("HZ-SVR-122QP")) {
+            IndexVal ssIndexVal = getIndexInfo(payloads,"ss","ldllj","water_levels");
+            indexValList.add(ssIndexVal);
 
-        //雷达流量计
-        if (payloads!=null&&payloads.get("device_model")!=null&&payloads.get("device_model").equals("HZ-SVR-122QP")) {
-            IndexVal ssIndex = new IndexVal();
-            Long id = SnowFlake.nextId();
-            ssIndex.setId(id);
-            ssIndex.setDeviceCode("ldllj");
-            ssIndex.setItCd("ss");
-            ssIndex.setItVal(String.valueOf(payloads.get("water_levels")));
-            Date collectTime;
-            try {
-                collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
-                ssIndex.setScadaTime(collectTime);
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            WisdomDisplayDto wis = new WisdomDisplayDto();
-            wis.setIndexCode("ss");
-            wis.setDeviceCode("ldllj");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal1 == null || indexVal1.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(ssIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                ssIndex.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
-                customDisplayMapper.updateTemp(ssIndex);
-            }
-            ssIndex.setId(id);
-            indexValList.add(ssIndex);
-
-            IndexVal ssllIndex = new IndexVal();
-            id = SnowFlake.nextId();
-            ssllIndex.setId(id);
-            ssllIndex.setItCd("ssll");
-            ssllIndex.setItVal(String.valueOf(payloads.get("instantaneous_flow")));
-            wis.setIndexCode("ssll");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal2 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal2 == null || indexVal2.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(ssllIndex);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                ssllIndex.setId(Long.parseLong(String.valueOf(indexVal2.get(0).get("id"))));
-                customDisplayMapper.updateTemp(ssllIndex);
-            }
-            ssllIndex.setId(id);
-            indexValList.add(ssllIndex);
+            IndexVal ssllIndexVal = getIndexInfo(payloads,"ssll","ldllj","instantaneous_flow");
+            indexValList.add(ssllIndexVal);
         }
-
-        //雷达流速仪
-        if (payloads!=null&&payloads.get("device_model")!=null&&payloads.get("device_model").equals("HZ-SVR-24V-200")) {
-            IndexVal indexVal = new IndexVal();
-            Long id = SnowFlake.nextId();
-            indexVal.setId(id);
-            indexVal.setDeviceCode("ldlsy");
-            indexVal.setItCd("bmls");
-            indexVal.setItVal(String.valueOf(payloads.get("surface_velocity")));
-            Date collectTime;
-            try {
-                collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
-                indexVal.setScadaTime(collectTime);
-            } catch (ParseException e) {
-                e.printStackTrace();
-            }
-            WisdomDisplayDto wis = new WisdomDisplayDto();
-            wis.setIndexCode("bmls");
-            wis.setDeviceCode("ldlsy");
-            wis.setTableName("tf_ywpn_monitor_reatime_copy");
-            List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
-            if (indexVal1 == null || indexVal1.size() == 0) {
-                List<IndexVal> indexValNewList = new ArrayList<>();
-                indexValNewList.add(indexVal);
-                customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
-            }else {
-                indexVal.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
-                customDisplayMapper.updateTemp(indexVal);
-            }
-            indexVal.setId(id);
-            indexValList.add(indexVal);
+        // 雷达流速仪
+        if (payloads != null && payloads.get("device_model") != null && payloads.get("device_model").equals("HZ-SVR-24V-200")) {
+            IndexVal ssIndexVal = getIndexInfo(payloads,"bmls","ldlsy","surface_velocity");
+            indexValList.add(ssIndexVal);
         }
-
-        //增加数据到历史表
+        // 增加数据到历史表
         customDisplayMapper.insertBacthTemp(indexValList,"tf_ywpn_monitor_history_copy");
         log.info("handler(),串口数据接收,payload:{}", payload);
     }
 
+    // 更新实时指标数据;添加历史指标数据
+    private IndexVal getIndexInfo(Map<String,Object> payloads, String indexCode, String deviceCode, String indexValCode){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        IndexVal indexVal = new IndexVal();
+        Long id = SnowFlake.nextId();
+        indexVal.setId(id);
+        indexVal.setDeviceCode(deviceCode);
+        indexVal.setItCd(indexCode);
+        indexVal.setItVal(String.valueOf(payloads.get(indexValCode)));
+        Date collectTime;
+        try {
+            collectTime = sdf.parse(String.valueOf(payloads.get("collect_time")));
+            indexVal.setScadaTime(collectTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        // 查询实时表是否存在此设备指标
+        WisdomDisplayDto wis = new WisdomDisplayDto();
+        wis.setIndexCode(indexCode);
+        wis.setDeviceCode(deviceCode);
+        wis.setTableName("tf_ywpn_monitor_reatime_copy");
+        List<Map<String,Object>> indexVal1 = customDisplayMapper.viewCopyIndex(wis);
+        if (indexVal1 == null || indexVal1.size() == 0) {
+            // 新增指标到实时表
+            List<IndexVal> indexValNewList = new ArrayList<>();
+            indexValNewList.add(indexVal);
+            customDisplayMapper.insertBacthTemp(indexValNewList,"tf_ywpn_monitor_reatime_copy");
+        }else {
+            // 修改实时表的指标数据
+            indexVal.setId(Long.parseLong(String.valueOf(indexVal1.get(0).get("id"))));
+            customDisplayMapper.updateTemp(indexVal);
+        }
+        indexVal.setId(id);
+        return indexVal;
+    }
+
 }

+ 2 - 2
snws-monitor/snws-monitor-boot/src/main/java/com/tofly/monitor/screenDisplay/mapper/CustomDisplayMapper.java

@@ -4,15 +4,15 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.tofly.monitor.screenDisplay.entity.dto.IndexNameTypeDto;
 import com.tofly.monitor.screenDisplay.entity.dto.WisdomDisplayDto;
 import com.tofly.monitor.screenDisplay.entity.vo.StationIndexRealValVo;
-import com.tofly.monitor.screenDisplay.entity.vo.StationIndexRealVo;
 import com.tofly.pojo.IndexVal;
-import com.tofly.pojo.TfYwpnMonitorIndexW;
 import com.tofly.pojo.vo.StationIndexVo;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
 
+@Mapper
 public interface CustomDisplayMapper {
 
     List<Map<String, Object>> getSewageList(@Param("wisdomDisplayDto") WisdomDisplayDto wisdomDisplayDto);