diff --git a/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java b/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java index e5c0062e..c1b25ae2 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java @@ -92,12 +92,16 @@ public class DcSdhsEventController { PoiUtil.createHeading1(newDoc,"交通事件"); for (String trafficIncidentType : exportKey) { if ("1".equals(trafficIncidentType)){ + //事故多发路段 } else if ("2".equals(trafficIncidentType)){ + //事件类型分析 } else if ("3".equals(trafficIncidentType)){ + //事故车型分析 } else if ("4".equals(trafficIncidentType)){ + //事故时间分析 } else if ("5".equals(trafficIncidentType)){ //事故地市分布 @@ -108,10 +112,12 @@ public class DcSdhsEventController { } } - } else if (exportKey.contains("7")){ + } + if (exportKey.contains("7")){ PoiUtil.createHeading1(newDoc,"天气情况统计"); wordController.weather(newDoc); - } else if (exportKey.contains("8") || exportKey.contains("9")){ + } + if (exportKey.contains("8") || exportKey.contains("9")){ PoiUtil.createHeading1(newDoc,"交通量统计"); for (String trafficIncidentType : exportKey) { if ("8".equals(trafficIncidentType)){ @@ -123,18 +129,21 @@ public class DcSdhsEventController { } } - } else if (exportKey.contains("10")){ + } + if (exportKey.contains("10")){ PoiUtil.createHeading1(newDoc,"交通事故情况"); //交通事故类型统计 + dcSdhsEventService.exportAccidentType(newDoc,dcSdhsEventQuery); - } else if (exportKey.contains("11") || exportKey.contains("12")){ - PoiUtil.createHeading1(newDoc,"交通量统计"); + } + if (exportKey.contains("11") || exportKey.contains("12")){ + PoiUtil.createHeading1(newDoc,"拥堵情况"); for (String trafficIncidentType : exportKey) { if ("11".equals(trafficIncidentType)){ //拥堵地点统计 } else if ("12".equals(trafficIncidentType)){ - //路段拥堵时长 + //路段平均拥堵时长 } @@ -160,6 +169,13 @@ public class DcSdhsEventController { } } + @ApiOperation("查询上次上传的文件信息") + @GetMapping("/getFileInfo") + public AjaxResult getFileInfo() + { + return dcSdhsEventService.getFileInfo(); + } + @ApiOperation("查询事故地市分布") @PostMapping("/selectRegionAnalysis") public AjaxResult selectRegionAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery) @@ -175,5 +191,13 @@ public class DcSdhsEventController { return dcSdhsEventService.selectStationAnalysis(dcSdhsEventQuery); } + @ApiOperation("查询交通事故类型统计") + @PostMapping("/selectAccidentType") + public AjaxResult selectAccidentType(@RequestBody DcSdhsEventQuery dcSdhsEventQuery) + { + return dcSdhsEventService.selectAccidentType(dcSdhsEventQuery); + } + + } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java b/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java index 32afb38d..b83c2f80 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java @@ -19,6 +19,8 @@ public interface IDcSdhsEventService // AjaxResult importData(MultipartFile file) throws Exception; AjaxResult importData(String fileName,String fileUrl) throws Exception; + AjaxResult getFileInfo(); + AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery); void exportRegionAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery); @@ -26,4 +28,8 @@ public interface IDcSdhsEventService AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery); void exportStationAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery); + + AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery); + + void exportAccidentType(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery); } 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 e78c70a7..454a47cd 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 @@ -134,11 +134,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { Map fileInfo = new HashMap<>(); fileInfo.put("fileName",fileName); fileInfo.put("fileUrl",fileUrl); + + Date now = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String updateTime = simpleDateFormat.format(new Date()); + String updateTime = simpleDateFormat.format(now); fileInfo.put("uploadTime",updateTime); - redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,updateTime,fileInfo); + redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,now.getTime(),fileInfo); return AjaxResult.success("导入成功"); } @@ -242,6 +244,26 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { return numbers; } + @Override + public AjaxResult getFileInfo(){ + Map> allFileInfo = redisCache.getCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE); + Map lastFile = new HashMap<>(); + if (allFileInfo != null && allFileInfo.size() > 0){ + String maxKeyNumerically = Collections.max(allFileInfo.keySet(), new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + return Long.compare(Long.parseLong(o1), Long.parseLong(o2)); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Keys cannot be parsed as numbers", e); + } + } + }); + lastFile = allFileInfo.get(maxKeyNumerically); + } + return AjaxResult.success(lastFile); + } + /** * @Description 事故地市分布 @@ -462,21 +484,28 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { List> list = new ArrayList<>(); for (String stationName : stationSet) { Map map = new HashMap<>(); + Long allNum = 0L; map.put("stationName",stationName); if (closeStation.containsKey(stationName)){ map.put("close",closeStation.get(stationName)); + allNum += closeStation.get(stationName); } else { map.put("close",0); } if (restrictionStation.containsKey(stationName)){ map.put("restriction",restrictionStation.get(stationName)); + allNum += restrictionStation.get(stationName); } else { map.put("restriction",0); } + + map.put("allNum",allNum); list.add(map); } + //根据总数排序 + list = list.stream().sorted(Comparator.comparing(item -> Long.parseLong(((Map) item).get("allNum").toString())).reversed()).collect(Collectors.toList()); return AjaxResult.success(list); } @@ -594,4 +623,123 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { } + /** + * @Description 查询交通事故类型统计 + * + * @author liuwenge + * @date 2024/8/21 10:56 + * @param dcSdhsEventQuery + * @return com.ruoyi.common.core.domain.AjaxResult + */ + @Override + public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery){ + List eventList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + if (eventList == null || eventList.size() == 0){ + return AjaxResult.error("请先导入数据"); + } + + eventList = eventList.stream().filter(item -> item.getStartTime() != null + && item.getStartTime().getTime() >= dcSdhsEventQuery.getStartTime().getTime() + && item.getStartTime().getTime() <= dcSdhsEventQuery.getEndTime().getTime() + && "交通事故".equals(item.getEventType())) + .collect(Collectors.toList()); + List> list = new ArrayList<>(); + + if(eventList.size() > 0){ + //根据详细类型 分组计数 + Map subclass = eventList.stream().collect(Collectors.groupingBy(DcSdhsEvent::getEventSubclass,Collectors.counting())); + subclass.forEach((key,count)->{ + Map map = new HashMap<>(); + map.put("subclassName",key); + map.put("num",count); + list.add(map); + }); + } + + return AjaxResult.success(list); + } + + /** + * @Description 导出交通事故类型统计 + * + * @author liuwenge + * @date 2024/8/21 11:07 + * @param doc + * @param dcSdhsEventQuery + * @return void + */ + @Override + public void exportAccidentType(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery){ + AjaxResult ajaxResult = selectAccidentType(dcSdhsEventQuery); + if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { + + PoiUtil.createHeading2(doc,"事故类型统计"); + List> data = (List>) ajaxResult.get("data"); + if (data != null && data.size() != UniversalEnum.ZERO.getNumber()){ + //插入图表 + try { + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/sdhsEventChart.docx"); + + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + + //获取word中所有图表对象 + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(1); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + + //系列信息 + String[] singleBarSeriesNames = {"数量"}; + //分类信息 + for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++){ + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(data.get(i).get("subclassName").toString()); + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(data.get(i).get("num").toString())); + } + + for (int i = sheet.getLastRowNum(); i > data.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); + + + //插入表格 + XWPFTable table = doc.createTable(data.size()+1, 2); + //列宽自动分割 + 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), "数量"); + + //excel + for (int i = 0; i < data.size(); i++){ + setTableFonts(table.getRow(i+1).getCell(0), data.get(i).get("subclassName").toString()); + setTableFonts(table.getRow(i+1).getCell(1), data.get(i).get("num").toString()); + } + } else { + addDescription(doc,UniversalEnum.NO_DATA_AVAILABLE.getValue()); + } + + } else { + addDescription(doc,UniversalEnum.NO_DATA_AVAILABLE.getValue()); + } + } } diff --git a/zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx b/zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx index a6afb431..bd477e23 100644 Binary files a/zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx and b/zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx differ