Browse Source

新增 获取阀门未配置的水肥要素接口

zhaiyifei 8 tháng trước cách đây
mục cha
commit
9b0bca4818

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

@@ -142,4 +142,38 @@ public class IotDeviceSfController extends BaseController {
         int status = iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
         return toAjax(status);
     }
+
+    /**
+     * 获取未配置的灌区元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+    @GetMapping("/group/unalready/list")
+    public TableDataInfo getGroupUnAlreadyElementList(IotSfElementfactorListReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("getGroupUnAlreadyElementList");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+    }
+
+    /**
+     * 获取未配置的电磁阀元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+    @GetMapping("/valve/unalready/list")
+    public TableDataInfo getValveUnAlreadyElementList(IotSfElementfactorListReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("getValveUnAlreadyElementList");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+    }
 }

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

@@ -1,5 +1,6 @@
 package com.yunfeiyun.agmp.iotm.device.sf.service;
 
+import cn.hutool.core.exceptions.ValidateException;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
@@ -173,4 +174,37 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
     }
 
+    /**
+     * 获取未配置的灌区元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+
+    public TableDataInfo getGroupUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+
+    /**
+     * 获取未配置的电磁阀元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+
+    /**
+     * 获取未配置的电磁阀元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+    public TableDataInfo getValveUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+
 }

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

@@ -1,5 +1,6 @@
 package com.yunfeiyun.agmp.iotm.device.sf.service.impl;
 
+import cn.hutool.core.exceptions.ValidateException;
 import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
@@ -9,22 +10,20 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
 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.RunHaoSfElementUtil;
+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.service.IIotSfCommService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 /**
  * 润浩水肥机
@@ -67,17 +66,12 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
         }
 
-        List<String> sfTypeList = new ArrayList<>();
-        sfTypeList.add(EnumSfElementType.WATER_SOURCE.getCode());
-        sfTypeList.add(EnumSfElementType.FERTILIZER.getCode());
-        sfTypeList.add(EnumSfElementType.SUCTION.getCode());
-        sfTypeList.add(EnumSfElementType.MIXING.getCode());
-        reqVo.setSfTypeList(sfTypeList);
-
-        List<IotSfElementfactor> elementfactorList = iotSfElementfactorService.selectIotSfElementfactorList(reqVo);
+        List<IotSfElementfactor> elementfactorList = iotSfElementfactorService.selectIotSfElementfactorListByPump(reqVo);
         Set<String> sfCodeSet = new java.util.HashSet<>();
         for (IotSfElementfactor elementfactor : elementfactorList) {
-            sfCodeSet.add(elementfactor.getSfCode());
+            if(StringUtils.isNotEmpty(elementfactor.getSfCode())){
+                sfCodeSet.add(elementfactor.getSfCode());
+            }
         }
 
         HashMap<String, String> params = new HashMap<>();
@@ -102,4 +96,166 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         rspData.setTotal(resultList.size());
         return rspData;
     }
+
+    /**
+     * 获取灌区和电磁阀的绑定关系数据
+     */
+    private Map<String, List<String>> getGroupValveMap(){
+        Map<String, List<String>> groupValveMap = new HashMap<>();
+
+        List<String> valveList = new ArrayList<>();
+        valveList.add("Btn-fa1");
+        valveList.add("Btn-fa2");
+
+        List<String> valveList2 = new ArrayList<>();
+        valveList2.add("Btn-fa3");
+
+        groupValveMap.put("Btn-qx01", valveList);
+        groupValveMap.put("Btn-qx02", valveList2);
+
+        return groupValveMap;
+
+    }
+
+
+    /**
+     * 获取未配置的灌区元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+
+    @Override
+    public TableDataInfo getGroupUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(ErrorCode.SUCCESS.getCode());
+        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
+        rspData.setData(new ArrayList<>());
+        rspData.setTotal(0);
+
+        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<IotSfElementfactor> elementfactorList = iotSfElementfactorService.selectIotSfElementfactorListByGroup(reqVo);
+        Set<String> sfCodeSet = new java.util.HashSet<>();
+        for (IotSfElementfactor elementfactor : elementfactorList) {
+            if(StringUtils.isNotEmpty(elementfactor.getSfCode())){
+                sfCodeSet.add(elementfactor.getSfCode());
+            }
+        }
+
+        HashMap<String, String> params = new HashMap<>();
+        params.put("devBid", devBid);
+
+        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
+        Map<String, List<String>> groupValveMap = getGroupValveMap();
+        List<IotSfElementfactorAlreadyListResVo> resultList = new ArrayList<>();
+        if (iotRunHaoSfdata != null) {
+            JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
+            for (String key : dataJson.keySet()) {
+                if(sfCodeSet.contains(key)){
+                    continue;
+                }
+                IotSfElementfactor elementFactor = RunHaoSfElementUtil.getGroupElementFactor(key);
+                if(elementFactor == null){
+                    continue;
+                }
+                IotSfElementfactorAlreadyListResVo resVo = new IotSfElementfactorAlreadyListResVo();
+                BeanUtils.copyProperties(elementFactor, resVo);
+
+                List<String> valveList = groupValveMap.get(key);
+                if(valveList != null && !valveList.isEmpty()){
+                    List<IotSfElementfactorAlreadyListResVo> childrenList = new ArrayList<>();
+                    for(String valve : valveList){
+                        IotSfElementfactor valveFactor = RunHaoSfElementUtil.getValveElementFactor(valve);
+                        if(valveFactor == null){
+                            continue;
+                        }
+                        IotSfElementfactorAlreadyListResVo valveVo = new IotSfElementfactorAlreadyListResVo();
+                        BeanUtils.copyProperties(valveFactor, valveVo);
+                        childrenList.add(valveVo);
+                    }
+                    if(!childrenList.isEmpty()){
+                        resVo.setChildrenList(childrenList);
+                    }
+                }
+                resultList.add(resVo);
+            }
+        }
+        rspData.setData(resultList);
+        rspData.setTotal(resultList.size());
+        return rspData;
+    }
+
+    /**
+     * 获取未配置的电磁阀元素列表
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等筛选条件
+     * @return 返回TableDataInfo对象,包含未分组的元素列表及相关信息
+     * @throws ValidateException 如果devBid为空或不符合要求,则抛出ValidateException异常
+     */
+
+    @Override
+    public TableDataInfo getValveUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(ErrorCode.SUCCESS.getCode());
+        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
+        rspData.setData(new ArrayList<>());
+        rspData.setTotal(0);
+
+        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<IotSfElementfactor> elementfactorList = iotSfElementfactorService.selectIotSfElementfactorListByValve(reqVo);
+        Set<String> sfCodeSet = new java.util.HashSet<>();
+        for (IotSfElementfactor elementfactor : elementfactorList) {
+            if(StringUtils.isNotEmpty(elementfactor.getSfCode())){
+                sfCodeSet.add(elementfactor.getSfCode());
+            }
+        }
+
+        HashMap<String, String> params = new HashMap<>();
+        params.put("devBid", devBid);
+
+        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
+        Map<String, List<String>> groupValveMap = getGroupValveMap();
+        Set<String> valveSet = new HashSet<>();
+        for (List<String> valveList : groupValveMap.values()) {
+            valveSet.addAll(valveList);
+        }
+        List<IotSfElementfactor> resultList = new ArrayList<>();
+        if (iotRunHaoSfdata != null) {
+            JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
+            for (String key : dataJson.keySet()) {
+                if(sfCodeSet.contains(key) || valveSet.contains(key)){
+                    continue;
+                }
+                IotSfElementfactor elementFactor = RunHaoSfElementUtil.getValveElementFactor(key);
+                if(elementFactor == null){
+                    continue;
+                }
+                resultList.add(elementFactor);
+            }
+        }
+        rspData.setData(resultList);
+        rspData.setTotal(resultList.size());
+        return rspData;
+    }
 }

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

