|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|