Prechádzať zdrojové kódy

新增 水肥机要素批量配置接口

zhaiyifei 8 mesiacov pred
rodič
commit
6c26b6d22e

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

@@ -9,16 +9,15 @@ import com.yunfeiyun.agmp.common.log.LogCore;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
-import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
-import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfConfigCmdReqVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAddReqVo;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorBatchAddReqVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
 import com.yunfeiyun.agmp.iotm.util.ValidateUtil;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
@@ -197,6 +196,26 @@ public class IotDeviceSfController extends BaseController {
     }
 
     /**
+     * 批量新增要素
+     * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     * @return 返回操作结果的表格数据信息
+     * @throws ValidateException 如果设备标识(devBid)无效,则抛出ValidateException异常
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @PostMapping("/ele/batch/add")
+    public AjaxResult elementBatchAdd(@RequestBody IotSfElementfactorBatchAddReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("elementBatchAdd");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        int status = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        return toAjax(status);
+    }
+
+    /**
      * 获取未配置的电磁阀元素列表
      *
      * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
@@ -277,33 +296,45 @@ public class IotDeviceSfController extends BaseController {
     }
 
     /**
-     * 下发杀虫灯配置指令
+     * 下发水肥机设备设置指令
      *
      * @return
      * @throws Exception
      */
     @PostMapping("/config/edit")
-    public AjaxResult sendConfigCmd(@RequestBody IotSfConfigCmdReqVo reqVo) {
-        log.info("【{}】【水肥机】【发指令配置】客户id {}", LogCore.getSeq(), getCustomerId());
+    public AjaxResult editConfig(@RequestBody IotSfConfigCmdReqVo reqVo) {
+        log.info("【{}】【水肥机】【发水肥机设备设置指令】客户id {}", LogCore.getSeq(), getCustomerId());
         String devBid = reqVo.getDevBid();
         ValidateUtil.validateDevBid(devBid);
-        JSONObject devConfig = reqVo.getData();
-        if(StringUtils.isEmpty(devBid) || devConfig == null){
-            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
-        }
-        IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
-
-        DevOperateUtil.sendConfigCmdCheck(iotDevice);
-
-        reqVo.setIotDevice(iotDevice);
 
         IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
         iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
-        iotDeviceBaseFunReqVo.setMethodName("sendConfigCmd");
+        iotDeviceBaseFunReqVo.setMethodName("editConfig");
         iotDeviceBaseFunReqVo.setParam(reqVo);
         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);
+//    }
 
 }

+ 9 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAddReqVo.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iotm.device.sf.domain;
 import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -53,6 +54,14 @@ public class IotSfElementfactorAddReqVo extends IotBaseEntity {
     /** 修改人 */
     private String sfModifier;
 
+    /** 纬度 */
+    private BigDecimal sfLat;
+    /** 经度 */
+    private BigDecimal sfLng;
+
+    /** 地址 */
+    private String sfAddress;
+
     private List<IotSfElementfactorAddReqVo> childrenList;
 
 }

+ 9 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAlreadyListResVo.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iotm.device.sf.domain;
 import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -53,6 +54,14 @@ public class IotSfElementfactorAlreadyListResVo extends IotBaseEntity {
     /** 修改人 */
     private String sfModifier;
 
+    /** 纬度 */
+    private BigDecimal sfLat;
+    /** 经度 */
+    private BigDecimal sfLng;
+
+    /** 地址 */
+    private String sfAddress;
+
     private List<IotSfElementfactorAlreadyListResVo> childrenList;
 
 }

+ 20 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorBatchAddReqVo.java

@@ -0,0 +1,20 @@
+package com.yunfeiyun.agmp.iotm.device.sf.domain;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 水肥机要素
+ */
+@Data
+public class IotSfElementfactorBatchAddReqVo extends IotBaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /** 设备编号 */
+    private String devBid;
+
+    private List<IotSfElementfactorAddReqVo> elementList;
+
+}

+ 9 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorInfoVo.java

