Parcourir la source

新增 吸虫塔获取设备配置和编辑设备配置接口

zhaiyifei il y a 9 mois
Parent
commit
26516b1dca

+ 42 - 53
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/XphYfQxzDeviceImpl.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iots.device.serviceImp;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.JSONUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
@@ -10,21 +11,25 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
 import com.yunfeiyun.agmp.iot.common.constant.mqtt.IotMqttConstant;
 import com.yunfeiyun.agmp.iot.common.domain.*;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdModel;
-import com.yunfeiyun.agmp.common.service.LocationService;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
 import com.yunfeiyun.agmp.iots.core.manager.MqttManager;
 import com.yunfeiyun.agmp.iots.device.common.DeviceAbstractImpl;
 import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzMsg;
-import com.yunfeiyun.agmp.iots.device.domain.yfqxz.YfQxzReqMsg;
 import com.yunfeiyun.agmp.iots.device.service.IXphYfQxzDevice;
-import com.yunfeiyun.agmp.iots.service.*;
+import com.yunfeiyun.agmp.iots.service.IIotCmdlogService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iots.service.IIotDeviceconfigService;
+import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
 import com.yunfeiyun.agmp.iots.service.impl.IotDeviceAddressService;
+import com.yunfeiyun.agmp.iots.warn.service.WarnService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.util.TextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 
@@ -52,7 +57,7 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
     private IIotDevicelasteddataService iIotDevicelasteddataService;
 
     @Autowired
-    private MongoService<IotBaseEntity> mongoService;
+    private MongoService mongoService;
 
     @Autowired
     private LocationService locationService;
@@ -63,10 +68,12 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
     @Autowired
     private IIotCmdlogService iIotCmdlogService;
 
-
     @Autowired
     private IotDeviceAddressService iotDeviceAddressService;
 
+    @Autowired
+    private WarnService warnService;
+
 
 
     @Override
@@ -189,9 +196,9 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
 
         // 更新设备数据信息到数据库 mongodb
         String cId = iotDeviceOld.getTid();
-
+        List<IotXphYfqxzdata> dataList = new ArrayList<>();
         for (Object item: jarrData) {
-            JSONObject jobj = (JSONObject) item;
+            JSONObject jobj = JSONObject.from(item);
             IotXphYfqxzdata qxzdata = new IotXphYfqxzdata();
             qxzdata.setCId(cId);
             qxzdata.setDevBid(iotDeviceOld.getDevBid());
@@ -199,42 +206,23 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
             qxzdata.setEName(jobj.getString("eName"));
             qxzdata.setEKey(jobj.getString("eKey"));
             qxzdata.setEValue(jobj.getString("eValue"));
-
             qxzdata.setTime(reportDt);
 
-            mongoService.saveOne(qxzdata);
+            dataList.add(qxzdata);
 
             //把“上报时间”放里面
             jobj.put("time",DateUtils.parseDateToStr("yyyy-MM-dd'T'HH:mm:ss.SSSX",reportDt));
             jobj.put("devBid",qxzdata.getDevBid());
             jobj.put("cId",qxzdata.getCId());
         }
+        if(!dataList.isEmpty()){
+            mongoService.insertList(IotXphYfqxzdata.class, dataList);
+        }
+
         iIotDevicelasteddataService.updateDeviceLastedData(iotDeviceOld,jarrData.toString(), devUpdateddate);
 
-        //预警
-        //云飞 气象站 和 墒情站  都从这里进数据
-/*        if( IotDeviceDictConst.TYPE_YF_QXZ.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkQxzData("0","",iotDeviceOld.getDevBid());
-        }else if( IotDeviceDictConst.TYPE_YF_SQZ.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkGssqData("0","",iotDeviceOld.getDevBid());
-        }else if( IotDeviceDictConst.TYPE_YF_GXZW.equals(iotDeviceOld.getDevtypeBid()) ){
-            warnService.checkGssqData("0","",iotDeviceOld.getDevBid());
-        }*/
-//        EnumWarnType warnType = EnumWarnType.findEnumByDevbid(iotDeviceOld.getDevtypeBid());
-//        if(warnType != null){
-//            warnService.checkSensData(warnType.getCode(),"0","",iotDeviceOld.getDevBid());
-//        }
-//
-//        if("3".equals(warnService.getWarnVer())){
-//            //要求预警检查 V3
-//            IotWarncheck warncheck = new IotWarncheck();
-//            warncheck.setDevBid(iotDeviceOld.getDevBid());
-//            // TODO
-//            //  iotsMqService.sendMsg(IotMqConstant.TOPIC_WARNCHECK, IotMqConstant.TOPIC_WARNCHECK, warncheck);
-//        }else{
-//            //预警检查 V2
-//            warnService.checkSensData("0","",iotDeviceOld.getDevBid());
-//        }
+        // 发送告警消息
+        warnService.processWarningReportData(iotDeviceOld, ext);
     }
 
 
