|
@@ -179,7 +179,7 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DataTrendDto getLastWeekDataTrend(String type) {
|
|
|
+ public DataTrendDto getLastWeekDataTrend() {
|
|
|
SaBaseLoginUser loginUser = StpLoginUserUtil.getLoginUser();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
DataTrendDto dataTrendDto = new DataTrendDto();
|
|
@@ -191,21 +191,18 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -8);
|
|
|
Date lastWeek = calendar.getTime();
|
|
|
|
|
|
- String alarmKeyword = null;
|
|
|
- // 查询超标或过低数据
|
|
|
- if (type.equals("1")) {
|
|
|
- alarmKeyword = "超标";
|
|
|
- } else if (type.equals("2")) {
|
|
|
- alarmKeyword = "过低";
|
|
|
- } else if (type.equals("3")) {
|
|
|
- alarmKeyword = "电量过低";
|
|
|
- } else if (type.equals("4")) {
|
|
|
- alarmKeyword = "设备离线";
|
|
|
- } else {
|
|
|
- throw new CommonException("type参数错误");
|
|
|
- }
|
|
|
+ List<String> alarmTypeList = new ArrayList<>();
|
|
|
+ alarmTypeList.add("温度超标");
|
|
|
+ alarmTypeList.add("湿度超标");
|
|
|
+ alarmTypeList.add("二氧化碳浓度超标");
|
|
|
+ alarmTypeList.add("温度过低");
|
|
|
+ alarmTypeList.add("湿度过低");
|
|
|
+ alarmTypeList.add("二氧化碳浓度过低");
|
|
|
+ alarmTypeList.add("电量过低");
|
|
|
+ alarmTypeList.add("设备离线");
|
|
|
List<DataTrendMapperDto> dataTrendMapperDtos = sensorAlarmMapper.countByType(
|
|
|
- loginUser.getOrgId(), alarmKeyword, sdf.format(lastWeek), sdf.format(now));
|
|
|
+ loginUser.getOrgId(), alarmTypeList, sdf.format(lastWeek), sdf.format(now));
|
|
|
+ log.info("报警统计数据:{}", dataTrendMapperDtos);
|
|
|
|
|
|
// 按日期分组统计数据
|
|
|
Map<String, Map<String, Integer>> dateDataMap = new LinkedHashMap<>();
|
|
@@ -221,13 +218,17 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
tempCal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
}
|
|
|
|
|
|
- // 填充统计数据
|
|
|
+ // 初始化各类型数据是否存在标志
|
|
|
boolean hasTemperature = false;
|
|
|
boolean hasHumidity = false;
|
|
|
boolean hasCo2 = false;
|
|
|
+ boolean hasTemperatureDown = false;
|
|
|
+ boolean hasHumidityDown = false;
|
|
|
+ boolean hasCo2Down = false;
|
|
|
boolean hasBattery = false;
|
|
|
boolean hasOffline = false;
|
|
|
|
|
|
+ // 填充统计数据
|
|
|
for (DataTrendMapperDto dto : dataTrendMapperDtos) {
|
|
|
String dateKey = dto.getAlarmTime().substring(0, 10);
|
|
|
String alarmType = dto.getAlarmType();
|
|
@@ -235,21 +236,39 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
|
|
|
Map<String, Integer> typeCountMap = dateDataMap.getOrDefault(dateKey, new HashMap<>());
|
|
|
|
|
|
- if (alarmType.contains("温度")) {
|
|
|
- typeCountMap.put("temperature", typeCountMap.getOrDefault("temperature", 0) + count);
|
|
|
- hasTemperature = true;
|
|
|
- } else if (alarmType.contains("湿度")) {
|
|
|
- typeCountMap.put("humidity", typeCountMap.getOrDefault("humidity", 0) + count);
|
|
|
- hasHumidity = true;
|
|
|
- } else if (alarmType.contains("二氧化碳") || alarmType.contains("CO2")) {
|
|
|
- typeCountMap.put("co2", typeCountMap.getOrDefault("co2", 0) + count);
|
|
|
- hasCo2 = true;
|
|
|
- } else if (alarmType.contains("电量过低")) {
|
|
|
- typeCountMap.put("battery", typeCountMap.getOrDefault("battery", 0) + count);
|
|
|
- hasBattery = true;
|
|
|
- } else if (alarmType.contains("设备离线")) {
|
|
|
- typeCountMap.put("offline", typeCountMap.getOrDefault("offline", 0) + count);
|
|
|
- hasOffline = true;
|
|
|
+ switch (alarmType) {
|
|
|
+ case "温度超标":
|
|
|
+ typeCountMap.put("temperature", typeCountMap.getOrDefault("temperature", 0) + count);
|
|
|
+ hasTemperature = true;
|
|
|
+ break;
|
|
|
+ case "湿度超标":
|
|
|
+ typeCountMap.put("humidity", typeCountMap.getOrDefault("humidity", 0) + count);
|
|
|
+ hasHumidity = true;
|
|
|
+ break;
|
|
|
+ case "二氧化碳浓度超标":
|
|
|
+ typeCountMap.put("co2", typeCountMap.getOrDefault("co2", 0) + count);
|
|
|
+ hasCo2 = true;
|
|
|
+ break;
|
|
|
+ case "温度过低":
|
|
|
+ typeCountMap.put("temperatureDown", typeCountMap.getOrDefault("temperatureDown", 0) + count);
|
|
|
+ hasTemperatureDown = true;
|
|
|
+ break;
|
|
|
+ case "湿度过低":
|
|
|
+ typeCountMap.put("humidityDown", typeCountMap.getOrDefault("humidityDown", 0) + count);
|
|
|
+ hasHumidityDown = true;
|
|
|
+ break;
|
|
|
+ case "二氧化碳浓度过低":
|
|
|
+ typeCountMap.put("co2Down", typeCountMap.getOrDefault("co2Down", 0) + count);
|
|
|
+ hasCo2Down = true;
|
|
|
+ break;
|
|
|
+ case "电量过低":
|
|
|
+ typeCountMap.put("battery", typeCountMap.getOrDefault("battery", 0) + count);
|
|
|
+ hasBattery = true;
|
|
|
+ break;
|
|
|
+ case "设备离线":
|
|
|
+ typeCountMap.put("offline", typeCountMap.getOrDefault("offline", 0) + count);
|
|
|
+ hasOffline = true;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
dateDataMap.put(dateKey, typeCountMap);
|
|
@@ -260,8 +279,11 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
List<Integer> yData1 = hasTemperature ? new ArrayList<>() : Collections.emptyList();
|
|
|
List<Integer> yData2 = hasHumidity ? new ArrayList<>() : Collections.emptyList();
|
|
|
List<Integer> yData3 = hasCo2 ? new ArrayList<>() : Collections.emptyList();
|
|
|
- List<Integer> yData4 = hasBattery ? new ArrayList<>() : Collections.emptyList();
|
|
|
- List<Integer> yData5 = hasOffline ? new ArrayList<>() : Collections.emptyList();
|
|
|
+ List<Integer> yData4 = hasTemperatureDown ? new ArrayList<>() : Collections.emptyList();
|
|
|
+ List<Integer> yData5 = hasHumidityDown ? new ArrayList<>() : Collections.emptyList();
|
|
|
+ List<Integer> yData6 = hasCo2Down ? new ArrayList<>() : Collections.emptyList();
|
|
|
+ List<Integer> yData7 = hasBattery ? new ArrayList<>() : Collections.emptyList();
|
|
|
+ List<Integer> yData8 = hasOffline ? new ArrayList<>() : Collections.emptyList();
|
|
|
|
|
|
// 按日期顺序填充数据
|
|
|
for (String date : dateList) {
|
|
@@ -277,11 +299,20 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
if (hasCo2) {
|
|
|
yData3.add(counts.getOrDefault("co2", 0));
|
|
|
}
|
|
|
+ if (hasTemperatureDown) {
|
|
|
+ yData4.add(counts.getOrDefault("temperatureDown", 0));
|
|
|
+ }
|
|
|
+ if (hasHumidityDown) {
|
|
|
+ yData5.add(counts.getOrDefault("humidityDown", 0));
|
|
|
+ }
|
|
|
+ if (hasCo2Down) {
|
|
|
+ yData6.add(counts.getOrDefault("co2Down", 0));
|
|
|
+ }
|
|
|
if (hasBattery) {
|
|
|
- yData4.add(counts.getOrDefault("battery", 0));
|
|
|
+ yData7.add(counts.getOrDefault("battery", 0));
|
|
|
}
|
|
|
if (hasOffline) {
|
|
|
- yData5.add(counts.getOrDefault("offline", 0));
|
|
|
+ yData8.add(counts.getOrDefault("offline", 0));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -290,8 +321,11 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
dataTrendDto.setTemperatureData(yData1);
|
|
|
dataTrendDto.setHumidityData(yData2);
|
|
|
dataTrendDto.setCo2Data(yData3);
|
|
|
- dataTrendDto.setBatteryData(yData4);
|
|
|
- dataTrendDto.setOfflineData(yData5);
|
|
|
+ dataTrendDto.setTemperatureDownData(yData4);
|
|
|
+ dataTrendDto.setHumidityDownData(yData5);
|
|
|
+ dataTrendDto.setCo2DownData(yData6);
|
|
|
+ dataTrendDto.setBatteryData(yData7);
|
|
|
+ dataTrendDto.setOfflineData(yData8);
|
|
|
|
|
|
return dataTrendDto;
|
|
|
}
|
|
@@ -354,10 +388,10 @@ public class SensorAlarmServiceImpl extends ServiceImpl<SensorAlarmMapper, Senso
|
|
|
? DateUtil.parse(messagePageParam.getEndTime(), "yyyy-MM-dd HH:mm:ss")
|
|
|
: null;
|
|
|
|
|
|
- long count = sensorAlarmMapper.countInPage(orgId, typeCodes, startTime, endTime);
|
|
|
+ long count = sensorAlarmMapper.countInPage(orgId, typeCodes, messagePageParam.getAlarmType(), startTime, endTime, messagePageParam.getKeyword());
|
|
|
|
|
|
// 按创建时间降序排序
|
|
|
- queryWrapper.lambda().orderByDesc(SensorAlarm::getCreateTime).last("limit " + messagePageParam.getSize() * (messagePageParam.getCurrent() - 1) + "," + messagePageParam.getSize() * messagePageParam.getCurrent());
|
|
|
+ queryWrapper.lambda().orderByDesc(SensorAlarm::getCreateTime).last("limit " + messagePageParam.getSize() * (messagePageParam.getCurrent() - 1) + "," + messagePageParam.getSize());
|
|
|
|
|
|
|
|
|
List<SensorAlarm> ids = list(queryWrapper);
|