|
|
@@ -5,6 +5,7 @@ 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.mqtt.IotMqttConstant;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.IotDeviceDelStatusEnum;
|
|
|
@@ -32,10 +33,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 设备基础Service业务层处理
|
|
|
@@ -111,20 +109,16 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
String firmBid = iotDeviceconn.getFirmBid();
|
|
|
String devtypeBid = iotDeviceconn.getDevtypeBid();
|
|
|
|
|
|
+ String devCodeExist = checkIotDeviceExist(devtypeBid, devCodeList);
|
|
|
+ if(StringUtils.isNotEmpty(devCodeExist) ){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCodeExist);
|
|
|
+ }
|
|
|
+
|
|
|
IotDevice selectIotDevice = new IotDevice();
|
|
|
selectIotDevice.setDevtypeBid(devtypeBid);
|
|
|
|
|
|
- List<IotDevice> iotDeviceList = checkIotDeviceList(selectIotDevice);
|
|
|
- Set<String> devCodeSet = new HashSet<>();
|
|
|
- for (IotDevice iotDevice : iotDeviceList) {
|
|
|
- devCodeSet.add(iotDevice.getDevtypeBid() + iotDevice.getDevCode());
|
|
|
- }
|
|
|
List<IotDevice> insertIotDeviceList = new ArrayList<>();
|
|
|
for (String devCode : devCodeList) {
|
|
|
- if(devCodeSet.contains(devtypeBid + devCode)){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCode);
|
|
|
- }
|
|
|
-
|
|
|
IotDevice iotDevice = new IotDevice();
|
|
|
iotDevice.setDevBid(iotDevice.getUUId());
|
|
|
iotDevice.setDevtypeBid(devtypeBid);
|
|
|
@@ -198,20 +192,15 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备连接不存在");
|
|
|
}
|
|
|
|
|
|
- IotDevice selectIotDevice = new IotDevice();
|
|
|
- selectIotDevice.setDevCode(devCode);
|
|
|
- selectIotDevice.setDevtypeBid(newIotDeviceconn.getDevtypeBid());
|
|
|
-
|
|
|
- List<IotDevice> iotDeviceList = checkIotDeviceList(selectIotDevice);
|
|
|
- Set<String> devSet = new HashSet<>();
|
|
|
- for (IotDevice item : iotDeviceList) {
|
|
|
- devSet.add(item.getFirmBid() + item.getDevtypeBid() + item.getDevCode());
|
|
|
- }
|
|
|
- String devKey = iotDevice.getFirmBid() + iotDevice.getDevtypeBid() + iotDevice.getDevCode();
|
|
|
- devSet.remove(devKey);
|
|
|
- if(!devSet.isEmpty()){
|
|
|
- throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备编码已存在");
|
|
|
+ String devtypeBid = newIotDeviceconn.getDevtypeBid();
|
|
|
+ if(!(devCode.equals(iotDevice.getDevCode()) && devtypeBid.equals(iotDevice.getDevtypeBid()))){
|
|
|
+ String[] devCodeList = {devCode};
|
|
|
+ String devCodeExist = checkIotDeviceExist(devtypeBid, devCodeList);
|
|
|
+ if(StringUtils.isNotEmpty(devCodeExist) ){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCodeExist);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
IotDevice updateIotDevice = new IotDevice();
|
|
|
updateIotDevice.setDevBid(iotDevice.getDevBid());
|
|
|
updateIotDevice.setDevName(devName);
|
|
|
@@ -385,15 +374,24 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
return iotDeviceMapper.selectIotDeviceListByType(reqVo);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 检查设备基础列表
|
|
|
- *
|
|
|
- * @param iotDevice 设备基础
|
|
|
- * @return 设备基础集合
|
|
|
- */
|
|
|
@Override
|
|
|
- public List<IotDevice> checkIotDeviceList(IotDevice iotDevice) {
|
|
|
- return selectIotDeviceList(iotDevice, false);
|
|
|
+ public String checkIotDeviceExist(String devtypeBid, String[] devCode){
|
|
|
+ List<IotDevice> iotDeviceList = selectIotDeviceList(new IotDevice(), false);
|
|
|
+ Set<String> devCodeSet = new HashSet<>();
|
|
|
+ Set<String> devTopicSet = new HashSet<>();
|
|
|
+ for(IotDevice iotDevice : iotDeviceList){
|
|
|
+ devCodeSet.add(iotDevice.getDevtypeBid() + iotDevice.getDevCode());
|
|
|
+ devTopicSet.add(IotMqttConstant.getReportTopicByDevtype(iotDevice.getDevtypeBid()));
|
|
|
+ }
|
|
|
+ String topic = IotMqttConstant.getReportTopicByDevtype(devtypeBid);
|
|
|
+ for(String code : devCode){
|
|
|
+ String key = devtypeBid + code;
|
|
|
+ // 同一个mqtt Topic只能有一个设备
|
|
|
+ // 同一个设备类型下不能有重复的设备编号
|
|
|
+ if(devTopicSet.contains(topic) || devCodeSet.contains(key)){
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
}
|