Jelajahi Sumber

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

zhaiyifei 8 bulan lalu
induk
melakukan
0ec70601c8

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

@@ -367,6 +367,23 @@ public class IotDeviceSfController extends BaseController {
 
         return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
     }
+
+    /**
+     * 开始自动灌溉
+     * @param
+     * @return
+     */
+    @PostMapping("/auto/start")
+    public AjaxResult autoStart(@RequestBody IotSfConfigCmdReqVo reqVo){
+        String devBid = reqVo.getDevBid();
+        ValidateUtil.validateDevBid(devBid);
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(devBid);
+        iotDeviceBaseFunReqVo.setMethodName("autoStart");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        String taskId = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        return new AjaxResult(ErrorCode.SUCCESS.getCode(), "下发成功,等待设备响应结果", taskId);
+    }
 //
 //    /**
 //     * 下发水肥机指令

+ 11 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/IIotSfCommService.java

@@ -401,4 +401,15 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return null;
     }
 
+    /**
+     * 开始自动灌溉
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     * @param reqVo
+     */
+    public String autoStart(IotSfConfigCmdReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+
 }

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

@@ -804,4 +804,98 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         cmdReqVo.setData(sendJson);
         return sendConfigCmd(cmdReqVo);
     }
+
+
+    /**
+     * 开始自动灌溉
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     * @param reqVo
+     */
+    public String autoStart(IotSfConfigCmdReqVo reqVo) {
+        String devBid = reqVo.getDevBid();
+        JSONObject data = reqVo.getData();
+
+        if(data == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "参数不能为空");
+        }
+
+        IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+        if(iotDevice == null){
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
+        }
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
+
+        JSONObject runStatusData = getRunStatus(devBid);
+        String yjqd = runStatusData.getString("Btn-yjqd");
+        if("1".equals(yjqd)) {
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌溉中,请先停止灌溉");
+        }
+        if("0".equals(runStatusData.getString("Btn-zdsd"))){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先切换到自动模式");
+        }
+
+        String dsdl = runStatusData.getString("Btn-dsdl");
+        String lgcs = runStatusData.getString("Num-lgcs");
+        String lgjg = runStatusData.getString("Num-lgjg");
+
+        if(StringUtils.isEmpty(dsdl)){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先设置施肥模式");
+        }
+        if(StringUtils.isEmpty(lgjg)){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先设置轮灌间隔");
+        }
+        if(StringUtils.isEmpty(lgcs)){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先设置轮灌次数");
+        }
+        IotSfElementfactorListReqVo selectGroupReqVo = new IotSfElementfactorListReqVo();
+        selectGroupReqVo.setDevBid(devBid);
+        List<IotSfElementfactorAlreadyListResVo> elementfactorList = iotSfElementfactorService.getGroupAlreadyElementList(selectGroupReqVo);
+        if(elementfactorList == null || elementfactorList.isEmpty()){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "未配置灌溉设备");
+        }
+
+        JSONObject sendJson = new JSONObject();
+        for(IotSfElementfactorAlreadyListResVo elementfactor : elementfactorList){
+            if(elementfactor.getChildrenList() == null || elementfactor.getChildrenList().isEmpty()){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌区未配置阀,无法开始灌溉");
+            }
+            String sfCode = elementfactor.getSfCode();
+            if(data.containsKey(sfCode)){
+                sendJson.put(sfCode, data.getString(sfCode));
+            }
+        }
+        if(sendJson.isEmpty()){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先选择灌区");
+        }
+        String[] keys = new String[]{"Btn-dsdl", "Num-lgcs", "Num-lgjg"};
+        for(String key : keys){
+            sendJson.put(key, data.getString(key));
+        }
+        sendJson.put("Btn-yjqd", "1");
+
+        Map<String, String> params = new HashMap<>();
+        params.put("devBid", devBid);
+        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
+        if(iotRunHaoSfdata == null || iotRunHaoSfdata.getSfdataContent() == null){
+            throw new IotBizException(IotErrorCode.DB_NOT_FOUND.getCode(), "未连接设备");
+        }
+
+        JSONObject sfdataContent = iotRunHaoSfdata.getSfdataContent();
+        for(String sfCode: sfdataContent.keySet()){
+            if(sfCode.startsWith("Btn-qx")){
+                if(!sendJson.containsKey(sfCode)){
+                    sendJson.put(sfCode, "0");
+                }
+            }
+        }
+
+        IotSfConfigCmdReqVo cmdReqVo = new IotSfConfigCmdReqVo();
+        cmdReqVo.setDevBid(devBid);
+        cmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
+        cmdReqVo.setIotDevice(iotDevice);
+        cmdReqVo.setData(sendJson);
+        return sendConfigCmd(cmdReqVo);
+    }
 }