|
@@ -12,6 +12,7 @@ import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.model.mq.IotDeviceEditMqModel;
|
|
import com.yunfeiyun.agmp.iot.common.model.mq.IotDeviceEditMqModel;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.TypeCacheService;
|
|
import com.yunfeiyun.agmp.iot.common.service.TypeCacheService;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceRefreshService;
|
|
|
import com.yunfeiyun.agmp.iotm.mq.service.SendToIotsMsgService;
|
|
import com.yunfeiyun.agmp.iotm.mq.service.SendToIotsMsgService;
|
|
|
import com.yunfeiyun.agmp.iotm.mq.service.SendToTosMsgService;
|
|
import com.yunfeiyun.agmp.iotm.mq.service.SendToTosMsgService;
|
|
|
import com.yunfeiyun.agmp.iotm.util.MyPageUtil;
|
|
import com.yunfeiyun.agmp.iotm.util.MyPageUtil;
|
|
@@ -23,6 +24,7 @@ import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceMapper;
|
|
import com.yunfeiyun.agmp.iotm.web.mapper.IotDeviceMapper;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconnService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconnService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -41,6 +43,7 @@ import java.util.Set;
|
|
|
* @date 2024-11-06
|
|
* @date 2024-11-06
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
|
|
+@Slf4j
|
|
|
public class IotDeviceServiceImpl implements IIotDeviceService
|
|
public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
{
|
|
{
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -57,6 +60,9 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IIotDeviceconnService iotDeviceconnService;
|
|
private IIotDeviceconnService iotDeviceconnService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotDeviceRefreshService iotDeviceRefreshService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 新增设备基础
|
|
* 新增设备基础
|
|
|
*
|
|
*
|
|
@@ -72,6 +78,16 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
if(devCodeList == null || devCodeList.length == 0){
|
|
if(devCodeList == null || devCodeList.length == 0){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能为空");
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能为空");
|
|
|
}
|
|
}
|
|
|
|
|
+ Set<String> tempDevCodeSet = new HashSet<>();
|
|
|
|
|
+ for(String devCode : devCodeList){
|
|
|
|
|
+ if(StringUtils.isEmpty(devCode)){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ tempDevCodeSet.add(devCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(tempDevCodeSet.size() != devCodeList.length){
|
|
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备编码不能重复");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
IotDeviceconn iotDeviceconn = iotDeviceconnService.selectIotDeviceconnByBid(devconnBid);
|
|
IotDeviceconn iotDeviceconn = iotDeviceconnService.selectIotDeviceconnByBid(devconnBid);
|
|
|
if(iotDeviceconn == null){
|
|
if(iotDeviceconn == null){
|
|
@@ -98,11 +114,11 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
|
|
List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
|
|
|
Set<String> devCodeSet = new HashSet<>();
|
|
Set<String> devCodeSet = new HashSet<>();
|
|
|
for (IotDevice iotDevice : iotDeviceList) {
|
|
for (IotDevice iotDevice : iotDeviceList) {
|
|
|
- devCodeSet.add(iotDevice.getFirmBid() + iotDevice.getDevtypeBid() + iotDevice.getDevCode());
|
|
|
|
|
|
|
+ devCodeSet.add(iotDevice.getDevtypeBid() + iotDevice.getDevCode());
|
|
|
}
|
|
}
|
|
|
List<IotDevice> insertIotDeviceList = new ArrayList<>();
|
|
List<IotDevice> insertIotDeviceList = new ArrayList<>();
|
|
|
for (String devCode : devCodeList) {
|
|
for (String devCode : devCodeList) {
|
|
|
- if(devCodeSet.contains(firmBid+devtypeBid+devCode)){
|
|
|
|
|
|
|
+ if(devCodeSet.contains(devtypeBid + devCode)){
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCode);
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备已存在:"+devCode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -284,6 +300,23 @@ public class IotDeviceServiceImpl implements IIotDeviceService
|
|
|
sendToTosMsgService.sendIotDeviceInsertMsg(iotDevice);
|
|
sendToTosMsgService.sendIotDeviceInsertMsg(iotDevice);
|
|
|
sendToIotsMsgService.sendIotDeviceInsertMsg(iotDevice);
|
|
sendToIotsMsgService.sendIotDeviceInsertMsg(iotDevice);
|
|
|
}
|
|
}
|
|
|
|
|
+ new Thread(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(2000);
|
|
|
|
|
+ // 刷新设备信息
|
|
|
|
|
+ for (IotDevice iotDevice : iotDeviceList) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ iotDeviceRefreshService.refresh(iotDevice.getDevBid());
|
|
|
|
|
+ log.info("创建设备刷新成功: " + iotDevice);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("创建设备刷新失败: " + iotDevice, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("创建设备刷新失败: " + iotDeviceList, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+
|
|
|
return status;
|
|
return status;
|
|
|
}
|
|
}
|
|
|
|
|
|