jinpengyong
2021-11-08 645f627a559585048032d1972f903f9b33918c26
screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
@@ -5,14 +5,18 @@
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.CityAqiYearly;
import com.moral.api.entity.Forecast;
import com.moral.api.entity.Organization;
import com.moral.api.entity.SysArea;
import com.moral.api.mapper.CityAqiMapper;
import com.moral.api.mapper.ForecastMapper;
import com.moral.api.service.CityAqiDailyService;
import com.moral.api.service.CityAqiMonthlyService;
import com.moral.api.service.CityAqiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.CityAqiYearlyService;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SysAreaService;
import com.moral.constant.Constants;
@@ -20,6 +24,7 @@
import com.moral.pojo.AQI;
import com.moral.util.AQIUtils;
import com.moral.util.AmendUtils;
import com.moral.util.ComprehensiveIndexUtils;
import com.moral.util.DateUtils;
import com.moral.util.MathUtils;
@@ -29,7 +34,9 @@
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
/**
@@ -60,6 +67,12 @@
    @Autowired
    private CityAqiDailyService cityAqiDailyService;
    @Autowired
    private CityAqiMonthlyService cityAqiMonthlyService;
    @Autowired
    private CityAqiYearlyService cityAqiYearlyService;
    @Override
    public List<Map<String, Object>> measuredCompareForecastOfO3(Map<String, Object> params) {
@@ -198,12 +211,526 @@
        //计算累计aqi和首要污染物
        Map<String, Object> result = new HashMap<>();
        AQI aqi = AQIUtils.hourlyAQI(sixParamAvg);
        result.put("aqi",aqi.getAQIValue());
        result.put("pollutant",aqi.getPrimaryPollutantNames());
        result.put("aqi", aqi.getAQIValue());
        result.put("pollutant", aqi.getPrimaryPollutantNames());
        //结果集添加时间
        CityAqi lastCityAqi = cityAqis.get(cityAqis.size() - 1);
        String time = DateUtils.dateToDateString(lastCityAqi.getTime(), "HH:mm");
        result.put("time", time);
        return result;
    }
    @Override
    public List<Map<String, Object>> rankingDetails(Map<String, Object> params) {
        List<Map<String, Object>> result = new ArrayList<>();
        int orgId = Integer.parseInt(params.get("organizationId").toString());
        String type = params.get("type").toString();
        String time = null;
        if (!ObjectUtils.isEmpty(params.get("time"))) {
            time = params.get("time").toString();
        }
        String start = null;
        String end = null;
        if (!ObjectUtils.isEmpty(params.get("start")) || !ObjectUtils.isEmpty(params.get("end"))) {
            start = params.get("start").toString();
            end = params.get("end").toString();
        }
        String cityType = params.get("cityType").toString();
        //获取省,市code
        Organization organization = organizationService.getById(orgId);
        Integer curProvinceCode = organization.getProvinceCode();
        Integer curCityCode = organization.getCityCode();
        QueryWrapper<SysArea> areaWrapper = new QueryWrapper<>();
        if ("province".equals(cityType)) {
            //获取省内所有市
            areaWrapper.select("area_code").eq("parent_code", curProvinceCode);
        } else {
            //获取市内所有县区
            areaWrapper.select("area_code").eq("parent_code", curCityCode);
        }
        List<Object> regionCodes = sysAreaService.listObjs(areaWrapper);
        switch (type) {
            case "today":
                result = accumulatedTodayRank(regionCodes);
                break;
            case "hour":
                time = new StringBuilder(time).replace(10, 11, " ").toString() + ":00:00";
                result = hourRank(regionCodes, time);
                break;
            case "day":
                time = time + " 00:00:00";
                result = dayRank(regionCodes, time);
                break;
            case "month":
                time = time + "-01 00:00:00";
                result = monthRank(regionCodes, time);
                break;
            case "year":
                time = time + "-01-01 00:00:00";
                result = yearRank(regionCodes, time);
                break;
            case "custom":
                start = start + " 00:00:00";
                end = end + " :00:00";
                result = customRank(regionCodes, start, end);
                break;
            default:
                break;
        }
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的地去编程集合
     * @return 功能:今日累计排名
     */
    private List<Map<String, Object>> accumulatedTodayRank(List<Object> regionCodes) {
        List<Map<String, Object>> result = new ArrayList<>();
        List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2", "CO", "O3");
        Date now = new Date();
        String today = DateUtils.dateToDateString(now, DateUtils.yyyy_MM_dd_EN);
        QueryWrapper<CityAqi> wrapper = new QueryWrapper<>();
        wrapper.select("city_code", "value")
                .ge("time", today)
                .in("city_code", regionCodes);
        List<Map<String, Object>> cumulativeData = cityAqiMapper.selectMaps(wrapper);
        //按city_code分组
        Map<String, List<Map<String, Object>>> data = cumulativeData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        data.forEach((cityCode, value) -> {
            List<Double> doubles = new ArrayList<>();
            for (Map<String, Object> objectMap : value) {
                Object o = JSONObject.parseObject((String) objectMap.get("value"), Map.class).get("O3_8H");
                if (!ObjectUtils.isEmpty(o)) {
                    double v = Double.parseDouble(o.toString());
                    doubles.add(v);
                }
            }
            Map<String, Object> dataMap = new HashMap<>();
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                    Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    Object o = sensorValue.get(sensor);
                    if (ObjectUtils.isEmpty(o)) {
                        return null;
                    }
                    double aDouble = Double.parseDouble(o.toString());
                    return DoubleStream.of(aDouble);
                }).average();
                if (optionalDouble.isPresent()) {
                    //银行家算法修约
                    double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
                    if ("CO".equals(sensor)) {
                        sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 1);
                    }
                    dataMap.put(sensor, sciCal);
                }
            });
            //今日累计O3_8H计算,取每小时O3——8H最大值
            if (!ObjectUtils.isEmpty(doubles)) {
                dataMap.put("O3_8H", Collections.max(doubles));
            }
            //今日累计aqi,首要污染物计算
            Map<String, Object> sixParamMap = new HashMap<>();
            sixParamMap.put(Constants.SENSOR_CODE_PM25, dataMap.get("PM2_5"));
            sixParamMap.put(Constants.SENSOR_CODE_PM10, dataMap.get("PM10"));
            sixParamMap.put(Constants.SENSOR_CODE_SO2, dataMap.get("SO2"));
            sixParamMap.put(Constants.SENSOR_CODE_NO2, dataMap.get("NO2"));
            sixParamMap.put(Constants.SENSOR_CODE_CO, dataMap.get("CO"));
            sixParamMap.put(Constants.SENSOR_CODE_O3, dataMap.get("O3"));
            AQI aqi = AQIUtils.dailyAQI(sixParamMap);
            dataMap.put("AQI", aqi.getAQIValue());
            dataMap.put("primaryPollutant", aqi.getPrimaryPollutantNames());
            //今日累计综合指数计算,O3分综指用O3_8H计算
            Map<String, Object> compositeIndexMap = new HashMap<>(dataMap);
            compositeIndexMap.put("O3", compositeIndexMap.get("O3_8H"));
            Double compositeIndex = ComprehensiveIndexUtils.dailyData(compositeIndexMap);
            dataMap.put("compositeIndex", compositeIndex);
            //城市名
            QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("area_name").eq("area_code", cityCode);
            String areaName = sysAreaService.getOne(queryWrapper).getAreaName();
            dataMap.put("cityName", areaName);
            result.add(dataMap);
        });
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的编码集合
     * @param time        所要获取数据的时间 2021-11-04 13:00:00
     * @return 功能:小时排名
     */
    private List<Map<String, Object>> hourRank(List<Object> regionCodes, String time) {
        List<Map<String, Object>> result = new ArrayList<>();
        QueryWrapper<CityAqi> wrapper = new QueryWrapper<>();
        wrapper.select("value")
                .eq("time", time)
                .in("city_code", regionCodes);
        List<Map<String, Object>> hourData = cityAqiMapper.selectMaps(wrapper);
        for (Map<String, Object> hourDatum : hourData) {
            Map<String, Object> value = JSONObject.parseObject((String) hourDatum.get("value"), Map.class);
            value.remove("pubtime");
            value.remove("rank");
            result.add(value);
        }
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的编码集合
     * @param time        所要获取数据的时间 2021-11-04 00:00:00
     * @return 功能:日排名
     */
    private List<Map<String, Object>> dayRank(List<Object> regionCodes, String time) {
        List<Map<String, Object>> result = new ArrayList<>();
        QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>();
        wrapper.select("city_code", "value")
                .eq("time", time)
                .in("city_code", regionCodes);
        List<Map<String, Object>> dayData = cityAqiDailyService.listMaps(wrapper);
        for (Map<String, Object> dayDatum : dayData) {
            Map<String, Object> value = JSONObject.parseObject((String) dayDatum.get("value"), Map.class);
            //城市名
            QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("area_name")
                    .eq("area_code", dayDatum.get("city_code"));
            String areaName = sysAreaService.getOne(queryWrapper).getAreaName();
            value.put("cityName", areaName);
            result.add(value);
        }
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的编码集合
     * @param time        所要获取数据的时间 2021-11-01 00:00:00 每月1号
     * @return 功能:月排名
     */
    private List<Map<String, Object>> monthRank(List<Object> regionCodes, String time) {
        //需要均值计算的因子
        List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
        List<Map<String, Object>> result = new ArrayList<>();
        //如果是本月,实时计算,其他直接从city_aqi_monthly获取
        if (!time.substring(0, 7).equals(DateUtils.dateToDateString(new Date(), DateUtils.yyyy_MM_EN))) {
            QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>();
            for (Object regionCode : regionCodes) {
                cityAqiMonthlyQueryWrapper.clear();
                cityAqiMonthlyQueryWrapper.select("value")
                        .eq("city_code", regionCode)
                        .eq("time", time);
                CityAqiMonthly cityAqiMonthly = cityAqiMonthlyService.getOne(cityAqiMonthlyQueryWrapper);
                if (cityAqiMonthly == null) {
                    continue;
                }
                String value = cityAqiMonthly.getValue();
                Map<String, Object> resultMap = JSONObject.parseObject(value, Map.class);
                //城市名
                QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
                sysAreaQueryWrapper.select("area_name")
                        .eq("area_code", regionCode);
                String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
                resultMap.put("cityName", areaName);
                result.add(resultMap);
            }
            return result;
        }
        QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
        cityAqiDailyQueryWrapper.select("city_code", "value")
                .ge("time", time)
                .in("city_code", regionCodes);
        List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
        //按city_code分组
        Map<String, List<Map<String, Object>>> thisMonthMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        thisMonthMap.forEach((cityCode, value) -> {
            Map<String, Object> resultMap = new HashMap<>();
            Map<String, Object> params = new HashMap<>();
            List<Map<String, Object>> temp = new ArrayList<>();
            for (Map<String, Object> map : value) {
                Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
                Map<String, Object> tempMap = new HashMap<>();
                tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
                tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
                Map<String, Object> hashMap = new HashMap<>();
                hashMap.put("value", JSONObject.toJSONString(tempMap));
                temp.add(hashMap);
            }
            params.put("data", temp);
            //1. CO 95百分位计算并修约
            Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
                resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
            }
            //2. O3 90百分位计算并修约
            Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
                resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
            }
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                    Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    Object o = sensorValue.get(sensor);
                    if (ObjectUtils.isEmpty(o)) {
                        return null;
                    }
                    double aDouble = Double.parseDouble(o.toString());
                    return DoubleStream.of(aDouble);
                }).average();
                if (optionalDouble.isPresent()) {
                    //银行家算法修约
                    double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
                    resultMap.put(sensor, sciCal);
                }
            });
            //本月综指计算
            Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
            resultMap.put("compositeIndex", compositeIndex);
            //前端O3用O3_8H显示
            resultMap.put("O3_8H", resultMap.remove("O3"));
            //本月综指同上月对比
            Date lastMonth = DateUtils.addMonths(DateUtils.getDate(time), -1);
            QueryWrapper<CityAqiMonthly> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("value")
                    .eq("city_code", cityCode)
                    .eq("time", DateUtils.dateToDateString(lastMonth));
            //获取上月数据
            CityAqiMonthly lastCityAqiMonthly = cityAqiMonthlyService.getOne(queryWrapper);
            String monthContrast = "";
            if (lastCityAqiMonthly != null) {
                Map<String, Object> map = JSONObject.parseObject(lastCityAqiMonthly.getValue(), Map.class);
                double lastCompositeIndex = Double.parseDouble(map.get("compositeIndex").toString());
                DecimalFormat decimalFormat = new DecimalFormat("0.00%");
                monthContrast = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);
            }
            resultMap.put("monthContrast", monthContrast);
            //城市名
            QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
            sysAreaQueryWrapper.select("area_name")
                    .eq("area_code", cityCode);
            String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
            resultMap.put("cityName", areaName);
            result.add(resultMap);
        });
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的编码集合
     * @param time        所要获取数据的时间 2021-11-01 00:00:00 每年1月1号
     * @return 功能:年排名
     */
    private List<Map<String, Object>> yearRank(List<Object> regionCodes, String time) {
        //需要均值计算的因子
        List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
        List<Map<String, Object>> result = new ArrayList<>();
        //如果是本月,实时计算,其他直接从city_aqi_monthly获取
        if (!time.substring(0, 4).equals(DateUtils.dateToDateString(new Date(), DateUtils.yyyy))) {
            QueryWrapper<CityAqiYearly> cityAqiYearlyQueryWrapper = new QueryWrapper<>();
            for (Object regionCode : regionCodes) {
                cityAqiYearlyQueryWrapper.clear();
                cityAqiYearlyQueryWrapper.select("value")
                        .eq("city_code", regionCode)
                        .eq("time", time);
                CityAqiYearly cityAqiYearly = cityAqiYearlyService.getOne(cityAqiYearlyQueryWrapper);
                if (cityAqiYearly == null) {
                    continue;
                }
                String value = cityAqiYearly.getValue();
                Map<String, Object> resultMap = JSONObject.parseObject(value, Map.class);
                //城市名
                QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
                sysAreaQueryWrapper.select("area_name")
                        .eq("area_code", regionCode);
                String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
                resultMap.put("cityName", areaName);
                result.add(resultMap);
            }
            return result;
        }
        QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
        cityAqiDailyQueryWrapper.select("city_code", "value")
                .ge("time", time)
                .in("city_code", regionCodes);
        List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
        //按city_code分组
        Map<String, List<Map<String, Object>>> thisYearMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        thisYearMap.forEach((cityCode, value) -> {
            Map<String, Object> resultMap = new HashMap<>();
            Map<String, Object> params = new HashMap<>();
            List<Map<String, Object>> temp = new ArrayList<>();
            for (Map<String, Object> map : value) {
                Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
                Map<String, Object> tempMap = new HashMap<>();
                tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
                tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
                Map<String, Object> hashMap = new HashMap<>();
                hashMap.put("value", JSONObject.toJSONString(tempMap));
                temp.add(hashMap);
            }
            params.put("data", temp);
            //1. CO 95百分位计算并修约
            Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
                resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
            }
            //2. O3 90百分位计算并修约
            Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
                resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
            }
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                    Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    Object o = sensorValue.get(sensor);
                    if (ObjectUtils.isEmpty(o)) {
                        return null;
                    }
                    double aDouble = Double.parseDouble(o.toString());
                    return DoubleStream.of(aDouble);
                }).average();
                if (optionalDouble.isPresent()) {
                    //银行家算法修约
                    double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
                    resultMap.put(sensor, sciCal);
                }
            });
            //本年综指计算
            Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
            resultMap.put("compositeIndex", compositeIndex);
            //前端O3用O3_8H显示
            resultMap.put("O3_8H", resultMap.remove("O3"));
            //本年综指同去年对比
            String lastYear = DateUtils.getDateAddYear(time.substring(0, 4), -1);
            QueryWrapper<CityAqiYearly> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("value")
                    .eq("city_code", cityCode)
                    .eq("time", lastYear);
            //获取去年数据
            CityAqiYearly lastCityAqiYearly = cityAqiYearlyService.getOne(queryWrapper);
            String yearContrast = "";
            if (lastCityAqiYearly != null) {
                Map<String, Object> map = JSONObject.parseObject(lastCityAqiYearly.getValue(), Map.class);
                double lastCompositeIndex = Double.parseDouble(map.get("compositeIndex").toString());
                DecimalFormat decimalFormat = new DecimalFormat("0.00%");
                yearContrast = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);
            }
            resultMap.put("yearContrast", yearContrast);
            //城市名
            QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
            sysAreaQueryWrapper.select("area_name").eq("area_code", cityCode);
            String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
            resultMap.put("cityName", areaName);
            result.add(resultMap);
        });
        return result;
    }
    /**
     * @param regionCodes 所要获取城市的编码集合
     * @param start       所要获取数据的开始时间,精确到日,2021-11-03 00:00:00
     * @param end         所要获取数据的结束时间,精确到日,2021-11-25 00:00:00
     * @return 功能:自定义排名
     */
    private List<Map<String, Object>> customRank(List<Object> regionCodes, String start, String end) {
        //需要均值计算的因子
        List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
        List<Map<String, Object>> result = new ArrayList<>();
        QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
        cityAqiDailyQueryWrapper.select("city_code", "value")
                .ge("time", start)
                .le("time", end)
                .in("city_code", regionCodes);
        List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
        //按city_code分组
        Map<String, List<Map<String, Object>>> customMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        customMap.forEach((cityCode, value) -> {
            Map<String, Object> resultMap = new HashMap<>();
            Map<String, Object> params = new HashMap<>();
            List<Map<String, Object>> temp = new ArrayList<>();
            for (Map<String, Object> map : value) {
                Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
                Map<String, Object> tempMap = new HashMap<>();
                tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
                tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
                Map<String, Object> hashMap = new HashMap<>();
                hashMap.put("value", JSONObject.toJSONString(tempMap));
                temp.add(hashMap);
            }
            params.put("data", temp);
            //1. CO 95百分位计算并修约
            Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
                resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
            }
            //2. O3 90百分位计算并修约
            Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
            if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
                resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
            }
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                    Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    Object o = sensorValue.get(sensor);
                    if (ObjectUtils.isEmpty(o)) {
                        return null;
                    }
                    double aDouble = Double.parseDouble(o.toString());
                    return DoubleStream.of(aDouble);
                }).average();
                if (optionalDouble.isPresent()) {
                    //银行家算法修约
                    double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
                    resultMap.put(sensor, sciCal);
                }
            });
            //自定义综指计算
            Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
            resultMap.put("compositeIndex", compositeIndex);
            //前端O3用O3_8H显示
            resultMap.put("O3_8H", resultMap.remove("O3"));
            //城市名
            QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
            sysAreaQueryWrapper.select("area_name").eq("area_code", cityCode);
            String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
            resultMap.put("cityName", areaName);
            result.add(resultMap);
        });
        return result;
    }
@@ -423,4 +950,5 @@
        return result;
    }
}