|
|
|
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.service.IDcGantryStatisticsDataService;
|
|
|
|
import com.zc.business.service.IDcHolidaysService;
|
|
|
|
import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl;
|
|
|
|
import com.zc.common.core.websocket.WebSocketService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class DcTrafficFlowWarning {
|
|
|
|
@Resource
|
|
|
|
private DcNoStakeWarningTableServiceImpl dcNoStakeWarningTableService;
|
|
|
|
@Autowired
|
|
|
|
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());
|
|
|
|
|
|
|
|
// 获取当前日期
|
|
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
// 获取当前年份
|
|
|
|
int currentYear = currentDate.getYear();
|
|
|
|
DcHolidays dcHolidays = new DcHolidays();
|
|
|
|
dcHolidays.setDate(currentYear);
|
|
|
|
//查询当前年份假期
|
|
|
|
List<DcHolidays> dcHolidaysList = dcHolidaysService.selectDcHolidaysList(dcHolidays);
|
|
|
|
// 计算当前日期加上七天的日期
|
|
|
|
LocalDate dateAfterSevenDays = currentDate.plusDays(7);
|
|
|
|
// 格式化日期输出(可选)
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
String formattedDate = dateAfterSevenDays.format(formatter);
|
|
|
|
//String formattedDate ="2024-05-01";
|
|
|
|
|
|
|
|
for (DcHolidays holidays : dcHolidaysList) {
|
|
|
|
String vacation = holidays.getVacation();
|
|
|
|
String[] dates = vacation.split("\\|");
|
|
|
|
//判断当前日期+ 7天 与 日期 数据对比
|
|
|
|
if (formattedDate.equals(dates[0])) {
|
|
|
|
//当前假期名称
|
|
|
|
String name = holidays.getName();
|
|
|
|
dcHolidays.setDate(currentYear-1);
|
|
|
|
|
|
|
|
DcHolidays dcHolidaysLast = dcHolidaysService.selectDcHolidaysListNameByDate(currentYear-1,name);
|
|
|
|
String vacation1 = dcHolidaysLast.getVacation();
|
|
|
|
|
|
|
|
|
|
|
|
String[] date = vacation1.split("\\|");
|
|
|
|
Map<String, Map<String, List<Map<String,String>>>> mapListOne = new HashMap<>();
|
|
|
|
|
|
|
|
Map<String, List<Map<String,String>>> map = new HashMap<>();
|
|
|
|
Map<String, List<Map<String,String>>> map2 = new HashMap<>();
|
|
|
|
for (int i1 = 0; i1 < date.length; i1++) {
|
|
|
|
List<Map<String,String>> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow( date[i1],"1","4");
|
|
|
|
List<Map<String,String>> mapList2 = dcGantryStatisticsDataService.realTimeTrafficFlow(date[i1],"3","4");
|
|
|
|
// 计算当前日期加上七天后的日期
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mapListOne.put("1",map);
|
|
|
|
mapListOne.put("3",map2);
|
|
|
|
|
|
|
|
// 创建Gson对象
|
|
|
|
Gson gson = new Gson();
|
|
|
|
// 将Map转换为JSON字符串
|
|
|
|
String jsonString = gson.toJson(mapListOne);
|
|
|
|
DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable();
|
|
|
|
|
|
|
|
dcNoStakeWarningTable.setWarningDescription(name +"交通流数据预警提醒");
|
|
|
|
dcNoStakeWarningTable.setWarningType("1");
|
|
|
|
dcNoStakeWarningTable.setOtherConfig(jsonString);
|
|
|
|
dcNoStakeWarningTable.setWarningTime(new Date());
|
|
|
|
|
|
|
|
dcNoStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable);
|
|
|
|
|
|
|
|
Map<String,Object> contentMap = new HashMap<>();
|
|
|
|
contentMap.put("content",name +"交通流数据预警提醒");
|
|
|
|
contentMap.put("trafficFlowDataEarlyWarning",jsonString);
|
|
|
|
WebSocketService.broadcast("trafficFlowDataEarlyWarning", contentMap);
|
|
|
|
|
|
|
|
// 打印JSON字符串
|
|
|
|
System.out.println(jsonString.length());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|