|
|
|
@ -12,6 +12,7 @@ import com.ruoyi.business.mapper.*;
|
|
|
|
|
import com.ruoyi.business.service.IHwDeviceService;
|
|
|
|
|
import com.ruoyi.common.core.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.core.constant.HwDictConstants;
|
|
|
|
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
|
|
|
|
import com.ruoyi.common.core.constant.TdEngineConstants;
|
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
|
|
import com.ruoyi.common.core.enums.DataTypeEnums;
|
|
|
|
@ -193,7 +194,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
*/
|
|
|
|
|
private void createTdTable(HwDevice hwDevice) {
|
|
|
|
|
TdTableVo tdTableVo = new TdTableVo();
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId());
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
|
String superTableName = TdEngineConstants.getSuperTableName(hwDevice.getDeviceModeId());
|
|
|
|
|
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
|
|
|
|
|
|
|
|
|
@ -204,7 +205,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
tdTableVo.setTableName(tableName);
|
|
|
|
|
tdTableVo.setTagsFieldValues(tagsFields);
|
|
|
|
|
|
|
|
|
|
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo);
|
|
|
|
|
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -225,7 +226,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
|
|
|
|
|
tdTableVo.setTagsFieldValues(tagsFields);
|
|
|
|
|
|
|
|
|
|
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo);
|
|
|
|
|
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -390,8 +391,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
Map<String, List<HwDeviceVo>> devicesMap = new HashMap<String, List<HwDeviceVo>>();
|
|
|
|
|
List<HwDeviceVo> controlDeviceVos = new ArrayList<HwDeviceVo>();
|
|
|
|
|
List<HwDeviceVo> acquisitionDeviceVos = new ArrayList<HwDeviceVo>();
|
|
|
|
|
Long sceneId = queryHwDevice.getSceneId();
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName(sceneId);
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
|
|
|
|
|
|
queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
|
|
|
|
|
List<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice);
|
|
|
|
@ -411,7 +411,9 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
deviceModeFunctions.forEach(mf -> {
|
|
|
|
|
if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
|
|
|
|
|
TdField field = new TdField();
|
|
|
|
|
field.setFieldName(mf.getFunctionIdentifier());
|
|
|
|
|
String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(mf.getFunctionIdentifier());
|
|
|
|
|
String functionIdentifier = functionIdentifierTransfer == null ? mf.getFunctionIdentifier() : functionIdentifierTransfer;
|
|
|
|
|
field.setFieldName(functionIdentifier);
|
|
|
|
|
schemaFieldValues.add(field);
|
|
|
|
|
} else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) {
|
|
|
|
|
modeFunctions.add(mf);
|
|
|
|
@ -421,7 +423,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
tdSelectDto.setSchemaFieldValues(schemaFieldValues);
|
|
|
|
|
//从tdengine获取此设备的最新数据
|
|
|
|
|
List<Map<String, Object>> deviceLatestDataMapList =
|
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData();
|
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto, SecurityConstants.INNER).getData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取此设备模型的功能列表
|
|
|
|
@ -437,8 +439,16 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
|
|
|
|
|
//转换成map,key为标识符,value为功能名称(主要tdengine存的是标识符,用来下面转换成功能名称)
|
|
|
|
|
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
|
|
|
|
|
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
|
|
|
|
|
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier,
|
|
|
|
|
HwDeviceModeFunction::getFunctionName));
|
|
|
|
|
Map<String, String> functionIndentifierNameMap = new HashMap<>();
|
|
|
|
|
functionIndentifierName.forEach((key, val) ->
|
|
|
|
|
{
|
|
|
|
|
String keyTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ?
|
|
|
|
|
key : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key);
|
|
|
|
|
functionIndentifierNameMap.put(keyTransfer, val);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//获取可控制设备,根据是否有服务判断
|
|
|
|
|
// List<HwDeviceModeFunction> modeFunctions = deviceModeFunctions.stream()
|
|
|
|
|
// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)
|
|
|
|
@ -451,6 +461,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE);
|
|
|
|
|
hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode());
|
|
|
|
|
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
|
|
|
|
|
hwDeviceVo.setDevicePic(hwDevice.getDevicePic());
|
|
|
|
|
hwDeviceVo.setDeviceModeFunction(modeFunction);
|
|
|
|
|
controlDeviceVos.add(hwDeviceVo);
|
|
|
|
|
});
|
|
|
|
@ -462,12 +473,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
deviceLatestDataMapList.forEach(deviceLatestDataMap -> {
|
|
|
|
|
Set<String> functionIdentifiers = deviceLatestDataMap.keySet();
|
|
|
|
|
for (String dataFunctionIdentifier : functionIdentifiers) {
|
|
|
|
|
if (functionIndentifierName.get(dataFunctionIdentifier) != null) {
|
|
|
|
|
ddValueMap.put(functionIndentifierName.get(dataFunctionIdentifier),
|
|
|
|
|
if (functionIndentifierNameMap.get(dataFunctionIdentifier) != null) {
|
|
|
|
|
ddValueMap.put(functionIndentifierNameMap.get(dataFunctionIdentifier),
|
|
|
|
|
deviceLatestDataMap.get(dataFunctionIdentifier));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//不论是否是控制型设备都显示最新数据
|
|
|
|
@ -609,11 +619,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return DevicesInfoVo
|
|
|
|
|
* @param: monitorUnitId
|
|
|
|
|
* @description 根据监控单元ID获取设备情况(包括在线和离线设备数量,正常的设备数量和报警的设备数量)
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-28 14:25
|
|
|
|
|
* @return DevicesInfoVo
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) {
|
|
|
|
@ -655,6 +665,21 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
return devicesInfoVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 重建tdengine所有设备表
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-10-10 20:05
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void rebuildTdTables() {
|
|
|
|
|
HwDevice queryDevice = new HwDevice();
|
|
|
|
|
queryDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
|
|
|
|
|
List<HwDevice> devices = hwDeviceMapper.selectHwDeviceList(queryDevice);
|
|
|
|
|
devices.forEach(device -> {
|
|
|
|
|
this.createTdTable(device);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: hwDevice 前端传的对象
|
|
|
|
|
* @param: dbDevice 目前数据库的对象
|
|
|
|
@ -664,7 +689,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
*/
|
|
|
|
|
private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) {
|
|
|
|
|
String deviceType = hwDevice.getDeviceType();
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId());
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
|
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
@ -676,7 +701,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'");
|
|
|
|
|
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -684,7 +709,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'");
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -693,7 +718,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getMonitorUnitId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -702,7 +727,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getDeviceModeId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
@ -737,14 +762,14 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
|
|
|
|
|
//先获取starttime和endtime时间范围内在线的设备状态信息
|
|
|
|
|
Map<Long, List<DeviceStatus>> groupDeviceStatuMapList =
|
|
|
|
|
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData();
|
|
|
|
|
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus, SecurityConstants.INNER).getData();
|
|
|
|
|
if (groupDeviceStatuMapList == null) {
|
|
|
|
|
groupDeviceStatuMapList = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取在endtime之前最后的设备状态信息(有些设备会一直在线,没有连续的上线下线记录,所以要获取最近的设备状态信息来补齐后面的设备在线情况)
|
|
|
|
|
List<Map<String, Object>> lastDeviceStatuMapList =
|
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData();
|
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus, SecurityConstants.INNER).getData();
|
|
|
|
|
if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
|
|
|
|
|
onlineDeviceCountByDay.put(startTime, 0);
|
|
|
|
|
} else {
|
|
|
|
|