From 495f2eabbe4e17b1748db7aa7edc6b469f846e3a Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Fri, 30 Aug 2024 14:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E9=A2=84=E6=8A=A5=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/WordController.java | 117 +++++++++++++----- 1 file changed, 84 insertions(+), 33 deletions(-) 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 406bc3d4..0786173d 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 @@ -1,7 +1,11 @@ package com.zc.business.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.DateUtils; import com.zc.business.domain.DcTollStationStatisticsData; import com.zc.business.enums.TrafficDataPeriodTypeEnum; @@ -59,6 +63,9 @@ public class WordController { @Autowired private IDcGantryStatisticsDataService dcGantryStatisticsDataService; + @Autowired + private RedisCache redisCache; + @PostMapping("/trafficSituationReport") @ApiOperation("导出通行情况快报") @@ -155,11 +162,14 @@ public class WordController { params.put("roadId",UniversalEnum.ROAD_ID.getValue()); params.put("stakeNum",UniversalEnum.STAKE_NUM.getValue()); params.put("forecastHour",UniversalEnum.TWENTY_FOUR.getValue()); - AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(params); - if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { + JSONArray jsonArray = redisCache.getCacheObject("twentyFourHourWeather"); + +// AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(params); + + if (jsonArray != null) { - List> data = (List>) ajaxResult.get("data"); + List> data = (List>) JSON.toJSON(jsonArray); if (data != null && data.size() != UniversalEnum.ZERO.getNumber()){ XWPFTable table = doc.createTable(UniversalEnum.NINE.getNumber(), UniversalEnum.TEN.getNumber()); @@ -171,15 +181,13 @@ public class WordController { DateTimeFormatter parseFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; data.forEach(dataItem ->{ - List> weatherList = (List>) dataItem.get("forecastList"); - if (weatherList != null && weatherList.size() > 0){ - weatherList = weatherList.stream() - .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) - .collect(Collectors.toList()); - - if (UniversalEnum.STAKE_NUM_K60.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.CHANG_QING_DISTRICT.getValue()); - + if (UniversalEnum.STAKE_NUM_K60.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.CHANG_QING_DISTRICT.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0){ + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { //第一行 格式化时间 LocalDateTime localDateTime = LocalDateTime.parse(weatherList.get(i).get("weatherTime").toString(), parseFormatter); @@ -187,40 +195,83 @@ public class WordController { setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()),localDateTime.format(formatFormatter)); setTableFonts(table.getRow(UniversalEnum.ONE.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K105.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.TWO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.PING_YIN_COUNTY.getValue()); + } + + } else if (UniversalEnum.STAKE_NUM_K105.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.TWO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.PING_YIN_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.TWO.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.TWO.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K145.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.THREE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.DONG_PING_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K145.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.THREE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.DONG_PING_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.THREE.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.THREE.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K165.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.FOUR.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.WEN_SHANG_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K165.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.FOUR.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.WEN_SHANG_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.FOUR.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.FOUR.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K175.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.FIVE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.LIANG_SHAN_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K175.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.FIVE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.LIANG_SHAN_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.FIVE.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.FIVE.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K190.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.SIX.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.JIA_XIANG_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K190.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.SIX.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.JIA_XIANG_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.SIX.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.SIX.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K200.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.SEVEN.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.JUYE_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K200.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.SEVEN.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.JUYE_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.SEVEN.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.SEVEN.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K205.getValue().equals(dataItem.get("stakeNum"))){ - setTableFonts(table.getRow(UniversalEnum.EIGHT.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.YUN_CHENG_COUNTY.getValue()); + } + } else if (UniversalEnum.STAKE_NUM_K205.getValue().equals(dataItem.get("stakeNum"))){ + setTableFonts(table.getRow(UniversalEnum.EIGHT.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), UniversalEnum.YUN_CHENG_COUNTY.getValue()); + List> weatherList = (List>) dataItem.get("forecastList"); + if (weatherList != null && weatherList.size() > 0) { + weatherList = weatherList.stream() + .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) + .collect(Collectors.toList()); for (int i = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - setTableFonts(table.getRow(UniversalEnum.EIGHT.getNumber()).getCell(i+UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); + setTableFonts(table.getRow(UniversalEnum.EIGHT.getNumber()).getCell(i + UniversalEnum.ONE.getNumber()), weatherList.get(i).get("weatherDescription").toString()); } } }