@@ -3,6 +3,7 @@ package com.yunfeiyun.agmp.iotm.device.sf.domain;
 import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -56,6 +57,14 @@ public class IotSfElementfactorInfoVo extends IotBaseEntity {
     /** 值 */
     private String value;
 
+    /** 纬度 */
+    private BigDecimal sfLat;
+    /** 经度 */
+    private BigDecimal sfLng;
+
+    /** 地址 */
+    private String sfAddress;
+
     private List<IotSfElementfactorInfoVo> childrenList;
 
 }

+ 9 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorListReqVo.java

@@ -2,6 +2,7 @@ package com.yunfeiyun.agmp.iotm.device.sf.domain;
 
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -52,6 +53,14 @@ public class IotSfElementfactorListReqVo {
     /** 修改人 */
     private String sfModifier;
 
+    /** 纬度 */
+    private BigDecimal sfLat;
+    /** 经度 */
+    private BigDecimal sfLng;
+
+    /** 地址 */
+    private String sfAddress;
+
     private List<String> sfTypeList;
 
 }

+ 22 - 4
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/IIotSfCommService.java

@@ -20,10 +20,7 @@ import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
 import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
-import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfConfigCmdReqVo;
-import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAddReqVo;
-import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
-import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.*;
 import com.yunfeiyun.agmp.iotm.web.service.IIotCmdtaskService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconfigService;
