ZhuDongming
2019-08-23 e5ca6ba196b8a311cbc0ea182bd6213914c3cce3
src/main/java/com/moral/controller/ScreenController.java
@@ -10,6 +10,7 @@
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1223,27 +1224,29 @@
            @ApiImplicitParam(name = "time", value = "查询时间(格式:2019-08-22)", required = true, paramType = "query", dataType = "String")})
    public ModelAndView pollutionSource(ModelAndView model, HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        LocalDate today=LocalDate.now();
        String time=parameters.get("time").toString();
        LocalDate today = LocalDate.now();
        String time = parameters.get("time").toString();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate selectTime = LocalDate.parse(time, dateTimeFormatter);
        LocalDate yesterday=today.minusDays(1);
        LocalDate futureDay=today.plusDays(14);
        Boolean isAfterYesterday=selectTime.isAfter(yesterday)||selectTime.isEqual(yesterday);
        Boolean isAfterFutureDay=selectTime.isAfter(futureDay);
        Map<String, Object> weatherInfoToday=weatherService.getWeatherDataByRegion(parameters);
        Map<String, Object> weatherInfoForecast=new HashMap<>();
        if(isAfterYesterday&&!isAfterFutureDay){
            weatherInfoForecast= weatherService.get15DayWeatherDataByRegion(parameters);
        int month = selectTime.getMonth().getValue();
        LocalDate yesterday = today.minusDays(1);
        LocalDate futureDay = today.plusDays(14);
        Boolean isAfterYesterday = selectTime.isAfter(yesterday) || selectTime.isEqual(yesterday);
        Boolean isAfterFutureDay = selectTime.isAfter(futureDay);
        Map<String, Object> weatherInfoToday = weatherService.getWeatherDataByRegion(parameters);
        Map<String, Object> weatherInfoForecast = new HashMap<>();
        if (isAfterYesterday && !isAfterFutureDay) {
            weatherInfoForecast = weatherService.get15DayWeatherDataByRegion(parameters);
        }
        Boolean isToday=selectTime.isEqual(today);
        String mac=parameters.get("mac").toString();
        Boolean isToday = selectTime.isEqual(today);
        String mac = parameters.get("mac").toString();
        Device device = deviceService.getDeviceByMac(mac, false);
        JSONObject params = new JSONObject();
        params.put("weatherInfoToday", weatherInfoToday);
        params.put("weatherInfoForecast", weatherInfoForecast);
        params.put("device", device);
        params.put("isToday",isToday);
        params.put("isToday", isToday);
        params.put("month", month);
        String paramsJson = params.toJSONString();
        model.addObject("pollutionSourceParams", paramsJson);
        model.setViewName("pollutionsource");