|
|
@@ -527,6 +527,126 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
*
|
|
|
* @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(), "名称不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// 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;
|
|
|
+// }
|
|
|
+
|
|
|
public int elementBatchAdd(IotSfElementfactorBatchAddReqVo reqVo) {
|
|
|
String devBid = reqVo.getDevBid();
|
|
|
if (StringUtils.isEmpty(devBid)) {
|
|
|
@@ -555,26 +675,19 @@ 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)){
|
|
|
- throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
|
|
|
+
|
|
|
+ if(sfCodeSet.contains(sfCode)){
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素已存在,请勿重复添加");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(sfType)) {
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
|
|
|
@@ -582,9 +695,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 +702,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 +794,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 +838,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
|
|
|
|
|
|
sendConfigCmd(configCmdReqVo);
|
|
|
}
|
|
|
-
|
|
|
- return status;
|
|
|
+ return iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
|
|
|
}
|
|
|
|
|
|
@Override
|