@@ -27,6 +27,24 @@ public interface IIotSfElementfactorService {
     public List<IotSfElementfactor> selectIotSfElementfactorListByPump(IotSfElementfactorListReqVo reqVo);
 
     /**
+     * 查询灌区已配置原始要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactor> selectIotSfElementfactorListByGroup(IotSfElementfactorListReqVo reqVo);
+
+    /**
+     * 查询电磁阀已配置原始要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactor> selectIotSfElementfactorListByValve(IotSfElementfactorListReqVo reqVo);
+
+
+
+    /**
      * 批量插入水肥机要素
      *
      * @param factorList 水肥机要素列表

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

@@ -131,6 +131,34 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
     }
 
     /**
+     * 查询灌区已配置原始要素列表
+     *
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotSfElementfactor> selectIotSfElementfactorListByGroup(IotSfElementfactorListReqVo reqVo) {
+        List<String> sfTypeList = new ArrayList<>();
+        sfTypeList.add(EnumSfElementType.GROUP.getCode());
+        reqVo.setSfTypeList(sfTypeList);
+        return selectIotSfElementfactorList(reqVo);
+    }
+
+    /**
+     * 查询电磁阀已配置原始要素列表
+     *
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotSfElementfactor> selectIotSfElementfactorListByValve(IotSfElementfactorListReqVo reqVo) {
+        List<String> sfTypeList = new ArrayList<>();
+        sfTypeList.add(EnumSfElementType.SOLENOID_VALVE.getCode());
+        reqVo.setSfTypeList(sfTypeList);
+        return selectIotSfElementfactorList(reqVo);
+    }
+
+    /**
      * 查询泵类已配置要素列表
      *
      * @param reqVo