Explorar el Código

新增 水肥机开始自动灌溉接口

zhaiyifei hace 8 meses
padre
commit
9a58493310

+ 21 - 21
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/controller/IotDeviceSfController.java

@@ -384,26 +384,26 @@ public class IotDeviceSfController extends BaseController {
         String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
         return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
     }
-//
-//    /**
-//     * 下发水肥机指令
-//     *
-//     * @return
-//     * @throws Exception
-//     */
-//    @PostMapping("/devctl")
-//    public AjaxResult sendCmd(@RequestBody IotSfConfigCmdReqVo reqVo) {
-//        log.info("【{}】【水肥机】【下发水肥机设备控制指令】客户id {}", LogCore.getSeq(), getCustomerId());
-//        String devBid = reqVo.getDevBid();
-//        ValidateUtil.validateDevBid(devBid);
-//
-//        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
-//        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
-//        iotDeviceBaseFunReqVo.setMethodName("devControl");
-//        iotDeviceBaseFunReqVo.setParam(reqVo);
-//        String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
-//
-//        return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
-//    }
+
+    /**
+     * 下发水肥机指令
+     *
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/devctl")
+    public AjaxResult devControl(@RequestBody IotSfConfigCmdReqVo reqVo) {
+        log.info("【{}】【水肥机】【下发水肥机设备控制指令】客户id {}", LogCore.getSeq(), getCustomerId());
+        String devBid = reqVo.getDevBid();
+        ValidateUtil.validateDevBid(devBid);
+
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("devControl");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+
+        return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
+    }
 
 }

+ 131 - 30
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/impl/IotRunHaoSfServiceImpl.java

@@ -677,36 +677,124 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
     @Override
     public String devControl(IotSfConfigCmdReqVo reqVo) {
-        // 仅支持 泵类 阀 手自动切换 启动 停止灌溉 功能
+        // 仅支持 泵类 阀 手自动切换 停止灌溉 功能
         String devBid = reqVo.getDevBid();
         JSONObject devConfig = reqVo.getData();
-        if(StringUtils.isEmpty(devBid) || devConfig == null){
+        if(StringUtils.isEmpty(devBid) || devConfig == null || devConfig.isEmpty()){
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
         }
+        if(devConfig.size() != 1){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请勿同时操作多个功能");
+        }
         IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+        if(iotDevice == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"设备不存在");
+        }
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
+
+        String runMode = "Btn-zdsd";
+        String runStatus = "Btn-yjqd";
 
         JSONObject runStatusData = getRunStatus(devBid);
-        String zdsd = runStatusData.getString("Btn-zdsd");
-        String yjqd = runStatusData.getString("Btn-yjqd");
-        String[] pumpValveKeys = new String[]{"Btn-ggbs", "Btn-sfbs", "Btn-fs", "Btn-js", "Btn-fa"};
+        String zdsd = runStatusData.getString(runMode);
+        String yjqd = runStatusData.getString(runStatus);
 
-        for(String key : devConfig.keySet()){
-            String value = devConfig.getString(key);
-            for(String pumpValveKey : pumpValveKeys){
-                if(key.startsWith(pumpValveKey) && "1".equals(zdsd)){
-                    throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先切换到手动模式");
-                }
+        if(zdsd == null || yjqd == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"设备状态异常");
+        }
+
+        Set<EnumSfElementType> typeSet = new HashSet<>();
+        typeSet.add(EnumSfElementType.WATER_SOURCE);
+        typeSet.add(EnumSfElementType.FERTILIZER);
+        typeSet.add(EnumSfElementType.SUCTION);
+        typeSet.add(EnumSfElementType.MIXING);
+        typeSet.add(EnumSfElementType.SOLENOID_VALVE);
+
+        TableDataInfo tableDataInfo = getStatus(devBid);
+        List<IotSfElementfactorInfoVo> resultList = (List<IotSfElementfactorInfoVo>) tableDataInfo.getData();
+        if(resultList == null || resultList.isEmpty()){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"未配置要素");
+        }
+
+        Map<String, EnumSfElementType> sfTypeMap = new HashMap<>();
+        sfTypeMap.put(runMode, null);
+        sfTypeMap.put(runStatus, null);
+
+        Map<EnumSfElementType, Integer> sfTypeValueMap = new HashMap<>();
+        for(IotSfElementfactorInfoVo element : resultList){
+            EnumSfElementType elementType = EnumSfElementType.findEnumByCode(element.getSfType());
+            if(elementType == null){
+                continue;
             }
-            if(key.startsWith("Btn-zdsd") && "1".equals(yjqd)){
-                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌溉中,请先停止灌溉");
+            if(elementType == EnumSfElementType.GROUP || elementType == EnumSfElementType.FERTILIZER_BUCKET){
+                List<IotSfElementfactorInfoVo> childrenList = element.getChildrenList();
+                if(childrenList == null || childrenList.isEmpty()){
+                    continue;
+                }
+
+                for(IotSfElementfactorInfoVo child : childrenList){
+                    EnumSfElementType childType = EnumSfElementType.findEnumByCode(child.getSfType());
+                    if(childType == null || !typeSet.contains(childType)){
+                        continue;
+                    }
+                    sfTypeValueMap.put(childType, Math.max(sfTypeValueMap.getOrDefault(childType, 0), Integer.parseInt(child.getValue())));
+                    sfTypeMap.put(child.getSfCode(), childType);
+                }
             }
-            if(key.startsWith("Btn-yjqd") && "0".equals(zdsd)){
-                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先切换到自动模式");
+            if(typeSet.contains(elementType)){
+                sfTypeValueMap.put(elementType, Math.max(sfTypeValueMap.getOrDefault(elementType, 0), Integer.parseInt(element.getValue())));
+                sfTypeMap.put(element.getSfCode(), elementType);
             }
         }
 
+        for(String key : devConfig.keySet()){
+            if(!sfTypeMap.containsKey(key)){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"不支持此操作");
+            }
+            if(Objects.equals(key, runMode)){
+                continue;
+            }
+            String v = devConfig.getString(key);
+            // 停止灌溉操作
+            if(Objects.equals(key, runStatus)){
+                if(!"1".equals(zdsd)){
+                    throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先切换到自动模式");
+                }
+                if(!"0".equals(v)){
+                    throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"仅支持停止灌溉");
+                }
+            }else{
+                if("1".equals(zdsd)){
+                    throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先切换到手动模式");
+                }
+                EnumSfElementType elementType = sfTypeMap.get(key);
+                if(elementType == EnumSfElementType.WATER_SOURCE && Objects.equals(v, "1")){
+                    // 请先打开阀
+                    Integer va = sfTypeValueMap.get(EnumSfElementType.SOLENOID_VALVE);
+                    if(va != 1){
+                        throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开阀门");
+                    }
+                }else if(elementType == EnumSfElementType.FERTILIZER){
+                    Integer va = sfTypeValueMap.get(EnumSfElementType.SUCTION);
+                    if(Objects.equals(v, "1")){
+                        if(va != 1){
+                            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先打开肥阀");
+                        }
+                    }else {
+                        if(va != 0){
+                            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先关闭肥阀");
+                        }
+                    }
+                }else if(elementType == EnumSfElementType.SOLENOID_VALVE && Objects.equals(v, "0")){
+                    Integer va = sfTypeValueMap.get(EnumSfElementType.WATER_SOURCE);
+                    if(va != 0){
+                        throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先关闭水源泵");
+                    }
+                }
+            }
+        }
 
-        DevOperateUtil.sendConfigCmdCheck(iotDevice);
         reqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
         reqVo.setIotDevice(iotDevice);
         return sendConfigCmd(reqVo);
@@ -782,25 +870,38 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数不能为空");
         }
 
-        Map<String, String> groupParamMap = new HashMap<>();
-        groupParamMap.put("Num-ggsj", "Btn-ggxr");
-        groupParamMap.put("Num-fqsj", "Btn-fqxr");
-        groupParamMap.put("Btn-fxz", "Btn-fxr");
-        groupParamMap.put("Num-fsj", "Btn-fsxr");
+        Map<String, String> groupParamMap = new LinkedHashMap<>();
+        groupParamMap.put("Btn-dsdl", "施肥模式");
+        groupParamMap.put("Num-ggsj", "灌溉时间");
+        groupParamMap.put("Num-fqsj", "肥前水时间");
+
+        IotSfElementfactorListReqVo selectReqVo = new IotSfElementfactorListReqVo();
+        selectReqVo.setDevBid(devBid);
+        selectReqVo.setSfType(EnumSfElementType.SUCTION.getCode());
+        List<IotSfElementfactor> sfElementfactorList = iotSfElementfactorService.selectIotSfElementfactorList(selectReqVo);
+
+        if(sfElementfactorList != null && !sfElementfactorList.isEmpty()){
+            for(IotSfElementfactor vo : sfElementfactorList){
+                String sfCode = vo.getSfCode();
+                String sfDisplayname = vo.getSfDisplayname();
+                String key = sfCode.replace("Btn-fs", "");
+                groupParamMap.put("Btn-fxz" + key, sfDisplayname + "开关");
+                groupParamMap.put("Num-fsj" + key, sfDisplayname);
+            }
+        }
 
         JSONObject sendJson = new JSONObject();
         for(String key : groupParamJson.keySet()) {
-            for(String groupKey : groupParamMap.keySet()){
-                if(key.startsWith(groupKey)){
-                    String sendKey = groupParamMap.get(groupKey) + key.replace(groupKey, "");
-                    sendJson.put(key, groupParamJson.getString(key));
-                    sendJson.put(sendKey, "1");
-                }
+            if(!groupParamMap.containsKey(key)){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数错误");
             }
+            if(StringUtils.isEmpty(groupParamJson.getString(key))){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数不能为空");
+            }
+            String value = groupParamJson.getString(key);
+            sendJson.put(key, value);
         }
-        if(!sendJson.isEmpty()){
-            sendJson.put("Btn-csbc", "1");
-        }
+        sendJson.put("Btn-csbc", "1");
 
         IotSfConfigCmdReqVo cmdReqVo = new IotSfConfigCmdReqVo();
         cmdReqVo.setDevBid(devBid);