From 1f46b7a18e34656baf965fa6627130ef59d14156 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Thu, 30 Dec 2021 13:26:07 +0800 Subject: [PATCH] 区域贡献率收据格式修改 --- screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java | 8 screen-api/src/main/java/com/moral/api/service/RegionService.java | 2 screen-api/src/main/java/com/moral/api/controller/RegionController.java | 2 screen-api/src/main/java/com/moral/api/service/impl/RegionServiceImpl.java | 309 +++++++++++++++++++++++++++++++-------------------- 4 files changed, 192 insertions(+), 129 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/controller/RegionController.java b/screen-api/src/main/java/com/moral/api/controller/RegionController.java index a88db8f..a05ce80 100644 --- a/screen-api/src/main/java/com/moral/api/controller/RegionController.java +++ b/screen-api/src/main/java/com/moral/api/controller/RegionController.java @@ -79,7 +79,7 @@ return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } - List<Map<String, Object>> response = regionService.regionContribution(params); + Map<String, Object> response = regionService.regionContribution(params); return ResultMessage.ok(response); } } diff --git a/screen-api/src/main/java/com/moral/api/service/RegionService.java b/screen-api/src/main/java/com/moral/api/service/RegionService.java index cb82fcb..b2ee965 100644 --- a/screen-api/src/main/java/com/moral/api/service/RegionService.java +++ b/screen-api/src/main/java/com/moral/api/service/RegionService.java @@ -13,6 +13,6 @@ Set<Map<String, Object>> getSensorByRegionCodesAndOrganizationId(Map<String, Object> params); //��������������� - List<Map<String, Object>> regionContribution(Map<String, Object> params); + Map<String, Object> regionContribution(Map<String, Object> params); } diff --git a/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java index 54daf3e..a4adcb6 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java @@ -281,15 +281,15 @@ allDeviceSum = Double.parseDouble(o.toString()); } - List<HistoryMonthly> preofessionDeviceHistoryMonthlyList = professionDataMap.get(resultTime); + List<HistoryMonthly> professionDeviceHistoryMonthlyList = professionDataMap.get(resultTime); //��������� String contributionRate = null; Double professionAvg = null; - if (!ObjectUtils.isEmpty(preofessionDeviceHistoryMonthlyList)) { + if (!ObjectUtils.isEmpty(professionDeviceHistoryMonthlyList)) { //��������������������� - professionAvg = historyMonthlyService.calculatedValue(preofessionDeviceHistoryMonthlyList, sensorCode, "avg"); + professionAvg = historyMonthlyService.calculatedValue(professionDeviceHistoryMonthlyList, sensorCode, "avg"); //������������������������ - Double professionSum = historyMonthlyService.calculatedValue(preofessionDeviceHistoryMonthlyList, sensorCode, "sum"); + Double professionSum = historyMonthlyService.calculatedValue(professionDeviceHistoryMonthlyList, sensorCode, "sum"); //��������������������� NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); diff --git a/screen-api/src/main/java/com/moral/api/service/impl/RegionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/RegionServiceImpl.java index 46be8ab..ae49a2e 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/RegionServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/RegionServiceImpl.java @@ -139,13 +139,13 @@ } @Override - public List<Map<String, Object>> regionContribution(Map<String, Object> params) { + public Map<String, Object> regionContribution(Map<String, Object> params) { int orgId = Integer.parseInt(params.get("organizationId").toString()); List<String> regionCodes = Arrays.asList(params.get("regionCodes").toString().split(",")); String type = params.get("type").toString(); String time = params.get("time").toString(); String sensorCode = params.get("sensorCode").toString(); - List<Map<String, Object>> result = new ArrayList<>(); + Map<String, Object> result = new HashMap<>(); switch (type) { case "year": result = regionContributionOfYear(orgId, regionCodes, time, sensorCode); @@ -163,8 +163,13 @@ } //��������������� - private List<Map<String, Object>> regionContributionOfYear(Integer orgId, List<String> regionCodes, String time, String sensorCode) { - List<Map<String, Object>> result = new ArrayList<>(); + private Map<String, Object> regionContributionOfYear(Integer orgId, List<String> regionCodes, String time, String sensorCode) { + Map<String, Object> result = new HashMap<>(); + + //1.������������������ + List<String> timeLag = DateUtils.getTimeLag(time); + result.put("time", timeLag); + //������������������������������ QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>(); @@ -172,10 +177,6 @@ .eq("id", orgId); Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode(); - //��������������������������� - List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); - - List<String> timeLag = DateUtils.getTimeLag(time); //��������������������������� QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>(); @@ -191,25 +192,26 @@ } - //��������������������������������� + //��������������������������������������������������� + List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); List<HistoryMonthly> allDeviceData = historyMonthlyService.getValueByMacs(allMacs, time); - //���time������ Map<String, List<HistoryMonthly>> allDeviceDataMap = allDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7))); + //��������������������� + Map<String, Object> resultCityDataMap = new HashMap<>(); + List<Map<String, Object>> cityDataList = new ArrayList<>(); + //������������������������������������ + Map<String, Object> allDeviceSumMap = new HashMap<>(); for (String yearMonth : timeLag) { - Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("time", yearMonth); - - //������������������������������ Double allDeviceSum = null; List<HistoryMonthly> historyMonthlyList = allDeviceDataMap.get(yearMonth); if (!ObjectUtils.isEmpty(historyMonthlyList)) { allDeviceSum = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "sum"); } - resultMap.put("allDeviceSum", allDeviceSum); + allDeviceSumMap.put(yearMonth, allDeviceSum); //��������� @@ -219,71 +221,92 @@ //������������aqi������������������������ String sensorName = senorMap.get(sensorCode); if (sensorName != null) { - cityValue = (Double) dataValue.get(sensorName); + cityValue = Double.parseDouble(dataValue.get(sensorName).toString()); } } - resultMap.put("cityValue", cityValue); - result.add(resultMap); + Map<String, Object> cityDataMap = new HashMap<>(); + //������������ + cityDataMap.put("name", cityValue); + cityDataList.add(cityDataMap); } + //2.������������������ + resultCityDataMap.put("data", cityDataList); + result.put("������", resultCityDataMap); + + for (String regionCode : regionCodes) { + //��������������������������������� + HashMap<String, Object> regionMap = new HashMap<>(); + List<Map<String, Object>> dataList = new ArrayList<>(); + + + //������������������ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>(); queryWrapper.select("area_name").eq("area_code", Integer.parseInt(regionCode)); String regionName = sysAreaService.getOne(queryWrapper).getAreaName(); - //��������������������������������� - List<String> regionMacs = deviceService.getMacsByOrgIdAndRegionCode(orgId, Integer.parseInt(regionCode)); - //������������������������������������������ + //���������������������������������,��������������������� + List<String> regionMacs = deviceService.getMacsByOrgIdAndRegionCode(orgId, Integer.parseInt(regionCode)); List<HistoryMonthly> regionDeviceData = historyMonthlyService.getValueByMacs(regionMacs, time); //���time������ Map<String, List<HistoryMonthly>> regionDataMap = regionDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7))); - for (Map<String, Object> map : result) { - Object allDeviceSum = map.get("allDeviceSum"); - String resultTime = map.get("time").toString(); - List<HistoryMonthly> historyMonthlyList = regionDataMap.get(resultTime); + for (String resultTime : timeLag) { + //��������������������� + Map<String, Object> timeDataMap = new HashMap<>(); + Object o = allDeviceSumMap.get(resultTime); + Double allDeviceSum = null; + if (o != null) { + allDeviceSum = Double.parseDouble(o.toString()); + } + + List<HistoryMonthly> regionDeviceHistoryMonthlyList = regionDataMap.get(resultTime); //��������� String contributionRate = null; Double regionAvg = null; - if (!ObjectUtils.isEmpty(historyMonthlyList)) { - regionAvg = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "avg"); - Double regionSum = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "sum"); - //��������������������� + if (!ObjectUtils.isEmpty(regionDeviceHistoryMonthlyList)) { + //��������������������������� + regionAvg = historyMonthlyService.calculatedValue(regionDeviceHistoryMonthlyList, sensorCode, "avg"); + //��������������������������� + Double regionSum = historyMonthlyService.calculatedValue(regionDeviceHistoryMonthlyList, sensorCode, "sum"); + //��������������������������� NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); - if (allDeviceSum != null && (Double) allDeviceSum != 0d) { - contributionRate = numberFormat.format(regionSum / ((Double) allDeviceSum) * 100) + "%"; - System.out.println(regionSum + "===" + allDeviceSum); + if (allDeviceSum != null && allDeviceSum != 0d) { + contributionRate = numberFormat.format(regionSum / (allDeviceSum) * 100) + "%"; } } - Map<String, Object> professionMap = new HashMap<>(); - professionMap.put("contributionRate", contributionRate); - professionMap.put("value", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); - map.put(regionName, professionMap); + + //������������������ + timeDataMap.put("name", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); + //��������������������� + timeDataMap.put("value", contributionRate); + dataList.add(timeDataMap); } + regionMap.put("data", dataList); + result.put(regionName, regionMap); } - result.forEach(map -> map.remove("allDeviceSum")); return result; } //��������������� - private List<Map<String, Object>> regionContributionOfMonth(Integer orgId, List<String> regionCodes, String time, String sensorCode) { - List<Map<String, Object>> result = new ArrayList<>(); + private Map<String, Object> regionContributionOfMonth(Integer orgId, List<String> regionCodes, String time, String sensorCode) { + Map<String, Object> result = new HashMap<>(); + + //1.������������������ + List<String> timeLag = DateUtils.getTimeLag(time); + result.put("time", timeLag); + //������������������������������ QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>(); organizationQueryWrapper.select("location_level_code") .eq("id", orgId); Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode(); - - //��������������������������� - List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); - - //������������ - List<String> timeLag = DateUtils.getTimeLag(time); //��������������������������� @@ -300,24 +323,26 @@ } - //��������������������������������� + //��������������������������������������������������� + List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); List<HistoryDaily> allDeviceData = historyDailyService.getValueByMacs(allMacs, time); - //���time������ Map<String, List<HistoryDaily>> allDeviceDataMap = allDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10))); + //��������������������� + Map<String, Object> resultCityDataMap = new HashMap<>(); + List<Map<String, Object>> cityDataList = new ArrayList<>(); + //������������������������������������ + Map<String, Object> allDeviceSumMap = new HashMap<>(); for (String yearMonthDay : timeLag) { - Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("time", yearMonthDay); - //������������������������������ Double allDeviceSum = null; List<HistoryDaily> historyDailyList = allDeviceDataMap.get(yearMonthDay); if (!ObjectUtils.isEmpty(historyDailyList)) { allDeviceSum = historyDailyService.calculatedValue(historyDailyList, sensorCode, "sum"); } - resultMap.put("allDeviceSum", allDeviceSum); + allDeviceSumMap.put(yearMonthDay, allDeviceSum); //��������� @@ -327,60 +352,85 @@ //������������aqi������������������������ String sensorName = senorMap.get(sensorCode); if (sensorName != null) { - cityValue = (Double) dataValue.get(sensorName); + cityValue = Double.parseDouble(dataValue.get(sensorName).toString()); } } - resultMap.put("cityValue", cityValue); - result.add(resultMap); + Map<String, Object> cityDataMap = new HashMap<>(); + //������������ + cityDataMap.put("name", cityValue); + cityDataList.add(cityDataMap); } + //2.������������������ + resultCityDataMap.put("data", cityDataList); + result.put("������", resultCityDataMap); + + for (String regionCode : regionCodes) { + //��������������������������������� + HashMap<String, Object> regionMap = new HashMap<>(); + List<Map<String, Object>> dataList = new ArrayList<>(); + + + //������������������ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>(); queryWrapper.select("area_name").eq("area_code", Integer.parseInt(regionCode)); String regionName = sysAreaService.getOne(queryWrapper).getAreaName(); - //��������������������������������� + + //���������������������������������,��������������������� List<String> regionMacs = deviceService.getMacsByOrgIdAndRegionCode(orgId, Integer.parseInt(regionCode)); - - - //������������������������������������ - List<HistoryDaily> professionDeviceData = historyDailyService.getValueByMacs(regionMacs, time); + List<HistoryDaily> regionDeviceData = historyDailyService.getValueByMacs(regionMacs, time); //���time������ - Map<String, List<HistoryDaily>> professionDataMap = professionDeviceData.stream() + Map<String, List<HistoryDaily>> regionDataMap = regionDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10))); - for (Map<String, Object> map : result) { - Object allDeviceSum = map.get("allDeviceSum"); - String resultTime = map.get("time").toString(); - List<HistoryDaily> historyDailyList = professionDataMap.get(resultTime); + for (String resultTime : timeLag) { + //��������������������� + Map<String, Object> timeDataMap = new HashMap<>(); + Object o = allDeviceSumMap.get(resultTime); + Double allDeviceSum = null; + if (o != null) { + allDeviceSum = Double.parseDouble(o.toString()); + } + + List<HistoryDaily> regionDeviceHistoryDailyList = regionDataMap.get(resultTime); //��������� String contributionRate = null; Double regionAvg = null; - if (!ObjectUtils.isEmpty(historyDailyList)) { - //��������������������� - regionAvg = historyDailyService.calculatedValue(historyDailyList, sensorCode, "avg"); - //������������������������ - Double regionSum = historyDailyService.calculatedValue(historyDailyList, sensorCode, "sum"); - //��������������������� + if (!ObjectUtils.isEmpty(regionDeviceHistoryDailyList)) { + //��������������������������� + regionAvg = historyDailyService.calculatedValue(regionDeviceHistoryDailyList, sensorCode, "avg"); + //��������������������������� + Double regionSum = historyDailyService.calculatedValue(regionDeviceHistoryDailyList, sensorCode, "sum"); + //��������������������������� NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); - if (allDeviceSum != null && (Double) allDeviceSum != 0d) { - contributionRate = numberFormat.format(regionSum / ((Double) allDeviceSum) * 100) + "%"; + if (allDeviceSum != null && allDeviceSum != 0d) { + contributionRate = numberFormat.format(regionSum / (allDeviceSum) * 100) + "%"; } } - Map<String, Object> professionMap = new HashMap<>(); - professionMap.put("contributionRate", contributionRate); - professionMap.put("value", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); - map.put(regionName, professionMap); + + //������������������ + timeDataMap.put("name", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); + //��������������������� + timeDataMap.put("value", contributionRate); + dataList.add(timeDataMap); } + regionMap.put("data", dataList); + result.put(regionName, regionMap); } - result.forEach(map -> map.remove("allDeviceSum")); return result; } - private List<Map<String, Object>> regionContributionOfDay(Integer orgId, List<String> regionCodes, String time, String sensorCode) { - List<Map<String, Object>> result = new ArrayList<>(); + private Map<String, Object> regionContributionOfDay(Integer orgId, List<String> regionCodes, String time, String sensorCode) { + Map<String, Object> result = new HashMap<>(); + + //1.������������������ + List<String> timeLag = DateUtils.getTimeLag(time); + result.put("time", timeLag); + //������������������������������ QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>(); @@ -399,14 +449,6 @@ sensorUpper = sensor.getUpper(); } - - //��������������������������� - List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); - - //��������������� - List<String> timeLag = DateUtils.getTimeLag(time); - - //������������������������������ QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>(); cityAqiQueryWrapper.select("time", "value") @@ -421,83 +463,104 @@ } - //������������������������������������ + //������������������������������������������������������ + List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); List<HistoryHourly> allDeviceData = historyHourlyService.getValueByMacs(allMacs, time); - //���time������ Map<String, List<HistoryHourly>> allDeviceDataMap = allDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13))); - for (String yearMonthDayHour : timeLag) { - Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("time", yearMonthDayHour); - - + //��������������������� + Map<String, Object> resultCityDataMap = new HashMap<>(); + List<Map<String, Object>> cityDataList = new ArrayList<>(); + //������������������������������������ + Map<String, Object> allDeviceSumMap = new HashMap<>(); + for (String yearMonthDay : timeLag) { //������������������������������ Double allDeviceSum = null; - List<HistoryHourly> historyHourlyList = allDeviceDataMap.get(yearMonthDayHour); + List<HistoryHourly> historyHourlyList = allDeviceDataMap.get(yearMonthDay); if (!ObjectUtils.isEmpty(historyHourlyList)) { allDeviceSum = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "sum", sensorLower, sensorUpper); } - resultMap.put("allDeviceSum", allDeviceSum); + allDeviceSumMap.put(yearMonthDay, allDeviceSum); //��������� Double cityValue = null; - if (cityAqiMap.get(yearMonthDayHour) != null) { - Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDayHour).toString(), Map.class); + if (cityAqiMap.get(yearMonthDay) != null) { + Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDay).toString(), Map.class); //������������aqi������������������������ String sensorName = senorMap.get(sensorCode); if (sensorName != null) { cityValue = Double.parseDouble(dataValue.get(sensorName).toString()); } } - resultMap.put("cityValue", cityValue); - result.add(resultMap); + Map<String, Object> cityDataMap = new HashMap<>(); + //������������ + cityDataMap.put("name", cityValue); + cityDataList.add(cityDataMap); } + //2.������������������ + resultCityDataMap.put("data", cityDataList); + result.put("������", resultCityDataMap); + + for (String regionCode : regionCodes) { + //��������������������������������� + HashMap<String, Object> regionMap = new HashMap<>(); + List<Map<String, Object>> dataList = new ArrayList<>(); + + + //������������������ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>(); queryWrapper.select("area_name").eq("area_code", Integer.parseInt(regionCode)); String regionName = sysAreaService.getOne(queryWrapper).getAreaName(); - //��������������������������������� + + //���������������������������������,������������������������ List<String> regionMacs = deviceService.getMacsByOrgIdAndRegionCode(orgId, Integer.parseInt(regionCode)); - - - //��������������������������������������� - List<HistoryHourly> professionDeviceData = historyHourlyService.getValueByMacs(regionMacs, time); + List<HistoryHourly> regionDeviceData = historyHourlyService.getValueByMacs(regionMacs, time); //���time������ - Map<String, List<HistoryHourly>> professionDataMap = professionDeviceData.stream() + Map<String, List<HistoryHourly>> regionDataMap = regionDeviceData.stream() .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13))); - for (Map<String, Object> map : result) { - Object allDeviceSum = map.get("allDeviceSum"); - String resultTime = map.get("time").toString(); - List<HistoryHourly> historyHourlyList = professionDataMap.get(resultTime); + for (String resultTime : timeLag) { + //��������������������� + Map<String, Object> timeDataMap = new HashMap<>(); + Object o = allDeviceSumMap.get(resultTime); + Double allDeviceSum = null; + if (o != null) { + allDeviceSum = Double.parseDouble(o.toString()); + } + + List<HistoryHourly> regionDeviceHistoryHourlyList = regionDataMap.get(resultTime); //��������� String contributionRate = null; Double regionAvg = null; - if (!ObjectUtils.isEmpty(historyHourlyList)) { - //��������������������� - regionAvg = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "avg", sensorLower, sensorUpper); - //������������������������ - Double regionSum = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "sum", sensorLower, sensorUpper); - //��������������������� + if (!ObjectUtils.isEmpty(regionDeviceHistoryHourlyList)) { + //��������������������������� + regionAvg = historyHourlyService.calculatedValue(regionDeviceHistoryHourlyList, sensorCode, "avg", sensorLower, sensorUpper); + //��������������������������� + Double regionSum = historyHourlyService.calculatedValue(regionDeviceHistoryHourlyList, sensorCode, "sum", sensorLower, sensorUpper); + //��������������������������� NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); - if (allDeviceSum != null && (Double) allDeviceSum != 0d) { - contributionRate = numberFormat.format(regionSum / ((Double) allDeviceSum) * 100) + "%"; + if (allDeviceSum != null && allDeviceSum != 0d) { + contributionRate = numberFormat.format(regionSum / (allDeviceSum) * 100) + "%"; } } - Map<String, Object> professionMap = new HashMap<>(); - professionMap.put("contributionRate", contributionRate); - professionMap.put("value", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); - map.put(regionName, professionMap); + + //������������������ + timeDataMap.put("name", regionAvg == null ? null : AmendUtils.sciCal(regionAvg, 0)); + //��������������������� + timeDataMap.put("value", contributionRate); + dataList.add(timeDataMap); } + regionMap.put("data", dataList); + result.put(regionName, regionMap); } - result.forEach(map -> map.remove("allDeviceSum")); return result; } } -- Gitblit v1.8.0