@@ -321,26 +309,27 @@ public class XphYfQxzDeviceImpl extends DeviceAbstractImpl implements IXphYfQxzD
 
         iIotDeviceService.updateIotDevice(newIotDevice);
         // 主动进行查询,以确保不是误判离线
-        if("offline".equalsIgnoreCase(cmd)){
-            new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.sleep(2*1000);
-                    }catch (InterruptedException e){
-                        e.printStackTrace();
-                    }
-                    //主动进行查询,以确保不是误判离线
-                    log.info("【YFQXZ】主动进行查询,以确保不是误判离线" + iotDeviceOld);
-                    YfQxzReqMsg reqMsg = new YfQxzReqMsg();
-                    JSONObject jobjParams = new JSONObject();
-                    jobjParams.put("type","data");
-                    reqMsg.setExt(jobjParams);
-
-                    publishMsg(iotDeviceOld, reqMsg);
-                }
-            }).start();
-        }
+        // 新普惠设备不能控制,不用在查询检测
+//        if("offline".equalsIgnoreCase(cmd)){
+//            new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+//                    try {
+//                        Thread.sleep(2*1000);
+//                    }catch (InterruptedException e){
+//                        e.printStackTrace();
+//                    }
+//                    //主动进行查询,以确保不是误判离线
+//                    log.info("【YFQXZ】主动进行查询,以确保不是误判离线" + iotDeviceOld);
+//                    YfQxzReqMsg reqMsg = new YfQxzReqMsg();
+//                    JSONObject jobjParams = new JSONObject();
+//                    jobjParams.put("type","data");
+//                    reqMsg.setExt(jobjParams);
+//
+//                    publishMsg(iotDeviceOld, reqMsg);
+//                }
+//            }).start();
+//        }
     }
 
     @Override

+ 21 - 1
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/YfScdDeviceImpl.java

