|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
|
|
|
import com.ruoyi.business.domain.HwDevice;
|
|
|
|
import com.ruoyi.business.domain.HwDevice;
|
|
|
|
|
|
|
|
import com.ruoyi.business.domain.HwDeviceMode;
|
|
|
|
import com.ruoyi.business.domain.HwDeviceModeFunction;
|
|
|
|
import com.ruoyi.business.domain.HwDeviceModeFunction;
|
|
|
|
import com.ruoyi.business.domain.HwScene;
|
|
|
|
import com.ruoyi.business.domain.HwScene;
|
|
|
|
import com.ruoyi.business.domain.VO.DeviceControlVo;
|
|
|
|
import com.ruoyi.business.domain.VO.DeviceControlVo;
|
|
|
@ -12,6 +13,7 @@ import com.ruoyi.business.domain.VO.DeviceModeVo;
|
|
|
|
import com.ruoyi.business.domain.VO.HwDeviceVo;
|
|
|
|
import com.ruoyi.business.domain.VO.HwDeviceVo;
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceMapper;
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceMapper;
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
|
|
|
|
|
|
|
|
import com.ruoyi.business.mapper.HwDeviceModeMapper;
|
|
|
|
import com.ruoyi.business.mapper.HwSceneMapper;
|
|
|
|
import com.ruoyi.business.mapper.HwSceneMapper;
|
|
|
|
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;
|
|
|
@ -46,6 +48,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private HwDeviceMapper hwDeviceMapper;
|
|
|
|
private HwDeviceMapper hwDeviceMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private HwDeviceModeMapper hwDeviceModeMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private HwSceneMapper hwSceneMapper;
|
|
|
|
private HwSceneMapper hwSceneMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
|
|
|
|
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
|
|
|
@ -75,7 +79,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) {
|
|
|
|
public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) {
|
|
|
|
return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
|
|
|
|
HwDevice device = hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
|
|
|
|
|
|
|
|
Long deviceModeId = device.getDeviceModeId();
|
|
|
|
|
|
|
|
if (deviceModeId != null) {
|
|
|
|
|
|
|
|
HwDeviceMode mode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId);
|
|
|
|
|
|
|
|
device.setGpsFlag(mode != null ? mode.getGpsFlag() : HwDictConstants.DEVICEMODE_GPS_FLAG_NO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -317,6 +327,58 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
return rows;
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 修改设备状态
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param hwDevice 设备信息
|
|
|
|
|
|
|
|
* @return 结果
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int changeDeviceStatus(HwDevice hwDevice) {
|
|
|
|
|
|
|
|
HwDevice dbDevice = hwDeviceMapper.selectHwDeviceByDeviceId(hwDevice.getDeviceId());
|
|
|
|
|
|
|
|
if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) {
|
|
|
|
|
|
|
|
throw new ServiceException("已发布状态不能修改");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hwDevice.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
|
|
|
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: hwDevice 前端传的对象
|
|
|
|
* @param: dbDevice 目前数据库的对象
|
|
|
|
* @param: dbDevice 目前数据库的对象
|
|
|
@ -494,8 +556,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
|
|
|
|
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
|
|
|
|
hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE);
|
|
|
|
hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE);
|
|
|
|
hwDeviceVo.setDeviceDataMap(ddValueMap);
|
|
|
|
hwDeviceVo.setDeviceDataMap(ddValueMap);
|
|
|
|
//TODO:去掉下边一行
|
|
|
|
|
|
|
|
ddValueMap.put("ii", "http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg");
|
|
|
|
|
|
|
|
acquisitionDeviceVos.add(hwDeviceVo);
|
|
|
|
acquisitionDeviceVos.add(hwDeviceVo);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -553,50 +613,76 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) {
|
|
|
|
private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) {
|
|
|
|
|
|
|
|
//先增加需要查询的字段名称(由于tdengine用last和last_row查询时字段显示有bug,所以需要设置要查询的字段)
|
|
|
|
|
|
|
|
List<TdField> schemaFields = new ArrayList<TdField>();
|
|
|
|
|
|
|
|
TdField deviceTypeField = new TdField();
|
|
|
|
|
|
|
|
deviceTypeField.setFieldName(TdEngineConstants.ST_TAG_DEVICETYPE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TdField onlineStatusField = new TdField();
|
|
|
|
|
|
|
|
onlineStatusField.setFieldName(TdEngineConstants.ST_TAG_ONLINESTATUS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
schemaFields.add(deviceTypeField);
|
|
|
|
|
|
|
|
schemaFields.add(onlineStatusField);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceStatus queryGroupStatus = new DeviceStatus();
|
|
|
|
DeviceStatus queryGroupStatus = new DeviceStatus();
|
|
|
|
queryGroupStatus.setStartTime(startTime);
|
|
|
|
queryGroupStatus.setStartTime(startTime);
|
|
|
|
queryGroupStatus.setEndTime(endTime);
|
|
|
|
queryGroupStatus.setEndTime(endTime);
|
|
|
|
|
|
|
|
queryGroupStatus.setSchemaFields(schemaFields);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceStatus queryLastStatus = new DeviceStatus();
|
|
|
|
DeviceStatus queryLastStatus = new DeviceStatus();
|
|
|
|
queryLastStatus.setEndTime(startTime);
|
|
|
|
queryLastStatus.setEndTime(startTime);
|
|
|
|
|
|
|
|
queryLastStatus.setSchemaFields(schemaFields);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// System.out.println(DateUtils.dateTime(new Date(startTime)) + "----" + DateUtils.dateTime(new Date(endTime)));
|
|
|
|
Map<Long, Integer> onlineDeviceCountByDay = new HashMap<Long, Integer>();
|
|
|
|
Map<Long, Integer> onlineDeviceCountByDay = new HashMap<Long, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//先获取starttime和endtime时间范围内在线的设备状态信息
|
|
|
|
Map<Long, List<DeviceStatus>> groupDeviceStatuMapList =
|
|
|
|
Map<Long, List<DeviceStatus>> groupDeviceStatuMapList =
|
|
|
|
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData();
|
|
|
|
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData();
|
|
|
|
if (groupDeviceStatuMapList == null) {
|
|
|
|
if (groupDeviceStatuMapList == null) {
|
|
|
|
groupDeviceStatuMapList = new HashMap<>();
|
|
|
|
groupDeviceStatuMapList = new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取在endtime之前最后的设备状态信息(有些设备会一直在线,没有连续的上线下线记录,所以要获取最近的设备状态信息来补齐后面的设备在线情况)
|
|
|
|
List<Map<String, Object>> lastDeviceStatuMapList =
|
|
|
|
List<Map<String, Object>> lastDeviceStatuMapList =
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData();
|
|
|
|
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData();
|
|
|
|
for (Map<String, Object> groupDeviceStatuMap : lastDeviceStatuMapList) {
|
|
|
|
if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
|
|
|
|
DeviceStatus ds = new DeviceStatus();
|
|
|
|
onlineDeviceCountByDay.put(startTime, 0);
|
|
|
|
for (Map.Entry<String, Object> entry : groupDeviceStatuMap.entrySet()) {
|
|
|
|
} else {
|
|
|
|
if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICEID)) {
|
|
|
|
for (Map<String, Object> groupDeviceStatuMap : lastDeviceStatuMapList) {
|
|
|
|
ds.setDeviceId((long) (Integer) entry.getValue());
|
|
|
|
DeviceStatus ds = new DeviceStatus();
|
|
|
|
} else if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICETYPE)) {
|
|
|
|
for (Map.Entry<String, Object> entry : groupDeviceStatuMap.entrySet()) {
|
|
|
|
ds.setDeviceType((Integer) entry.getValue());
|
|
|
|
switch (entry.getKey()) {
|
|
|
|
} else if (entry.getKey().equals(TdEngineConstants.ST_TAG_ONLINESTATUS)) {
|
|
|
|
case TdEngineConstants.ST_TAG_DEVICEID:
|
|
|
|
ds.setOnlineStatus((Integer) entry.getValue());
|
|
|
|
ds.setDeviceId((long) (Integer) entry.getValue());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TdEngineConstants.ST_TAG_DEVICETYPE:
|
|
|
|
|
|
|
|
ds.setDeviceType((Integer) entry.getValue());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TdEngineConstants.ST_TAG_ONLINESTATUS:
|
|
|
|
|
|
|
|
ds.setOnlineStatus((Integer) entry.getValue());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());
|
|
|
|
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
if (dss == null) {
|
|
|
|
if (dss == null) {
|
|
|
|
if (String.valueOf(ds.getOnlineStatus())
|
|
|
|
if (String.valueOf(ds.getOnlineStatus())
|
|
|
|
.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
|
|
|
|
.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
|
|
|
|
count = this.getDeviceCount(ds);
|
|
|
|
count = this.getDeviceCount(ds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
count = this.getDeviceCount(dss.get(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
count = this.getDeviceCount(dss.get(0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (onlineDeviceCountByDay.get(startTime) == null) {
|
|
|
|
if (onlineDeviceCountByDay.get(startTime) == null) {
|
|
|
|
onlineDeviceCountByDay.put(startTime, count);
|
|
|
|
onlineDeviceCountByDay.put(startTime, count);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count);
|
|
|
|
onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -646,16 +732,4 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param: deviceControlVo
|
|
|
|
|
|
|
|
* @description 下发当网关,主题带设备编号
|
|
|
|
|
|
|
|
* @author xins
|
|
|
|
|
|
|
|
* @date 2023-09-25 14:56
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void publishControlCommand(DeviceControlVo deviceControlVo) {
|
|
|
|
|
|
|
|
String channel = "";
|
|
|
|
|
|
|
|
String message = "";
|
|
|
|
|
|
|
|
redisTemplate.convertAndSend(channel, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|