@@ -148,6 +145,17 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
     }
 
     /**
+     * 批量新增要素
+     * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     */
+    public int elementBatchAdd(IotSfElementfactorBatchAddReqVo reqVo) {
+        // 由具体子类实现
+        return 0;
+    }
+
+    /**
      * 获取未配置的灌区元素列表
      *
      * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
@@ -313,4 +321,14 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return cmdGroupModel.getTaskUuid();
     }
 
+    public String editConfig(IotSfConfigCmdReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+
+    public String devControl(IotSfConfigCmdReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+
 }

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

@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.cmd.CmdDef;
@@ -15,6 +16,7 @@ import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
+import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iot.common.util.dev.RunHaoSfElementUtil;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.*;
 import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
@@ -364,6 +366,18 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         return runStatus;
     }
 
+    private void sendGroupConfig(IotSfElementfactorAddReqVo reqVo, IotDevice iotDevice){
+        String devBid = reqVo.getDevBid();
+
+        IotSfConfigCmdReqVo configCmdReqVo = new IotSfConfigCmdReqVo();
+        configCmdReqVo.setDevBid(devBid);
+        configCmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_GROUP_CONFIG);
+        configCmdReqVo.setIotDevice(iotDevice);
+        configCmdReqVo.setData(JSONObject.from(reqVo));
+
+        sendConfigCmd(configCmdReqVo);
+    }
+
     /**
      * 新增要素
      * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
@@ -438,14 +452,161 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         int status = iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
 
         if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
-            IotSfConfigCmdReqVo configCmdReqVo = new IotSfConfigCmdReqVo();
-            configCmdReqVo.setDevBid(devBid);
-            configCmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_GROUP_CONFIG);
-            configCmdReqVo.setIotDevice(findDevice);
-            configCmdReqVo.setData(JSONObject.from(reqVo));
+            sendGroupConfig(reqVo, findDevice);
+        }
+        return status;
+    }
 
-            sendConfigCmd(configCmdReqVo);
+    private Map<String, List<String>> getGroupValveMap(JSONObject jsonObject){
+        Map<String, List<String>> groupValveMap = new HashMap<>();
+        for(String key:jsonObject.keySet()){
+            if(key.startsWith("Btn-fx")){
+                try{
+                    int groupIndex = (int)Math.floor(Double.parseDouble(jsonObject.getString(key)));
+                    if(groupIndex == 0){
+                        continue;
+                    }
+                    String groupCode = String.format("Btn-qx%02d", groupIndex);
+                    int valveIndex = Integer.parseInt(key.replace("Btn-fx", ""));
+                    String valveCode = String.format("Btn-fa%d", valveIndex);
+                    if(!groupValveMap.containsKey(groupCode)){
+                        groupValveMap.put(groupCode, new ArrayList<>());
+                    }
+                    groupValveMap.get(groupCode).add(valveCode);
+                }catch (Exception e){
+                    continue;
+                }
+            }
+        }
+        return groupValveMap;
+    }
+
+
+    /**
+     * 批量新增要素
+     * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     */
+    public int elementBatchAdd(IotSfElementfactorBatchAddReqVo reqVo) {
+        String devBid = reqVo.getDevBid();
+        if (StringUtils.isEmpty(devBid)) {
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
+        }
+
+        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
+        if (findDevice == null) {
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
+        }
+        List<IotSfElementfactorAddReqVo> elementList = reqVo.getElementList();
+        if(elementList == null || elementList.isEmpty()){
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "元素列表不能为空");
+        }
+
+        IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
+        reqVo1.setDevBid(devBid);
+        List<IotSfElementfactor> dataList = iotSfElementfactorService.selectIotSfElementfactorList(reqVo1);
+        Set<String> sfCodeSet = new HashSet<>();
+        Map<String, IotSfElementfactor> elementMap = new HashMap<>();
+        for (IotSfElementfactor element : dataList) {
+            if(StringUtils.isNotEmpty(element.getSfCode())){
+                sfCodeSet.add(element.getSfCode());
+                elementMap.put(element.getSfBid(), element);
+            }
+        }
+
+        String createDate = DateUtils.dateTimeNow();
+        List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
+        Set<String> sfCodeAlreadySet = new HashSet<>();
+        List<IotSfElementfactorAddReqVo> valveList = new ArrayList<>();
+        IotSfElementfactor parentElement = null;
+
+        Map<String, List<String>> groupValveMap = new HashMap<>();
+        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 ){
+            groupValveMap = getGroupValveMap(iotRunHaoSfdata.getSfdataContent());
+        }
+        Set<String> sfTypeSet = new HashSet<>();
+        for(IotSfElementfactorAddReqVo element : elementList) {
+            String sfType = element.getSfType();
+            String sfCode = element.getSfCode();
+            String sfDisplayname = element.getSfDisplayname();
+            String sfParentBid = element.getSfParentBid();
+            if(sfCodeSet.contains(sfCode) || sfCodeAlreadySet.contains(sfCode)){
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
+            }
+            if (StringUtils.isEmpty(sfType)) {
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
+            }
+            if (StringUtils.isEmpty(sfDisplayname)) {
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "名称不能为空");
+            }
+
+            if(!sfTypeSet.contains(sfType)){
+                sfTypeSet.add(sfType);
+            }
+
+            IotSfElementfactor elementfactor = makeIotSfElementfactor(element, createDate);
+
+            if(Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
+                if(StringUtils.isEmpty(sfParentBid)){
+                    throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区标识不能为空");
+                }
+                parentElement = elementMap.get(sfParentBid);
+                if(parentElement == null || !Objects.equals(parentElement.getSfType(), EnumSfElementType.GROUP.getCode())){
+                    throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区不存在");
+                }
+                valveList.add(element);
+
+            }else if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
+                List<String> valveCodeList = groupValveMap.get(sfCode);
+                if(valveCodeList!= null &&!valveCodeList.isEmpty()){
+                    for(String valveCode : valveCodeList){
+                        IotSfElementfactor valvefactor = RunHaoSfElementUtil.getValveElementFactor(valveCode);
+                        if(valvefactor == null){
+                            continue;
+                        }
+                        valvefactor.setSfParentBid(element.getSfBid());
+                        valvefactor.setTid(element.getTid());
+                        valvefactor.setDevBid(devBid);
+                        valvefactor.setSfCreatedDate(createDate);
+                        valvefactor.setSfCreator(SecurityUtils.getUserId());
+                        valvefactor.setSfModifieddate(createDate);
+                        valvefactor.setSfModifier(SecurityUtils.getUserId());
+
+                        sfElementfactorList.add(valvefactor);
+                    }
+                }
+            }
+
+            sfElementfactorList.add(elementfactor);
+
+            sfCodeAlreadySet.add(sfCode);
+        }
+
+        if(sfTypeSet.size() > 1){
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "批量新增一次只能操作一种类型");
+        }
+
+        if(parentElement != null){
+            iotSfElementfactorService.deleteIotSfElementfactorBySfBid(parentElement.getSfBid());
         }
