|
|
@@ -9,20 +9,30 @@ import com.github.microservice.types.deviceUse.DeviceCategory;
|
|
|
import com.github.microservice.types.deviceUse.DeviceType;
|
|
|
import com.github.microservice.types.deviceUse.OnLineState;
|
|
|
import com.zhongshu.iot.client.model.artemis.OperationMessageSearchParam;
|
|
|
+import com.zhongshu.iot.client.model.deskStatistics.TopologyTreeModel;
|
|
|
+import com.zhongshu.iot.client.model.deskStatistics.TopologyTreeSearch;
|
|
|
import com.zhongshu.iot.client.model.iot.statistics.DeviceStatisticsModel;
|
|
|
import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
|
|
|
import com.zhongshu.iot.client.type.OperationBusType;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
|
|
|
+import com.zhongshu.iot.server.core.dao.mqtt.GateWay2DeviceDao;
|
|
|
+import com.zhongshu.iot.server.core.dao.mqtt.GateWayUserInfoDao;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.OperationMessageDao;
|
|
|
+import com.zhongshu.iot.server.core.domain.iot.device.DeviceInfo;
|
|
|
+import com.zhongshu.iot.server.core.domain.iot.device.GateWay2Device;
|
|
|
+import com.zhongshu.iot.server.core.domain.iot.device.GateWayUserInfo;
|
|
|
import com.zhongshu.iot.server.core.util.CommonUtil;
|
|
|
import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 设备统计服务
|
|
|
@@ -40,6 +50,12 @@ public class DeviceStatisticsService {
|
|
|
@Autowired
|
|
|
private OperationMessageDao operationMessageDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GateWayUserInfoDao gateWayUserInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GateWay2DeviceDao gateWay2DeviceDao;
|
|
|
+
|
|
|
/**
|
|
|
* 设备等的统计
|
|
|
*
|
|
|
@@ -98,8 +114,7 @@ public class DeviceStatisticsService {
|
|
|
Long endTime = search.getEndTime();
|
|
|
// 已分钟一条数据
|
|
|
while (startTime <= endTime) {
|
|
|
- String minuteKey = com.zhongshu.card.client.utils.DateUtils.paresTime(startTime,
|
|
|
- com.zhongshu.card.client.utils.DateUtils.patternyyyyMMddHHmmKey);
|
|
|
+ String minuteKey = com.zhongshu.card.client.utils.DateUtils.paresTime(startTime, com.zhongshu.card.client.utils.DateUtils.patternyyyyMMddHHmmKey);
|
|
|
String xAxi = com.zhongshu.card.client.utils.DateUtils.paresTime(startTime, com.zhongshu.card.client.utils.DateUtils.patternHHmm);
|
|
|
|
|
|
xAxis.add(xAxi);
|
|
|
@@ -150,4 +165,84 @@ public class DeviceStatisticsService {
|
|
|
return pieModel;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 物联网设备数据拓扑图
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent<List<TopologyTreeModel>> deviceTopologyData(TopologyTreeSearch param) {
|
|
|
+ List<TopologyTreeModel> models = new ArrayList<>();
|
|
|
+ List<GateWayUserInfo> gateWayUserInfos = gateWayUserInfoDao.findByIsDelete(Boolean.FALSE);
|
|
|
+ if (ObjectUtils.isNotEmpty(gateWayUserInfos)) {
|
|
|
+ gateWayUserInfos = gateWayUserInfos.stream().filter(it -> {
|
|
|
+ return !it.getUserName().equals("admin");
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<DeviceInfo> deviceInfos = deviceInfoDao.findByIsDelete(Boolean.FALSE);
|
|
|
+ Map<String, List<DeviceInfo>> mqttUser2GateWayInfo = new HashMap<>();
|
|
|
+ for (DeviceInfo deviceInfo : deviceInfos) {
|
|
|
+ if (deviceInfo.getDeviceCategory() == DeviceCategory.GW) {
|
|
|
+ // 网关
|
|
|
+ List<DeviceInfo> list = new ArrayList<>();
|
|
|
+ if (mqttUser2GateWayInfo.containsKey(deviceInfo.getMqttUserName())) {
|
|
|
+ list = mqttUser2GateWayInfo.get(deviceInfo.getMqttUserName());
|
|
|
+ }
|
|
|
+ list.add(deviceInfo);
|
|
|
+ mqttUser2GateWayInfo.put(deviceInfo.getMqttUserName(), list);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ gateWayUserInfos.stream().forEach(it -> {
|
|
|
+ TopologyTreeModel mqttModel = mqttUserTopologyTreeModel(it);
|
|
|
+ // 查询网关信息
|
|
|
+ if (mqttUser2GateWayInfo.containsKey(it.getUserName())) {
|
|
|
+ List<DeviceInfo> gateWays = mqttUser2GateWayInfo.get(it.getUserName());
|
|
|
+ List<TopologyTreeModel> children = new ArrayList<>();
|
|
|
+ for (DeviceInfo deviceInfo : gateWays) {
|
|
|
+ TopologyTreeModel gateWayModel = deviceTopologyTreeModel(deviceInfo);
|
|
|
+ List<GateWay2Device> gateWay2Devices = gateWay2DeviceDao.findByGateWayInfo(deviceInfo);
|
|
|
+ if (ObjectUtils.isNotEmpty(gateWay2Devices)) {
|
|
|
+ List<TopologyTreeModel> deviceModels = gateWay2Devices.stream().map(it2 -> {
|
|
|
+ return deviceTopologyTreeModel(it2.getDeviceInfo());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ gateWayModel.setChildren(deviceModels);
|
|
|
+ }
|
|
|
+ children.add(gateWayModel);
|
|
|
+ }
|
|
|
+ mqttModel.setChildren(children);
|
|
|
+ }
|
|
|
+ models.add(mqttModel);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
+ }
|
|
|
+
|
|
|
+ private TopologyTreeModel deviceTopologyTreeModel(DeviceInfo entity) {
|
|
|
+ TopologyTreeModel model = new TopologyTreeModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model.setId(entity.getDeviceId());
|
|
|
+ model.setName(entity.getDeviceName());
|
|
|
+ model.setType(entity.getDeviceCategory().name());
|
|
|
+ model.setTypeStr(entity.getDeviceCategory().getRemark());
|
|
|
+ model.setTypeLevel2(entity.getDeviceType().name());
|
|
|
+ model.setTypeLevel2Str(entity.getDeviceType().getRemark());
|
|
|
+ model.setState(entity.getState().name());
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TopologyTreeModel mqttUserTopologyTreeModel(GateWayUserInfo entity) {
|
|
|
+ TopologyTreeModel model = new TopologyTreeModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model.setId(entity.getUserName());
|
|
|
+ model.setName(entity.getUserName());
|
|
|
+ model.setType("gatewayUser");
|
|
|
+ model.setTypeStr("连接账号");
|
|
|
+ model.setTypeLevel2("gatewayUser");
|
|
|
+ model.setTypeLevel2Str("连接账号");
|
|
|
+ model.setState(entity.getState().name());
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
}
|