diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java index 371404bf..ad90deb4 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java +++ b/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 timeList = dcSdhsEventMapper.selectTimeList(); - if (timeList != null && timeList.size() > 0 && importData != null && importData.size() > 0){ - List 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 duplicateData = new ArrayList<>(); List 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)) { @@ -131,7 +128,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { String stakeMark = dcSdhsEvent.getStakeMark(); if (StringUtils.isNotEmpty(stakeMark) && !"无".equals(stakeMark)) { - if (!StakeMarkUtils.checkStakeMark(stakeMark)){ + if (!StakeMarkUtils.checkStakeMark(stakeMark)) { //尝试桩号补零 List numbers = new ArrayList<>(); @@ -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 fileInfo = new HashMap<>(); @@ -184,21 +182,25 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { fileInfo.put("uploadTime", updateTime); redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE, now.getTime(), fileInfo); - return AjaxResult.success("导入成功"); + + Map result = new HashMap<>(); + result.put("successNum",successNum); + result.put("errorNum",duplicateData.size()); + + return AjaxResult.success(result); } /** + * @param startTime + * @param endTime + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 根据时间范围删除数据 - * * @author liuwenge * @date 2024/9/9 11:58 - * @param startTime - * @param endTime - * @return com.ruoyi.common.core.domain.AjaxResult */ @Override - public AjaxResult deleteData(String startTime, String endTime){ - dcSdhsEventMapper.deleteByTimeRange(startTime,endTime); + public AjaxResult deleteData(String startTime, String endTime) { + dcSdhsEventMapper.deleteByTimeRange(startTime, endTime); return AjaxResult.success("删除成功"); } @@ -719,116 +721,176 @@ 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> result = accidentModelAnalysis(dcSdhsEventQuery); + Map>> map = accidentModelAnalysis(dcSdhsEventQuery); + Map> result = map.get(dcSdhsEventQuery.getThisTime()); + Map> result2 = map.get(dcSdhsEventQuery.getLastTime()); PoiUtil.createHeading2(doc, "事故车型分析"); if (result != null && result.size() != UniversalEnum.ZERO.getNumber()) { // 计算最大车辆类型数量 - int maxVehicleTypes = 5; + int maxVehicleTypes = 5; // 创建一个具有最大车辆类型数量的列的表格 - XWPFTable table = doc.createTable(result.size() + 1, maxVehicleTypes); + XWPFTable table = doc.createTable(result.size() + 1, maxVehicleTypes); CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); infoTableWidth.setType(STTblWidth.DXA); infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); // 提取所有不同的车辆类型作为列标题 - Set vehicleTypes = new HashSet<>(); - vehicleTypes.add("货车"); - vehicleTypes.add("小型车"); - vehicleTypes.add("客车"); - vehicleTypes.add("罐车"); + Set vehicleTypes = new HashSet<>(); + vehicleTypes.add("货车"); + vehicleTypes.add("小型车"); + vehicleTypes.add("客车"); + vehicleTypes.add("罐车"); // 设置表头 - XWPFTableRow headerRow = table.getRow(0); - setTableFonts(headerRow.getCell(0), ""); // 第一列是事件类型 - int colIdx = 1; - for (String vehicleType : vehicleTypes) { - table.getRow(0).getCell(colIdx++).setText(vehicleType); - } - -// 填充表格内容 - int rowIdx = 1; - for (Map.Entry> entry : result.entrySet()) { - XWPFTableRow row = table.getRow(rowIdx++); - setTableFonts(row.getCell(0), entry.getKey()); // 事件类型 - - int cellIdx = 1; + XWPFTableRow headerRow = table.getRow(0); + setTableFonts(headerRow.getCell(0), dcSdhsEventQuery.getThisTime() + "(" + (stringType) + ")"); // 第一列是事件类型 dcSdhsEventQuery.getThisTime() + int colIdx = 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 + table.getRow(0).getCell(colIdx++).setText(vehicleType); } - } - -// 创建柱状图 - try { - // 复制Word模板 - InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/accidentModelAnalysis.docx"); - XWPFDocument copiedTemplate = new XWPFDocument(inputStream); - // 获取word中所有图表对象 - List 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; // 开始填充数据的行号 + int rowIdx = 1; for (Map.Entry> entry : result.entrySet()) { + XWPFTableRow row = table.getRow(rowIdx++); + setTableFonts(row.getCell(0), entry.getKey()); // 事件类型 - XSSFRow row = sheet.getRow(rowId); - if (row == null) { - row = sheet.createRow(rowId); // 如果行不存在,则创建新行 + 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 } + } -// 获取当前行的第一个单元格 - Cell cell1 = row.getCell(0); - -// 如果单元格为 null,则创建一个新的单元格 - if (cell1 == null) { - cell1 = row.createCell(0); - } +// 创建第二个具有最大车辆类型数量的列的表格 + 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> entry : result2.entrySet()) { + XWPFTableRow row = table2.getRow(rowIdx2++); + setTableFonts(row.getCell(0), entry.getKey()); // 事件类型 -// 设置单元格的值 - cell1.setCellValue(entry.getKey()); - row.getCell(0).setCellValue(entry.getKey()); // 设置事件类型 int cellIdx = 1; for (String vehicleType : vehicleTypes) { Integer count = entry.getValue().get(vehicleType); - XSSFCell cell = row.getCell(cellIdx); // 获取或创建单元格 - if (cell == null) { - cell = row.createCell(cellIdx); // 如果单元格不存在,则创建新单元格 - } - cell.setCellValue(count != null ? count : 0); // 设置单元格值 - cellIdx++; + XWPFTableCell cell = row.getCell(cellIdx++); + XWPFRun run = cell.getParagraphs().get(0).createRun(); + run.setText(String.valueOf(count != null ? count : 0)); // 如果该事件没有这种车辆类型,则设为0 } - rowId++; // 移动到下一行 - } - for (int i = sheet.getLastRowNum(); i > result.size(); i--) { - sheet.removeRow(sheet.getRow(i)); } - // 创建柱状图 - PoiUtil.wordExportChar(chart, "事故车型分析", singleBarSeriesNames, sheet); - // 追加到同一个Word文档中 - mergeChart(chart, doc); - // 关闭复制的模板文档 - copiedTemplate.close(); +// 创建柱状图 + try { + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/accidentModelAnalysis.docx"); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + // 获取word中所有图表对象 + List 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> entry : result.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(entry.getKey()); + row.getCell(0).setCellValue(entry.getKey() + dcSdhsEventQuery.getThisTime()); // 设置事件类型 + int cellIdx = 1; + for (String vehicleType : vehicleTypes) { + Integer count = entry.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(); i--) { + sheet.removeRow(sheet.getRow(i)); + } - } catch (Exception e) { - e.printStackTrace(); - } + for (Map.Entry> 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(); + } // 换行 - createLineBreak(doc); + createLineBreak(doc); -}else { + } else { addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue()); } } @@ -840,68 +902,66 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { * @return */ @Override - public Map> accidentModelAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { - List 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(); - -// 在指定时间范围内的事件 - String direction = dcSdhsEventQuery.getDirection(); // 获取方向查询参数 + public Map>> accidentModelAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { - List 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 thisTimeList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime()); // 初始化一个空的结果映射 Map> result = new HashMap<>(); - - for (DcSdhsEvent event : filteredEvents) { - String eventType = event.getEventType(); - if ("交通事故".equals(eventType)) { - String eventSubclass = event.getEventSubclass(); - String carNums = event.getCarNum(); - - // 分割字符串,得到每种类型的车辆数量 - List carNumList = Arrays.asList(carNums.split(",")); - - // 如果结果映射中还没有这个事件子类,就初始化一个新的映射 - if (!result.containsKey(eventSubclass)) { - result.put(eventSubclass, new HashMap<>()); + for (DcSdhsEvent event : thisTimeList) { + String eventSubclass = event.getEventSubclass(); + String carNums = event.getCarNum(); + // 分割字符串,得到每种类型的车辆数量 + List carNumList = Arrays.asList(carNums.split(",")); + // 如果结果映射中还没有这个事件子类,就初始化一个新的映射 + if (!result.containsKey(eventSubclass)) { + result.put(eventSubclass, new HashMap<>()); + } + // 统计每种类型的车辆数量 + Map carNumCount = result.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); } - - // 统计每种类型的车辆数量 - Map carNumCount = result.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); - } + } + } + //上一期数据 + List lastTimeList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getLastTime()); + // 初始化一个空的结果映射 + Map> resultLast = new HashMap<>(); + for (DcSdhsEvent event : lastTimeList) { + String eventSubclass = event.getEventSubclass(); + String carNums = event.getCarNum(); + // 分割字符串,得到每种类型的车辆数量 + List carNumList = Arrays.asList(carNums.split(",")); + // 如果结果映射中还没有这个事件子类,就初始化一个新的映射 + if (!resultLast.containsKey(eventSubclass)) { + resultLast.put(eventSubclass, new HashMap<>()); + } + // 统计每种类型的车辆数量 + Map 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>> 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 accidentTimeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { - List cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + public Map> accidentTimeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { + List dcSdhsEventList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime()); + Map thisAccidentTimeAnalysis = thisAccidentTimeAnalysis(dcSdhsEventList, dcSdhsEventQuery); + List lastdcSdhsEventList = dcSdhsEventMapper.selectAccidentModelAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getLastTime()); + Map lastAccidentTimeAnalysis = thisAccidentTimeAnalysis(lastdcSdhsEventList, dcSdhsEventQuery); + Map> map = new HashMap<>(); + map.put(dcSdhsEventQuery.getThisTime(), thisAccidentTimeAnalysis); + map.put(dcSdhsEventQuery.getLastTime(), lastAccidentTimeAnalysis); + return map; + } + + + + public MapthisAccidentTimeAnalysis(List 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 filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, queryEnd); // 按小时分组并统计每个小时内的事件数量 - Map hourlyCounts = filteredEvents.stream() + Map 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 hourlyCountsTreeMap = new TreeMap<>(hourlyCounts); + Map sortedMonthlyCounts = new LinkedHashMap<>(); - return hourlyCountsTreeMap; + Map 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 filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, endOfMonth); + // 定义日期格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd"); -// 按天分组并统计每一天内的事件数量 - Map dailyCounts = filteredEvents.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); + +// 定义日期格式 + DateTimeFormatter monthYearFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); +// 解析月份 + YearMonth startOfMonth = YearMonth.parse(dcSdhsEventQuery.getThisTime(), monthYearFormatter); + LocalDate startLocalDate = startOfMonth.atDay(1); + LocalDate endLocalDate = startOfMonth.atEndOfMonth(); + +// 创建初始化每个日期的事件计数为0 + Map allDaysInMonth = new HashMap<>(); + for (LocalDate date = startLocalDate; !date.isAfter(endLocalDate); date = date.plusDays(1)) { + allDaysInMonth.put(date.format(formatter), 0L); } - // 将键值对放入TreeMap中,TreeMap会自动按键排序 - Map dailyCountsTreeMap = new TreeMap<>(dailyCounts); - return dailyCountsTreeMap; + + Map dailyCounts = dcSdhsEventList.stream() + .collect(Collectors.groupingBy( + event -> event.getStartTime().toInstant().atZone(zoneId).toLocalDate().format(formatter), + Collectors.counting() + )); +// 将统计结果合并,确保所有日期都有对应的计数值 + dailyCounts.forEach((day, count) -> allDaysInMonth.merge(day, count, Long::sum)); + + Map sortedMonthlyCounts = new LinkedHashMap<>(); + + Map 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 filteredEvents = getDcSdhsEvents(dcSdhsEventQuery, cacheList, zoneId, queryStart, endOfYear); - // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); // 按月分组并统计每个月内的事件数量 - Map monthlyCounts = filteredEvents.stream() + Map 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 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 sortedMonthlyCounts = new LinkedHashMap<>(); Map 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 getDcSdhsEvents(DcSdhsEventQuery dcSdhsEventQuery, List cacheList, ZoneId zoneId, LocalDateTime queryStart, LocalDateTime queryEnd) { + private List getDcSdhsEvents(DcSdhsEventQuery dcSdhsEventQuery, List cacheList, ZoneId zoneId, LocalDateTime queryStart, LocalDateTime queryEnd) { String direction = dcSdhsEventQuery.getDirection(); // 获取方向查询参数 List filteredEvents = cacheList.stream() @@ -1055,9 +1118,9 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { */ @Override public void exportAccidentTimeAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { - - Map currentYearData = accidentTimeAnalysis(dcSdhsEventQuery); - // 获取一年前的日期 + Map> stringMapMap = accidentTimeAnalysis(dcSdhsEventQuery); + Map currentYearData = stringMapMap.get(dcSdhsEventQuery.getThisTime()); +/* // 获取一年前的日期 Date startTime = dcSdhsEventQuery.getStartTime(); // 使用 Calendar 计算一年前的时间 Calendar calendar = Calendar.getInstance(); @@ -1067,11 +1130,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { DcSdhsEventQuery dcSdhsEventQuery1 = new DcSdhsEventQuery(); dcSdhsEventQuery1.setStartTime(oneYearAgoStart); dcSdhsEventQuery1.setType(dcSdhsEventQuery.getType()); - dcSdhsEventQuery1.setEndTime(dcSdhsEventQuery.getEndTime()); - Map lastYearData = accidentTimeAnalysis(dcSdhsEventQuery1); + dcSdhsEventQuery1.setEndTime(dcSdhsEventQuery.getEndTime());*/ + Map lastYearData = stringMapMap.get(dcSdhsEventQuery.getLastTime()); String type = dcSdhsEventQuery.getType(); - int rows = currentYearData.size()+1; + int rows = currentYearData.size() + 1; String stingType = ""; String name = ""; if (type.equals("2")) { @@ -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 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); @@ -1200,7 +1263,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { //换行 createLineBreak(doc); - }else { + } else { addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue()); } } @@ -1257,25 +1320,25 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { @Override public AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { - if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){ + if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())) { return AjaxResult.error("参数错误"); } - List> thisTimeData = dcSdhsEventMapper.selectRegionAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()); + List> thisTimeData = dcSdhsEventMapper.selectRegionAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime(), dcSdhsEventQuery.getLastTime()); return AjaxResult.success(thisTimeData); } - private int getCitySorted(String city){ - if (StringUtils.isEmpty(city)){ + private int getCitySorted(String city) { + if (StringUtils.isEmpty(city)) { return 5; } - if ("济南".equals(city)){ + if ("济南".equals(city)) { return 1; - } else if ("泰安".equals(city)){ + } else if ("泰安".equals(city)) { return 2; - } else if ("济宁".equals(city)){ + } else if ("济宁".equals(city)) { return 3; - } else if ("菏泽".equals(city)){ + } else if ("菏泽".equals(city)) { return 4; } else { return 5; @@ -1334,7 +1397,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); //系列信息 - String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()}; + String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(), dcSdhsEventQuery.getLastTime()}; //分类信息 for (int i = 0; i < data.size(); i++) { @@ -1400,12 +1463,12 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { @Override public AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { - if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){ + if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())) { return AjaxResult.error("参数错误"); } //本期数据 - List thisTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime()); + List thisTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime()); Set stationSet = new HashSet<>(); List thisTimeCloseList = thisTimeList.stream() .filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭")) @@ -1426,7 +1489,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { //上期数据 - List lastTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getLastTime()); + List lastTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getLastTime()); List lastTimeCloseList = thisTimeList.stream() .filter(item -> item.getEventType().equals("交通管制") && item.getEventSubclass().equals("收费站封闭")) @@ -1538,19 +1601,19 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); //系列信息 - String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime()+"封闭", dcSdhsEventQuery.getThisTime()+"限行",dcSdhsEventQuery.getLastTime()+"封闭", dcSdhsEventQuery.getLastTime()+"限行"}; + String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime() + "封闭", dcSdhsEventQuery.getThisTime() + "限行", dcSdhsEventQuery.getLastTime() + "封闭", dcSdhsEventQuery.getLastTime() + "限行"}; - sheet.getRow(0).getCell(1).setCellValue(dcSdhsEventQuery.getThisTime()+"封闭"); - sheet.getRow(0).getCell(2).setCellValue(dcSdhsEventQuery.getThisTime()+"限行"); - sheet.getRow(0).getCell(3).setCellValue(dcSdhsEventQuery.getLastTime()+"封闭"); - sheet.getRow(0).getCell(4).setCellValue(dcSdhsEventQuery.getLastTime()+"限行"); + sheet.getRow(0).getCell(1).setCellValue(dcSdhsEventQuery.getThisTime() + "封闭"); + sheet.getRow(0).getCell(2).setCellValue(dcSdhsEventQuery.getThisTime() + "限行"); + sheet.getRow(0).getCell(3).setCellValue(dcSdhsEventQuery.getLastTime() + "封闭"); + sheet.getRow(0).getCell(4).setCellValue(dcSdhsEventQuery.getLastTime() + "限行"); //分类信息 for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) { sheet.getRow(i + 1).getCell(0).setCellValue(data.get(i).get("stationName").toString()); - sheet.getRow(i + 1).getCell(1).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()+"close").toString())); - sheet.getRow(i + 1).getCell(2).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()+"restriction").toString())); - sheet.getRow(i + 1).getCell(3).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()+"close").toString())); - sheet.getRow(i + 1).getCell(4).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()+"restriction").toString())); + sheet.getRow(i + 1).getCell(1).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime() + "close").toString())); + sheet.getRow(i + 1).getCell(2).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime() + "restriction").toString())); + sheet.getRow(i + 1).getCell(3).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime() + "close").toString())); + sheet.getRow(i + 1).getCell(4).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime() + "restriction").toString())); } for (int i = sheet.getLastRowNum(); i > data.size(); i--) { @@ -1582,18 +1645,18 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { infoTableWidth.setType(STTblWidth.DXA); infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); - setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime()+"封闭"); - setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getThisTime()+"限行"); - setTableFonts(table.getRow(0).getCell(3), dcSdhsEventQuery.getLastTime()+"封闭"); - setTableFonts(table.getRow(0).getCell(4), dcSdhsEventQuery.getLastTime()+"限行"); + setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime() + "封闭"); + setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getThisTime() + "限行"); + setTableFonts(table.getRow(0).getCell(3), dcSdhsEventQuery.getLastTime() + "封闭"); + setTableFonts(table.getRow(0).getCell(4), dcSdhsEventQuery.getLastTime() + "限行"); //excel for (int i = 0; i < data.size(); i++) { setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("stationName").toString()); - setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get(dcSdhsEventQuery.getThisTime()+"close").toString()); - setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get(dcSdhsEventQuery.getThisTime()+"restriction").toString()); - setTableFonts(table.getRow(i + 1).getCell(3), data.get(i).get(dcSdhsEventQuery.getLastTime()+"close").toString()); - setTableFonts(table.getRow(i + 1).getCell(4), data.get(i).get(dcSdhsEventQuery.getLastTime()+"restriction").toString()); + setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get(dcSdhsEventQuery.getThisTime() + "close").toString()); + setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get(dcSdhsEventQuery.getThisTime() + "restriction").toString()); + setTableFonts(table.getRow(i + 1).getCell(3), data.get(i).get(dcSdhsEventQuery.getLastTime() + "close").toString()); + setTableFonts(table.getRow(i + 1).getCell(4), data.get(i).get(dcSdhsEventQuery.getLastTime() + "restriction").toString()); } } else { addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue()); @@ -1615,11 +1678,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { @Override public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery) { - if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){ + if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())) { return AjaxResult.error("参数错误"); } - List> list = dcSdhsEventMapper.selectAccidentType(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()); + List> list = dcSdhsEventMapper.selectAccidentType(dcSdhsEventQuery.getType(), dcSdhsEventQuery.getThisTime(), dcSdhsEventQuery.getLastTime()); return AjaxResult.success(list); } @@ -1654,7 +1717,7 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); //系列信息 - String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()}; + String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(), dcSdhsEventQuery.getLastTime()}; //分类信息 for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) { sheet.getRow(i + 1).getCell(0).setCellValue(data.get(i).get("eventSubclass").toString()); @@ -1711,37 +1774,36 @@ 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(){ - HashMap params = new HashMap<>(); - params.put("roadId",UniversalEnum.ROAD_ID.getValue()); - params.put("stakeNum",UniversalEnum.STAKE_NUM.getValue()); - params.put("forecastHour",UniversalEnum.TWENTY_FOUR.getValue()); + public AjaxResult selectWeather() { + HashMap params = new HashMap<>(); + 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); - Map result = new HashMap<>(); - Map column = new HashMap<>(); - List> dataList = new ArrayList<>(); + Map result = new HashMap<>(); + Map column = new HashMap<>(); + List> dataList = new ArrayList<>(); if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { - List> data = (List>) ajaxResult.get("data"); - if (data != null && data.size() != UniversalEnum.ZERO.getNumber()){ + List> data = (List>) ajaxResult.get("data"); + if (data != null && data.size() != UniversalEnum.ZERO.getNumber()) { DateTimeFormatter parseFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; - data.forEach(dataItem ->{ + data.forEach(dataItem -> { - Map regionMap = new HashMap<>(); - if (UniversalEnum.STAKE_NUM_K60.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","长清区"); - List> weatherList = (List>) dataItem.get("forecastList"); + Map regionMap = new HashMap<>(); + if (UniversalEnum.STAKE_NUM_K60.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "长清区"); + List> weatherList = (List>) dataItem.get("forecastList"); weatherList = weatherList.stream() .sorted(Comparator.comparing(map -> LocalDateTime.parse(map.get("weatherTime").toString(), parseFormatter))) .collect(Collectors.toList()); @@ -1750,72 +1812,72 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { LocalDateTime localDateTime = LocalDateTime.parse(weatherList.get(i).get("weatherTime").toString(), parseFormatter); DateTimeFormatter formatFormatter = DateTimeFormatter.ofPattern("dd日HH时"); - column.put("time"+(i+1),localDateTime.format(formatFormatter)); - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + column.put("time" + (i + 1), localDateTime.format(formatFormatter)); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K105.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","平阴县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K105.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "平阴县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K145.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","东平县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K145.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "东平县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K165.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","汶上县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K165.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "汶上县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K175.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","梁山县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K175.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "梁山县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K190.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","嘉祥县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K190.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "嘉祥县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K200.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","巨野县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K200.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "巨野县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } - } else if (UniversalEnum.STAKE_NUM_K205.getValue().equals(dataItem.get("stakeNum"))){ - regionMap.put("regionName","郓城县"); - List> weatherList = (List>) dataItem.get("forecastList"); + } else if (UniversalEnum.STAKE_NUM_K205.getValue().equals(dataItem.get("stakeNum"))) { + regionMap.put("regionName", "郓城县"); + 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 = UniversalEnum.ZERO.getNumber(); i < weatherList.size(); i++) { - regionMap.put("time"+(i+1),weatherList.get(i).get("weatherDescription").toString()); + regionMap.put("time" + (i + 1), weatherList.get(i).get("weatherDescription").toString()); } } dataList.add(regionMap); @@ -1827,8 +1889,8 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { } else { return AjaxResult.error("查询失败"); } - result.put("column",column); - result.put("dataList",dataList); + result.put("column", column); + result.put("dataList", dataList); return AjaxResult.success(result); } @@ -1840,12 +1902,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { */ @Override public Map> 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> map = new HashMap<>(); //入口 - List entrance = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "1",periodType); + List entrance = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "1", periodType); //出口 - List exit = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "2",periodType); - map.put("entrance", entrance); - map.put("exit", exit); + List exit = dcTollStationStatisticsDataService.TollBoothStatisticsList(startDate, "2", periodType); + //lastTime入口 + List lastTimeEntrance = dcTollStationStatisticsDataService.TollBoothStatisticsList(lastTime, "1", periodType); + //lastTime出口 + List 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; } + /** * 收费站出入口导出 * @@ -1875,9 +1950,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { */ @Override public void exporttollGateEntrance(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { - Map> map = TollBoothStatisticsList( dcSdhsEventQuery); - List entrance = map.get("entrance"); - List exit = map.get("exit"); + Map> map = TollBoothStatisticsList(dcSdhsEventQuery); + List entrance = map.get(dcSdhsEventQuery.getThisTime()+"entrance"); + List exit = map.get(dcSdhsEventQuery.getThisTime()+"exit"); + + List lastExit = map.get(dcSdhsEventQuery.getLastTime()+"exit"); + List 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); @@ -1973,11 +2069,12 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { } //换行 createLineBreak(doc); - }else { + } else { addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue()); } } + /** * 收门架数据导出 * @@ -1986,9 +2083,12 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { */ @Override public void exporFrameDataAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { - Map> map = trafficFlowStatistics( dcSdhsEventQuery); - Listentrance = map.get("hezeDirection"); - List exit = map.get("jinanDirection"); + Map> map = trafficFlowStatistics(dcSdhsEventQuery); + List entrance = map.get(dcSdhsEventQuery.getThisTime()+"heze"); + List exit = map.get(dcSdhsEventQuery.getThisTime()+"jinan"); + + List lastEntrance = map.get(dcSdhsEventQuery.getLastTime()+"heze"); + List lastExit = map.get(dcSdhsEventQuery.getLastTime()+"jinan"); int rows = entrance.size(); String name = "wordTemplate/frameDataAnalysis.docx"; PoiUtil.createHeading2(doc, "门架车流量"); @@ -1996,96 +2096,117 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { if (map != null && map.size() != UniversalEnum.ZERO.getNumber()) { // 创建表格 - XWPFTable table = doc.createTable(rows+1, 3); - CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); - infoTableWidth.setType(STTblWidth.DXA); - infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); + 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(0), "门架"); + 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++) { + 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(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)); - setTableFonts(table.getRow(i + 1).getCell(1), String.valueOf(entranceValue)); - Long exitValue = exit.get(i).getTrafficVolume()!=null ?exit.get(i).getTrafficVolume() : 0; - setTableFonts(table.getRow(i + 1).getCell(2), String.valueOf(exitValue)); - } + 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(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)); + + } // 图表部分 - try { + try { + + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(name); - InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(name); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); - XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(0); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + // 更新图表数据 + for (int i = UniversalEnum.ZERO.getNumber(); i < rows; i++) { - List charts = copiedTemplate.getCharts(); - XWPFChart chart = charts.get(0); - XSSFWorkbook workbook = chart.getWorkbook(); - XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); - // 更新图表数据 - for (int i = UniversalEnum.ZERO.getNumber(); i < rows; i++) { + sheet.getRow(i + 1).getCell(0).setCellValue(entrance.get(i).getFacilityName()); + int rowIndex = i + UniversalEnum.ONE.getNumber(); // 计算行索引 + Row row = sheet.getRow(rowIndex); + if (row == null) { + // 如果行不存在,则创建新行 + row = sheet.createRow(rowIndex); + } - sheet.getRow(i + 1).getCell(0).setCellValue(entrance.get(i).getFacilityName()); - int rowIndex = i + UniversalEnum.ONE.getNumber(); // 计算行索引 - Row row = sheet.getRow(rowIndex); - if (row == null) { - // 如果行不存在,则创建新行 - row = sheet.createRow(rowIndex); - } + // 现在可以安全地访问或创建单元格了 + Cell cell = row.getCell(UniversalEnum.ONE.getNumber()); + if (cell == null) { + // 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一 + cell = row.createCell(UniversalEnum.ONE.getNumber(), CellType.NUMERIC); + } + // 设置单元格的值 + sheet.getRow(i + 1).getCell(1).setCellValue(entrance.get(i).getTrafficVolume() != null ? entrance.get(i).getTrafficVolume() : 0); + int rowIndexTwo = i + 1 + UniversalEnum.ONE.getNumber(); // 计算行索引 + Row rowTwo = sheet.getRow(rowIndexTwo); + if (rowTwo == null) { + // 如果行不存在,则创建新行 + rowTwo = sheet.createRow(rowIndexTwo); + } - // 现在可以安全地访问或创建单元格了 - Cell cell = row.getCell(UniversalEnum.ONE.getNumber()); - if (cell == null) { - // 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一 - cell = row.createCell(UniversalEnum.ONE.getNumber(), CellType.NUMERIC); - } - // 设置单元格的值 - sheet.getRow(i + 1).getCell(1).setCellValue( entrance.get(i).getTrafficVolume()!=null ?entrance.get(i).getTrafficVolume() : 0); - int rowIndexTwo = i + 1 + UniversalEnum.ONE.getNumber(); // 计算行索引 - Row rowTwo = sheet.getRow(rowIndexTwo); - if (rowTwo == null) { - // 如果行不存在,则创建新行 - rowTwo = sheet.createRow(rowIndexTwo); - } + // 现在可以安全地访问或创建单元格了 + Cell cellTwo = row.getCell(UniversalEnum.TWO.getNumber()); + if (cellTwo == null) { + // 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一 + 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 cellTwo = row.getCell(UniversalEnum.TWO.getNumber()); - if (cellTwo == null) { - // 通常情况下,getCell 会创建新的单元格,但这里我们显式地检查以防万一 - cell = row.createCell(UniversalEnum.TWO.getNumber(), CellType.NUMERIC); + 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())); } - sheet.getRow(i + 1).getCell(2).setCellValue(exit.get(i).getTrafficVolume()!=null ?exit.get(i).getTrafficVolume() : 0); - //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++) { sheet.getRow(i + 1).getCell(0).setCellValue((i) + "点"); sheet.getRow(i + 1).getCell(1).setCellValue(currentYearData.get(i)); sheet.getRow(i + 1).getCell(2).setCellValue(lastYearData.get(i)); }*/ - for (int i = sheet.getLastRowNum(); i > entrance.size(); i--) { - sheet.removeRow(sheet.getRow(i)); - } - // 更新图表 - PoiUtil.wordExportChar(chart, "门架车流量", new String[]{"菏泽", "济南"}, sheet); + for (int i = sheet.getLastRowNum(); i > entrance.size(); i--) { + sheet.removeRow(sheet.getRow(i)); + } + // 更新图表 + PoiUtil.wordExportChar(chart, "门架车流量", new String[]{dcSdhsEventQuery.getThisTime()+"(菏泽)",dcSdhsEventQuery.getLastTime()+"(菏泽)", dcSdhsEventQuery.getThisTime()+"(济南)",dcSdhsEventQuery.getLastTime()+"(济南)",}, sheet); - // 合并图表到Word文档 - mergeChart(chart, doc); + // 合并图表到Word文档 + mergeChart(chart, doc); - // 关闭模板文档 - copiedTemplate.close(); - } catch (Exception e) { - e.printStackTrace(); - } - //换行 - createLineBreak(doc); -}else { + // 关闭模板文档 + copiedTemplate.close(); + } catch (Exception e) { + e.printStackTrace(); + } + //换行 + createLineBreak(doc); + } else { addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue()); } @@ -2093,17 +2214,14 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { /** * 门架数据分析 + * * @param dcSdhsEventQuery * @return */ @Override - public Map> 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); + public Map> trafficFlowStatistics(DcSdhsEventQuery dcSdhsEventQuery) { + 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 hezeDirection = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate,startDate,"1",periodType); + List heze = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate, startDate, "1", periodType); //济南方向 - List jinanDirection = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate,startDate,"3",periodType); - Map> map = new HashMap<>(); - map.put("hezeDirection",hezeDirection); - map.put("jinanDirection",jinanDirection); + List jinan = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(startDate, startDate, "3", periodType); + //菏泽方向 + List lastHeze = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(lastTime, lastTime, "1", periodType); + //济南方向 + List lastJinan = dcGantryStatisticsDataService.trafficFlowStatisticsAsc(lastTime, lastTime, "3", periodType); + + + Map> map = new HashMap<>(); + 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 selectDcSdhsEventList(DcSdhsEvent dcSdhsEvent) - { + public List 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 list = dcSdhsEventMapper.getDataCalendar(month); + return AjaxResult.success(list); + } }