+        int status = 0;
+        if(!sfElementfactorList.isEmpty()){
+            status = iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
+        }
+        // 下发 灌区和阀的关联配置命令
+        if(parentElement != null){
+            IotSfElementfactorAddReqVo groupReqVo = new IotSfElementfactorAddReqVo();
+            BeanUtils.copyProperties(parentElement, groupReqVo);
+
+            groupReqVo.setChildrenList(valveList);
+
+            sendGroupConfig(groupReqVo, findDevice);
+        }
+
         return status;
     }
 
@@ -499,4 +660,57 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
         return status;
     }
+
+    @Override
+    public String editConfig(IotSfConfigCmdReqVo reqVo) {
+        String devBid = reqVo.getDevBid();
+        JSONObject devConfig = reqVo.getData();
+        if(StringUtils.isEmpty(devBid) || devConfig == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
+        }
+        IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
+
+        reqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
+        reqVo.setIotDevice(iotDevice);
+        return sendConfigCmd(reqVo);
+    }
+
+    @Override
+    public String devControl(IotSfConfigCmdReqVo reqVo) {
+        // 仅支持 泵类 阀 手自动切换 启动 停止灌溉 功能
+        String devBid = reqVo.getDevBid();
+        JSONObject devConfig = reqVo.getData();
+        if(StringUtils.isEmpty(devBid) || devConfig == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
+        }
+        IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+
+        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"};
+
+        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(key.startsWith("Btn-zdsd") && "1".equals(yjqd)){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌溉中,请先停止灌溉");
+            }
+            if(key.startsWith("Btn-yjqd") && "0".equals(zdsd)){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先切换到自动模式");
+            }
+        }
+
+
+        DevOperateUtil.sendConfigCmdCheck(iotDevice);
+        reqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
+        reqVo.setIotDevice(iotDevice);
+        return sendConfigCmd(reqVo);
+    }
 }

+ 6 - 6
src/main/resources/mapper/IotSfElementfactorMapper.xml

@@ -7,7 +7,7 @@
     <select id="selectIotSfElementfactorList" parameterType="com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor" >
         SELECT sf.id, sf.sfBid, sf.devBid, sf.sfType, sf.sfCode, sf.sfName, sf.sfDisplayname, sf.sfParentBid, sf.sfSequence,
-            sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier
+            sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier, sf.sfLng, sf.sfLat, sf.sfAddress
         FROM IotSfElementfactor AS sf
         <where>
             sf.tid = #{tid}
@@ -34,18 +34,18 @@
 
     <select id="selectIotSfElementfactorBySfBid" resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor" parameterType="string">
         SELECT sf.id, sf.sfBid, sf.devBid, sf.sfType, sf.sfCode, sf.sfName, sf.sfDisplayname, sf.sfParentBid, sf.sfSequence,
-        sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier
+        sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier, sf.sfLng, sf.sfLat, sf.sfAddress
         FROM IotSfElementfactor AS sf
         where sf.sfBid = #{sfBid}
     </select>
 
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
-        INSERT INTO IotSfElementfactor (id, sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
-            tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier)
+        INSERT INTO IotSfElementfactor (sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
+            tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier, sfLng, sfLat, sfAddress)
         VALUES
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.id}, #{item.sfBid}, #{item.devBid}, #{item.sfType}, #{item.sfCode}, #{item.sfName}, #{item.sfDisplayname}, #{item.sfParentBid}, #{item.sfSequence},
-            #{item.tid}, #{item.sfCreatedDate}, #{item.sfCreator}, #{item.sfModifieddate}, #{item.sfModifier})
+            (#{item.sfBid}, #{item.devBid}, #{item.sfType}, #{item.sfCode}, #{item.sfName}, #{item.sfDisplayname}, #{item.sfParentBid}, #{item.sfSequence},
+            #{item.tid}, #{item.sfCreatedDate}, #{item.sfCreator}, #{item.sfModifieddate}, #{item.sfModifier}, #{item.sfLng}, #{item.sfLat}, #{item.sfAddress})
         </foreach>
     </insert>