Browse Source

导出

develop
wangsixiang 2 months ago
parent
commit
a330879db7
  1. 496
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

496
zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

@ -39,6 +39,7 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
@ -92,24 +93,20 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//根据开始事件验重,如果有时间重复的则本次不导入
List<Date> timeList = dcSdhsEventMapper.selectTimeList();
if (timeList != null && timeList.size() > 0 && importData != null && importData.size() > 0){
List<String> duplicateData = new ArrayList<>();
for (DcSdhsEvent importDatum : importData) {
if (timeList.contains(importDatum.getStartTime())){
duplicateData.add(df.format(importDatum.getStartTime()));
}
}
if (duplicateData.size() > 0){
return AjaxResult.error("本次导入含有重复数据",duplicateData);
}
}
//整理数据后批量插入数据库
List<String> duplicateData = new ArrayList<>();
List<DcSdhsEvent> eventList = new ArrayList<>();
if (importData != null && importData.size() > 0) {
for (DcSdhsEvent dcSdhsEvent : importData) {
if (timeList != null && timeList.size() > 0){
if (timeList.contains(dcSdhsEvent.getStartTime())){
duplicateData.add(df.format(dcSdhsEvent.getStartTime()));
continue;
}
}
//是否多车事故
String carNum = dcSdhsEvent.getCarNum();
if (StringUtils.isNotEmpty(carNum)) {
@ -154,6 +151,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//如果还验证不通过 则此条信息作废
if (!StakeMarkUtils.checkStakeMark(stakeMark)) {
duplicateData.add(df.format(dcSdhsEvent.getStartTime()));
continue;
}
}
@ -170,9 +168,9 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
//保存至数据库
int successNum = 0;
if (eventList.size() > 0) {
dcSdhsEventMapper.batchInsert(eventList);
//redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT, eventList);
successNum = dcSdhsEventMapper.batchInsert(eventList);
}
Map<String, Object> fileInfo = new HashMap<>();
@ -184,17 +182,21 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
fileInfo.put("uploadTime", updateTime);
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE, now.getTime(), fileInfo);
return AjaxResult.success("导入成功");
Map<String,Object> result = new HashMap<>();
result.put("successNum",successNum);
result.put("errorNum",duplicateData.size());
return AjaxResult.success(result);
}
/**
* @Description 根据时间范围删除数据
*
* @author liuwenge
* @date 2024/9/9 11:58
* @param startTime
* @param endTime
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 根据时间范围删除数据
* @author liuwenge
* @date 2024/9/9 11:58
*/
@Override
public AjaxResult deleteData(String startTime, String endTime) {
@ -719,8 +721,19 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
*/
@Override
public void exportAccidentModelAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) {
String type = dcSdhsEventQuery.getType();
String stringType = "";
if (type.equals("0")) {
stringType = "年";
} else if (type.equals("1")) {
stringType = "月";
} else {
stringType = "日";
}
// 初始化一个空的结果映射
Map<String, Map<String, Integer>> result = accidentModelAnalysis(dcSdhsEventQuery);
Map<String, Map<String, Map<String, Integer>>> map = accidentModelAnalysis(dcSdhsEventQuery);
Map<String, Map<String, Integer>> result = map.get(dcSdhsEventQuery.getThisTime());
Map<String, Map<String, Integer>> result2 = map.get(dcSdhsEventQuery.getLastTime());
PoiUtil.createHeading2(doc, "事故车型分析");
if (result != null && result.size() != UniversalEnum.ZERO.getNumber()) {
@ -741,12 +754,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
// 设置表头
XWPFTableRow headerRow = table.getRow(0);
setTableFonts(headerRow.getCell(0), ""); // 第一列是事件类型
setTableFonts(headerRow.getCell(0), dcSdhsEventQuery.getThisTime() + "(" + (stringType) + ")"); // 第一列是事件类型 dcSdhsEventQuery.getThisTime()
int colIdx = 1;
for (String vehicleType : vehicleTypes) {
table.getRow(0).getCell(colIdx++).setText(vehicleType);
}
// 填充表格内容
int rowIdx = 1;
for (Map.Entry<String, Map<String, Integer>> entry : result.entrySet()) {
@ -762,6 +774,33 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
}
// 创建第二个具有最大车辆类型数量的列的表格
XWPFTable table2 = doc.createTable(result2.size() + 1, maxVehicleTypes);
CTTblWidth infoTableWidth2 = table2.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth2.setType(STTblWidth.DXA);
infoTableWidth2.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
XWPFTableRow headerRow2 = table2.getRow(0);
setTableFonts(headerRow2.getCell(0), dcSdhsEventQuery.getLastTime() + "(" + (stringType) + ")"); // 第一列是事件类型 dcSdhsEventQuery.getThisTime()
int colIdx2 = 1;
for (String vehicleType : vehicleTypes) {
table2.getRow(0).getCell(colIdx2++).setText(vehicleType);
}
// 填充表格内容
int rowIdx2 = 1;
for (Map.Entry<String, Map<String, Integer>> entry : result2.entrySet()) {
XWPFTableRow row = table2.getRow(rowIdx2++);
setTableFonts(row.getCell(0), entry.getKey()); // 事件类型
int cellIdx = 1;
for (String vehicleType : vehicleTypes) {
Integer count = entry.getValue().get(vehicleType);
XWPFTableCell cell = row.getCell(cellIdx++);
XWPFRun run = cell.getParagraphs().get(0).createRun();
run.setText(String.valueOf(count != null ? count : 0)); // 如果该事件没有这种车辆类型,则设为0
}
}
// 创建柱状图
try {
// 复制Word模板
@ -769,13 +808,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
XWPFDocument copiedTemplate = new XWPFDocument(inputStream);
// 获取word中所有图表对象
List<XWPFChart> charts = copiedTemplate.getCharts();
XWPFChart chart = charts.get(0);
XSSFWorkbook workbook = chart.getWorkbook();
XSSFSheet sheet = workbook.getSheetAt(0);
// 系列信息
String[] singleBarSeriesNames = vehicleTypes.toArray(new String[0]);
// 填充表格内容
int rowId = 1; // 开始填充数据的行号
for (Map.Entry<String, Map<String, Integer>> entry : result.entrySet()) {
@ -784,18 +821,15 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
if (row == null) {
row = sheet.createRow(rowId); // 如果行不存在,则创建新行
}
// 获取当前行的第一个单元格
Cell cell1 = row.getCell(0);
// 如果单元格为 null,则创建一个新的单元格
if (cell1 == null) {
cell1 = row.createCell(0);
}
// 设置单元格的值
cell1.setCellValue(entry.getKey());
row.getCell(0).setCellValue(entry.getKey()); // 设置事件类型
row.getCell(0).setCellValue(entry.getKey() + dcSdhsEventQuery.getThisTime()); // 设置事件类型
int cellIdx = 1;
for (String vehicleType : vehicleTypes) {
Integer count = entry.getValue().get(vehicleType);
@ -812,15 +846,43 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
sheet.removeRow(sheet.getRow(i));
}
for (Map.Entry<String, Map<String, Integer>> entry2 : result2.entrySet()) {
XSSFRow row = sheet.getRow(rowId);
if (row == null) {
row = sheet.createRow(rowId); // 如果行不存在,则创建新行
}
// 获取当前行的第一个单元格
Cell cell1 = row.getCell(0);
// 如果单元格为 null,则创建一个新的单元格
if (cell1 == null) {
cell1 = row.createCell(0);
}
// 设置单元格的值
cell1.setCellValue(entry2.getKey());
row.getCell(0).setCellValue(entry2.getKey() + dcSdhsEventQuery.getLastTime()); // 设置事件类型
int cellIdx = 1;
for (String vehicleType : vehicleTypes) {
Integer count = entry2.getValue().get(vehicleType);
XSSFCell cell = row.getCell(cellIdx); // 获取或创建单元格
if (cell == null) {
cell = row.createCell(cellIdx); // 如果单元格不存在,则创建新单元格
}
cell.setCellValue(count != null ? count : 0); // 设置单元格值
cellIdx++;
}
rowId++; // 移动到下一行
}
for (int i = sheet.getLastRowNum(); i > result.size() + result2.size(); i--) {
sheet.removeRow(sheet.getRow(i));
}
// 创建柱状图
PoiUtil.wordExportChar(chart, "事故车型分析", singleBarSeriesNames, sheet);
// 追加到同一个Word文档中
mergeChart(chart, doc);
// 关闭复制的模板文档
copiedTemplate.close();
} catch (Exception e) {
e.printStackTrace();
}
@ -840,52 +902,23 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return
*/
@Override
public Map<String, Map<String, Integer>> accidentModelAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT);
// 将查询开始时间和结束时间转换为 LocalDateTime
ZoneId zoneId = ZoneId.systemDefault(); // 获取系统默认时区
LocalDateTime queryStart = dcSdhsEventQuery.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
LocalDateTime queryEnd = dcSdhsEventQuery.getEndTime().toInstant().atZone(zoneId).toLocalDateTime();
public Map<String, Map<String, Map<String, Integer>>> accidentModelAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
// 在指定时间范围内的事件
String direction = dcSdhsEventQuery.getDirection(); // 获取方向查询参数
List<DcSdhsEvent> filteredEvents = cacheList.stream()
.filter(event -> {
LocalDateTime eventTime = event.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
boolean timeCondition =
(eventTime.isAfter(queryStart) || eventTime.isEqual(queryStart)) &&
(eventTime.isBefore(queryEnd) || eventTime.isEqual(queryEnd));
// 如果 direction 不为空,则添加方向过滤条件
if (direction != null && !direction.isEmpty()) {
return timeCondition && direction.equals(event.getDirection());
} else {
return timeCondition;
}
})
.collect(Collectors.toList());
//本期数据
List<DcSdhsEvent> thisTimeList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime());
// 初始化一个空的结果映射
Map<String, Map<String, Integer>> result = new HashMap<>();
for (DcSdhsEvent event : filteredEvents) {
String eventType = event.getEventType();
if ("交通事故".equals(eventType)) {
for (DcSdhsEvent event : thisTimeList) {
String eventSubclass = event.getEventSubclass();
String carNums = event.getCarNum();
// 分割字符串,得到每种类型的车辆数量
List<String> carNumList = Arrays.asList(carNums.split(","));
// 如果结果映射中还没有这个事件子类,就初始化一个新的映射
if (!result.containsKey(eventSubclass)) {
result.put(eventSubclass, new HashMap<>());
}
// 统计每种类型的车辆数量
Map<String, Integer> carNumCount = result.get(eventSubclass);
for (String carNum : carNumList) {
// 检查字符串格式是否正确
int index = carNum.indexOf("辆");
@ -893,15 +926,42 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
// 提取车辆类型和数量
String carType = carNum.substring(0, index - 1); // 车辆类型
int carCount = Integer.parseInt(carNum.substring(index - 1, index)); // 数量
// 在映射中累加数量
carNumCount.merge(carType, carCount, Integer::sum);
}
}
}
//上一期数据
List<DcSdhsEvent> lastTimeList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getLastTime());
// 初始化一个空的结果映射
Map<String, Map<String, Integer>> resultLast = new HashMap<>();
for (DcSdhsEvent event : lastTimeList) {
String eventSubclass = event.getEventSubclass();
String carNums = event.getCarNum();
// 分割字符串,得到每种类型的车辆数量
List<String> carNumList = Arrays.asList(carNums.split(","));
// 如果结果映射中还没有这个事件子类,就初始化一个新的映射
if (!resultLast.containsKey(eventSubclass)) {
resultLast.put(eventSubclass, new HashMap<>());
}
// 统计每种类型的车辆数量
Map<String, Integer> carNumCount = resultLast.get(eventSubclass);
for (String carNum : carNumList) {
// 检查字符串格式是否正确
int index = carNum.indexOf("辆");
if (index > 0) { // 确保 "辆" 的索引大于 0,表示字符串中包含 "辆" 且前面有字符
// 提取车辆类型和数量
String carType = carNum.substring(0, index - 1); // 车辆类型
int carCount = Integer.parseInt(carNum.substring(index - 1, index)); // 数量
// 在映射中累加数量
carNumCount.merge(carType, carCount, Integer::sum);
}
}
}
return result;
Map<String, Map<String, Map<String, Integer>>> map = new HashMap<>();
map.put(dcSdhsEventQuery.getThisTime(), result);
map.put(dcSdhsEventQuery.getLastTime(), resultLast);
return map;
}
/**
@ -911,18 +971,24 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return
*/
@Override
public Map<String, Long> accidentTimeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT);
public Map<String, Map<String, Long>> accidentTimeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> dcSdhsEventList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime());
Map<String, Long> thisAccidentTimeAnalysis = thisAccidentTimeAnalysis(dcSdhsEventList, dcSdhsEventQuery);
List<DcSdhsEvent> lastdcSdhsEventList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getLastTime());
Map<String, Long> lastAccidentTimeAnalysis = thisAccidentTimeAnalysis(lastdcSdhsEventList, dcSdhsEventQuery);
Map<String, Map<String, Long>> map = new HashMap<>();
map.put(dcSdhsEventQuery.getThisTime(), thisAccidentTimeAnalysis);
map.put(dcSdhsEventQuery.getLastTime(), lastAccidentTimeAnalysis);
return map;
}
public Map<String, Long>thisAccidentTimeAnalysis(List<DcSdhsEvent> dcSdhsEventList,DcSdhsEventQuery dcSdhsEventQuery) {
ZoneId zoneId = ZoneId.systemDefault(); // 获取系统默认时区
if (dcSdhsEventQuery.getType().equals("2")) {
// 将查询开始时间和结束时间转换为 LocalDateTime
LocalDateTime queryStart = dcSdhsEventQuery.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
// LocalDateTime endTime = dcSdhsEventQuery.getEndTime().toInstant().atZone(zoneId).toLocalDateTime();
// 计算当天的结束时间
LocalDateTime queryEnd = queryStart.withHour(23).withMinute(59).withSecond(59);
List<DcSdhsEvent> filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, queryEnd);
// 按小时分组并统计每个小时内的事件数量
Map<String, Long> hourlyCounts = filteredEvents.stream()
Map<String, Long> hourlyCounts = dcSdhsEventList.stream()
.collect(
Collectors.groupingBy(
event -> String.format("%02d", event.getStartTime().toInstant().atZone(zoneId).toLocalDateTime().getHour()),
@ -935,76 +1001,75 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
String hourString = String.format("%02d", hour);
hourlyCounts.merge(hourString, 0L, Long::sum);
}
Map<String, Long> hourlyCountsTreeMap = new TreeMap<>(hourlyCounts);
Map<String, Long> sortedMonthlyCounts = new LinkedHashMap<>();
return hourlyCountsTreeMap;
Map<Integer, Long> tempMap = new TreeMap<>();
hourlyCounts.forEach((key, value) -> tempMap.put(Integer.parseInt(key), value));
// 将排序后的数据重新放入LinkedHashMap
tempMap.forEach((key, value) -> {
String formattedKey = String.format("%02d", key);
sortedMonthlyCounts.put(formattedKey, value);
});
return sortedMonthlyCounts;
} else if (dcSdhsEventQuery.getType().equals("1")) {
// 将查询开始时间和结束时间转换为 LocalDateTime
LocalDateTime queryStart = dcSdhsEventQuery.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
LocalDateTime endOfMonth = dcSdhsEventQuery.getEndTime().toInstant().atZone(zoneId).toLocalDateTime();
/* // 获取该月的最后一天
LocalDate lastDayOfMonth = queryStart.toLocalDate().with(TemporalAdjusters.lastDayOfMonth());
// 构建该月的最后一刻(23:59:59)
LocalDateTime endOfMonth = LocalDateTime.of(lastDayOfMonth, LocalTime.MAX);*/
List<DcSdhsEvent> filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, endOfMonth);
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd");
// 按天分组并统计每一天内的事件数量
Map<String, Long> dailyCounts = filteredEvents.stream()
.collect(
Collectors.groupingBy(
// 定义日期格式
DateTimeFormatter monthYearFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
// 解析月份
YearMonth startOfMonth = YearMonth.parse(dcSdhsEventQuery.getThisTime(), monthYearFormatter);
LocalDate startLocalDate = startOfMonth.atDay(1);
LocalDate endLocalDate = startOfMonth.atEndOfMonth();
// 创建初始化每个日期的事件计数为0
Map<String, Long> allDaysInMonth = new HashMap<>();
for (LocalDate date = startLocalDate; !date.isAfter(endLocalDate); date = date.plusDays(1)) {
allDaysInMonth.put(date.format(formatter), 0L);
}
Map<String, Long> dailyCounts = dcSdhsEventList.stream()
.collect(Collectors.groupingBy(
event -> event.getStartTime().toInstant().atZone(zoneId).toLocalDate().format(formatter),
Collectors.counting()
)
);
// 确保所有日期都出现在结果中
LocalDate queryStartLocalDate = queryStart.toLocalDate();
LocalDate queryEndLocalDate = endOfMonth.toLocalDate();
// 确保所有日期都出现在结果中
for (LocalDate date = queryStartLocalDate; date.isBefore(queryEndLocalDate.plusDays(1)); date = date.plusDays(1)) {
String dateString = date.format(formatter);
dailyCounts.merge(dateString, 0L, Long::sum);
}
// 将键值对放入TreeMap中,TreeMap会自动按键排序
Map<String, Long> dailyCountsTreeMap = new TreeMap<>(dailyCounts);
return dailyCountsTreeMap;
));
// 将统计结果合并,确保所有日期都有对应的计数值
dailyCounts.forEach((day, count) -> allDaysInMonth.merge(day, count, Long::sum));
Map<String, Long> sortedMonthlyCounts = new LinkedHashMap<>();
Map<Integer, Long> tempMap = new TreeMap<>();
allDaysInMonth.forEach((key, value) -> tempMap.put(Integer.parseInt(key), value));
// 将排序后的数据重新放入LinkedHashMap
tempMap.forEach((key, value) -> {
String formattedKey = String.format("%02d", key);
sortedMonthlyCounts.put(formattedKey, value);
});
return sortedMonthlyCounts;
} else {
// 将查询开始时间和结束时间转换为 LocalDateTime
LocalDateTime queryStart = dcSdhsEventQuery.getStartTime().toInstant().atZone(zoneId).toLocalDateTime();
// 获取该年的最后一天
LocalDate lastDayOfYear = queryStart.toLocalDate().with(TemporalAdjusters.lastDayOfYear());
// 构建该年的最后一刻(23:59:59)
// LocalDateTime endOfYear = LocalDateTime.of(lastDayOfYear, LocalTime.MAX);
LocalDateTime endOfYear = dcSdhsEventQuery.getEndTime().toInstant().atZone(zoneId).toLocalDateTime();
List<DcSdhsEvent> filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, endOfYear);
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM");
// 按月分组并统计每个月内的事件数量
Map<String, Long> monthlyCounts = filteredEvents.stream()
Map<String, Long> monthlyCounts = dcSdhsEventList.stream()
.collect(
Collectors.groupingBy(
event -> event.getStartTime().toInstant().atZone(zoneId).toLocalDate().format(formatter),
Collectors.counting()
)
);
// 确保所有月份都出现在结果中
// 目标年的年末之后的一个月
LocalDate queryEnd = endOfYear.toLocalDate().plusMonths(0); // 确保包含结束月份
LocalDate currentMonth = queryStart.toLocalDate();
while (currentMonth.isBefore(queryEnd)) {
String monthString = currentMonth.format(formatter);
monthlyCounts.merge(monthString, 0L, Long::sum);
currentMonth = currentMonth.plusMonths(1);
// 创建一个包含指定年份所有月份的地图,并初始化每个月的事件计数为0
Map<String, Long> allMonthsOfYear = new HashMap<>();
for (int month = 1; month <= 12; month++) {
String monthStr = String.format("%02d", month); // 确保月份为两位数字
allMonthsOfYear.put(monthStr, 0L);
}
//
monthlyCounts.forEach((month, count) -> allMonthsOfYear.merge(month, count, Long::sum));
Map<String, Long> sortedMonthlyCounts = new LinkedHashMap<>();
Map<Integer, Long> tempMap = new TreeMap<>();
monthlyCounts.forEach((key, value) -> tempMap.put(Integer.parseInt(key), value));
allMonthsOfYear.forEach((key, value) -> tempMap.put(Integer.parseInt(key), value));
// 将排序后的数据重新放入LinkedHashMap
tempMap.forEach((key, value) -> {
String formattedKey = String.format("%02d", key);
@ -1013,9 +1078,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
return sortedMonthlyCounts;
}
}
/**
* // 在指定时间范围内的事件
*
@ -1026,7 +1089,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @param queryEnd
* @return
*/
private static List<DcSdhsEvent> getDcSdhsEvents(DcSdhsEventQuery dcSdhsEventQuery, List<DcSdhsEvent> cacheList, ZoneId zoneId, LocalDateTime queryStart, LocalDateTime queryEnd) {
private List<DcSdhsEvent> getDcSdhsEvents(DcSdhsEventQuery dcSdhsEventQuery, List<DcSdhsEvent> cacheList, ZoneId zoneId, LocalDateTime queryStart, LocalDateTime queryEnd) {
String direction = dcSdhsEventQuery.getDirection(); // 获取方向查询参数
List<DcSdhsEvent> filteredEvents = cacheList.stream()
@ -1055,9 +1118,9 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
*/
@Override
public void exportAccidentTimeAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) {
Map<String, Long> currentYearData = accidentTimeAnalysis(dcSdhsEventQuery);
// 获取一年前的日期
Map<String, Map<String, Long>> stringMapMap = accidentTimeAnalysis(dcSdhsEventQuery);
Map<String, Long> currentYearData = stringMapMap.get(dcSdhsEventQuery.getThisTime());
/* // 获取一年前的日期
Date startTime = dcSdhsEventQuery.getStartTime();
// 使用 Calendar 计算一年前的时间
Calendar calendar = Calendar.getInstance();
@ -1067,8 +1130,8 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
DcSdhsEventQuery dcSdhsEventQuery1 = new DcSdhsEventQuery();
dcSdhsEventQuery1.setStartTime(oneYearAgoStart);
dcSdhsEventQuery1.setType(dcSdhsEventQuery.getType());
dcSdhsEventQuery1.setEndTime(dcSdhsEventQuery.getEndTime());
Map<String, Long> lastYearData = accidentTimeAnalysis(dcSdhsEventQuery1);
dcSdhsEventQuery1.setEndTime(dcSdhsEventQuery.getEndTime());*/
Map<String, Long> lastYearData = stringMapMap.get(dcSdhsEventQuery.getLastTime());
String type = dcSdhsEventQuery.getType();
int rows = currentYearData.size() + 1;
@ -1099,8 +1162,8 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
// 表头
setTableFonts(table.getRow(0).getCell(0), "时段");
setTableFonts(table.getRow(0).getCell(1), "今年同期");
setTableFonts(table.getRow(0).getCell(2), "去年同期");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime());
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getLastTime());
// 定义一个从数字到日期字符串的映射
Map<Integer, String> indexToDateMap = new HashMap<>();
for (int i = 0; i <= 32; i++) {
@ -1187,7 +1250,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
sheet.removeRow(sheet.getRow(i));
}
// 更新图表
PoiUtil.wordExportChar(chart, "事故时间分析", new String[]{"今年同期", "去年同期"}, sheet);
PoiUtil.wordExportChar(chart, "事故时间分析", new String[]{dcSdhsEventQuery.getThisTime(), dcSdhsEventQuery.getLastTime()}, sheet);
// 合并图表到Word文档
mergeChart(chart, doc);
@ -1711,12 +1774,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
/**
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 查询天气情况统计
*
* @author liuwenge
* @date 2024/8/21 17:14
* @param
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@Override
public AjaxResult selectWeather() {
@ -1840,12 +1902,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
*/
@Override
public Map<String, List<DcTollStationStatisticsDataMap>> TollBoothStatisticsList(DcSdhsEventQuery dcSdhsEventQuery) {
Date startTime = dcSdhsEventQuery.getStartTime();
/* Date startTime = dcSdhsEventQuery.getStartTime();
LocalDateTime localDateTime = startTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 将 LocalDateTime 转换为字符串
String startDate = localDateTime.format(formatter);
// 将 LocalDateTime 转换为字符串*/
String startDate = dcSdhsEventQuery.getThisTime();
String lastTime = dcSdhsEventQuery.getLastTime();
String type = dcSdhsEventQuery.getType();
String periodType = "";
if (type.equals("2")) {
@ -1853,20 +1916,32 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
if (type.equals("1")) {
periodType = "3";
startDate=startDate+"-01";
}
if (type.equals("0")) {
periodType = "1";
startDate=startDate+"-01-01";
}
Map<String, List<DcTollStationStatisticsDataMap>> map = new HashMap<>();
//入口
List<DcTollStationStatisticsDataMap> entrance = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "1", periodType);
//出口
List<DcTollStationStatisticsDataMap> exit = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "2", periodType);
map.put("entrance", entrance);
map.put("exit", exit);
//lastTime入口
List<DcTollStationStatisticsDataMap> lastTimeEntrance = dcTollStationStatisticsDataService.TollBoothStatisticsList(lastTime, "1", periodType);
//lastTime出口
List<DcTollStationStatisticsDataMap> lastTimeExit = dcTollStationStatisticsDataService.TollBoothStatisticsList(lastTime, "2", periodType);
map.put(dcSdhsEventQuery.getThisTime()+"entrance", entrance);
map.put(dcSdhsEventQuery.getThisTime()+"exit", exit);
map.put(dcSdhsEventQuery.getLastTime()+"entrance", lastTimeEntrance);
map.put(dcSdhsEventQuery.getLastTime()+"exit", lastTimeExit);
return map;
}
/**
* 收费站出入口导出
*
@ -1876,8 +1951,12 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public void exporttollGateEntrance(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) {
Map<String, List<DcTollStationStatisticsDataMap>> map = TollBoothStatisticsList(dcSdhsEventQuery);
List<DcTollStationStatisticsDataMap> entrance = map.get("entrance");
List<DcTollStationStatisticsDataMap> exit = map.get("exit");
List<DcTollStationStatisticsDataMap> entrance = map.get(dcSdhsEventQuery.getThisTime()+"entrance");
List<DcTollStationStatisticsDataMap> exit = map.get(dcSdhsEventQuery.getThisTime()+"exit");
List<DcTollStationStatisticsDataMap> lastExit = map.get(dcSdhsEventQuery.getLastTime()+"exit");
List<DcTollStationStatisticsDataMap> lastEntrance = map.get(dcSdhsEventQuery.getLastTime()+"entrance");
int rows = entrance.size();
String name = "wordTemplate/tollGateEntrance.docx";
PoiUtil.createHeading2(doc, "收费站出入口车流量");
@ -1885,23 +1964,29 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
// 创建表格
XWPFTable table = doc.createTable(rows + 1, 3);
XWPFTable table = doc.createTable(rows + 1, 5);
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
// 表头
setTableFonts(table.getRow(0).getCell(0), "收费站");
setTableFonts(table.getRow(0).getCell(1), "入口");
setTableFonts(table.getRow(0).getCell(2), "出口");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime()+"(入口)");
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getLastTime()+"(入口)");
setTableFonts(table.getRow(0).getCell(3), dcSdhsEventQuery.getThisTime()+"(出口)");
setTableFonts(table.getRow(0).getCell(4), dcSdhsEventQuery.getLastTime()+"(出口)");
// 填充表格数据
for (int i = 0; i < rows; i++) {
setTableFonts(table.getRow(i + 1).getCell(0), (entrance.get(i).getFacilityName()));
Integer entranceValue = entrance.get(i).getTrafficVolume();
setTableFonts(table.getRow(i + 1).getCell(1), String.valueOf(entranceValue));
setTableFonts(table.getRow(i + 1).getCell(1), String.valueOf(entranceValue));//入口
Integer lastEntranceValue = lastEntrance.get(i).getTrafficVolume();
setTableFonts(table.getRow(i + 1).getCell(2), String.valueOf(lastEntranceValue));//last入口
Integer exitValue = exit.get(i).getTrafficVolume();
setTableFonts(table.getRow(i + 1).getCell(2), String.valueOf(exitValue));
setTableFonts(table.getRow(i + 1).getCell(3), String.valueOf(exitValue));//出口
Integer lastExitValue = lastExit.get(i).getTrafficVolume();
setTableFonts(table.getRow(i + 1).getCell(4), String.valueOf(lastExitValue));//last出口
}
// 图表部分
@ -1949,7 +2034,18 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
cell = row.createCell(UniversalEnum.TWO.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(2).setCellValue(exit.get(i).getTrafficVolume());
//sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString()));
Cell cellThree = row.getCell(UniversalEnum.THREE.getNumber());
if (cellThree == null) {
// 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一
cell = row.createCell(UniversalEnum.THREE.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(3).setCellValue(lastEntrance.get(i).getTrafficVolume());
Cell cellFour = row.getCell(UniversalEnum.FOUR.getNumber());
if (cellFour == null) {
// 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一
cell = row.createCell(UniversalEnum.FOUR.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(4).setCellValue(lastExit.get(i).getTrafficVolume());
}
/* for (int i = 0; i < 24; i++) {
@ -1961,7 +2057,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
sheet.removeRow(sheet.getRow(i));
}
// 更新图表
PoiUtil.wordExportChar(chart, "收费站出入口车流量", new String[]{"入口", "出口"}, sheet);
PoiUtil.wordExportChar(chart, "收费站出入口车流量", new String[]{dcSdhsEventQuery.getThisTime()+"(入口)", dcSdhsEventQuery.getThisTime()+"(出口)",dcSdhsEventQuery.getLastTime()+"(入口)", dcSdhsEventQuery.getLastTime()+"(出口)"}, sheet);
// 合并图表到Word文档
mergeChart(chart, doc);
@ -1978,6 +2074,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
}
/**
* 收门架数据导出
*
@ -1987,8 +2084,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public void exporFrameDataAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) {
Map<String, List<TrafficFlowStatisticsMap>> map = trafficFlowStatistics(dcSdhsEventQuery);
List<TrafficFlowStatisticsMap>entrance = map.get("hezeDirection");
List<TrafficFlowStatisticsMap> exit = map.get("jinanDirection");
List<TrafficFlowStatisticsMap> entrance = map.get(dcSdhsEventQuery.getThisTime()+"heze");
List<TrafficFlowStatisticsMap> exit = map.get(dcSdhsEventQuery.getThisTime()+"jinan");
List<TrafficFlowStatisticsMap> lastEntrance = map.get(dcSdhsEventQuery.getLastTime()+"heze");
List<TrafficFlowStatisticsMap> lastExit = map.get(dcSdhsEventQuery.getLastTime()+"jinan");
int rows = entrance.size();
String name = "wordTemplate/frameDataAnalysis.docx";
PoiUtil.createHeading2(doc, "门架车流量");
@ -1996,24 +2096,32 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
if (map != null && map.size() != UniversalEnum.ZERO.getNumber()) {
// 创建表格
XWPFTable table = doc.createTable(rows+1, 3);
XWPFTable table = doc.createTable(rows + 1, 5);
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
// 表头
setTableFonts(table.getRow(0).getCell(0), "门架");
setTableFonts(table.getRow(0).getCell(1), "菏泽方向");
setTableFonts(table.getRow(0).getCell(2), "济南方向");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime()+"(菏泽方向)");
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getLastTime()+"(菏泽方向)");
setTableFonts(table.getRow(0).getCell(3), dcSdhsEventQuery.getThisTime()+"(济南方向)");
setTableFonts(table.getRow(0).getCell(4), dcSdhsEventQuery.getLastTime()+"(济南方向)");
// 填充表格数据
for (int i = 0; i < rows; i++) {
setTableFonts(table.getRow(i + 1).getCell(0), (entrance.get(i).getFacilityName()));
Long entranceValue = entrance.get(i).getTrafficVolume() != null ? entrance.get(i).getTrafficVolume() : 0;
setTableFonts(table.getRow(i + 1).getCell(1), String.valueOf(entranceValue));
Long lastEntranceValue = lastEntrance.get(i).getTrafficVolume() != null ? lastEntrance.get(i).getTrafficVolume() : 0;
setTableFonts(table.getRow(i + 1).getCell(2), String.valueOf(lastEntranceValue));
Long exitValue = exit.get(i).getTrafficVolume() != null ? exit.get(i).getTrafficVolume() : 0;
setTableFonts(table.getRow(i + 1).getCell(2), String.valueOf(exitValue));
setTableFonts(table.getRow(i + 1).getCell(3), String.valueOf(exitValue));
Long lastExitValue = lastExit.get(i).getTrafficVolume() != null ? lastExit.get(i).getTrafficVolume() : 0;
setTableFonts(table.getRow(i + 1).getCell(4), String.valueOf(lastExitValue));
}
// 图表部分
@ -2061,6 +2169,19 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
cell = row.createCell(UniversalEnum.TWO.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(2).setCellValue(exit.get(i).getTrafficVolume() != null ? exit.get(i).getTrafficVolume() : 0);
Cell cellThree = row.getCell(UniversalEnum.THREE.getNumber());
if (cellThree == null) {
// 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一
cell = row.createCell(UniversalEnum.THREE.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(3).setCellValue(lastEntrance.get(i).getTrafficVolume());
Cell cellFour = row.getCell(UniversalEnum.FOUR.getNumber());
if (cellFour == null) {
// 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一
cell = row.createCell(UniversalEnum.FOUR.getNumber(), CellType.NUMERIC);
}
sheet.getRow(i + 1).getCell(4).setCellValue(lastExit.get(i).getTrafficVolume());
//sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString()));
}
/* for (int i = 0; i < 24; i++) {
@ -2073,7 +2194,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
sheet.removeRow(sheet.getRow(i));
}
// 更新图表
PoiUtil.wordExportChar(chart, "门架车流量", new String[]{"菏泽", "济南"}, sheet);
PoiUtil.wordExportChar(chart, "门架车流量", new String[]{dcSdhsEventQuery.getThisTime()+"(菏泽)",dcSdhsEventQuery.getLastTime()+"(菏泽)", dcSdhsEventQuery.getThisTime()+"(济南)",dcSdhsEventQuery.getLastTime()+"(济南)",}, sheet);
// 合并图表到Word文档
mergeChart(chart, doc);
@ -2093,17 +2214,14 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
/**
* 门架数据分析
*
* @param dcSdhsEventQuery
* @return
*/
@Override
public Map<String, List<TrafficFlowStatisticsMap>> trafficFlowStatistics(DcSdhsEventQuery dcSdhsEventQuery) {
Date startTime = dcSdhsEventQuery.getStartTime();
LocalDateTime localDateTime = startTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 将 LocalDateTime 转换为字符串
String startDate = localDateTime.format(formatter);
String startDate = dcSdhsEventQuery.getThisTime();
String lastTime = dcSdhsEventQuery.getLastTime();
String type = dcSdhsEventQuery.getType();
String periodType = "";
if (type.equals("2")) {
@ -2111,17 +2229,29 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
if (type.equals("1")) {
periodType = "3";
startDate=startDate+"-01";
lastTime=lastTime+"-01";
}
if (type.equals("0")) {
periodType = "1";
startDate=startDate+"-01-01";
lastTime=lastTime+"-01-01";
}
//菏泽方向
List<TrafficFlowStatisticsMap> hezeDirection = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate,startDate,"1",periodType);
List<TrafficFlowStatisticsMap> heze = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate, startDate, "1", periodType);
//济南方向
List<TrafficFlowStatisticsMap> jinan = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate, startDate, "3", periodType);
//菏泽方向
List<TrafficFlowStatisticsMap> lastHeze = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(lastTime, lastTime, "1", periodType);
//济南方向
List<TrafficFlowStatisticsMap> jinanDirection = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate,startDate,"3",periodType);
List<TrafficFlowStatisticsMap> lastJinan = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(lastTime, lastTime, "3", periodType);
Map<String, List<TrafficFlowStatisticsMap>> map = new HashMap<>();
map.put("hezeDirection",hezeDirection);
map.put("jinanDirection",jinanDirection);
map.put(dcSdhsEventQuery.getThisTime()+"heze", heze);
map.put(dcSdhsEventQuery.getThisTime()+"jinan", jinan);
map.put(dcSdhsEventQuery.getLastTime()+"heze", lastHeze);
map.put(dcSdhsEventQuery.getLastTime()+"jinan", lastJinan);
return map;
}
@ -2133,8 +2263,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 高速云事件
*/
@Override
public DcSdhsEvent selectDcSdhsEventById(Long id)
{
public DcSdhsEvent selectDcSdhsEventById(Long id) {
return dcSdhsEventMapper.selectDcSdhsEventById(id);
}
@ -2145,8 +2274,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 高速云事件
*/
@Override
public List<DcSdhsEvent> selectDcSdhsEventList(DcSdhsEvent dcSdhsEvent)
{
public List<DcSdhsEvent> selectDcSdhsEventList(DcSdhsEvent dcSdhsEvent) {
return dcSdhsEventMapper.selectDcSdhsEventList(dcSdhsEvent);
}
@ -2157,8 +2285,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 结果
*/
@Override
public int insertDcSdhsEvent(DcSdhsEvent dcSdhsEvent)
{
public int insertDcSdhsEvent(DcSdhsEvent dcSdhsEvent) {
return dcSdhsEventMapper.insertDcSdhsEvent(dcSdhsEvent);
}
@ -2169,8 +2296,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 结果
*/
@Override
public int updateDcSdhsEvent(DcSdhsEvent dcSdhsEvent)
{
public int updateDcSdhsEvent(DcSdhsEvent dcSdhsEvent) {
return dcSdhsEventMapper.updateDcSdhsEvent(dcSdhsEvent);
}
@ -2181,8 +2307,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 结果
*/
@Override
public int deleteDcSdhsEventByIds(Long[] ids)
{
public int deleteDcSdhsEventByIds(Long[] ids) {
return dcSdhsEventMapper.deleteDcSdhsEventByIds(ids);
}
@ -2193,8 +2318,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
* @return 结果
*/
@Override
public int deleteDcSdhsEventById(Long id)
{
public int deleteDcSdhsEventById(Long id) {
return dcSdhsEventMapper.deleteDcSdhsEventById(id);
}
@Override
public AjaxResult getDataCalendar(String month){
List<String> list = dcSdhsEventMapper.getDataCalendar(month);
return AjaxResult.success(list);
}
}

Loading…
Cancel
Save