From caf0e22cb16cc01d3775db11b82787d5ba22c402 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Wed, 29 Dec 2021 16:02:27 +0800 Subject: [PATCH] 行业贡献率因子上下限判断 --- screen-api/src/main/java/com/moral/api/service/impl/ProfessionServiceImpl.java | 500 +++++++++++++++++++++++++++++++++--------------------- 1 files changed, 305 insertions(+), 195 deletions(-) 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 fa708b8..0a7dcfa 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 @@ -16,14 +16,18 @@ import java.util.Set; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.entity.CityAqi; import com.moral.api.entity.CityAqiDaily; import com.moral.api.entity.CityAqiMonthly; import com.moral.api.entity.Device; import com.moral.api.entity.HistoryDaily; +import com.moral.api.entity.HistoryHourly; import com.moral.api.entity.HistoryMonthly; +import com.moral.api.entity.Organization; import com.moral.api.entity.Sensor; +import com.moral.api.entity.SysDictData; import com.moral.api.service.CityAqiDailyService; import com.moral.api.service.CityAqiMonthlyService; import com.moral.api.service.CityAqiService; @@ -34,6 +38,7 @@ import com.moral.api.service.OrganizationService; import com.moral.api.service.ProfessionService; +import com.moral.api.service.SensorService; import com.moral.constant.Constants; import com.moral.constant.RedisConstants; @@ -77,6 +82,9 @@ @Autowired private OrganizationService organizationService; + + @Autowired + private SensorService sensorService; private static Map<String, String> senorMap = new HashMap<>(); @@ -169,91 +177,117 @@ private List<Map<String, Object>> professionContributionOfYear(Integer orgId, List<String> professions, String time, String sensorCode) { List<Map<String, Object>> result = new ArrayList<>(); + //������������������������������ + QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>(); + organizationQueryWrapper.select("location_level_code") + .eq("id", orgId); + Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode(); + //��������������������������� - List allMacs = getMacsByOrgId(orgId); + List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); List<String> timeLag = DateUtils.getTimeLag(time); + + //��������������������������� + QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>(); + cityAqiMonthlyQueryWrapper.select("time", "value") + .eq("city_code", locationLevelCode) + .likeRight("time", time); + List<Map<String, Object>> cityAqis = cityAqiMonthlyService.listMaps(cityAqiMonthlyQueryWrapper); + Map<String, Object> cityAqiMap = new HashMap<>(); + if (!ObjectUtils.isEmpty(cityAqis)) { + for (Map<String, Object> cityAqi : cityAqis) { + cityAqiMap.put(cityAqi.get("time").toString().substring(0, 7), cityAqi.get("value")); + } + } + + + //��������������������������������� + 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))); + + for (String yearMonth : timeLag) { Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("time", yearMonth.split("-")[1]); - yearMonth = yearMonth + "-01 00:00:00"; + resultMap.put("time", yearMonth); //������������������������������ Double allDeviceSum = null; - QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>(); - historyMonthlyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonth) - .in("mac", allMacs); - Map<String, Object> allDeviceSumMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper); - if (!ObjectUtils.isEmpty(allDeviceSumMap)) { - allDeviceSum = (Double) allDeviceSumMap.get("result"); + List<HistoryMonthly> historyMonthlyList = allDeviceDataMap.get(yearMonth); + if (!ObjectUtils.isEmpty(historyMonthlyList)) { + allDeviceSum = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "sum"); } + resultMap.put("allDeviceSum", allDeviceSum); - //������������ + //��������� Double cityValue = null; - //������������������������������ - Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode(); - QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>(); - cityAqiMonthlyQueryWrapper.select("`value`->'$." + sensorCode + "' AS result") - .eq("city_code", locationLevelCode) - .eq("time", yearMonth); - Map<String, Object> cityValueMap = cityAqiMonthlyService.getMap(cityAqiMonthlyQueryWrapper); - if (!ObjectUtils.isEmpty(cityValueMap)) { - cityValue = (Double) cityValueMap.get("result"); + if (cityAqiMap.get(yearMonth) != null) { + Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonth).toString(), Map.class); + //������������aqi������������������������ + String sensorName = senorMap.get(sensorCode); + if (sensorName != null) { + cityValue = Double.parseDouble(dataValue.get(sensorName).toString()); + } } resultMap.put("cityValue", cityValue); - - - for (String profession : professions) { - Map<String, Object> professionMap = new HashMap<>(); - - //��������������������� - List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); - List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList()); - - - //������������������ - Double professionSum = null; - historyMonthlyQueryWrapper.clear(); - historyMonthlyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonth) - .in("mac", professionMacs); - Map<String, Object> professionSumMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper); - if (!ObjectUtils.isEmpty(professionSumMap)) { - professionSum = (Double) professionSumMap.get("result"); - } - - - //������������������ - Double professionAvg = null; - historyMonthlyQueryWrapper.clear(); - historyMonthlyQueryWrapper.select("AVG(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonth) - .in("mac", professionMacs); - Map<String, Object> professionAvgMap = historyMonthlyService.getMap(historyMonthlyQueryWrapper); - if (!ObjectUtils.isEmpty(professionAvgMap)) { - professionAvg = (Double) professionAvgMap.get("result"); - } - - //��������������������� - String contributionRate = null; - NumberFormat numberFormat = NumberFormat.getInstance(); - numberFormat.setMaximumFractionDigits(2); - if (professionSum != null && allDeviceSum != null) { - contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%"; - } - - //������������ - professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); - //��������������� - professionMap.put("contributionRate", contributionRate); - - resultMap.put(profession, professionMap); - } result.add(resultMap); } + + for (String profession : professions) { + //������������������ + String professionName = null; + Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY); + List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession"); + for (SysDictData sysDictData : professionInfo) { + if (sysDictData.getDataKey().equals(profession)) { + professionName = sysDictData.getDataValue(); + break; + } + } + + + //��������������������� + List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); + List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList()); + + + //������������������������������������ + List<HistoryMonthly> professionDeviceData = historyMonthlyService.getValueByMacs(professionMacs, time); + //���time������ + Map<String, List<HistoryMonthly>> professionDataMap = professionDeviceData.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 = professionDataMap.get(resultTime); + //��������� + String contributionRate = null; + Double professionAvg = null; + if (!ObjectUtils.isEmpty(historyMonthlyList)) { + //��������������������� + professionAvg = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "avg"); + //������������������������ + Double professionSum = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "sum"); + //��������������������� + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (allDeviceSum != null && (Double) allDeviceSum != 0d) { + contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%"; + } + } + Map<String, Object> professionMap = new HashMap<>(); + professionMap.put("contributionRate", contributionRate); + professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); + map.put(professionName, professionMap); + } + } + result.forEach(map -> map.remove("allDeviceSum")); return result; } @@ -261,168 +295,244 @@ private List<Map<String, Object>> professionContributionOfMonth(Integer orgId, List<String> professions, String time, String sensorCode) { List<Map<String, Object>> result = new ArrayList<>(); - //��������������������������� - List allMacs = getMacsByOrgId(orgId); + //������������������������������ + 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); + + + //��������������������������� + QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>(); + cityAqiDailyQueryWrapper.select("time", "value") + .eq("city_code", locationLevelCode) + .likeRight("time", time); + List<Map<String, Object>> cityAqis = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper); + Map<String, Object> cityAqiMap = new HashMap<>(); + if (!ObjectUtils.isEmpty(cityAqis)) { + for (Map<String, Object> cityAqi : cityAqis) { + cityAqiMap.put(cityAqi.get("time").toString().substring(0, 10), cityAqi.get("value")); + } + } + + + //��������������������������������� + 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))); + + for (String yearMonthDay : timeLag) { Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("time", yearMonthDay.split("-")[2]); - yearMonthDay = yearMonthDay + " 00:00:00"; - + resultMap.put("time", yearMonthDay); //������������������������������ Double allDeviceSum = null; - QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>(); - historyDailyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonthDay) - .in("mac", allMacs); - Map<String, Object> allDeviceSumMap = historyDailyService.getMap(historyDailyQueryWrapper); - if (!ObjectUtils.isEmpty(allDeviceSumMap)) { - allDeviceSum = (Double) allDeviceSumMap.get("result"); + List<HistoryDaily> historyDailyList = allDeviceDataMap.get(yearMonthDay); + if (!ObjectUtils.isEmpty(historyDailyList)) { + allDeviceSum = historyDailyService.calculatedValue(historyDailyList, sensorCode, "sum"); } + resultMap.put("allDeviceSum", allDeviceSum); - //������������ + //��������� Double cityValue = null; - //������������������������������ - Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode(); - QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>(); - cityAqiDailyQueryWrapper.select("`value`->'$." + sensorCode + "' AS result") - .eq("city_code", locationLevelCode) - .eq("time", yearMonthDay); - Map<String, Object> cityValueMap = cityAqiDailyService.getMap(cityAqiDailyQueryWrapper); - if (!ObjectUtils.isEmpty(cityValueMap)) { - cityValue = (Double) cityValueMap.get("result"); + 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); - - - - for (String profession : professions) { - Map<String, Object> professionMap = new HashMap<>(); - - //��������������������� - List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); - List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList()); - - - //������������������ - Double professionSum = null; - historyDailyQueryWrapper.clear(); - historyDailyQueryWrapper.select("SUM(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonthDay) - .in("mac", professionMacs); - Map<String, Object> professionSumMap = historyDailyService.getMap(historyDailyQueryWrapper); - if (!ObjectUtils.isEmpty(professionSumMap)) { - professionSum = (Double) professionSumMap.get("result"); - } - - - //������������������ - Double professionAvg = null; - historyDailyQueryWrapper.clear(); - historyDailyQueryWrapper.select("AVG(`value`->'$." + sensorCode + "') AS result") - .eq("time", yearMonthDay) - .in("mac", professionMacs); - Map<String, Object> professionAvgMap = historyDailyService.getMap(historyDailyQueryWrapper); - if (!ObjectUtils.isEmpty(professionAvgMap)) { - professionAvg = (Double) professionAvgMap.get("result"); - } - - - //��������������������� - String contributionRate = null; - NumberFormat numberFormat = NumberFormat.getInstance(); - numberFormat.setMaximumFractionDigits(2); - if (professionSum != null && allDeviceSum != null) { - contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%"; - } - - //������������ - professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); - //��������������� - professionMap.put("contributionRate", contributionRate); - - resultMap.put(profession, professionMap); - } result.add(resultMap); } + + for (String profession : professions) { + String professionName = null; + Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY); + List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession"); + for (SysDictData sysDictData : professionInfo) { + if (sysDictData.getDataKey().equals(profession)) { + professionName = sysDictData.getDataValue(); + break; + } + } + + //��������������������� + List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); + List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList()); + + + //������������������������������������ + List<HistoryDaily> professionDeviceData = historyDailyService.getValueByMacs(professionMacs, time); + //���time������ + Map<String, List<HistoryDaily>> professionDataMap = professionDeviceData.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); + //��������� + String contributionRate = null; + Double professionAvg = null; + if (!ObjectUtils.isEmpty(historyDailyList)) { + //��������������������� + professionAvg = historyDailyService.calculatedValue(historyDailyList, sensorCode, "avg"); + //������������������������ + Double professionSum = historyDailyService.calculatedValue(historyDailyList, sensorCode, "sum"); + //��������������������� + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (allDeviceSum != null && (Double) allDeviceSum != 0d) { + contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%"; + } + } + Map<String, Object> professionMap = new HashMap<>(); + professionMap.put("contributionRate", contributionRate); + professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); + map.put(professionName, professionMap); + } + } + result.forEach(map -> map.remove("allDeviceSum")); return result; } private List<Map<String, Object>> professionContributionOfDay(Integer orgId, List<String> professions, String time, String sensorCode) { List<Map<String, Object>> result = new ArrayList<>(); - //��������������������������� - List allMacs = getMacsByOrgId(orgId); + //������������������������������ + QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>(); + organizationQueryWrapper.select("location_level_code") + .eq("id", orgId); + Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode(); + //��������������������� + QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>(); + sensorQueryWrapper.select("lower", "upper").eq("code", sensorCode); + Sensor sensor = sensorService.getOne(sensorQueryWrapper); + Double sensorLower = null; + Double sensorUpper = null; + if (sensor != null) { + sensorLower = sensor.getLower(); + sensorUpper = sensor.getUpper(); + } + + //��������������������������� + List<String> allMacs = deviceService.getMacsByOrganizationId(orgId); + + //��������������� List<String> timeLag = DateUtils.getTimeLag(time); + + + //������������������������������ + QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>(); + cityAqiQueryWrapper.select("time", "value") + .eq("city_code", locationLevelCode) + .likeRight("time", time); + List<Map<String, Object>> cityAqis = cityAqiService.listMaps(cityAqiQueryWrapper); + Map<String, Object> cityAqiMap = new HashMap<>(); + if (!ObjectUtils.isEmpty(cityAqis)) { + for (Map<String, Object> cityAqi : cityAqis) { + cityAqiMap.put(cityAqi.get("time").toString().substring(0, 13), cityAqi.get("value")); + } + } + + + //������������������������������������ + 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.split(" ")[1]); - yearMonthDayHour = yearMonthDayHour + ":00:00"; + resultMap.put("time", yearMonthDayHour); //������������������������������ - Double allDeviceSum = historyHourlyService.getSensorSumByMacs(sensorCode, allMacs, yearMonthDayHour); + Double allDeviceSum = null; + List<HistoryHourly> historyHourlyList = allDeviceDataMap.get(yearMonthDayHour); + if (!ObjectUtils.isEmpty(historyHourlyList)) { + allDeviceSum = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "sum", sensorLower, sensorUpper); + } + resultMap.put("allDeviceSum", allDeviceSum); - //������������ + //��������� Double cityValue = null; - //������������������������������ - Integer locationLevelCode = organizationService.getById(orgId).getLocationLevelCode(); - QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>(); - cityAqiQueryWrapper.select("`value`->'$." + sensorCode + "' AS result") - .eq("city_code", locationLevelCode) - .eq("time", yearMonthDayHour); - Map<String, Object> cityValueMap = cityAqiService.getMap(cityAqiQueryWrapper); - if (!ObjectUtils.isEmpty(cityValueMap)) { - cityValue = (Double) cityValueMap.get("result"); + if (cityAqiMap.get(yearMonthDayHour) != null) { + Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDayHour).toString(), Map.class); + //������������aqi������������������������ + String sensorName = senorMap.get(sensorCode); + if (sensorName != null) { + cityValue = Double.parseDouble(dataValue.get(sensorName).toString()); + } } resultMap.put("cityValue", cityValue); - - - for (String profession : professions) { - Map<String, Object> professionMap = new HashMap<>(); - - //��������������������� - List<Device> devices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); - List<String> professionMacs = devices.stream().map(Device::getMac).collect(Collectors.toList()); - - //��������������������������������������������������� - Double professionAvg = historyHourlyService.getSensorAvgByMacs(sensorCode, professionMacs, yearMonthDayHour); - Double professionSum = historyHourlyService.getSensorSumByMacs(sensorCode, professionMacs, yearMonthDayHour); - - //��������������������� - String contributionRate = null; - NumberFormat numberFormat = NumberFormat.getInstance(); - numberFormat.setMaximumFractionDigits(2); - if (professionSum != null && allDeviceSum != null) { - contributionRate = numberFormat.format(professionSum / allDeviceSum * 100) + "%"; - } - - //������������ - professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); - //��������������� - professionMap.put("contributionRate", contributionRate); - - resultMap.put(profession, professionMap); - } result.add(resultMap); } + + for (String profession : professions) { + String professionName = null; + Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY); + List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession"); + for (SysDictData sysDictData : professionInfo) { + if (sysDictData.getDataKey().equals(profession)) { + professionName = sysDictData.getDataValue(); + break; + } + } + + //��������������������� + List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession)); + List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList()); + + + //��������������������������������������� + List<HistoryHourly> professionDeviceData = historyHourlyService.getValueByMacs(professionMacs, time); + //���time������ + Map<String, List<HistoryHourly>> professionDataMap = professionDeviceData.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); + //��������� + String contributionRate = null; + Double professionAvg = null; + if (!ObjectUtils.isEmpty(historyHourlyList)) { + //��������������������� + professionAvg = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "avg", sensorLower, sensorUpper); + //������������������������ + Double professionSum = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "sum", sensorLower, sensorUpper); + //��������������������� + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (allDeviceSum != null && (Double) allDeviceSum != 0d) { + contributionRate = numberFormat.format(professionSum / ((Double) allDeviceSum) * 100) + "%"; + } + } + Map<String, Object> professionMap = new HashMap<>(); + professionMap.put("contributionRate", contributionRate); + professionMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0)); + map.put(professionName, professionMap); + } + } + result.forEach(map -> map.remove("allDeviceSum")); return result; } - - //������������id������������macs - private List getMacsByOrgId(Integer orgId) { - //��������������������������� - QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>(); - deviceQueryWrapper.select("mac") - .eq("organization_id", orgId) - .eq("is_delete", Constants.NOT_DELETE); - return deviceService.listObjs(deviceQueryWrapper); - } - - } -- Gitblit v1.8.0