jinpengyong
2021-12-31 a470e75012381d51b14065c34424e619c86b16e5
screen-job/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java
@@ -60,7 +60,7 @@
        QueryWrapper<CityAqi> wrapper = new QueryWrapper<>();
        wrapper.select("city_code", "time", "value")
                .ge("time", DateUtils.dateToDateString(start))
                .le("time", DateUtils.dateToDateString(end));
                .lt("time", DateUtils.dateToDateString(end));
        List<Map<String, Object>> dailyData = cityAqiService.listMaps(wrapper);
        if (dailyData.size() == 0) {
@@ -69,29 +69,21 @@
        //按city_code分组
        Map<String, List<Map<String, Object>>> data = dailyData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
        CityAqiDaily cityAqiDaily = new CityAqiDaily();
        data.forEach((cityCode, value) -> {
            Map<String, Object> jsonMap = new HashMap<>();
            CityAqiDaily cityAqiDaily = new CityAqiDaily();
            cityAqiDaily.setCityCode(Integer.parseInt(cityCode));
            cityAqiDaily.setTime(start);
            //中间变量,用于计算除臭氧外其它因子
            List<Map<String, Object>> tempValue = new ArrayList<>(value);
            //移除第一天数据(0点的),O3滑动值第一条数据是从1点-8点
            value.removeIf(map -> ((Date) map.get("time")).getTime() == start.getTime());
            //O3日均值单独计算,滑动值算法
            Double o3OfDay = AmendUtils.o3OfDay(value);
            if (o3OfDay != null) {
                jsonMap.put("O3", o3OfDay);
            if (!ObjectUtils.isEmpty(value)) {
                Double o3OfDay = AmendUtils.o3OfDay(value);
                if (o3OfDay != null) {
                    jsonMap.put("O3", o3OfDay);
                }
            }
            //除臭氧外其他因子均值计算
            tempValue.removeIf(o -> ((Date) o.get("time")).getTime() == end.getTime());
            sensors.forEach(sensor -> {
                OptionalDouble optionalDouble = tempValue.parallelStream().flatMapToDouble(v -> {
                OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
                    Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class);
                    Object sensorValue = dataValue.get(sensor);
                    if (ObjectUtils.isEmpty(sensorValue)) {