@@ -90,9 +90,29 @@ public class YfScdDeviceImpl extends DeviceAbstractImpl implements IYfScdDevice
         switch (methodName) {
             case CmdDef.YfScdCmdDef.CMD_CONFIG:{
                 JSONObject jobjParam = cmdDistribution.getJsons();
+                Map<String, String> keyMap = new HashMap<>();
+                keyMap.put("ds", "ds");
+                keyMap.put("tt", "tt");
+                keyMap.put("dat_f", "dattim");
+                keyMap.put("ts", "ts");
+                keyMap.put("st", "st");
+                keyMap.put("et", "et");
+
+                JSONObject configObj = new JSONObject();
+                for(Map.Entry<String, String> entry : keyMap.entrySet()) {
+                    String key = entry.getKey();
+                    String keyName = entry.getValue();
+
+                    if (jobjParam.containsKey(key)) {
+                        Object value = jobjParam.get(key);
+                        if (value != null) {
+                            configObj.put(keyName, value);
+                        }
+                    }
+                }
                 JSONObject devConfig = new JSONObject();
                 devConfig.put("cmd", "paramconf");
-                devConfig.put("ext", jobjParam);
+                devConfig.put("ext", configObj);
                 mqttMsgContent = devConfig.toString();
                 log.info("【杀虫灯】发送指令【config】 mqttMsgContent={}", mqttMsgContent);
                 break;

+ 21 - 0
src/main/java/com/yunfeiyun/agmp/iots/warn/model/WarnQxSqInfoDto.java

@@ -0,0 +1,21 @@
+package com.yunfeiyun.agmp.iots.warn.model;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceTypeLv1Enum;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevicefactor;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class WarnQxSqInfoDto {
+    private IotDevice iotDevice;
+    private List<WarnConfigInfo> configList;
+    private JSONObject jsonObject;
+    private Map<String, IotDevicefactor> factorMap;
+    private IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum;
+    private Map<String, String> currentValueMap;
+
+}

+ 56 - 28
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java

@@ -12,6 +12,7 @@ import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
 import com.yunfeiyun.agmp.iot.common.enums.EnumWarnRuleOp;
 import com.yunfeiyun.agmp.iots.service.IIotDevicefactorService;
 import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
+import com.yunfeiyun.agmp.iots.warn.model.WarnQxSqInfoDto;
 import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
 import com.yunfeiyun.agmp.iots.warn.model.WarnStatusDto;
 import com.yunfeiyun.agmp.iots.warn.util.CompareUtil;
@@ -105,16 +106,28 @@ public class WarnService {
             for(Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
                 List<WarnConfigInfo> configList = entry.getValue();
                 WarnResult warnResult = null;
+
+                WarnQxSqInfoDto warnQxSqInfoDto = new WarnQxSqInfoDto();
+                warnQxSqInfoDto.setIotDevice(iotDevice);
+                warnQxSqInfoDto.setConfigList(configList);
+                warnQxSqInfoDto.setJsonObject(data);
+                warnQxSqInfoDto.setFactorMap(factorMap);
+                warnQxSqInfoDto.setIotDeviceTypeLv1Enum(iotDeviceTypeLv1Enum);
+
                 try{
                     switch (iotDeviceTypeLv1Enum) {
                         case QXZ: {
-                            warnResult = comparableQxzReportData(iotDevice, configList, data, factorMap);
+                            warnResult = comparableQxzReportData(warnQxSqInfoDto);
                             break;
                         }
-//                    case SQZ: {
-//                        warnResult = comparableSqzReportData(devBid, config, data);
-//                        break;
-//                    }
+//                        case SQZ: {
+//                            warnResult = comparableSqzReportData(warnQxSqInfoDto);
+//                            break;
+//                        }
+//                        case GSSQ: {
+//                            warnResult = comparableGssqReportData(warnQxSqInfoDto);
+//                            break;
+//                        }
 //                    case "病虫害": {
 //                        warnResult = comparableBchReportData(devBid, config, data);
 //                        break;
@@ -205,8 +218,13 @@ public class WarnService {
         return wiName;
     }
 
-    private WarnStatusDto getQxzWarnStatusDto(WarnConfigInfo config, Map<String, String> currentValueMap, Map<String,
-            IotDevicefactor> factorMap, String devCode) {
+    private WarnStatusDto getQxzWarnStatusDto(WarnConfigInfo config, WarnQxSqInfoDto warnQxSqInfoDto) {
+        IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
+        String devCode = iotDevice.getDevCode();
+        Map<String, String> currentValueMap = warnQxSqInfoDto.getCurrentValueMap();
+        Map<String, IotDevicefactor> factorMap = warnQxSqInfoDto.getFactorMap();
+        IotDeviceTypeLv1Enum iotDeviceTypeLv1Enum = warnQxSqInfoDto.getIotDeviceTypeLv1Enum();
+
         String targetValue = config.getWiValue();
         String wiAddress = config.getWiAddress();
         String wiCode = config.getWiCode();
@@ -254,7 +272,7 @@ public class WarnService {
         boolean tempSuccess = CompareUtil.comp(currentValue, expression, targetValue);
 
         WarnStatusDto warnStatusDto = new WarnStatusDto();
-        warnStatusDto.setDevType("气象站");
+        warnStatusDto.setDevType(iotDeviceTypeLv1Enum.getName());
         warnStatusDto.setDevCode(devCode);
         warnStatusDto.setName(wiName);
         warnStatusDto.setValue(currentValue);
@@ -274,11 +292,11 @@ public class WarnService {
      * @param devCode
      * @return
      */
-    public WarnResult comparableQxzSingleIndicator(WarnResult warnResult, List<WarnConfigInfo> configList, Map<String, IotDevicefactor> factorMap,
-                                                   Map<String, String> currentValueMap, String devCode) {
+    public WarnResult comparableQxzSingleIndicator(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
         WarnStatusDto warnStatusDto = null;
         for (WarnConfigInfo config : configList) {
-            warnStatusDto = getQxzWarnStatusDto(config, currentValueMap, factorMap, devCode);
+            warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
             // 如果没有预警配置,直接返回null,不进行预警判断
             if(warnStatusDto == null){
                 continue;
@@ -312,12 +330,12 @@ public class WarnService {
      * @param jsonObject 上报的数据
      * @return WarnResult 包含是否触发告警的信息
      */
-    public WarnResult comparableQxzMultipleIndicators(WarnResult warnResult, List<WarnConfigInfo> configList, Map<String, IotDevicefactor> factorMap,
-                                                      Map<String, String> currentValueMap, String devCode) {
+    public WarnResult comparableQxzMultipleIndicators(WarnResult warnResult, WarnQxSqInfoDto warnQxSqInfoDto) {
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
         WarnStatusDto warnStatusDto = null;
         List<WarnStatusDto> warnStatusDtos = new ArrayList<>();
         for (WarnConfigInfo config : configList) {
-            warnStatusDto = getQxzWarnStatusDto(config, currentValueMap, factorMap, devCode);
+            warnStatusDto = getQxzWarnStatusDto(config, warnQxSqInfoDto);
             // 如果没有预警配置,直接返回null,不进行预警判断
             if(warnStatusDto == null){
                 continue;
@@ -364,15 +382,18 @@ public class WarnService {
      * @param config     对应的配置
      * @param jsonObject 上报的数据
      */
-    private WarnResult comparableQxzReportData(IotDevice iotDevice, List<WarnConfigInfo> configList,
-                                               JSONObject jsonObject, Map<String, IotDevicefactor> factorMap) {
-        String devCode = iotDevice.getDevCode();
+    private WarnResult comparableQxzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        IotDevice iotDevice = warnQxSqInfoDto.getIotDevice();
+        List<WarnConfigInfo> configList = warnQxSqInfoDto.getConfigList();
+        JSONObject jsonObject = warnQxSqInfoDto.getJsonObject();
+        JSONArray jsonArray = jsonObject.getJSONArray("data");
+        Map<String, String> currentValueMap = getQxzCurrentValueMap(iotDevice, jsonArray);
+
+        warnQxSqInfoDto.setCurrentValueMap(currentValueMap);
+
         String devBid = iotDevice.getDevBid();
         WarnConfigInfo configInfo = configList.get(0);
         String wcCondition = configInfo.getWcCondition();
-        JSONArray jsonArray = jsonObject.getJSONArray("data");
-
-        Map<String, String> currentValueMap = getQxzCurrentValueMap(iotDevice, jsonArray);
 
         IotWarnconfig iotWarnconfig = new IotWarnconfig();
         BeanUtils.copyProperties(configInfo, iotWarnconfig);
@@ -387,24 +408,31 @@ public class WarnService {
         warnResult.setDevtypeBid(iotDevice.getDevtypeBid());
         warnResult.setConfig(iotWarnconfig);
         warnResult.setTriggered(false);
+
         if("0".equals(wcCondition)){
-            warnResult = comparableQxzSingleIndicator(warnResult, configList, factorMap, currentValueMap, devCode);
+            warnResult = comparableQxzSingleIndicator(warnResult, warnQxSqInfoDto);
         } else {
-            warnResult = comparableQxzMultipleIndicators(warnResult, configList, factorMap, currentValueMap, devCode);
+            warnResult = comparableQxzMultipleIndicators(warnResult, warnQxSqInfoDto);
         }
         return warnResult;
     }
 
 
     /**
-     * 【墒情站】比较该设备上报的要素和配置是否达到预警条件,暂不实现,预留
+     * 【墒情站】比较该设备上报的要素和配置是否达到预警条件
      *
-     * @param devId
-     * @param config
-     * @param jsonObject
      */
-    WarnResult comparableSqzReportData(String devId, Object config, JSONObject jsonObject) {
-        return null;
+    WarnResult comparableSqzReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        return comparableQxzReportData(warnQxSqInfoDto);
+
+    }
+
+    /**
+     * 【管式墒情】比较该设备上报的要素和配置是否达到预警条件
+     *
+     */
+    WarnResult comparableGssqReportData(WarnQxSqInfoDto warnQxSqInfoDto) {
+        return comparableQxzReportData(warnQxSqInfoDto);
 
     }