jinpengyong
2022-01-17 3ec35029adfb63e79ad17bf351317768e687ec2b
screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java
@@ -69,7 +69,18 @@
            return;
        }
        //按city_code分组
        Map<String, List<Map<String, Object>>> data = monthlyData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        Map<String, List<Map<String, Object>>> data = monthlyData.stream()
                .collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        //获取上月数据,本月综指同上月对比
        QueryWrapper<CityAqiMonthly> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("city_code", "value")
                .eq("time", DateUtils.dateToDateString(lastLastMonth));
        //获取上月数据
        List<CityAqiMonthly> lastCityAqiMonthly = cityAqiMonthlyMapper.selectList(queryWrapper);
        Map<Integer, List<CityAqiMonthly>> lastMonthData = lastCityAqiMonthly.stream()
                .collect(Collectors.groupingBy(CityAqiMonthly::getCityCode));
        CityAqiMonthly cityAqiMonthly = new CityAqiMonthly();
        data.forEach((cityCode, value) -> {
@@ -102,7 +113,7 @@
            }
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                OptionalDouble optionalDouble = value.stream().flatMapToDouble(v -> {
                    Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    double aDouble = Double.parseDouble(dataValue.get(sensor).toString());
                    return DoubleStream.of(aDouble);
@@ -118,14 +129,10 @@
            jsonMap.put("compositeIndex", compositeIndex);
            //本月综指同上月对比
            QueryWrapper<CityAqiMonthly> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("value")
                    .eq("city_code", cityCode)
                    .eq("time", DateUtils.dateToDateString(lastLastMonth));
            //获取上上月数据
            CityAqiMonthly lastCityAqiMonthly = cityAqiMonthlyMapper.selectOne(queryWrapper);
            if (lastCityAqiMonthly != null) {
                Map<String, Object> map = JSONObject.parseObject(lastCityAqiMonthly.getValue(), Map.class);
            List<CityAqiMonthly> cityAqiMonthlies = lastMonthData.get(Integer.parseInt(cityCode));
            if (!ObjectUtils.isEmpty(cityAqiMonthlies)) {
                CityAqiMonthly monthly = cityAqiMonthlies.get(0);
                Map<String, Object> map = JSONObject.parseObject(monthly.getValue(), Map.class);
                double lastCompositeIndex = Double.parseDouble(map.get("compositeIndex").toString());
                DecimalFormat decimalFormat = new DecimalFormat("0.00%");
                String format = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);