|  |  |  | 
|---|
|  |  |  | 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) -> { | 
|---|
|  |  |  | CityAqiYearly cityAqiYearly = new CityAqiYearly(); | 
|---|
|  |  |  | Map<String, Object> jsonMap = new HashMap<>(); | 
|---|
|  |  |  | cityAqiYearly.setCityCode(Integer.parseInt(cityCode)); | 
|---|
|  |  |  | cityAqiYearly.setTime(start); | 
|---|
|  |  |  | 
|---|
|  |  |  | jsonMap.put("yearContrast", format); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cityAqiYearly.setValue(JSONObject.toJSONString(jsonMap)); | 
|---|
|  |  |  | cityAqiYearlyMapper.insert(cityAqiYearly); | 
|---|
|  |  |  | cityAqiYearlyList.add(cityAqiYearly); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | cityAqiYearlyMapper.insertCityAqiYearly(cityAqiYearlyList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|