|
@@ -1,6 +1,9 @@
|
|
package com.usky.issue.service.impl;
|
|
package com.usky.issue.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.usky.common.core.bean.CommonPage;
|
|
import com.usky.common.core.bean.CommonPage;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.issue.domain.YtDeviceStatus;
|
|
import com.usky.issue.domain.YtDeviceStatus;
|
|
@@ -71,53 +74,60 @@ public class YtDeviceStatusServiceImpl extends AbstractCrudService<YtDeviceStatu
|
|
根据传入单位编号查询所有设备信息
|
|
根据传入单位编号查询所有设备信息
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<Map<String, Object>> deviceList(YtDeviceStatusRequestVO requestVO) {
|
|
|
|
- String companyCode = requestVO.getCompanyCode();
|
|
|
|
|
|
+ public List<Map<String, Object>> deviceList(String requestBody) {
|
|
|
|
+ JSONObject requestVO = JSONObject.parseObject(requestBody);
|
|
|
|
+ String companyCode = requestVO.get("companyCode").toString();
|
|
|
|
+ QueryWrapper<YtDeviceStatus> queryWrapper = Wrappers.query();
|
|
|
|
+ queryWrapper.select("device_type AS deviceType","COUNT(*) AS deviceTypeCounts","COUNT(difference < 48 OR " +
|
|
|
|
+ "NULL) AS onlineCount","COUNT(difference >= 48 OR NULL) AS offlineCount")
|
|
|
|
+ .eq("company_code",companyCode)
|
|
|
|
+ .groupBy("device_type");
|
|
|
|
+ List<Map<String, Object>> deviceStatusList = this.listMaps(queryWrapper);
|
|
// 查询各类型设备的总数以及在线、离线设备数量
|
|
// 查询各类型设备的总数以及在线、离线设备数量
|
|
- List<Map<String, Object>> statusCounts = ytDeviceStatusMapper.deviceList(companyCode);
|
|
|
|
- Map<String, Map<String, Integer>> statusMap = new HashMap<>();
|
|
|
|
- for (Map<String, Object> statusCount : statusCounts) {
|
|
|
|
- String deviceType = (String) statusCount.get("deviceType");
|
|
|
|
- Integer onlineCount = ((Number) statusCount.get("onlineCount")).intValue();
|
|
|
|
- Integer offlineCount = ((Number) statusCount.get("offlineCount")).intValue();
|
|
|
|
- statusMap.computeIfAbsent(deviceType, k -> new HashMap<>())
|
|
|
|
- .put("onlineCount", onlineCount);
|
|
|
|
- statusMap.computeIfAbsent(deviceType, k -> new HashMap<>())
|
|
|
|
- .put("offlineCount", offlineCount);
|
|
|
|
- int totalCount = ((Number) statusCount.get("deviceTypeCounts")).intValue();
|
|
|
|
- statusMap.computeIfAbsent(deviceType, k -> new HashMap<>()).put("deviceTypeCounts", totalCount);
|
|
|
|
- }
|
|
|
|
- // 统计设备总数和在线、离线设备数
|
|
|
|
- Map<String, Integer> deviceTypeCounts = new HashMap<>();
|
|
|
|
- Map<String, Integer> onlineDeviceCount = new HashMap<>();
|
|
|
|
- Map<String, Integer> offlineDeviceCount = new HashMap<>();
|
|
|
|
-
|
|
|
|
- // 设置设备状态并统计设备数量
|
|
|
|
- List<Map<String, Object>> deviceList = ytDeviceStatusMapper.deviceList(companyCode);
|
|
|
|
- for (Map<String, Object> device : deviceList) {
|
|
|
|
- String deviceType = (String) device.get("deviceType");
|
|
|
|
- deviceTypeCounts.merge(deviceType, (Integer) statusMap.getOrDefault(deviceType, Collections.emptyMap()).getOrDefault("deviceTypeCounts", 0), Integer::sum);
|
|
|
|
-
|
|
|
|
- Integer onlineCount = statusMap.getOrDefault(deviceType, Collections.emptyMap())
|
|
|
|
- .getOrDefault("onlineCount", 0);
|
|
|
|
- Integer offlineCount = statusMap.getOrDefault(deviceType, Collections.emptyMap())
|
|
|
|
- .getOrDefault("offlineCount", 0);
|
|
|
|
- Integer currentOnlineCount = onlineDeviceCount.getOrDefault(deviceType, 0);
|
|
|
|
- Integer currentOfflineCount = offlineDeviceCount.getOrDefault(deviceType, 0);
|
|
|
|
- onlineDeviceCount.put(deviceType, currentOnlineCount + onlineCount);
|
|
|
|
- offlineDeviceCount.put(deviceType, currentOfflineCount + offlineCount);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 添加设备类型、设备总数和在线、离线设备数到结果列表
|
|
|
|
- List<Map<String, Object>> deviceStatusList = new ArrayList<>();
|
|
|
|
- for (String deviceType : deviceTypeCounts.keySet()) {
|
|
|
|
- Map<String, Object> deviceInfo = new HashMap<>();
|
|
|
|
- deviceInfo.put("deviceType", deviceType);
|
|
|
|
- deviceInfo.put("deviceTypeCounts", deviceTypeCounts.getOrDefault(deviceType, 0));
|
|
|
|
- deviceInfo.put("onlineDeviceCount", onlineDeviceCount.getOrDefault(deviceType, 0));
|
|
|
|
- deviceInfo.put("offlineDeviceCount", offlineDeviceCount.getOrDefault(deviceType, 0));
|
|
|
|
- deviceStatusList.add(deviceInfo);
|
|
|
|
- }
|
|
|
|
|
|
+// List<Map<String, Object>> statusCounts = ytDeviceStatusMapper.deviceList(companyCode);
|
|
|
|
+// Map<String, Map<String, Integer>> statusMap = new HashMap<>();
|
|
|
|
+// for (Map<String, Object> statusCount : statusCounts) {
|
|
|
|
+// String deviceType = (String) statusCount.get("deviceType");
|
|
|
|
+// Integer onlineCount = ((Number) statusCount.get("onlineCount")).intValue();
|
|
|
|
+// Integer offlineCount = ((Number) statusCount.get("offlineCount")).intValue();
|
|
|
|
+// statusMap.computeIfAbsent(deviceType, k -> new HashMap<>())
|
|
|
|
+// .put("onlineCount", onlineCount);
|
|
|
|
+// statusMap.computeIfAbsent(deviceType, k -> new HashMap<>())
|
|
|
|
+// .put("offlineCount", offlineCount);
|
|
|
|
+// int totalCount = ((Number) statusCount.get("deviceTypeCounts")).intValue();
|
|
|
|
+// statusMap.computeIfAbsent(deviceType, k -> new HashMap<>()).put("deviceTypeCounts", totalCount);
|
|
|
|
+// }
|
|
|
|
+// // 统计设备总数和在线、离线设备数
|
|
|
|
+// Map<String, Integer> deviceTypeCounts = new HashMap<>();
|
|
|
|
+// Map<String, Integer> onlineDeviceCount = new HashMap<>();
|
|
|
|
+// Map<String, Integer> offlineDeviceCount = new HashMap<>();
|
|
|
|
+//
|
|
|
|
+// // 设置设备状态并统计设备数量
|
|
|
|
+// List<Map<String, Object>> deviceList = ytDeviceStatusMapper.deviceList(companyCode);
|
|
|
|
+// for (Map<String, Object> device : deviceList) {
|
|
|
|
+// String deviceType = (String) device.get("deviceType");
|
|
|
|
+// deviceTypeCounts.merge(deviceType, (Integer) statusMap.getOrDefault(deviceType, Collections.emptyMap()).getOrDefault("deviceTypeCounts", 0), Integer::sum);
|
|
|
|
+//
|
|
|
|
+// Integer onlineCount = statusMap.getOrDefault(deviceType, Collections.emptyMap())
|
|
|
|
+// .getOrDefault("onlineCount", 0);
|
|
|
|
+// Integer offlineCount = statusMap.getOrDefault(deviceType, Collections.emptyMap())
|
|
|
|
+// .getOrDefault("offlineCount", 0);
|
|
|
|
+// Integer currentOnlineCount = onlineDeviceCount.getOrDefault(deviceType, 0);
|
|
|
|
+// Integer currentOfflineCount = offlineDeviceCount.getOrDefault(deviceType, 0);
|
|
|
|
+// onlineDeviceCount.put(deviceType, currentOnlineCount + onlineCount);
|
|
|
|
+// offlineDeviceCount.put(deviceType, currentOfflineCount + offlineCount);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 添加设备类型、设备总数和在线、离线设备数到结果列表
|
|
|
|
+// List<Map<String, Object>> deviceStatusList = new ArrayList<>();
|
|
|
|
+// for (String deviceType : deviceTypeCounts.keySet()) {
|
|
|
|
+// Map<String, Object> deviceInfo = new HashMap<>();
|
|
|
|
+// deviceInfo.put("deviceType", deviceType);
|
|
|
|
+// deviceInfo.put("deviceTypeCounts", deviceTypeCounts.getOrDefault(deviceType, 0));
|
|
|
|
+// deviceInfo.put("onlineDeviceCount", onlineDeviceCount.getOrDefault(deviceType, 0));
|
|
|
|
+// deviceInfo.put("offlineDeviceCount", offlineDeviceCount.getOrDefault(deviceType, 0));
|
|
|
|
+// deviceStatusList.add(deviceInfo);
|
|
|
|
+// }
|
|
|
|
|
|
return deviceStatusList;
|
|
return deviceStatusList;
|
|
}
|
|
}
|