cjl
2024-04-01 f70a481c8658ae60a1827486c81d6b37ad575b07
screen-job/src/main/java/com/moral/api/service/impl/ForecastServiceImpl.java
@@ -22,12 +22,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
@@ -57,7 +52,7 @@
    private CityAqiService cityAqiService;
    @Autowired
    private ForecastService forecastService;
    private ForecastMapper forecastMapper;
    private static final Map<String, Integer> weatherScore = new HashMap<>();
@@ -129,15 +124,14 @@
        //获取前后一小时map
        Map<Date, List<Integer>> hours = DateUtils.getBeforeAndAfterHourDate(nextDay);
        Forecast forecast = new Forecast();
        List<Forecast> forecastList = new ArrayList<>();
        Map<String, Object> forecastMap = new HashMap<>();
        for (Object obj : cityCodes) {
            Integer cityCode = Integer.parseInt(obj.toString());
            forecast.setCityCode(cityCode);
            //预测
            List<CityWeatherForecast> cityWeatherForecasts = cityForecast.get(cityCode);
            List<CityWeatherForecast> cityWeatherForecasts = Objects.isNull(cityForecast.get(cityCode))?new ArrayList<>():cityForecast.get(cityCode);
            //获取城市历史气象数据
            List<CityWeather> cityWeathers = cityHistoryWeather.get(cityCode);
@@ -170,6 +164,8 @@
            }
            for (CityWeatherForecast cityWeatherForecast : cityWeatherForecasts) {
                Forecast forecast = new Forecast();
                forecast.setCityCode(cityCode);
                Date time = cityWeatherForecast.getTime();
                Map<String, Object> value = JSONObject.parseObject(cityWeatherForecast.getValue(), Map.class);
                String weather = value.get("text").toString();
@@ -205,11 +201,14 @@
                if (!Double.isNaN(o3Forecast)) {
                    forecastMap.put("O3", AmendUtils.sciCal(o3Forecast, 0));
                    forecast.setValue(JSONObject.toJSONString(forecastMap));
                    forecastService.save(forecast);
                    forecastList.add(forecast);
                }
            }
        }
        if(forecastList.size()>0){
            forecastMapper.insertForecast(forecastList);
        }
    }
    private Double calculateAvg(List<Map<String, Object>> list, String param) {