Procházet zdrojové kódy

新增 同步灌区配置,以设备为准,解决平台与设备双边不一致的问题

zhaiyifei před 10 měsíci
rodič
revize
85a6c8e4b8

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

@@ -10,6 +10,7 @@ import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 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.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iot.common.util.dev.DevOperateUtil;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
@@ -146,7 +147,16 @@ public class IotDeviceSfController extends BaseController {
         if(StringUtils.isEmpty(sfBid)){
         if(StringUtils.isEmpty(sfBid)){
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素标识不能为空");
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素标识不能为空");
         }
         }
-        int status = iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
+        IotSfElementfactor iotSfElementfactor = iotSfElementfactorService.selectIotSfElementfactorBySfBid(sfBid);
+        if(iotSfElementfactor == null){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素不存在");
+        }
+
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(iotSfElementfactor.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("elementDelete");
+        iotDeviceBaseFunReqVo.setParam(iotSfElementfactor);
+        int status = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
         return toAjax(status);
         return toAjax(status);
     }
     }
 
 

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

@@ -124,6 +124,18 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return elementfactor;
         return elementfactor;
     }
     }
 
 
+
+    /**
+     * 删除元素
+     *
+     * @param reqVo 请求对象,包含了要删除的元素信息
+     * @return 返回删除结果,返回值为0表示删除成功,非0表示删除失败
+     */
+    public int elementDelete(IotSfElementfactor reqVo) {
+        // 由具体子类实现
+        return 0;
+    }
+
     /**
     /**
      * 新增要素
      * 新增要素
      * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
      * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。

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

@@ -110,32 +110,6 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
     }
     }
 
 
     /**
     /**
-     * 获取灌区和电磁阀的绑定关系数据
-     */
-    private Map<String, List<String>> getGroupValveMap(JSONObject dataJson){
-        Map<String, List<String>> groupValveMap = new HashMap<>();
-        for (String key : dataJson.keySet()) {
-            if(!key.startsWith("Btn-fx")){
-                continue;
-            }
-            String groupIndexString = dataJson.getString(key);
-            int groupIndex = 0;
-            try{
-                groupIndex = (int) Math.round(Double.parseDouble(groupIndexString));
-                String groupKey = "Btn-qx" + String.format("%02d", groupIndex);
-                if(!groupValveMap.containsKey(groupKey)){
-                    List<String> valveList = new ArrayList<>();
-                    groupValveMap.put(groupKey, valveList);
-                }
-                String suffix = key.split("Btn-fx")[1];
-                String valveKey = "Btn-fa" + Integer.valueOf(suffix);
-                groupValveMap.get(groupKey).add(valveKey);
-            }catch (Exception e){}
-        }
-        return groupValveMap;
-    }
-
-    /**
      * 获取未配置的灌区元素列表
      * 获取未配置的灌区元素列表
      *
      *
      * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
      * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
@@ -474,4 +448,55 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         }
         }
         return status;
         return status;
     }
     }
+
+
+    /**
+     * 删除元素
+     *
+     * @param reqVo 请求对象,包含了要删除的元素信息
+     * @return 返回删除结果,返回值为0表示删除成功,非0表示删除失败
+     */
+    @Override
+    public int elementDelete(IotSfElementfactor reqVo) {
+        String sfBid = reqVo.getSfBid();
+        String sfType = reqVo.getSfType();
+        String devBid = reqVo.getDevBid();
+        String sfCode = reqVo.getSfCode();
+        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+
+        int status = iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
+        Map<String, String> payload = new HashMap<>();
+        if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
+            IotSfElementfactorListReqVo selectReqVo = new IotSfElementfactorListReqVo();
+            selectReqVo.setDevBid(devBid);
+            List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getGroupAlreadyElementList(selectReqVo);
+            IotSfElementfactorAlreadyListResVo alreadyResVo = resVoList.get(0);
+            List<IotSfElementfactorAlreadyListResVo> childrenList = alreadyResVo.getChildrenList();
+
+            if(childrenList != null && !childrenList.isEmpty()){
+                for(IotSfElementfactorAlreadyListResVo child : childrenList){
+                    String childSfCode = child.getSfCode();
+                    int valveIndex = Integer.parseInt(childSfCode.replace("Btn-fa", ""));
+                    String key = "Btn-fx" + String.format("%02d", valveIndex);
+                    payload.put(key, "0");
+                }
+            }
+
+        }else if(Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
+            int valveIndex = Integer.parseInt(sfCode.replace("Btn-fa", ""));
+            String key = "Btn-fx" + String.format("%02d", valveIndex);
+            payload.put(key, "0");
+        }
+        if(!payload.isEmpty()){
+            IotSfConfigCmdReqVo configCmdReqVo = new IotSfConfigCmdReqVo();
+            configCmdReqVo.setDevBid(devBid);
+            configCmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
+            configCmdReqVo.setIotDevice(findDevice);
+            configCmdReqVo.setData(JSONObject.from(payload));
+
+            sendConfigCmd(configCmdReqVo);
+        }
+
+        return status;
+    }
 }
 }

+ 8 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotSfElementfactorMapper.java

@@ -36,4 +36,12 @@ public interface IotSfElementfactorMapper {
      */
      */
     public int deleteIotSfElementfactorBySfBid(String sfBid);
     public int deleteIotSfElementfactorBySfBid(String sfBid);
 
 
+    /**
+     * 查询水肥机要素
+     *
+     * @param iotSfElementfactor 水肥机要素
+     * @return 水肥机要素集合
+     */
+    public IotSfElementfactor selectIotSfElementfactorBySfBid(String sfBid);
+
 }
 }

+ 9 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotSfElementfactorService.java

@@ -10,6 +10,15 @@ import java.util.List;
  * 水肥机要素Service
  * 水肥机要素Service
  */
  */
 public interface IIotSfElementfactorService {
 public interface IIotSfElementfactorService {
+
+    /**
+     * 查询水肥机要素
+     *
+     * @param iotSfElementfactor 水肥机要素
+     * @return 水肥机要素集合
+     */
+    public IotSfElementfactor selectIotSfElementfactorBySfBid(String sfBid);
+
     /**
     /**
      * 查询水肥机要素列表
      * 查询水肥机要素列表
      *
      *

+ 11 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotSfElementfactorServiceImpl.java

@@ -23,6 +23,17 @@ import java.util.Map;
 public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService {
 public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService {
     @Autowired
     @Autowired
     private IotSfElementfactorMapper iotSfElementfactorMapper;
     private IotSfElementfactorMapper iotSfElementfactorMapper;
+
+    /**
+     * 查询水肥机要素
+     *
+     * @param reqVo@return 水肥机要素集合
+     */
+    @Override
+    public IotSfElementfactor selectIotSfElementfactorBySfBid(String sfBid) {
+        return iotSfElementfactorMapper.selectIotSfElementfactorBySfBid(sfBid);
+    }
+
     /**
     /**
      * 查询水肥机要素列表
      * 查询水肥机要素列表
      *
      *

+ 7 - 0
src/main/resources/mapper/IotSfElementfactorMapper.xml

@@ -32,6 +32,13 @@
         </where>
         </where>
     </select>
     </select>
 
 
+    <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
+        FROM IotSfElementfactor AS sf
+        where sf.sfBid = #{sfBid}
+    </select>
+
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
         INSERT INTO IotSfElementfactor (id, sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
         INSERT INTO IotSfElementfactor (id, sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
             tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier)
             tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier)