|
|
@@ -56,24 +56,20 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
|
|
|
|
@Override
|
|
|
- public int addDeviceconn(IotDeviceconnAddReqVo reqVo, boolean isCreateConnect) {
|
|
|
+ public int addDeviceconn(IotDeviceconnAddReqVo reqVo) {
|
|
|
String devconnType = reqVo.getDevconnType();
|
|
|
String devtypeBid = reqVo.getDevtypeBid();
|
|
|
-
|
|
|
TosDevicetype tosDevicetype = tosDevicetypeService.selectTosDevicetypeByDevtypeBid(devtypeBid);
|
|
|
if(tosDevicetype == null){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
|
|
|
}
|
|
|
IotDeviceconn selectIotDeviceconn = new IotDeviceconn();
|
|
|
selectIotDeviceconn.setDevtypeBid(devtypeBid);
|
|
|
-
|
|
|
List<IotDeviceconn> iotDeviceconnList = selectIotDeviceconnList(selectIotDeviceconn);
|
|
|
if(iotDeviceconnList != null && !iotDeviceconnList.isEmpty()){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备型号已存在连接配置");
|
|
|
}
|
|
|
-
|
|
|
List<IotDeviceconn> insertIotDeviceconnList = new ArrayList<>();
|
|
|
-
|
|
|
if(IotDeviceconnTypeEnum.COMMON.getCode().equals(devconnType)){
|
|
|
IotDeviceconn iotDeviceconn = new IotDeviceconn();
|
|
|
String bid = reqVo.getCommonConnBid();
|
|
|
@@ -86,6 +82,8 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
iotDeviceconn.setDevconnCreateddate(DateUtils.dateTimeNow());
|
|
|
insertIotDeviceconnList.add(iotDeviceconn);
|
|
|
}else{
|
|
|
+ // 租户的私有连接创建需要再iots创建连接信息
|
|
|
+
|
|
|
List<IotDevconnConfigInfoVo> devconnConfigList = reqVo.getDevconnConfigList();
|
|
|
if(devconnConfigList == null || devconnConfigList.isEmpty()){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置不能为空");
|
|
|
@@ -126,28 +124,22 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
diffName = devconnName;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
int status = insertIotDeviceconnByBatch(insertIotDeviceconnList);
|
|
|
- if(isCreateConnect) {
|
|
|
- // 发送消息,创建设备连接
|
|
|
- for(IotDeviceconn iotDeviceconn : insertIotDeviceconnList){
|
|
|
- sendToIotsMsgService.sendIotDeviceconnInsertMsg(iotDeviceconn);
|
|
|
- }
|
|
|
+ // 发送消息,创建设备连接
|
|
|
+ for(IotDeviceconn iotDeviceconn : insertIotDeviceconnList){
|
|
|
+ sendToIotsMsgService.sendIotDeviceconnInsertMsg(iotDeviceconn);
|
|
|
}
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int addDeviceconn(IotDeviceconnAddReqVo reqVo) {
|
|
|
- return addDeviceconn(reqVo, true);
|
|
|
- }
|
|
|
- private int addDeviceconn(String devtypeBid,String connType,List<IotDevconnConfigInfoVo> list,String commonConnBid,boolean isCreateConnect){
|
|
|
+
|
|
|
+ private int addDeviceconn(String devtypeBid,String connType,List<IotDevconnConfigInfoVo> list,String commonConnBid){
|
|
|
IotDeviceconnAddReqVo iotDeviceconnAddReqVo = new IotDeviceconnAddReqVo();
|
|
|
iotDeviceconnAddReqVo.setDevtypeBid(devtypeBid);
|
|
|
iotDeviceconnAddReqVo.setDevconnType(connType);
|
|
|
iotDeviceconnAddReqVo.setDevconnConfigList(list);
|
|
|
iotDeviceconnAddReqVo.setCommonConnBid(commonConnBid);
|
|
|
- return addDeviceconn(iotDeviceconnAddReqVo,isCreateConnect);
|
|
|
+ return addDeviceconn(iotDeviceconnAddReqVo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -243,7 +235,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
// 先删除该租户的旧的通用配置信息
|
|
|
result = result + iotDeviceconnMapper.deleteIotDeviceconnByBids(new String[]{iotDeviceconn.getDevconnBid()});
|
|
|
// 再创建该租户的新的私有连接信息
|
|
|
- result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null,true);
|
|
|
+ result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null);
|
|
|
// TODO: 此处用于解绑设备的旧配置以及创建新配置,后续可以优化
|
|
|
for(IotDevice iotDevice : iotDeviceList){
|
|
|
IotDevice newIotDevice =new IotDevice();
|
|
|
@@ -296,7 +288,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
result = result + deleteIotDeviceconnByBids(iotDeviceconnList,true);
|
|
|
String newConnBid = iotDeviceQuery.getUUId();
|
|
|
// 创建该租户新的通用连接
|
|
|
- result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),newConnBid,true);
|
|
|
+ result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),newConnBid);
|
|
|
for(IotDevice iotDevice : iotDeviceList){
|
|
|
iotDevice.setDevconnBid(newConnBid);
|
|
|
iotDeviceMapper.updateIotDevice(iotDevice);
|
|
|
@@ -316,7 +308,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
// 先删除该租户的旧的私有连接,该接口会自动解绑设备
|
|
|
result = result + deleteIotDeviceconnByBids(iotDeviceconnList,true);
|
|
|
// 再创建该租户的新的私有连接信息
|
|
|
- result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null,true);
|
|
|
+ result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null);
|
|
|
// TODO: 此处用于解绑设备的旧配置以及创建新配置,后续可以优化
|
|
|
for(IotDevice iotDevice : iotDeviceList){
|
|
|
iotDevice.setDevconnBid(newConfig.getDevconnBid());
|