From 5b94d3c5dd431ae55e63fc309d883ae7556beb4a Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Thu, 28 Sep 2023 13:19:40 +0800 Subject: [PATCH] chore:补充提交 --- screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java | 95 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 92 insertions(+), 3 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java index 85c0244..bd62813 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java @@ -6,6 +6,7 @@ import com.moral.api.config.mybatis.MybatisPlusConfig; import com.moral.api.entity.*; import com.moral.api.mapper.DeviceMapper; +import com.moral.api.mapper.HistoryFiveMinutelyMapper; import com.moral.api.mapper.HistoryHourlyMapper; import com.moral.api.mapper.OrganizationUnitAlarmMapper; import com.moral.api.mapper.UnitConversionMapper; @@ -57,11 +58,24 @@ @Autowired HistoryHourlyMapper historyHourlyMapper; + @Autowired + HistoryFiveMinutelyMapper historyFiveMinutelyMapper; + @Override public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { QueryWrapper<Device> wrapper = new QueryWrapper(); wrapper.eq("monitor_point_id", monitorPointId); wrapper.eq("is_delete", Constants.NOT_DELETE); + wrapper.orderByAsc("dev_num"); + return deviceMapper.selectList(wrapper); + } + + @Override + public List<Device> getDevicesByMonitorPointId(List<Integer> monitorPointId) { + QueryWrapper<Device> wrapper = new QueryWrapper(); + wrapper.in("monitor_point_id", monitorPointId); + wrapper.eq("is_delete", Constants.NOT_DELETE); + wrapper.orderByAsc("dev_num"); return deviceMapper.selectList(wrapper); } @@ -191,6 +205,7 @@ QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); queryWrapper.select("mac", "name").in("mac", macs); + queryWrapper.orderByAsc("dev_num","name","id"); List<Device> devices = deviceMapper.selectList(queryWrapper); Map<String,Object> devicesInfo = new HashMap<>(); for (Device device:devices) { @@ -219,11 +234,21 @@ wrapper.between("time", startDate, endDate); List<HistoryHourly> historyHourlies = multiTableQuery(wrapper, tableNames); historyHourlies = historyHourlies.stream().distinct().collect(Collectors.toList()); + List<HistoryHourly> distinctHistoryHourlies = new ArrayList<>(); + Map<String, Object> disMap = new HashMap<>(); for (HistoryHourly historyHourly:historyHourlies) { + Date time = historyHourly.getTime(); + String timeStr = DateUtils.dateToDateString(time,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + if (!disMap.containsKey(timeStr)){ + distinctHistoryHourlies.add(historyHourly); + disMap.put(timeStr,true); + } + } + for (HistoryHourly historyHourly:distinctHistoryHourlies) { Map<String,Object> historyHourlyMap = new HashMap<>(); historyHourlyMap.put("mac",mac); - JSONObject value = JSONObject.parseObject(historyHourly.getValue()); - Double sensorValue = Double.parseDouble(value.get(sensorCode).toString()); + JSONObject value= JSONObject.parseObject(historyHourly.getValue()); + Double sensorValue = Objects.nonNull(value)&&Objects.nonNull(value.get(sensorCode))?Double.parseDouble(value.get(sensorCode).toString()):0d; historyHourlyMap.put(sensorCode,sensorValue); Date time = historyHourly.getTime(); String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_EN); @@ -280,7 +305,7 @@ } middleDate = DateUtils.addDays(middleDate,1); } - } else { + } else if ("month".equals(type)){ end = DateUtils.getDateAddMonth(endTime, 1); timeUnits = "monthly"; dateFormat = "%Y-%m"; @@ -310,6 +335,44 @@ } middleDate = DateUtils.addMonths(middleDate,1); } + }else { + Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH); + for (String mac:macs) { + QueryWrapper<HistoryFiveMinutely> wrapper = new QueryWrapper<>(); + wrapper.eq("mac", mac); + wrapper.between("time", startDate, endDate); + List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(wrapper, tableNames); + HistoryFiveMinutelys = HistoryFiveMinutelys.stream().distinct().collect(Collectors.toList()); + List<HistoryFiveMinutely> distinctHistoryHourlies = new ArrayList<>(); + Map<String, Object> disMap = new HashMap<>(); + for (HistoryFiveMinutely historyFiveMinutely:HistoryFiveMinutelys) { + Date time = historyFiveMinutely.getTime(); + String timeStr = DateUtils.dateToDateString(time,DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + if (!disMap.containsKey(timeStr)){ + distinctHistoryHourlies.add(historyFiveMinutely); + disMap.put(timeStr,true); + } + } + for (HistoryFiveMinutely historyFiveMinutely:distinctHistoryHourlies) { + Map<String,Object> historyHourlyMap = new HashMap<>(); + historyHourlyMap.put("mac",mac); + JSONObject value = JSONObject.parseObject(historyFiveMinutely.getValue()); + if (value.get(sensorCode)==null){ + historyHourlyMap.put(sensorCode,0.0); + }else { + Double sensorValue = Double.parseDouble(value.get(sensorCode).toString()); + historyHourlyMap.put(sensorCode,sensorValue); + } +// Double sensorValue = Double.parseDouble(value.get(sensorCode).toString()); +// historyHourlyMap.put(sensorCode,sensorValue); + Date time = historyFiveMinutely.getTime(); + String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); + historyHourlyMap.put("time",timeStr); + list.add(historyHourlyMap); + } + } } for (Map map:list) { String time = map.get("time").toString(); @@ -323,6 +386,11 @@ List<Map<String,Object>> deviceData = new ArrayList<>(); deviceData = (List<Map<String,Object>>)resultMap.get("deviceData"); deviceData.add(deviceMap); + Collections.sort(deviceData, (map1,map2) -> { + String name1 = map1.get("name").toString();//name1���������list������������������������ + String name2 = map2.get("name").toString(); //name1���������list���������������������������name + return name1.compareTo(name2); + }); resultMap.put("deviceData",deviceData); //result.add(resultMap); flag = false; @@ -332,6 +400,11 @@ if (flag){ List<Map<String,Object>> deviceData = new ArrayList<>(); deviceData.add(deviceMap); + Collections.sort(deviceData, (map1,map2) -> { + String name1 = map1.get("name").toString();//name1���������list������������������������ + String name2 = map2.get("name").toString(); //name1���������list���������������������������name + return name1.compareTo(name2); + }); Map<String,Object> resultMap = new HashMap<>(); resultMap.put("deviceData",deviceData); resultMap.put("time",time); @@ -340,6 +413,11 @@ }else { List<Map<String,Object>> deviceData = new ArrayList<>(); deviceData.add(deviceMap); + Collections.sort(deviceData, (map1,map2) -> { + String name1 = map1.get("name").toString();//name1���������list������������������������ + String name2 = map2.get("name").toString(); //name1���������list���������������������������name + return name1.compareTo(name2); + }); Map<String,Object> resultMap = new HashMap<>(); resultMap.put("deviceData",deviceData); resultMap.put("time",time); @@ -472,5 +550,16 @@ return result; } + private List<HistoryFiveMinutely> FiveMinuteTableQuery(QueryWrapper<HistoryFiveMinutely> wrapper, List<String> tableNames) { + List<HistoryFiveMinutely> result = new ArrayList<>(); + for (String tableName : tableNames) { + MybatisPlusConfig.tableName.set(tableName); + List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.selectList(wrapper); + result.addAll(datas); + } + MybatisPlusConfig.tableName.remove(); + return result; + } + } -- Gitblit v1.8.0