|
@@ -1,5 +1,6 @@
|
|
|
package com.yunfeiyun.agmp.iotm.device.sf.service.impl;
|
|
package com.yunfeiyun.agmp.iotm.device.sf.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.exceptions.ValidateException;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
|
|
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.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
|
|
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.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
import com.yunfeiyun.agmp.iot.common.util.dev.RunHaoSfElementUtil;
|
|
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.domain.IotSfElementfactorListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
|
|
import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
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(), "设备不存在");
|
|
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<>();
|
|
Set<String> sfCodeSet = new java.util.HashSet<>();
|
|
|
for (IotSfElementfactor elementfactor : elementfactorList) {
|
|
for (IotSfElementfactor elementfactor : elementfactorList) {
|
|
|
- sfCodeSet.add(elementfactor.getSfCode());
|
|
|
|
|
|
|
+ if(StringUtils.isNotEmpty(elementfactor.getSfCode())){
|
|
|
|
|
+ sfCodeSet.add(elementfactor.getSfCode());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
HashMap<String, String> params = new HashMap<>();
|
|
HashMap<String, String> params = new HashMap<>();
|
|
@@ -102,4 +96,166 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
rspData.setTotal(resultList.size());
|
|
rspData.setTotal(resultList.size());
|
|
|
return rspData;
|
|
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;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|