|
|
|
@ -3,18 +3,12 @@ package com.ruoyi.business.service.impl;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
|
|
|
|
import com.ruoyi.business.domain.HwDevice;
|
|
|
|
|
import com.ruoyi.business.domain.HwDeviceMode;
|
|
|
|
|
import com.ruoyi.business.domain.HwDeviceModeFunction;
|
|
|
|
|
import com.ruoyi.business.domain.HwScene;
|
|
|
|
|
import com.ruoyi.business.domain.*;
|
|
|
|
|
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.HwDeviceMapper;
|
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
|
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceModeMapper;
|
|
|
|
|
import com.ruoyi.business.mapper.HwSceneMapper;
|
|
|
|
|
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;
|
|
|
|
@ -35,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -57,6 +52,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
private RemoteTdEngineService remoteTdEngineService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
@Autowired
|
|
|
|
|
private HwAlarmInfoMapper hwAlarmInfoMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询设备信息
|
|
|
|
@ -294,7 +291,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
list.get(i).setPercentage(NumberUtils.getPercentage(list.get(i).getSum(), sums));
|
|
|
|
|
System.out.println(list.get(i).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -343,97 +339,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
return hwDeviceMapper.updateHwDevice(hwDevice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: deviceControlVo
|
|
|
|
|
* @description 下发当网关,主题带设备编号
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-25 14:56
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void publishControlCommand(DeviceControlVo deviceControlVo) {
|
|
|
|
|
JSONObject controlCommandJson = new JSONObject();
|
|
|
|
|
StringBuilder controlCommandTopic = new StringBuilder();
|
|
|
|
|
Long deviceId = deviceControlVo.getDeviceId();
|
|
|
|
|
HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId);
|
|
|
|
|
String deviceType = device.getDeviceType();
|
|
|
|
|
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
|
|
|
|
|
Long gatewayDeviceId = device.getReleatedDeviceId();
|
|
|
|
|
HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId);
|
|
|
|
|
controlCommandTopic.append(StringUtils
|
|
|
|
|
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode()));
|
|
|
|
|
} else {
|
|
|
|
|
controlCommandTopic.append(StringUtils
|
|
|
|
|
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode()));
|
|
|
|
|
}
|
|
|
|
|
JSONObject payloadJson = new JSONObject();
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode());
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位:s
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType());
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}");
|
|
|
|
|
|
|
|
|
|
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString());
|
|
|
|
|
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString());
|
|
|
|
|
|
|
|
|
|
System.out.println("---" + controlCommandJson.toString());
|
|
|
|
|
redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: hwDevice 前端传的对象
|
|
|
|
|
* @param: dbDevice 目前数据库的对象
|
|
|
|
|
* @description 更新TdEngine数据库tag
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-19 10:55
|
|
|
|
|
*/
|
|
|
|
|
private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) {
|
|
|
|
|
String deviceType = hwDevice.getDeviceType();
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId());
|
|
|
|
|
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
|
alterTagVo.setTableName(tableName);
|
|
|
|
|
R<?> tdReturnMsg;
|
|
|
|
|
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE)
|
|
|
|
|
|| deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
|
|
|
|
|
if (!hwDevice.getDeviceCode().equals(dbDevice.getDeviceCode())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'");
|
|
|
|
|
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'");
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getMonitorUnitId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getDeviceModeId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量删除设备信息
|
|
|
|
|
*
|
|
|
|
@ -452,8 +357,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
* @return 结果 true 存在 false 不存在
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean checkExistSubDevice(Long releatedDeviceId)
|
|
|
|
|
{
|
|
|
|
|
public boolean checkExistSubDevice(Long releatedDeviceId) {
|
|
|
|
|
int result = hwDeviceMapper.checkExistSubDevice(releatedDeviceId);
|
|
|
|
|
return result > 0;
|
|
|
|
|
}
|
|
|
|
@ -580,7 +484,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
return devicesMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询设备信息列表,join监控单元、设备模型等表
|
|
|
|
|
*
|
|
|
|
@ -593,7 +496,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
return hwDeviceMapper.selectHwDeviceJoinList(hwDevice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: days
|
|
|
|
|
* @description 计算前几天的设备在线数量
|
|
|
|
@ -626,6 +528,185 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO, jsonObject.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: deviceControlVo
|
|
|
|
|
* @description 下发当网关,主题带设备编号
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-25 14:56
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void publishControlCommand(DeviceControlVo deviceControlVo) {
|
|
|
|
|
JSONObject controlCommandJson = new JSONObject();
|
|
|
|
|
StringBuilder controlCommandTopic = new StringBuilder();
|
|
|
|
|
Long deviceId = deviceControlVo.getDeviceId();
|
|
|
|
|
HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId);
|
|
|
|
|
String deviceType = device.getDeviceType();
|
|
|
|
|
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
|
|
|
|
|
Long gatewayDeviceId = device.getReleatedDeviceId();
|
|
|
|
|
HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId);
|
|
|
|
|
controlCommandTopic.append(StringUtils
|
|
|
|
|
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode()));
|
|
|
|
|
} else {
|
|
|
|
|
controlCommandTopic.append(StringUtils
|
|
|
|
|
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode()));
|
|
|
|
|
}
|
|
|
|
|
JSONObject payloadJson = new JSONObject();
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode());
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位:s
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType());
|
|
|
|
|
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}");
|
|
|
|
|
|
|
|
|
|
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString());
|
|
|
|
|
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString());
|
|
|
|
|
|
|
|
|
|
redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return HwDevice
|
|
|
|
|
* @param: deviceCode
|
|
|
|
|
* @description 根据设备编号获取设备信息
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-28 13:24
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public HwDevice selectHwDeviceByDeviceCode(String deviceCode) {
|
|
|
|
|
return hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return String
|
|
|
|
|
* @param: sceneId
|
|
|
|
|
* @description 获取最近几天在线设备数量
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-21 9:09
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getOnlineDevicesCount(Long sceneId) {
|
|
|
|
|
JSONObject returnObj = new JSONObject();
|
|
|
|
|
int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId);
|
|
|
|
|
|
|
|
|
|
JSONObject sortedJsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO);
|
|
|
|
|
if (onlineDeviceCountJsonStr != null) {
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr);
|
|
|
|
|
|
|
|
|
|
jsonObject.forEach((key, value) -> {
|
|
|
|
|
String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key)));
|
|
|
|
|
sortedJsonObject.put(dateStrKey, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
returnObj.put("onlineDevicesTrend", sortedJsonObject);
|
|
|
|
|
returnObj.put("onlineDevicesCount", onlineDevicesCount);
|
|
|
|
|
return returnObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: monitorUnitId
|
|
|
|
|
* @description 根据监控单元ID获取设备情况(包括在线和离线设备数量,正常的设备数量和报警的设备数量)
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-28 14:25
|
|
|
|
|
* @return DevicesInfoVo
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) {
|
|
|
|
|
HwDevice queryDevice = new HwDevice();
|
|
|
|
|
queryDevice.setMonitorUnitId(monitorUnitId);
|
|
|
|
|
queryDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH);
|
|
|
|
|
List<HwDevice> devices = this.selectHwDeviceList(queryDevice);
|
|
|
|
|
Map<String, List<HwDevice>> hwDevicesMap = devices.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(HwDevice::getDeviceType));
|
|
|
|
|
List<HwDevice> gatewayDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE);
|
|
|
|
|
List<HwDevice> subDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
|
|
|
|
|
//根据关联网关设备ID进行分组
|
|
|
|
|
Map<Long, List<HwDevice>> releatedDeviceIdDevicesMap = subDevices.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(HwDevice::getReleatedDeviceId));
|
|
|
|
|
int onlineDevicesCount = 0;
|
|
|
|
|
int offlineDevicesCount = 0;
|
|
|
|
|
for (HwDevice gatewayDevice : gatewayDevices) {
|
|
|
|
|
String onlineStatus = gatewayDevice.getOnlineStatus();
|
|
|
|
|
//获取关联子设备的数量
|
|
|
|
|
int gatewaySubPublishedDevicesCount =
|
|
|
|
|
releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()) == null ?
|
|
|
|
|
0 : releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()).size();
|
|
|
|
|
if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
|
|
|
|
|
onlineDevicesCount += gatewaySubPublishedDevicesCount;
|
|
|
|
|
} else if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) {
|
|
|
|
|
offlineDevicesCount += gatewaySubPublishedDevicesCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int alarmDevicesCount = hwAlarmInfoMapper.selectAlarmCountByMonitorUnitId(monitorUnitId);
|
|
|
|
|
int normalDevicesCount = onlineDevicesCount + offlineDevicesCount - alarmDevicesCount;
|
|
|
|
|
|
|
|
|
|
DevicesInfoVo devicesInfoVo = new DevicesInfoVo();
|
|
|
|
|
devicesInfoVo.setOnlineDevicesCount(onlineDevicesCount);
|
|
|
|
|
devicesInfoVo.setOfflineDevicesCount(offlineDevicesCount);
|
|
|
|
|
devicesInfoVo.setNormalDevicesCount(normalDevicesCount);
|
|
|
|
|
devicesInfoVo.setAlarmDevicesCount(alarmDevicesCount);
|
|
|
|
|
|
|
|
|
|
return devicesInfoVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param: hwDevice 前端传的对象
|
|
|
|
|
* @param: dbDevice 目前数据库的对象
|
|
|
|
|
* @description 更新TdEngine数据库tag
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-19 10:55
|
|
|
|
|
*/
|
|
|
|
|
private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) {
|
|
|
|
|
String deviceType = hwDevice.getDeviceType();
|
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId());
|
|
|
|
|
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
|
|
|
|
|
AlterTagVo alterTagVo = new AlterTagVo();
|
|
|
|
|
alterTagVo.setDatabaseName(databaseName);
|
|
|
|
|
alterTagVo.setTableName(tableName);
|
|
|
|
|
R<?> tdReturnMsg;
|
|
|
|
|
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE)
|
|
|
|
|
|| deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
|
|
|
|
|
if (!hwDevice.getDeviceCode().equals(dbDevice.getDeviceCode())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'");
|
|
|
|
|
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME);
|
|
|
|
|
alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'");
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getMonitorUnitId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) {
|
|
|
|
|
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID);
|
|
|
|
|
alterTagVo.setTagValue(hwDevice.getDeviceModeId());
|
|
|
|
|
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
|
|
|
|
|
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
|
|
|
|
|
throw new RuntimeException(tdReturnMsg.getMsg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) {
|
|
|
|
|
//先增加需要查询的字段名称(由于tdengine用last和last_row查询时字段显示有bug,所以需要设置要查询的字段)
|
|
|
|
|
List<TdField> schemaFields = new ArrayList<TdField>();
|
|
|
|
@ -715,35 +796,4 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return String
|
|
|
|
|
* @param: sceneId
|
|
|
|
|
* @description 获取最近几天在线设备数量
|
|
|
|
|
* @author xins
|
|
|
|
|
* @date 2023-09-21 9:09
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getOnlineDevicesCount(Long sceneId) {
|
|
|
|
|
JSONObject returnObj = new JSONObject();
|
|
|
|
|
int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId);
|
|
|
|
|
|
|
|
|
|
JSONObject sortedJsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO);
|
|
|
|
|
if (onlineDeviceCountJsonStr != null) {
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr);
|
|
|
|
|
|
|
|
|
|
jsonObject.forEach((key, value) -> {
|
|
|
|
|
String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key)));
|
|
|
|
|
sortedJsonObject.put(dateStrKey, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
returnObj.put("onlineDevicesTrend", sortedJsonObject);
|
|
|
|
|
returnObj.put("onlineDevicesCount", onlineDevicesCount);
|
|
|
|
|
return returnObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|