|
@@ -13,6 +13,8 @@ import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
|
|
import com.yunfeiyun.agmp.iot.common.domain.TosDevicetype;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.IotDeviceconnTypeEnum;
|
|
import com.yunfeiyun.agmp.iot.common.enums.IotDeviceconnTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.service.DeviceconnCacheService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.mq.service.SendToIotsMsgService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.IotDevconnConfigInfoVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.IotDevconnConfigInfoVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceconnAddReqVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceconnAddReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceconnEditReqVo;
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceconnEditReqVo;
|
|
@@ -26,6 +28,9 @@ import com.yunfeiyun.agmp.iotm.web.service.ITosDevicetypeService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设备连接配置Service业务层处理
|
|
* 设备连接配置Service业务层处理
|
|
|
*
|
|
*
|
|
@@ -43,6 +48,18 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IIotDeviceService iotDeviceService;
|
|
private IIotDeviceService iotDeviceService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DeviceconnCacheService deviceconnCacheService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SendToIotsMsgService sendToIotsMsgService;
|
|
|
|
|
+
|
|
|
|
|
+ @PostConstruct
|
|
|
|
|
+ public void init(){
|
|
|
|
|
+ List<IotDeviceconn> iotDeviceconnList = iotDeviceconnMapper.selectIotDeviceconnAllList();
|
|
|
|
|
+ for(IotDeviceconn iotDeviceconn :iotDeviceconnList){
|
|
|
|
|
+ deviceconnCacheService.setCache(iotDeviceconn);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int addDeviceconn(IotDeviceconnAddReqVo reqVo, boolean isCreateConnect) {
|
|
public int addDeviceconn(IotDeviceconnAddReqVo reqVo, boolean isCreateConnect) {
|
|
@@ -118,7 +135,10 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
|
|
|
|
|
int status = insertIotDeviceconnByBatch(insertIotDeviceconnList);
|
|
int status = insertIotDeviceconnByBatch(insertIotDeviceconnList);
|
|
|
if(isCreateConnect) {
|
|
if(isCreateConnect) {
|
|
|
- // Todo 发送消息,创建设备连接
|
|
|
|
|
|
|
+ // 发送消息,创建设备连接
|
|
|
|
|
+ for(IotDeviceconn iotDeviceconn : insertIotDeviceconnList){
|
|
|
|
|
+ sendToIotsMsgService.sendIotDeviceconnInsertMsg(iotDeviceconn);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return status;
|
|
return status;
|
|
|
}
|
|
}
|
|
@@ -197,24 +217,12 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
if(tosDevicetype == null){
|
|
if(tosDevicetype == null){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- List<String> devconnBids = new ArrayList<>();
|
|
|
|
|
- for(IotDeviceconn iotDeviceconn : iotDeviceconnList){
|
|
|
|
|
- devconnBids.add(iotDeviceconn.getDevconnBid());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- deleteIotDeviceconnByBids(devconnBids.toArray(new String[0]), false);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ deleteIotDeviceconnByBids(iotDeviceconnList, true);
|
|
|
IotDeviceconnAddReqVo addReqVo = new IotDeviceconnAddReqVo();
|
|
IotDeviceconnAddReqVo addReqVo = new IotDeviceconnAddReqVo();
|
|
|
addReqVo.setDevtypeBid(newDevtypeBid);
|
|
addReqVo.setDevtypeBid(newDevtypeBid);
|
|
|
addReqVo.setDevconnType(devconnType);
|
|
addReqVo.setDevconnType(devconnType);
|
|
|
addReqVo.setDevconnConfigList(reqVo.getDevconnConfigList());
|
|
addReqVo.setDevconnConfigList(reqVo.getDevconnConfigList());
|
|
|
-
|
|
|
|
|
- int status = addDeviceconn(addReqVo, false);
|
|
|
|
|
- // Todo 发送消息,删除设备连接
|
|
|
|
|
- // Todo 发送消息,更新设备连接
|
|
|
|
|
-
|
|
|
|
|
- return status;
|
|
|
|
|
|
|
+ return addDeviceconn(addReqVo, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -241,11 +249,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
if(iotDeviceList != null && !iotDeviceList.isEmpty()){
|
|
if(iotDeviceList != null && !iotDeviceList.isEmpty()){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备类型下存在设备,无法删除");
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备类型下存在设备,无法删除");
|
|
|
}
|
|
}
|
|
|
- List<String> devconnBids = new ArrayList<>();
|
|
|
|
|
- for(IotDeviceconn iotDeviceconn : iotDeviceconnList){
|
|
|
|
|
- devconnBids.add(iotDeviceconn.getDevconnBid());
|
|
|
|
|
- }
|
|
|
|
|
- return deleteIotDeviceconnByBids(devconnBids.toArray(new String[0]));
|
|
|
|
|
|
|
+ return deleteIotDeviceconnByBids(iotDeviceconnList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -256,10 +260,16 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
* @return 结果
|
|
* @return 结果
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public int deleteIotDeviceconnByBids(String[] devconnBids, boolean isDeleteConnect) {
|
|
|
|
|
|
|
+ public int deleteIotDeviceconnByBids(List<IotDeviceconn> iotDeviceconnList, boolean isDeleteConnect) {
|
|
|
|
|
+ String[] devconnBids = new String[iotDeviceconnList.size()];
|
|
|
|
|
+ for(int i = 0;i<devconnBids.length;i++){
|
|
|
|
|
+ devconnBids[i] = iotDeviceconnList.get(i).getDevconnBid();
|
|
|
|
|
+ }
|
|
|
int status = iotDeviceconnMapper.deleteIotDeviceconnByBids(devconnBids);
|
|
int status = iotDeviceconnMapper.deleteIotDeviceconnByBids(devconnBids);
|
|
|
if(isDeleteConnect) {
|
|
if(isDeleteConnect) {
|
|
|
- // 删除设备连接配置
|
|
|
|
|
|
|
+ for(IotDeviceconn iotDeviceconn : iotDeviceconnList){
|
|
|
|
|
+ sendToIotsMsgService.sendIotDeviceconnDeleteMsg(iotDeviceconn);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return status;
|
|
return status;
|
|
|
}
|
|
}
|
|
@@ -272,8 +282,8 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
|
|
|
* @return 结果
|
|
* @return 结果
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public int deleteIotDeviceconnByBids(String[] devconnBids) {
|
|
|
|
|
- return deleteIotDeviceconnByBids(devconnBids, true);
|
|
|
|
|
|
|
+ public int deleteIotDeviceconnByBids(List<IotDeviceconn> iotDeviceconnList) {
|
|
|
|
|
+ return deleteIotDeviceconnByBids(iotDeviceconnList, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|