|
|
@@ -1,8 +1,6 @@
|
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
@@ -65,12 +63,12 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
@Override
|
|
|
public int addIotDevice(IotDeviceAddReqVo reqVo) {
|
|
|
String devconnBid = reqVo.getDevconnBid();
|
|
|
- String devCode = reqVo.getDevCode();
|
|
|
- String devName = reqVo.getDevName();
|
|
|
+ String[] devCodeList = reqVo.getDevCodeList();
|
|
|
|
|
|
- if(StringUtils.isEmpty(devCode) || StringUtils.isEmpty(devName) ){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码或设备名称不能为空");
|
|
|
+ if(devCodeList == null || devCodeList.length == 0){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能为空");
|
|
|
}
|
|
|
+
|
|
|
IotDeviceconn selectDeviceconn = new IotDeviceconn();
|
|
|
selectDeviceconn.setDevconnBid(devconnBid);
|
|
|
List<IotDeviceconn> iotDeviceconnList = iotDeviceconnService.selectIotDeviceconnList(selectDeviceconn);
|
|
|
@@ -79,34 +77,50 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
}
|
|
|
|
|
|
IotDeviceconn iotDeviceconn = iotDeviceconnList.get(0);
|
|
|
+ String devName = iotDeviceconn.getDevtypeName();
|
|
|
+ if(devCodeList.length == 1){
|
|
|
+ devName = reqVo.getDevName();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(devName) ){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备名称不能为空");
|
|
|
+ }
|
|
|
|
|
|
String firmBid = iotDeviceconn.getFirmBid();
|
|
|
String devtypeBid = iotDeviceconn.getDevtypeBid();
|
|
|
|
|
|
IotDevice selectIotDevice = new IotDevice();
|
|
|
- selectIotDevice.setDevCode(devCode);
|
|
|
selectIotDevice.setFirmBid(firmBid);
|
|
|
selectIotDevice.setDevtypeBid(devtypeBid);
|
|
|
|
|
|
List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
|
|
|
- if(iotDeviceList != null && !iotDeviceList.isEmpty()){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在");
|
|
|
+ Set<String> devCodeSet = new HashSet<>();
|
|
|
+ for (IotDevice iotDevice : iotDeviceList) {
|
|
|
+ devCodeSet.add(iotDevice.getFirmBid() + iotDevice.getDevtypeBid() + iotDevice.getDevCode());
|
|
|
+ }
|
|
|
+ List<IotDevice> insertIotDeviceList = new ArrayList<>();
|
|
|
+ for (String devCode : devCodeList) {
|
|
|
+ if(devCodeSet.contains(firmBid+devtypeBid+devCode)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice iotDevice = new IotDevice();
|
|
|
+ iotDevice.setDevBid(iotDevice.getUUId());
|
|
|
+ iotDevice.setDevtypeBid(devtypeBid);
|
|
|
+ iotDevice.setDevclassBid(iotDeviceconn.getDevclassBid());
|
|
|
+ iotDevice.setFirmBid(firmBid);
|
|
|
+ iotDevice.setDevconnBid(devconnBid);
|
|
|
+ iotDevice.setDevCode(devCode);
|
|
|
+ iotDevice.setDevName(devName);
|
|
|
+ iotDevice.setDevStatus(IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode());
|
|
|
+ iotDevice.setDevCreator(SecurityUtils.getUserId());
|
|
|
+ iotDevice.setDevCreateddate(DateUtils.dateTimeNow());
|
|
|
+ iotDevice.setDevDelstatus(IotDeviceDelStatusEnum.NOT_DELETE.getCode());
|
|
|
+
|
|
|
+ insertIotDeviceList.add(iotDevice);
|
|
|
}
|
|
|
|
|
|
- IotDevice iotDevice = new IotDevice();
|
|
|
- iotDevice.setDevBid(iotDeviceconn.getUUId());
|
|
|
- iotDevice.setDevtypeBid(devtypeBid);
|
|
|
- iotDevice.setDevclassBid(iotDeviceconn.getDevclassBid());
|
|
|
- iotDevice.setFirmBid(firmBid);
|
|
|
- iotDevice.setDevconnBid(devconnBid);
|
|
|
- iotDevice.setDevCode(devCode);
|
|
|
- iotDevice.setDevName(devName);
|
|
|
- iotDevice.setDevStatus(IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode());
|
|
|
- iotDevice.setDevCreator(SecurityUtils.getUserId());
|
|
|
- iotDevice.setDevCreateddate(DateUtils.dateTimeNow());
|
|
|
- iotDevice.setDevDelstatus(IotDeviceDelStatusEnum.NOT_DELETE.getCode());
|
|
|
-
|
|
|
- return insertIotDevice(iotDevice);
|
|
|
+ return insertIotDeviceByBatch(insertIotDeviceList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -170,6 +184,23 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 批量新增设备基础
|
|
|
+ *
|
|
|
+ * @param iotDeviceList 设备基础列表
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertIotDeviceByBatch(List<IotDevice> iotDeviceList) {
|
|
|
+ for (IotDevice iotDevice : iotDeviceList) {
|
|
|
+ iotDevice.setTid(SecurityUtils.getTid());
|
|
|
+ }
|
|
|
+ int status = iotDeviceMapper.insertIotDeviceByBatch(iotDeviceList);
|
|
|
+ // TODO 发送消息
|
|
|
+ // 获取连接 订阅设备
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 修改设备基础
|
|
|
*
|
|
|
* @param iotDevice 设备基础
|