|
|
@ -3,14 +3,8 @@ package com.ruoyi.business.service.impl;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.ruoyi.business.domain.HwDevice;
|
|
|
|
import com.ruoyi.business.domain.*;
|
|
|
|
import com.ruoyi.business.domain.HwDeviceMode;
|
|
|
|
import com.ruoyi.business.domain.VO.*;
|
|
|
|
import com.ruoyi.business.domain.HwDeviceModeFunction;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.HwScene;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.VO.DeviceControlVo;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.VO.DeviceModeVo;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.VO.DevicesInfoVo;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.VO.HwDeviceVo;
|
|
|
|
|
|
|
|
import com.ruoyi.business.mapper.*;
|
|
|
|
import com.ruoyi.business.mapper.*;
|
|
|
|
import com.ruoyi.business.service.IHwDeviceService;
|
|
|
|
import com.ruoyi.business.service.IHwDeviceService;
|
|
|
|
import com.ruoyi.common.core.constant.Constants;
|
|
|
|
import com.ruoyi.common.core.constant.Constants;
|
|
|
@ -19,6 +13,7 @@ import com.ruoyi.common.core.constant.SecurityConstants;
|
|
|
|
import com.ruoyi.common.core.constant.TdEngineConstants;
|
|
|
|
import com.ruoyi.common.core.constant.TdEngineConstants;
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
|
import com.ruoyi.common.core.enums.DataTypeEnums;
|
|
|
|
import com.ruoyi.common.core.enums.DataTypeEnums;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.enums.DeviceTypeEnums;
|
|
|
|
import com.ruoyi.common.core.exception.ServiceException;
|
|
|
|
import com.ruoyi.common.core.exception.ServiceException;
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
|
import com.ruoyi.common.core.utils.NumberUtils;
|
|
|
|
import com.ruoyi.common.core.utils.NumberUtils;
|
|
|
@ -51,6 +46,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private HwSceneMapper hwSceneMapper;
|
|
|
|
private HwSceneMapper hwSceneMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private HwMonitorUnitMapper hwMonitorUnitMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
|
|
|
|
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RemoteTdEngineService remoteTdEngineService;
|
|
|
|
private RemoteTdEngineService remoteTdEngineService;
|
|
|
@ -513,6 +510,133 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
return hwDeviceMapper.selectHwDeviceJoinList(hwDevice);
|
|
|
|
return hwDeviceMapper.selectHwDeviceJoinList(hwDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 导入设备数据
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceImportVoList 设备数据列表
|
|
|
|
|
|
|
|
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
|
|
|
|
|
|
|
* @param sceneId 场景ID
|
|
|
|
|
|
|
|
* @return 结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String importDevices(List<HwDeviceImportVo> deviceImportVoList, Boolean isUpdateSupport, Long sceneId) {
|
|
|
|
|
|
|
|
if (StringUtils.isNull(deviceImportVoList) || deviceImportVoList.size() == 0) {
|
|
|
|
|
|
|
|
throw new ServiceException("导入标准数据不能为空!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int successNum = 0;
|
|
|
|
|
|
|
|
int failureNum = 0;
|
|
|
|
|
|
|
|
StringBuilder successMsg = new StringBuilder();
|
|
|
|
|
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
|
|
|
|
|
String operName = SecurityUtils.getUsername();
|
|
|
|
|
|
|
|
Long tenantId = SecurityUtils.getTenantId();
|
|
|
|
|
|
|
|
String infoSeparator = "-";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断场景是否属于此租户
|
|
|
|
|
|
|
|
HwScene scene = hwSceneMapper.selectHwSceneBySceneId(sceneId);
|
|
|
|
|
|
|
|
if (!scene.getTenantId().equals(tenantId)) {
|
|
|
|
|
|
|
|
throw new ServiceException("选择场景不属于此租户!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (HwDeviceImportVo deviceImportVo : deviceImportVoList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
String checkMsg = this.checkImportDeviceData(deviceImportVo, sceneId, infoSeparator);
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(checkMsg)) {
|
|
|
|
|
|
|
|
failureNum++;
|
|
|
|
|
|
|
|
failureMsg.append(
|
|
|
|
|
|
|
|
"<br/>"
|
|
|
|
|
|
|
|
+ failureNum + "、"
|
|
|
|
|
|
|
|
+ checkMsg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String deviceCode = deviceImportVo.getDeviceCode();
|
|
|
|
|
|
|
|
String deviceName = deviceImportVo.getDeviceName();
|
|
|
|
|
|
|
|
String deviceType = deviceImportVo.getDeviceType();
|
|
|
|
|
|
|
|
String monitorUnitInfo = deviceImportVo.getMonitorUnitInfo();
|
|
|
|
|
|
|
|
String gateWayDeviceInfo = deviceImportVo.getReleatedDeviceInfo();
|
|
|
|
|
|
|
|
String deviceModeInfo = deviceImportVo.getDeviceModeInfo();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Long monitorUnitId = Long.valueOf(monitorUnitInfo.substring(0, monitorUnitInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
Long gatewayDeviceId = null;
|
|
|
|
|
|
|
|
Long deviceModeId = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据设备类型名称获取code
|
|
|
|
|
|
|
|
String deviceTypeCode = DeviceTypeEnums.dataTypeCodeMap.get(deviceType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//验证是否存在这个设备
|
|
|
|
|
|
|
|
HwDevice d = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceImportVo.getDeviceCode());
|
|
|
|
|
|
|
|
if (d == null) {
|
|
|
|
|
|
|
|
HwDevice device = new HwDevice();
|
|
|
|
|
|
|
|
device.setDeviceCode(deviceCode);
|
|
|
|
|
|
|
|
device.setDeviceName(deviceName);
|
|
|
|
|
|
|
|
device.setDeviceType(deviceTypeCode);
|
|
|
|
|
|
|
|
device.setSceneId(sceneId);
|
|
|
|
|
|
|
|
device.setMonitorUnitId(monitorUnitId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (deviceTypeCode) {
|
|
|
|
|
|
|
|
case HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE:
|
|
|
|
|
|
|
|
device.setNetworkingMode(HwDictConstants.DEVICE_NETWORKING_MODE_WIFI);
|
|
|
|
|
|
|
|
device.setAccessProtocol(HwDictConstants.DEVICE_ACCESS_PROTOCOL_MQTT);
|
|
|
|
|
|
|
|
device.setDataFormat(HwDictConstants.DEVICE_DATA_FORMAT_JSON);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT:
|
|
|
|
|
|
|
|
gatewayDeviceId = Long.valueOf(gateWayDeviceInfo.substring(0, gateWayDeviceInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
deviceModeId = Long.valueOf(deviceModeInfo.substring(0, deviceModeInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
device.setDeviceModeId(deviceModeId);
|
|
|
|
|
|
|
|
device.setReleatedDeviceId(gatewayDeviceId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE:
|
|
|
|
|
|
|
|
deviceModeId = Long.valueOf(deviceModeInfo.substring(0, deviceModeInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
device.setNetworkingMode(HwDictConstants.DEVICE_NETWORKING_MODE_WIFI);
|
|
|
|
|
|
|
|
device.setAccessProtocol(HwDictConstants.DEVICE_ACCESS_PROTOCOL_MQTT);
|
|
|
|
|
|
|
|
device.setDataFormat(HwDictConstants.DEVICE_DATA_FORMAT_JSON);
|
|
|
|
|
|
|
|
device.setDeviceModeId(deviceModeId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device.setTenantId(tenantId);
|
|
|
|
|
|
|
|
device.setCreateBy(operName);
|
|
|
|
|
|
|
|
device.setCreateTime(new Date());
|
|
|
|
|
|
|
|
hwDeviceMapper.insertHwDevice(device);
|
|
|
|
|
|
|
|
successNum++;
|
|
|
|
|
|
|
|
successMsg.append(
|
|
|
|
|
|
|
|
"<br/>" + successNum + "、 " + device.getDeviceName() + " 导入成功");
|
|
|
|
|
|
|
|
} else if (isUpdateSupport) {//不支持更新
|
|
|
|
|
|
|
|
// device.setDeviceId(d.getDeviceId());
|
|
|
|
|
|
|
|
// device.setUpdateBy(operName);
|
|
|
|
|
|
|
|
// device.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
// hwDeviceMapper.updateHwDevice(device);
|
|
|
|
|
|
|
|
successNum++;
|
|
|
|
|
|
|
|
successMsg.append(
|
|
|
|
|
|
|
|
"<br/>" + successNum + "、" + deviceImportVo.getDeviceName() + " 更新成功");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
failureNum++;
|
|
|
|
|
|
|
|
failureMsg.append(
|
|
|
|
|
|
|
|
"<br/>"
|
|
|
|
|
|
|
|
+ failureNum
|
|
|
|
|
|
|
|
+ "、"
|
|
|
|
|
|
|
|
+ deviceImportVo.getDeviceCode()
|
|
|
|
|
|
|
|
+ "、"
|
|
|
|
|
|
|
|
+ deviceImportVo.getDeviceName()
|
|
|
|
|
|
|
|
+ " 已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
failureNum++;
|
|
|
|
|
|
|
|
String msg = "<br/>" + failureNum + "、设备名称 " + deviceImportVo.getDeviceName() + " 导入失败:";
|
|
|
|
|
|
|
|
failureMsg.append(msg + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failureNum > 0) {
|
|
|
|
|
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
|
|
|
|
|
throw new ServiceException(failureMsg.toString());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return successMsg.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param: days
|
|
|
|
* @param: days
|
|
|
|
* @description 计算前几天的设备在线数量
|
|
|
|
* @description 计算前几天的设备在线数量
|
|
|
@ -889,4 +1013,73 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @return String
|
|
|
|
|
|
|
|
* @param: deviceImportVo
|
|
|
|
|
|
|
|
* @param: sceneId
|
|
|
|
|
|
|
|
* @param: infoSeparator
|
|
|
|
|
|
|
|
* @description 在导入设备信息时校验数据正确性
|
|
|
|
|
|
|
|
* @author xins
|
|
|
|
|
|
|
|
* @date 2023-11-10 10:50
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String checkImportDeviceData(HwDeviceImportVo deviceImportVo, Long sceneId, String infoSeparator) {
|
|
|
|
|
|
|
|
String deviceCode = deviceImportVo.getDeviceCode();
|
|
|
|
|
|
|
|
String deviceName = deviceImportVo.getDeviceName();
|
|
|
|
|
|
|
|
String deviceType = deviceImportVo.getDeviceType();
|
|
|
|
|
|
|
|
String monitorUnitInfo = deviceImportVo.getMonitorUnitInfo();
|
|
|
|
|
|
|
|
String gateWayDeviceInfo = deviceImportVo.getReleatedDeviceInfo();
|
|
|
|
|
|
|
|
String deviceModeInfo = deviceImportVo.getDeviceModeInfo();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceCode) || StringUtils.isEmpty(deviceName)
|
|
|
|
|
|
|
|
|| StringUtils.isEmpty(deviceType) || StringUtils.isEmpty(monitorUnitInfo)) {
|
|
|
|
|
|
|
|
return "设备编号、设备名称、监控单元和设备类型不能为空";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否是子级监控单元,并且属于此场景
|
|
|
|
|
|
|
|
Long monitorUnitId = Long.valueOf(monitorUnitInfo.substring(0, monitorUnitInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
HwMonitorUnit monitorUnit = hwMonitorUnitMapper.selectHwMonitorUnitByMonitorUnitId(monitorUnitId);
|
|
|
|
|
|
|
|
if (!monitorUnit.getSceneId().equals(sceneId)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 监控单元不属于所选择场景";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (monitorUnit.getParentId() != null && !monitorUnit.getParentId().equals(0L)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 此监控单元不是子级监控单元";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果是直连设备或子设备,必选选择设备模型,判断设备模型是否存在,并且属于此场景
|
|
|
|
|
|
|
|
if (deviceType.equals(DeviceTypeEnums.DIRECT_CONNECT_DEVICE.getDataType())
|
|
|
|
|
|
|
|
|| deviceType.equals(DeviceTypeEnums.SUB_DEVICE.getDataType())) {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceModeInfo)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 设备模型不能为空";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Long deviceModeId = Long.valueOf(deviceModeInfo.substring(0, deviceModeInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
HwDeviceMode deviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId);
|
|
|
|
|
|
|
|
if (deviceMode == null || deviceMode.getDeviceModeStatus().equals(HwDictConstants.DEVICE_MODE_STATUS_DELETED)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 设备模型不存在";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!deviceMode.getSceneId().equals(sceneId)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 设备模型不属于所选择场景";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果是网关子设备,必须有关联网关设备,并且关联网关设备属于此场景
|
|
|
|
|
|
|
|
if (deviceType.equals(DeviceTypeEnums.SUB_DEVICE.getDataType())) {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(gateWayDeviceInfo)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 关联网关设备不能为空";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Long gatewayDeviceId = Long.valueOf(gateWayDeviceInfo.substring(0, gateWayDeviceInfo.indexOf(infoSeparator)));
|
|
|
|
|
|
|
|
HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId);
|
|
|
|
|
|
|
|
if (gatewayDevice == null || gatewayDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_DELETE)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 关联网关设备不存在";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gatewayDevice.getSceneId().equals(sceneId)) {
|
|
|
|
|
|
|
|
return "设备名称 " + deviceImportVo.getDeviceName() + " 关联网关设备不属于所选择场景";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|