From 4f689a89ba2b4fd92335270de963fd2c6356607b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Tue, 25 Jun 2024 15:00:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E9=80=9A=E6=B5=81=E9=A2=84=E8=AD=A6?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcTrafficFlowWarning.java | 97 +++++++++++++------ .../DcTollStationStatisticsDataMapper.xml | 16 +-- 2 files changed, 75 insertions(+), 38 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficFlowWarning.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficFlowWarning.java index 06dee7a5..9e11d6cf 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficFlowWarning.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficFlowWarning.java @@ -1,12 +1,13 @@ package com.zc.business.controller; import com.google.gson.Gson; -import com.ruoyi.common.utils.uuid.IdUtils; -import com.ruoyi.common.utils.uuid.UUID; import com.zc.business.domain.DcHolidays; import com.zc.business.domain.DcNoStakeWarningTable; +import com.zc.business.domain.DcTollStationStatisticsData; +import com.zc.business.domain.DcTollStationStatisticsDataMap; import com.zc.business.service.IDcGantryStatisticsDataService; import com.zc.business.service.IDcHolidaysService; +import com.zc.business.service.IDcTollStationStatisticsDataService; import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl; import com.zc.common.core.websocket.WebSocketService; import org.springframework.beans.factory.annotation.Autowired; @@ -14,9 +15,13 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; /** * @@ -31,11 +36,12 @@ public class DcTrafficFlowWarning { private IDcHolidaysService dcHolidaysService; @Autowired private IDcGantryStatisticsDataService dcGantryStatisticsDataService; - //@Scheduled(cron = "0/10 * * * * ?") - //@Scheduled(cron = "0 0/5 * * * ?") - public void DcTrafficFlow() { - System.out.println("每隔10秒执行一次:" + new Date()); + @Autowired + private IDcTollStationStatisticsDataService iDcTollStationStatisticsDataService; + //@Scheduled(cron = "0/10 * * * * ?") + @Scheduled(cron = "0 0 9 * * ?") + public void DcTrafficFlow() throws ParseException { // 获取当前日期 LocalDate currentDate = LocalDate.now(); // 获取当前年份 @@ -48,8 +54,10 @@ public class DcTrafficFlowWarning { LocalDate dateAfterSevenDays = currentDate.plusDays(7); // 格式化日期输出(可选) DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String formattedDate = dateAfterSevenDays.format(formatter); - //String formattedDate ="2024-05-01"; + DateTimeFormatter formatterStr = DateTimeFormatter.ofPattern("yyyy年M月d日"); + // String formattedDate = dateAfterSevenDays.format(formatter); + String formattedDateStr = dateAfterSevenDays.format(formatterStr); + String formattedDate ="2024-05-01"; for (DcHolidays holidays : dcHolidaysList) { String vacation = holidays.getVacation(); @@ -58,31 +66,55 @@ public class DcTrafficFlowWarning { if (formattedDate.equals(dates[0])) { //当前假期名称 String name = holidays.getName(); - dcHolidays.setDate(currentYear-1); + dcHolidays.setDate(currentYear - 1); - DcHolidays dcHolidaysLast = dcHolidaysService.selectDcHolidaysListNameByDate(currentYear-1,name); + DcHolidays dcHolidaysLast = dcHolidaysService.selectDcHolidaysListNameByDate(currentYear - 1, name); String vacation1 = dcHolidaysLast.getVacation(); String[] date = vacation1.split("\\|"); - Map>>> mapListOne = new HashMap<>(); + Map>>> mapListOne = new HashMap<>(); - Map>> map = new HashMap<>(); - Map>> map2 = new HashMap<>(); + Map>> map = new HashMap<>(); + Map>> map2 = new HashMap<>(); + Map>> map3 = new HashMap<>(); + Map>> map4 = new HashMap<>(); for (int i1 = 0; i1 < date.length; i1++) { - List> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow( date[i1],"1","4"); - List> mapList2 = dcGantryStatisticsDataService.realTimeTrafficFlow(date[i1],"3","4"); + //交通流 + List> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow(date[i1], "1", "4"); + List> mapList2 = dcGantryStatisticsDataService.realTimeTrafficFlow(date[i1], "3", "4"); + //收费站 + // access_type 1 入口 2出口 + // period_type 时间颗粒度 + List> dcTollStationStatisticsDataTwo = iDcTollStationStatisticsDataService.TollBoothStatistics(date[i1], "2", "4"); + List> dcTollStationStatisticsData = iDcTollStationStatisticsDataService.TollBoothStatistics(date[i1], "1", "4"); + // 计算当前日期加上七天后的日期 - LocalDate dateAfterSevenDay = currentDate.plusDays(7+i1); + LocalDate dateAfterSevenDay = currentDate.plusDays(7 + i1); DateTimeFormatter formattedDateLst = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String formatted = dateAfterSevenDay.format(formattedDateLst); - map.put(formatted,mapList); - map2.put(formatted,mapList2); + map.put(formatted, mapList); + map2.put(formatted, mapList2); + map3.put(formatted, dcTollStationStatisticsData); + map4.put(formatted, dcTollStationStatisticsDataTwo); } - - mapListOne.put("1",map); - mapListOne.put("3",map2); +/* //根据时间进行升序排序 + Map>> sortedMap = map3.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (oldValue, newValue) -> oldValue, // 如果有重复的key,默认保留旧值 + LinkedHashMap::new // 为了保持排序,使用LinkedHashMap + )); + +// 用排序后的Map替换原来的map3 + map3 = sortedMap;*/ + mapListOne.put("1", map);//菏泽方向 + mapListOne.put("3", map2);//济南方向 + mapListOne.put("4", map3);//收费站入口 + mapListOne.put("5", map4);//收费站出口 // 创建Gson对象 Gson gson = new Gson(); @@ -90,21 +122,26 @@ public class DcTrafficFlowWarning { String jsonString = gson.toJson(mapListOne); DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable(); - dcNoStakeWarningTable.setWarningDescription(name +"交通流数据预警提醒"); + // 计算当前日期加上七天的日期 + LocalDate dateAfterSevenDa = currentDate.plusDays(7+date.length); + // 计算当前日期加上七天的日期 + // 格式化日期输出(可选) + DateTimeFormatter formatte = DateTimeFormatter.ofPattern("M月d日"); + String formattedDa = dateAfterSevenDa.format(formatte); + + dcNoStakeWarningTable.setWarningDescription("预计"+ formattedDateStr+"-"+formattedDa+",高速车流量剧增。平台预警提醒您:提前调度路管人员前往匝道等交通事故多发路段巡查,以便及时救援。"); dcNoStakeWarningTable.setWarningType("1"); dcNoStakeWarningTable.setOtherConfig(jsonString); dcNoStakeWarningTable.setWarningTime(new Date()); - +//存入记录 dcNoStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable); - - Map contentMap = new HashMap<>(); - contentMap.put("content",name +"交通流数据预警提醒"); - contentMap.put("trafficFlowDataEarlyWarning",jsonString); + Long id = dcNoStakeWarningTable.getId(); + Map contentMap = new HashMap<>(); + contentMap.put("content", "预计"+ formattedDateStr+"-"+formattedDa+",高速车流量剧增。平台预警提醒您:提前调度路管人员前往匝道等交通事故多发路段巡查,以便及时救援。"); + contentMap.put("id", id); WebSocketService.broadcast("trafficFlowDataEarlyWarning", contentMap); - // 打印JSON字符串 - System.out.println(jsonString.length()); - + System.out.println(jsonString); } } } diff --git a/zc-business/src/main/resources/mapper/business/DcTollStationStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcTollStationStatisticsDataMapper.xml index dec49031..a08b9fa8 100644 --- a/zc-business/src/main/resources/mapper/business/DcTollStationStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcTollStationStatisticsDataMapper.xml @@ -103,14 +103,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"