|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface ForecastWeatherMapper { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertForecastWeather(List<Map<String,Object>> list); | 
|---|
|  |  |  | int insertForecastWeather(List<Map<String,Object>> list); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void deleteByTime(Map<String,Object> parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface RealWeatherMapper { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertRealWeather(List<Map<String,Object>> list); | 
|---|
|  |  |  | int insertRealWeather(List<Map<String,Object>> list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface AlarmService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertAlarmDaily(); | 
|---|
|  |  |  | int insertAlarmDaily(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void createTable(String yearAndMonth); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface ForecastWeatherService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertForecastWeather() throws ParseException; | 
|---|
|  |  |  | int insertForecastWeather() throws ParseException; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface RealWeatherService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void insertRealWeather() throws ParseException; | 
|---|
|  |  |  | int insertRealWeather() throws ParseException; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | private AlarmMapper alarmMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void insertAlarmDaily() { | 
|---|
|  |  |  | public int insertAlarmDaily() { | 
|---|
|  |  |  | LocalDateTime time = LocalDateTime.now(); | 
|---|
|  |  |  | LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS); | 
|---|
|  |  |  | LocalDateTime startTime = endTime.minusDays(1); | 
|---|
|  |  |  | 
|---|
|  |  |  | devices.put("end", endTime); | 
|---|
|  |  |  | devices.put("yearAndMonth", yearAndMonth); | 
|---|
|  |  |  | List<String> macs = alarmMapper.getMacs(devices); | 
|---|
|  |  |  | int count = 0; | 
|---|
|  |  |  | for (String mac : macs) { | 
|---|
|  |  |  | List<Map<String, Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | devices.put("mac", mac); | 
|---|
|  |  |  | 
|---|
|  |  |  | map.put("json",JSONUtils.toJSONString(jsonMap)); | 
|---|
|  |  |  | resultList.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | alarmMapper.insertAlarmDaily(resultList); | 
|---|
|  |  |  | count = count + alarmMapper.insertAlarmDaily(resultList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return count; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | private ProvinceMapper provinceMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void insertForecastWeather() throws ParseException { | 
|---|
|  |  |  | public int insertForecastWeather() throws ParseException { | 
|---|
|  |  |  | Calendar c = Calendar.getInstance(); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int count=0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> map : hashSet) { | 
|---|
|  |  |  | String id = map.get("cityID").toString(); | 
|---|
|  |  |  | Map<String, Object> dataMap = restTemplate.getForObject("https://api.heweather.net/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, id); | 
|---|
|  |  |  | if (dataMap == null) { | 
|---|
|  |  |  | dataMap = new HashMap<>(); | 
|---|
|  |  |  | return count; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String json = JSONObject.toJSONString(dataMap); | 
|---|
|  |  |  | dataMap = (Map<String, Object>) JSONObject.parse(json); | 
|---|
|  |  |  | 
|---|
|  |  |  | jsonMap.remove("fxTime"); | 
|---|
|  |  |  | map.put("json", JSONObject.toJSONString(jsonMap)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | forecastWeatherMapper.insertForecastWeather(arrayList); | 
|---|
|  |  |  | count = count+forecastWeatherMapper.insertForecastWeather(arrayList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return count; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | private ProvinceMapper provinceMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void insertRealWeather() throws ParseException { | 
|---|
|  |  |  | public int insertRealWeather() throws ParseException { | 
|---|
|  |  |  | Calendar c = Calendar.getInstance(); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | 
|---|
|  |  |  | for (Map<String, Object> map : resultList) { | 
|---|
|  |  |  | map.remove("name"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | realWeatherMapper.insertRealWeather(resultList); | 
|---|
|  |  |  | return realWeatherMapper.insertRealWeather(resultList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("alarmDaily") | 
|---|
|  |  |  | public ReturnT insertAlarmDailyTable(String param) { | 
|---|
|  |  |  | alarmService.insertAlarmDaily(); | 
|---|
|  |  |  | int count = alarmService.insertAlarmDaily(); | 
|---|
|  |  |  | if(count>0){ | 
|---|
|  |  |  | return new ReturnT(200, "插入天表成功"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return new ReturnT(200, "插入天表成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("createAlarmSubTable") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("forecastWeatherHour") | 
|---|
|  |  |  | public ReturnT insertForecastWeather(String param) throws ParseException { | 
|---|
|  |  |  | forecastWeatherService.insertForecastWeather(); | 
|---|
|  |  |  | int count = forecastWeatherService.insertForecastWeather(); | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | return new ReturnT(200, "插入成功"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return new ReturnT(200, "插入失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @XxlJob("realWeatherHour") | 
|---|
|  |  |  | public ReturnT insertRealWeather(String param) throws ParseException { | 
|---|
|  |  |  | realWeatherService.insertRealWeather(); | 
|---|
|  |  |  | int count = realWeatherService.insertRealWeather(); | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | return new ReturnT(200, "插入成功"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return new ReturnT(200, "插入失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|