| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityAqiDaily; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityAqiDailyMapper extends BaseMapper<CityAqiDaily> { |
| | | |
| | | void insertCityAqiDaily(List<CityAqiDaily> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityAqi; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityAqiMapper extends BaseMapper<CityAqi> { |
| | | |
| | | void insertCityAqi(List<CityAqi> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityAqiMonthly; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityAqiMonthlyMapper extends BaseMapper<CityAqiMonthly> { |
| | | |
| | | void insertCityAqiMonthly(List<CityAqiMonthly> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityAqiMonthly; |
| | | import com.moral.api.entity.CityAqiYearly; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityAqiYearlyMapper extends BaseMapper<CityAqiYearly> { |
| | | |
| | | void insertCityAqiYearly(List<CityAqiYearly> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityWeatherForecast; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityWeatherForecastMapper extends BaseMapper<CityWeatherForecast> { |
| | | |
| | | void insertCityWeatherForecast(List<CityWeatherForecast> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.CityWeather; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface CityWeatherMapper extends BaseMapper<CityWeather> { |
| | | |
| | | void insertCityWeather(List<CityWeather> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.Forecast; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface ForecastMapper extends BaseMapper<Forecast> { |
| | | |
| | | void insertForecast(List<Forecast> list); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.moral.api.entity.HistoryAqi; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface HistoryAqiMapper extends BaseMapper<HistoryAqi> { |
| | | |
| | | void insertHistoryAqi(List<HistoryAqi> list); |
| | | |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | //按city_code分组 |
| | | Map<String, List<Map<String, Object>>> data = dailyData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString())); |
| | | Map<String, List<Map<String, Object>>> data = dailyData.stream() |
| | | .collect(Collectors.groupingBy(o -> o.get("city_code").toString())); |
| | | |
| | | List<CityAqiDaily> cityAqiDailies = new ArrayList<>(); |
| | | CityAqiDaily cityAqiDaily = new CityAqiDaily(); |
| | | data.forEach((cityCode, value) -> { |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | |
| | | } |
| | | |
| | | 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); |
| | | Object sensorValue = dataValue.get(sensor); |
| | | if (ObjectUtils.isEmpty(sensorValue)) { |
| | |
| | | jsonMap.put("compositeIndex", compositeIndex); |
| | | |
| | | cityAqiDaily.setValue(JSONObject.toJSONString(jsonMap)); |
| | | cityAqiDailyMapper.insert(cityAqiDaily); |
| | | cityAqiDailies.add(cityAqiDaily); |
| | | }); |
| | | cityAqiDailyMapper.insertCityAqiDaily(cityAqiDailies); |
| | | } |
| | | } |
| | |
| | | Map<Integer, List<CityAqiMonthly>> lastMonthData = lastCityAqiMonthly.stream() |
| | | .collect(Collectors.groupingBy(CityAqiMonthly::getCityCode)); |
| | | |
| | | |
| | | List<CityAqiMonthly> cityAqiMonthlyList = new ArrayList<>(); |
| | | CityAqiMonthly cityAqiMonthly = new CityAqiMonthly(); |
| | | data.forEach((cityCode, value) -> { |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | |
| | | jsonMap.put("monthContrast", format); |
| | | } |
| | | cityAqiMonthly.setValue(JSONObject.toJSONString(jsonMap)); |
| | | cityAqiMonthlyMapper.insert(cityAqiMonthly); |
| | | cityAqiMonthlyList.add(cityAqiMonthly); |
| | | }); |
| | | cityAqiMonthlyMapper.insertCityAqiMonthly(cityAqiMonthlyList); |
| | | } |
| | | } |
| | |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | wrapper.select("city_code", "city_id").eq("is_delete", Constants.NOT_DELETE); |
| | | List<CityConfigAqi> list = cityConfigAqiService.list(wrapper); |
| | | |
| | | List<CityAqi> cityAqiList = new ArrayList<>(); |
| | | CityAqi cityAqi = new CityAqi(); |
| | | for (CityConfigAqi cityConfigAqi : list) { |
| | | Integer cityCode = cityConfigAqi.getCityCode(); |
| | |
| | | cityAqi.setCityCode(cityCode); |
| | | cityAqi.setTime(dataTime); |
| | | cityAqi.setValue(JSONObject.toJSONString(aqi)); |
| | | cityAqiMapper.insert(cityAqi); |
| | | cityAqiList.add(cityAqi); |
| | | //存入redis |
| | | redisTemplate.opsForHash().put(RedisConstants.CITY_AQI, cityCode.toString(), aqi); |
| | | } |
| | | cityAqiMapper.insertCityAqi(cityAqiList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | * SO2,NO2,日均值98百分位 |
| | | * O3,日最大值90百分位 |
| | | * */ |
| | | List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2"); |
| | | |
| | | //开始时间,去年1号 |
| | | Date start = DateUtils.getFirstDayOfLastYear(); |
| | |
| | | Map<Integer, List<CityAqiYearly>> lastYearData = lastCityAqiYearly.stream() |
| | | .collect(Collectors.groupingBy(CityAqiYearly::getCityCode)); |
| | | |
| | | |
| | | List<CityAqiYearly> cityAqiYearlyList = new ArrayList<>(); |
| | | CityAqiYearly cityAqiYearly = new CityAqiYearly(); |
| | | data.forEach((cityCode, value) -> { |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | |
| | | jsonMap.put("yearContrast", format); |
| | | } |
| | | cityAqiYearly.setValue(JSONObject.toJSONString(jsonMap)); |
| | | cityAqiYearlyMapper.insert(cityAqiYearly); |
| | | cityAqiYearlyList.add(cityAqiYearly); |
| | | }); |
| | | cityAqiYearlyMapper.insertCityAqiYearly(cityAqiYearlyList); |
| | | } |
| | | } |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | QueryWrapper<CityConfigWeatherForecast> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("city_code", "location_id").eq("is_delete", Constants.NOT_DELETE); |
| | | List<CityConfigWeatherForecast> list = cityConfigWeatherForecastService.list(wrapper); |
| | | |
| | | List<CityWeatherForecast> cityWeatherForecasts = new ArrayList<>(); |
| | | CityWeatherForecast cityWeatherForecast = new CityWeatherForecast(); |
| | | for (CityConfigWeatherForecast cityConfigWeatherForecast : list) { |
| | | Integer cityCode = cityConfigWeatherForecast.getCityCode(); |
| | |
| | | cityWeatherForecast.setCityCode(cityCode); |
| | | cityWeatherForecast.setTime(DateUtils.getDate(hourTime, DateUtils.yyyy_MM_dd_HH_EN)); |
| | | cityWeatherForecast.setValue(JSONObject.toJSONString(hourlyMap)); |
| | | cityWeatherForecastMapper.insert(cityWeatherForecast); |
| | | cityWeatherForecasts.add(cityWeatherForecast); |
| | | } |
| | | } |
| | | } |
| | | cityWeatherForecastMapper.insertCityWeatherForecast(cityWeatherForecasts); |
| | | } |
| | | } |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | QueryWrapper<CityConfigWeather> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("city_code", "location_id").eq("is_delete", Constants.NOT_DELETE); |
| | | List<CityConfigWeather> list = cityConfigWeatherService.list(wrapper); |
| | | |
| | | List<CityWeather> cityWeathers = new ArrayList<>(); |
| | | CityWeather cityWeather = new CityWeather(); |
| | | for (CityConfigWeather cityConfigWeather : list) { |
| | | Integer cityCode = cityConfigWeather.getCityCode(); |
| | |
| | | cityWeather.setValue(JSONObject.toJSONString(now)); |
| | | Date time = DateUtils.dataToTimeStampTime(new Date(), DateUtils.yyyy_MM_dd_HH_EN); |
| | | cityWeather.setTime(time); |
| | | //存入数据库 |
| | | cityWeatherMapper.insert(cityWeather); |
| | | cityWeathers.add(cityWeather); |
| | | //存入redis |
| | | redisTemplate.opsForHash().put(RedisConstants.CITY_WEATHER, String.valueOf(cityCode), now); |
| | | } |
| | | cityWeatherMapper.insertCityWeather(cityWeathers); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | private CityAqiService cityAqiService; |
| | | |
| | | @Autowired |
| | | private ForecastService forecastService; |
| | | private ForecastMapper forecastMapper; |
| | | |
| | | private static final Map<String, Integer> weatherScore = new HashMap<>(); |
| | | |
| | |
| | | //获取前后一小时map |
| | | Map<Date, List<Integer>> hours = DateUtils.getBeforeAndAfterHourDate(nextDay); |
| | | |
| | | List<Forecast> forecastList = new ArrayList<>(); |
| | | Forecast forecast = new Forecast(); |
| | | Map<String, Object> forecastMap = new HashMap<>(); |
| | | for (Object obj : cityCodes) { |
| | |
| | | if (!Double.isNaN(o3Forecast)) { |
| | | forecastMap.put("O3", AmendUtils.sciCal(o3Forecast, 0)); |
| | | forecast.setValue(JSONObject.toJSONString(forecastMap)); |
| | | forecastService.save(forecast); |
| | | forecastList.add(forecast); |
| | | } |
| | | } |
| | | |
| | | } |
| | | forecastMapper.insertForecast(forecastList); |
| | | } |
| | | |
| | | private Double calculateAvg(List<Map<String, Object>> list, String param) { |
| | |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | List<GovMonitorPoint> govMonitorPoints = govMonitorPointService.list(queryWrapper); |
| | | Date time = DateUtils.dataToTimeStampTime(new Date(), DateUtils.yyyy_MM_dd_HH_EN); |
| | | String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | |
| | | List<HistoryAqi> historyAqis = new ArrayList<>(); |
| | | HistoryAqi historyAqi = new HistoryAqi(); |
| | | for (GovMonitorPoint govMonitorPoint : govMonitorPoints) { |
| | | String guid = govMonitorPoint.getGuid(); |
| | |
| | | historyAqi.setTime(DateUtils.addHours(time, -1)); |
| | | //存入数据库 |
| | | historyAqi.setValue(JSONObject.toJSONString(map)); |
| | | historyAqiMapper.insert(historyAqi); |
| | | |
| | | historyAqis.add(historyAqi); |
| | | |
| | | Map<String, Object> value = new HashMap<>(); |
| | | Object pm2_5 = map.get("pm2_5"); |
| | |
| | | //aqi数据存入redis |
| | | redisTemplate.opsForHash().put(RedisConstants.AQI_DATA, guid, value); |
| | | } |
| | | //存入数据库 |
| | | historyAqiMapper.insertHistoryAqi(historyAqis); |
| | | } |
| | | |
| | | @Override |
| | |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityAqiDaily"> |
| | | INSERT INTO city_aqi_daily |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.CityAqiMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqi"> |
| | | <result column="city_code" property="cityCode" /> |
| | | <result column="time" property="time" /> |
| | | <result column="value" property="value" /> |
| | | </resultMap> |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqi"> |
| | | <result column="city_code" property="cityCode"/> |
| | | <result column="time" property="time"/> |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityAqi"> |
| | | INSERT INTO city_aqi |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | </mapper> |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.CityAqiMonthlyMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqiMonthly"> |
| | | <result column="city_code" property="cityCode" /> |
| | | <result column="time" property="time" /> |
| | | <result column="value" property="value" /> |
| | | </resultMap> |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqiMonthly"> |
| | | <result column="city_code" property="cityCode"/> |
| | | <result column="time" property="time"/> |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityAqiMonthly"> |
| | | INSERT INTO city_aqi_monthly |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.CityAqiYearlyMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqiYearly"> |
| | | <result column="city_code" property="cityCode" /> |
| | | <result column="time" property="time" /> |
| | | <result column="value" property="value" /> |
| | | </resultMap> |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityAqiYearly"> |
| | | <result column="city_code" property="cityCode"/> |
| | | <result column="time" property="time"/> |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityAqiYearly"> |
| | | INSERT INTO city_aqi_yearly |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityWeatherForecast"> |
| | | INSERT INTO city_weather_forecast |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertCityWeather"> |
| | | INSERT INTO city_weather |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertForecast"> |
| | | INSERT INTO forecast |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.cityCode},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | <insert id="insertHistoryAqi"> |
| | | INSERT INTO history_aqi |
| | | VALUES |
| | | <foreach collection="list" item="item" separator=","> |
| | | (#{item.guid},#{item.time},#{item.value}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | </mapper> |