|
|
@@ -4,35 +4,42 @@ import cn.hutool.core.exceptions.ValidateException;
|
|
|
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.log.LogCore;
|
|
|
+import com.yunfeiyun.agmp.common.utils.JSONUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
|
|
|
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.IotDeviceconfig;
|
|
|
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.iot.common.model.cmd.CmdGroupModel;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
|
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.IotSfConfigCmdReqVo;
|
|
|
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.IIotCmdtaskService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconfigService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 水肥机通用服务
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDeviceBaseService {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -44,6 +51,9 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
@Resource
|
|
|
private IIotDeviceconfigService iIotDeviceconfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IIotCmdtaskService iIotCmdtaskService;
|
|
|
+
|
|
|
|
|
|
public Class getTableClass(String devtypeBid) {
|
|
|
Class tableClass = null;
|
|
|
@@ -98,7 +108,7 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private IotSfElementfactor makeIotSfElementfactor(IotSfElementfactorAddReqVo reqVo, String date){
|
|
|
+ public IotSfElementfactor makeIotSfElementfactor(IotSfElementfactorAddReqVo reqVo, String date){
|
|
|
String tid = SecurityUtils.getTid();
|
|
|
String userId = SecurityUtils.getUserId();
|
|
|
|
|
|
@@ -121,65 +131,8 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
* @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
|
|
|
*/
|
|
|
public int elementAdd(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.selectIotSfElementfactorList(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);
|
|
|
+ // 由具体子类实现
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -283,7 +236,7 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
/**
|
|
|
* 获取水肥机状态信息
|
|
|
*
|
|
|
- * @param reqVo 请求对象,包含设备标识等信息
|
|
|
+ * @param devBid 请求对象,包含设备标识等信息
|
|
|
* @return TableDataInfo 包含响应码、消息、数据和总数
|
|
|
* @throws IotBizException 抛出业务异常,包含错误码和错误信息
|
|
|
*/
|
|
|
@@ -324,4 +277,28 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public String sendConfigCmd(IotSfConfigCmdReqVo reqVo) {
|
|
|
+ IotDevice iotDevice = reqVo.getIotDevice();
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ JSONObject data = reqVo.getData();
|
|
|
+ IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
|
|
|
+ iotDeviceconfig.setDevBid(devBid);
|
|
|
+ iotDeviceconfig.setDevcfgContext(data.toJSONString());
|
|
|
+ iotDeviceconfig.setTid(iotDevice.getTid());
|
|
|
+
|
|
|
+ String func = reqVo.getCmd();
|
|
|
+ CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createCmd(iotDeviceconfig, func);
|
|
|
+ log.info("【{}】【水肥机 [下发配置]】【构建 cmdGroupModel】{}", LogCore.getSeq(), JSONUtils.toJSONString(cmdGroupModel));
|
|
|
+ cmdGroupModel.setRequestId(IdUtils.fastUUID());
|
|
|
+
|
|
|
+ // 适配增加详细日志使用
|
|
|
+ cmdGroupModel.setDevCode(iotDevice.getDevCode());
|
|
|
+ cmdGroupModel.setCtBiztitle(iotDevice.getDevtypeName() + ":" + iotDevice.getDevCode());
|
|
|
+ cmdGroupModel.setCtBiztype("3");
|
|
|
+ cmdGroupModel.setCtDevtype(iotDevice.getDevtypeBid());
|
|
|
+ cmdGroupModel.setCtParam(JSONUtils.toJSONString(reqVo));
|
|
|
+ iIotCmdtaskService.handInternalCmd(cmdGroupModel);
|
|
|
+ return cmdGroupModel.getTaskUuid();
|
|
|
+ }
|
|
|
+
|
|
|
}
|