diff --git a/zc-business/src/main/java/com/zc/business/controller/WordController.java b/zc-business/src/main/java/com/zc/business/controller/WordController.java index 775ff31f..76929ef0 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WordController.java +++ b/zc-business/src/main/java/com/zc/business/controller/WordController.java @@ -2,6 +2,7 @@ package com.zc.business.controller; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcTrafficSectionData; import com.zc.business.mapper.DcTrafficIncidentsMapper; import com.zc.business.utils.PoiUtil; import io.swagger.annotations.Api; @@ -19,9 +20,12 @@ import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.math.BigInteger; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; import static com.zc.business.utils.PoiUtil.*; @@ -128,68 +132,102 @@ public class WordController { PoiUtil.createHeading2(doc,"天气情况统计"); - AjaxResult ajaxResult = weatherForecastController.hourlyWeather(); +// AjaxResult ajaxResult = weatherForecastController.hourlyWeather(); + HashMap params = new HashMap<>(); + params.put("roadId","G003537"); + params.put("stakeNum","K60+000|K105+000|K145+000|K165+000|K175+000|K190+000|K200+000|K205+000"); + params.put("forecastHour","24"); + AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(params); + if (ajaxResult.get("code").equals(200)) { - Map>> data = (Map>>) ajaxResult.get("data"); + List> data = (List>) ajaxResult.get("data"); if (data != null && data.size() != 0){ - XWPFTable table = doc.createTable(9, 25); + XWPFTable table = doc.createTable(9, 10); //列宽自动分割 CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); infoTableWidth.setType(STTblWidth.DXA); infoTableWidth.setW(BigInteger.valueOf(9072)); - data.keySet().forEach(key ->{ - if ("hourlyWeather1".equals(key)){ + DateTimeFormatter parseFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + + data.forEach(dataItem ->{ + if ("K60+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(1).getCell(0), "长清区"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - OffsetDateTime offsetDateTime = OffsetDateTime.parse(weatherList.get(i).get("fxTime").toString()); - setTableFonts(table.getRow(0).getCell(i+1),offsetDateTime.format(DateTimeFormatter.ofPattern("dd日HH时"))); - setTableFonts(table.getRow(1).getCell(i+1), weatherList.get(i).get("text").toString()); + //第一行 格式化时间 + LocalDateTime localDateTime = LocalDateTime.parse(weatherList.get(i).get("weatherTime").toString(), parseFormatter); + DateTimeFormatter formatFormatter = DateTimeFormatter.ofPattern("dd日HH时"); + setTableFonts(table.getRow(0).getCell(i+1),localDateTime.format(formatFormatter)); + setTableFonts(table.getRow(1).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather2".equals(key)){ + } else if ("K105+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(2).getCell(0), "平阴县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(2).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(2).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather3".equals(key)){ + } else if ("K145+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(3).getCell(0), "东平县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(3).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(3).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather4".equals(key)){ + } else if ("K165+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(4).getCell(0), "汶上县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(4).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(4).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather5".equals(key)){ + } else if ("K175+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(5).getCell(0), "梁山县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(5).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(5).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather6".equals(key)){ + } else if ("K190+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(6).getCell(0), "嘉祥县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(6).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(6).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather7".equals(key)){ + } else if ("K200+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(7).getCell(0), "巨野县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(7).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(7).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } - } else if ("hourlyWeather8".equals(key)){ + } else if ("K205+000".equals(dataItem.get("stakeNum"))){ setTableFonts(table.getRow(8).getCell(0), "郓城县"); - List> weatherList = data.get(key); + List> weatherList = (List>) dataItem.get("forecastList"); + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = 0; i < weatherList.size(); i++) { - setTableFonts(table.getRow(8).getCell(i+1), weatherList.get(i).get("text").toString()); + setTableFonts(table.getRow(8).getCell(i+1), weatherList.get(i).get("weatherDescription").toString()); } } }); @@ -197,6 +235,8 @@ public class WordController { addDescription(doc,"暂无数据"); } + } else { + addDescription(doc,"暂无数据"); } //换行