|
|
@@ -2,22 +2,27 @@ package com.yunfeiyun.agmp.iotm.device.sf.service;
|
|
|
|
|
|
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.devicetype.IotDeviceDictConst;
|
|
|
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.iotm.device.common.service.IotDeviceBaseService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAddReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 水肥机通用服务
|
|
|
@@ -40,13 +45,13 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取已存在的元素列表
|
|
|
+ * 获取泵类设备已存在的元素列表
|
|
|
*
|
|
|
* @param reqVo 请求对象,包含设备标识等信息
|
|
|
* @return TableDataInfo 包含响应码、消息、数据和总数
|
|
|
* @throws IotBizException 抛出业务异常,包含错误码和错误信息
|
|
|
*/
|
|
|
- public TableDataInfo getAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
|
|
|
+ public TableDataInfo getPumpAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
|
|
|
TableDataInfo rspData = new TableDataInfo();
|
|
|
rspData.setCode(ErrorCode.SUCCESS.getCode());
|
|
|
rspData.setMsg(ErrorCode.SUCCESS.getMessage());
|
|
|
@@ -63,8 +68,8 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
|
|
|
}
|
|
|
|
|
|
- List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getAlreadyElementList(reqVo);
|
|
|
- if (resVoList != null && resVoList.size() > 0){
|
|
|
+ List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getPumpAlreadyElementList(reqVo);
|
|
|
+ if (resVoList != null && !resVoList.isEmpty()){
|
|
|
rspData.setData(resVoList);
|
|
|
rspData.setTotal(resVoList.size());
|
|
|
}
|
|
|
@@ -72,15 +77,100 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取未处理的元素列表
|
|
|
+ * 获取泵类未处理的元素列表
|
|
|
* 该接口用于根据请求参数获取未处理的元素列表,并返回相关数据。
|
|
|
*
|
|
|
* @param reqVo 请求参数,包含设备标识(devBid)等信息
|
|
|
* @return TableDataInfo 包含未处理的元素列表的数据封装对象
|
|
|
* @throws IllegalArgumentException 如果devBid为空,则抛出非法参数异常
|
|
|
*/
|
|
|
- public TableDataInfo getUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
|
|
|
+ public TableDataInfo getPumpUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
|
|
|
// 由具体子类实现
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private IotSfElementfactor makeIotSfElementfactor(IotSfElementfactorAddReqVo reqVo, String date){
|
|
|
+ String tid = SecurityUtils.getTid();
|
|
|
+ String userId = SecurityUtils.getUserId();
|
|
|
+
|
|
|
+ IotSfElementfactor elementfactor = new IotSfElementfactor();
|
|
|
+ String sfBid = elementfactor.getUUId();
|
|
|
+ BeanUtils.copyProperties(reqVo, elementfactor);
|
|
|
+ elementfactor.setSfBid(sfBid);
|
|
|
+ elementfactor.setTid(tid);
|
|
|
+ elementfactor.setSfCreatedDate(date);
|
|
|
+ elementfactor.setSfCreator(userId);
|
|
|
+ elementfactor.setSfModifieddate(date);
|
|
|
+ elementfactor.setSfModifier(userId);
|
|
|
+ return elementfactor;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增泵类要素
|
|
|
+ * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
|
|
|
+ *
|
|
|
+ * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
|
|
|
+ */
|
|
|
+ public int pumpAdd(IotSfElementfactorAddReqVo 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(), "设备不存在");
|
|
|
+ }
|
|
|
+ String sfType = reqVo.getSfType();
|
|
|
+ String sfCode = reqVo.getSfCode();
|
|
|
+ // 肥料桶是虚拟的,不需要检测code重复问题
|
|
|
+ if(!Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
|
|
|
+ if (StringUtils.isEmpty(sfCode)) {
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String sfDisplayname = reqVo.getSfDisplayname();
|
|
|
+ if (StringUtils.isEmpty(sfType)) {
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素类型不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(sfDisplayname)) {
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
|
|
|
+ reqVo1.setDevBid(devBid);
|
|
|
+ List<IotSfElementfactor> elementList = iotSfElementfactorService.selectIotSfElementfactorListByPump(reqVo1);
|
|
|
+ Set<String> sfCodeSet = new HashSet<>();
|
|
|
+ for (IotSfElementfactor element : elementList) {
|
|
|
+ if(StringUtils.isNotEmpty(element.getSfCode())){
|
|
|
+ sfCodeSet.add(element.getSfCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String createDate = DateUtils.dateTimeNow();
|
|
|
+ List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
|
|
|
+
|
|
|
+ IotSfElementfactor elementfactor = makeIotSfElementfactor(reqVo, createDate);
|
|
|
+ sfElementfactorList.add(elementfactor);
|
|
|
+
|
|
|
+ List<IotSfElementfactorAddReqVo> childrenList = reqVo.getChildrenList();
|
|
|
+ if (childrenList!= null &&!childrenList.isEmpty()){
|
|
|
+ for (IotSfElementfactorAddReqVo child : childrenList) {
|
|
|
+ child.setDevBid(devBid);
|
|
|
+ IotSfElementfactor childElementfactor = makeIotSfElementfactor(child, createDate);
|
|
|
+ childElementfactor.setSfParentBid(elementfactor.getSfBid());
|
|
|
+ sfElementfactorList.add(childElementfactor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(IotSfElementfactor element : sfElementfactorList){
|
|
|
+ if(sfCodeSet.contains(element.getSfCode())){
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|