|
|
@@ -364,10 +364,11 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
params.put("devBid", devBid);
|
|
|
|
|
|
IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
|
|
|
- JSONObject dataJson = new JSONObject();
|
|
|
- if (iotRunHaoSfdata != null) {
|
|
|
- dataJson = iotRunHaoSfdata.getSfdataContent();
|
|
|
+ if(iotRunHaoSfdata == null){
|
|
|
+ return new JSONObject();
|
|
|
}
|
|
|
+ JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
|
|
|
+
|
|
|
String[] keys = new String[]{"Num-dqqf", "Num-ggsj", "Num-fqs", "Num-lgjg", "Num-lgcs", "Btn-yjqd", "Btn-zdsd"};
|
|
|
String[] feiKeys = new String[]{"Num-fsjA", "Num-fsjB", "Num-fsjC", "Num-fsjD"};
|
|
|
JSONObject runStatus = new JSONObject();
|
|
|
@@ -439,16 +440,16 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
// 肥料桶是虚拟的,不需要检测code重复问题
|
|
|
if(!Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
|
|
|
if (StringUtils.isEmpty(sfCode)) {
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码不能为空");
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "编码不能为空");
|
|
|
}
|
|
|
}
|
|
|
String sfDisplayname = reqVo.getSfDisplayname();
|
|
|
if (StringUtils.isEmpty(sfType)) {
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素类型不能为空");
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(sfDisplayname)) {
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素名称不能为空");
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "名称不能为空");
|
|
|
}
|
|
|
List<IotSfElementfactorAddReqVo> childrenList = reqVo.getChildrenList();
|
|
|
if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
|
|
|
@@ -485,7 +486,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
|
|
|
for(IotSfElementfactor element : sfElementfactorList){
|
|
|
if(sfCodeSet.contains(element.getSfCode())){
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码重复");
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "编码重复");
|
|
|
}
|
|
|
}
|
|
|
int status = iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
|
|
|
@@ -539,7 +540,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}
|
|
|
List<IotSfElementfactorAddReqVo> elementList = reqVo.getElementList();
|
|
|
if(elementList == null || elementList.isEmpty()){
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "元素列表不能为空");
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "列表不能为空");
|
|
|
}
|
|
|
|
|
|
IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
|
|
|
@@ -555,25 +556,18 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}
|
|
|
|
|
|
String createDate = DateUtils.dateTimeNow();
|
|
|
+ Set<String> sfTypeSet = new HashSet<>();
|
|
|
+
|
|
|
List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
|
|
|
- Set<String> sfCodeAlreadySet = new HashSet<>();
|
|
|
- List<IotSfElementfactorAddReqVo> valveList = new ArrayList<>();
|
|
|
+ String sfType = null;
|
|
|
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();
|
|
|
+ for(IotSfElementfactorAddReqVo element : elementList){
|
|
|
String sfCode = element.getSfCode();
|
|
|
+ sfType = element.getSfType();
|
|
|
String sfDisplayname = element.getSfDisplayname();
|
|
|
String sfParentBid = element.getSfParentBid();
|
|
|
- if(sfCodeSet.contains(sfCode) || sfCodeAlreadySet.contains(sfCode)){
|
|
|
+
|
|
|
+ if(sfCodeSet.contains(sfCode)){
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(sfType)) {
|
|
|
@@ -582,9 +576,6 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
if (StringUtils.isEmpty(sfDisplayname)) {
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "名称不能为空");
|
|
|
}
|
|
|
-
|
|
|
- sfTypeSet.add(sfType);
|
|
|
-
|
|
|
IotSfElementfactor elementfactor = makeIotSfElementfactor(element, createDate);
|
|
|
|
|
|
if(Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
|
|
|
@@ -592,62 +583,84 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区标识不能为空");
|
|
|
}
|
|
|
parentElement = elementMap.get(sfParentBid);
|
|
|
- if(parentElement == null || !Objects.equals(parentElement.getSfType(), EnumSfElementType.GROUP.getCode())){
|
|
|
+ if(parentElement == null){
|
|
|
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);
|
|
|
- }
|
|
|
- }
|
|
|
+ elementfactor.setSfParentBid(sfParentBid);
|
|
|
}
|
|
|
-
|
|
|
sfElementfactorList.add(elementfactor);
|
|
|
-
|
|
|
- sfCodeAlreadySet.add(sfCode);
|
|
|
+ sfTypeSet.add(sfType);
|
|
|
}
|
|
|
|
|
|
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){
|
|
|
+ if(parentElement != null && Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
|
|
|
IotSfElementfactorAddReqVo groupReqVo = new IotSfElementfactorAddReqVo();
|
|
|
BeanUtils.copyProperties(parentElement, groupReqVo);
|
|
|
-
|
|
|
- groupReqVo.setChildrenList(valveList);
|
|
|
+ groupReqVo.setChildrenList(elementList);
|
|
|
|
|
|
sendGroupConfig(groupReqVo, findDevice);
|
|
|
}
|
|
|
-
|
|
|
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;
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 删除元素
|
|
|
*
|
|
|
@@ -662,13 +675,25 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
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);
|
|
|
+ if(resVoList == null || resVoList.isEmpty()){
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌区不存在");
|
|
|
+ }
|
|
|
+ IotSfElementfactorAlreadyListResVo alreadyResVo = null;
|
|
|
+ for(IotSfElementfactorAlreadyListResVo resVo : resVoList){
|
|
|
+ if(Objects.equals(resVo.getSfBid(), sfBid)){
|
|
|
+ alreadyResVo = resVo;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(alreadyResVo == null){
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌区不存在");
|
|
|
+ }
|
|
|
List<IotSfElementfactorAlreadyListResVo> childrenList = alreadyResVo.getChildrenList();
|
|
|
|
|
|
if(childrenList != null && !childrenList.isEmpty()){
|
|
|
@@ -694,8 +719,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
|
|
|
sendConfigCmd(configCmdReqVo);
|
|
|
}
|
|
|
-
|
|
|
- return status;
|
|
|
+ return iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -753,7 +777,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
TableDataInfo tableDataInfo = getStatus(devBid);
|
|
|
List<IotSfElementfactorInfoVo> resultList = (List<IotSfElementfactorInfoVo>) tableDataInfo.getData();
|
|
|
if(resultList == null || resultList.isEmpty()){
|
|
|
- throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"未配置要素");
|
|
|
+ throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"未配置");
|
|
|
}
|
|
|
|
|
|
Map<String, EnumSfElementType> sfTypeMap = new HashMap<>();
|
|
|
@@ -856,22 +880,6 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
iotSfIrrigationOprecordService.createIotSfIrrigationOprecord(devBid, oprecdName, oprecdContent, oprecdStatus);
|
|
|
}
|
|
|
}
|
|
|
-//
|
|
|
-// if(groupResVo != null){
|
|
|
-// String v = "0";
|
|
|
-// for(IotSfElementfactorAlreadyListResVo child : groupResVo.getChildrenList()){
|
|
|
-// String key = child.getSfCode();
|
|
|
-// v = devConfig.getString(key);
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(Objects.equals(v, "1")){
|
|
|
-// String sfdataBid = runStatusData.getString("sfdataBid");
|
|
|
-// List<IotSfElementfactorAlreadyListResVo> groupList = new ArrayList<>();
|
|
|
-// groupList.add(groupResVo);
|
|
|
-// iotSfIrrigationRecordService.createIotSfIrrigationRecordList(groupList, EnumIrrigationRecord.MODE_MANUAL.getCode(), sfdataBid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
|
|
|
// 切换到自动模式,先重置状态
|
|
|
String value = devConfig.getString(runMode);
|
|
|
@@ -1064,7 +1072,14 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
if(elementfactor.getChildrenList() == null || elementfactor.getChildrenList().isEmpty()){
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌区未配置阀,无法开始灌溉");
|
|
|
}
|
|
|
+ // 打开灌区
|
|
|
sendJson.put(sfCode, "1");
|
|
|
+ // 打开灌区下发阀
|
|
|
+ List<IotSfElementfactorAlreadyListResVo> childrenList = elementfactor.getChildrenList();
|
|
|
+ for(IotSfElementfactorAlreadyListResVo child : childrenList){
|
|
|
+ String childSfCode = child.getSfCode();
|
|
|
+ sendJson.put(childSfCode, "1");
|
|
|
+ }
|
|
|
groupList.add(elementfactor);
|
|
|
if("0".equals(dqqf) && sfCode.startsWith("Btn-qx")){
|
|
|
try{
|
|
|
@@ -1075,11 +1090,25 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- sendJson.put("Num-dqqf", dqqf);
|
|
|
-
|
|
|
if(sendJson.isEmpty()){
|
|
|
throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先选择灌区");
|
|
|
}
|
|
|
+ IotSfElementfactorListReqVo pumpVo = new IotSfElementfactorListReqVo();
|
|
|
+ pumpVo.setDevBid(devBid);
|
|
|
+ pumpVo.setTid(SecurityUtils.getTid());
|
|
|
+ List<IotSfElementfactor> sfElementfactorList = iotSfElementfactorService.selectIotSfElementfactorListByPump(pumpVo);
|
|
|
+ if(sfElementfactorList != null &&!sfElementfactorList.isEmpty()){
|
|
|
+ for(IotSfElementfactor vo : sfElementfactorList){
|
|
|
+ String sfCode = vo.getSfCode();
|
|
|
+ String sfType = vo.getSfType();
|
|
|
+ if(Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sendJson.put(sfCode, "1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sendJson.put("Num-dqqf", dqqf);
|
|
|
String[] keys = new String[]{"Btn-dsdl", "Num-lgcs", "Num-lgjg"};
|
|
|
for(String key : keys){
|
|
|
sendJson.put(key, data.getString(key));
|