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 2e1f0c9e..6ca262f8 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 @@ -2,6 +2,9 @@ package com.zc.business.controller; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcSdhsEvent; +import com.zc.business.domain.DcSdhsEventQuery; +import com.zc.business.enums.UniversalEnum; import com.zc.business.domain.DcSdhsEventQuery; import com.zc.business.enums.UniversalEnum; import com.ruoyi.common.utils.SecurityUtils; @@ -12,6 +15,16 @@ import com.zc.business.service.IDcSdhsEventService; import com.zc.business.utils.PoiUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xwpf.usermodel.XWPFChart; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; import io.swagger.annotations.ApiParam; import org.apache.poi.xwpf.usermodel.ParagraphAlignment; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -26,8 +39,24 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.*; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import sun.reflect.generics.tree.VoidDescriptor; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static com.zc.business.utils.PoiUtil.mergeChart; +import static com.zc.business.utils.PoiUtil.setTableFonts; import javax.servlet.http.HttpServletResponse; import java.io.FileOutputStream; @@ -81,6 +110,47 @@ public class DcSdhsEventController { return dcSdhsEventService.importData(fileName,fileUrl); } + //事故多发路段分析 + @ApiOperation("查询事故多发路段分析") + @PostMapping("/sectionAnalysis") + public AjaxResult sectionAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ + return AjaxResult.success(dcSdhsEventService.accidentSectionAnalysis(dcSdhsEventQuery)); + } + //事故类型分析 + @ApiOperation("查询事故类型分析") + @PostMapping("/typeAnalysis") + public AjaxResult accidentTypeAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ + return AjaxResult.success(dcSdhsEventService.accidentTypeAnalysis(dcSdhsEventQuery)); + } + //事故拥堵时间 + @ApiOperation("查询事故拥堵时间分析") + @PostMapping("/congestedTime") + public AjaxResult accidentCongestedTime(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ + return AjaxResult.success(dcSdhsEventService.accidentCongestedTime(dcSdhsEventQuery)); + } + //事故拥堵地点 + @ApiOperation("查询事故拥堵地点分析") + @PostMapping("/congestedLocation") + public AjaxResult accidentCongestedLocation(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ + return AjaxResult.success(dcSdhsEventService.accidentCongestedLocation(dcSdhsEventQuery)); + } + + //事故多发路段、类型分析导出 + @PostMapping("/sectionTypeAnalysisExport") + public void sectionTypeAnalysisExport(HttpServletResponse response,@RequestBody DcSdhsEventQuery dcSdhsEventQuery) throws IOException { + // 读取Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.EXPORT_TRAFFIC_REPORT.getValue()); + XWPFDocument newDoc = new XWPFDocument(inputStream); + dcSdhsEventService.sectionAnalysisExport(newDoc,dcSdhsEventQuery); + dcSdhsEventService.accidentTypeAnalysisExport(newDoc,dcSdhsEventQuery); + dcSdhsEventService.accidentCongestedTimeExport(newDoc,dcSdhsEventQuery); + dcSdhsEventService.accidentCongestedLocationExport(newDoc,dcSdhsEventQuery); + // 不保存直接返回文件流 + newDoc.write(response.getOutputStream()); + // 关闭文档 + newDoc.close(); + System.out.println("生成通行情况快报成功!"); + } @PostMapping("/export") @ApiOperation("导出") public void trafficSituationReport(HttpServletResponse response,@RequestBody DcSdhsEventQuery dcSdhsEventQuery) throws Exception { @@ -113,10 +183,10 @@ public class DcSdhsEventController { for (String trafficIncidentType : exportKey) { if ("1".equals(trafficIncidentType)){ //事故多发路段 - + dcSdhsEventService.sectionAnalysisExport(newDoc,dcSdhsEventQuery); } else if ("2".equals(trafficIncidentType)){ //事件类型分析 - + dcSdhsEventService.accidentTypeAnalysisExport(newDoc,dcSdhsEventQuery); } else if ("3".equals(trafficIncidentType)){ //事故车型分析 //事故车型 @@ -165,10 +235,10 @@ public class DcSdhsEventController { for (String trafficIncidentType : exportKey) { if ("11".equals(trafficIncidentType)){ //拥堵地点统计 - + dcSdhsEventService.accidentCongestedLocationExport(newDoc,dcSdhsEventQuery); } else if ("12".equals(trafficIncidentType)){ //路段平均拥堵时长 - + dcSdhsEventService.accidentCongestedTimeExport(newDoc,dcSdhsEventQuery); } } diff --git a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java index 0ae7cf56..93eb0450 100644 --- a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java @@ -105,7 +105,14 @@ public enum UniversalEnum { // 图模板2 DRAWING_TEMPLATE_2(0, "wordTemplate/chartTemplate2.docx"), - + // 路段事故模板 + CHAR_SECTION(0, "wordTemplate/charSection.docx"), + // 事件类型模板 + TYPE_ANALYSIS(0, "wordTemplate/typeAnalysis.docx"), + //事故拥堵时长模板 + CONGESTION_TIME(0, "wordTemplate/congestionTime.docx"), + //事故拥堵地点模板 + CONGESTED_LOCATION(0, "wordTemplate/congestedLocation.docx"), // 总体情况 GENERAL_SITUATION(0, "总体情况"), 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 1b030d7e..39f38e4a 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 @@ -1,6 +1,10 @@ package com.zc.business.service; import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcSdhsEvent; +import com.zc.business.domain.DcSdhsEventQuery; +import org.apache.poi.xddf.usermodel.XDDFAdjustHandleXY; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import com.zc.business.domain.*; import org.apache.poi.xwpf.usermodel.XWPFDocument; import com.zc.business.domain.DcSdhsEventQuery; @@ -26,6 +30,24 @@ public interface IDcSdhsEventService AjaxResult getFileInfo(); + + //事故多发路段分析 + public Map accidentSectionAnalysis(DcSdhsEventQuery dcSdhsEventQuery); + //事故类型分析 + public Map accidentTypeAnalysis(DcSdhsEventQuery dcSdhsEventQuery); + //事故拥堵地点 + public Map accidentCongestedLocation(DcSdhsEventQuery dcSdhsEventQuery); + //事故拥堵时间 + public Map accidentCongestedTime(DcSdhsEventQuery dcSdhsEventQuery); + //事故多发路段分析导出 + public void sectionAnalysisExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery); + //事故类型分析导出 + public void accidentTypeAnalysisExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery); + //事故拥堵时长导出 + void accidentCongestedTimeExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery); + //事故拥堵地点导出 + void accidentCongestedLocationExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery); + AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery); void exportRegionAnalysis(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 5b50cd82..8c11a9bb 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 @@ -20,6 +20,17 @@ import com.zc.business.utils.PoiUtil; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xwpf.usermodel.XWPFChart; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; +import com.zc.business.utils.PoiUtil; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -34,6 +45,16 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; +import java.text.DecimalFormat; +import java.util.ArrayList; + + +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.io.InputStream; +import java.math.BigInteger; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -48,6 +69,9 @@ import java.util.stream.Collectors; import static com.zc.business.utils.PoiUtil.*; +import static com.zc.business.utils.PoiUtil.mergeChart; +import static com.zc.business.utils.PoiUtil.setTableFonts; + /** * 高速云事件分析Service业务层处理 * @@ -160,6 +184,440 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE, now.getTime(), fileInfo); return AjaxResult.success("导入成功"); } + //事故多发路段分析 + @Override + public Map accidentSectionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { + List cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + Map groupCountMap = new HashMap<>(); + try { + long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); + long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); +// String direction = dcSdhsEventQuery.getDirection();//方向 + for (DcSdhsEvent event : cacheList) { + if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { + continue; + } + + if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { + continue; + } + String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头 + if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { + continue; + } + int km = Integer.parseInt(kmStr.split("\\+")[0]); // 假设+后面还有其他内容,我们只取+前面的部分 + + // 计算分组startKm,确保是5的倍数且不大于km + int startKm = ((km / 10) * 10) + (km % 10 >= 5 ? 10 : 0); + startKm = startKm - startKm % 5; // 确保startKm是5的倍数 + if (startKm%5==0){ + if ((startKm / 5) % 2 == 0) { + startKm -= 5; + } + } + // 计算分组endKm,找到比startKm大、最接近的、以5结尾的数 + int endKm = startKm + 10; + while (endKm % 5 != 0) { + endKm++; + } + // 构造分组key + String groupKey = "K" + startKm + "-" + "K" + endKm; + //groupCountMap.put(groupKey, groupCountMap.getOrDefault(groupKey, 0) + 1); + if (groupCountMap.get(groupKey)==null){ //事件还为存入map + groupCountMap.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1 + }else { + Integer currentSum = groupCountMap.get(groupKey); + groupCountMap.put(groupKey, currentSum +1 ); + } + } + List> entries = new ArrayList<>(groupCountMap.entrySet()); + entries.sort(Comparator.comparingInt(e -> { + String[] parts = e.getKey().split("-"); + int start = Integer.parseInt(parts[0].substring(1)); // 去掉'K'并解析为整数 + int end = Integer.parseInt(parts[1].substring(1)); // 去掉'K'并解析为整数 + return start + end; // 返回两个数字之和 + })); + // 将排序后的 List 转换回 LinkedHashMap 以保持顺序 + LinkedHashMap sortedMap = new LinkedHashMap<>(); + for (Map.Entry entry : entries) { + sortedMap.put(entry.getKey(), entry.getValue()); + } + return sortedMap; + } catch (Exception e) { + e.printStackTrace(); + } + return groupCountMap; + } + //事故类型分析 + @Override + public Map accidentTypeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { + List cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + Map groupCountMap = new HashMap<>(); + try { + long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); + long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); +// String direction = dcSdhsEventQuery.getDirection();//方向 + for (DcSdhsEvent event : cacheList) { + if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { + continue; + } + if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { + continue; + } + String eventType = event.getEventType();//事件类型 + if (groupCountMap.get(eventType)==null){ //事件还为存入map + groupCountMap.putIfAbsent(eventType, UniversalEnum.ONE.getNumber());//事件类型不存在存1 + }else { + Integer currentSum = groupCountMap.get(eventType); + groupCountMap.put(eventType, currentSum +1 ); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return groupCountMap; + } + + //事故拥堵地点 + @Override + public Map accidentCongestedLocation(DcSdhsEventQuery dcSdhsEventQuery) { + List cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + Map groupCountMap = new HashMap<>(); + try { + long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); + long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); + for (DcSdhsEvent event : cacheList) { + if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { + continue; + } + if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { + continue; + } + String eventType = event.getEventType();//事件类型 + if (!"交通拥堵".equals(eventType)){ + continue; + } + String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头 + if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { + continue; + } + String eventSubclass = event.getEventSubclass();//事件子类型 + if (groupCountMap.get(eventSubclass)==null){ //事件还为存入map + groupCountMap.putIfAbsent(eventSubclass, UniversalEnum.ONE.getNumber());//事件类型不存在存1 + }else { + Integer currentSum = Integer.valueOf(groupCountMap.get(eventSubclass).toString()); + groupCountMap.put(eventSubclass, currentSum +1 ); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return groupCountMap; + } + //事故拥堵时间 + @Override + public Map accidentCongestedTime(DcSdhsEventQuery dcSdhsEventQuery) { + List cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + Map averageMap = new HashMap<>(); + Map map = new HashMap<>(); + Map groupCountMap = new HashMap<>(); + try { + long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); + long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); + for (DcSdhsEvent event : cacheList) { + if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { + continue; + } + if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { + continue; + } + String eventType = event.getEventType();//事件类型 + if (!"交通拥堵".equals(eventType)){ + continue; + } + String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头 + if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { + continue; + } + int km = Integer.parseInt(kmStr.split("\\+")[0]); // 假设+后面还有其他内容,我们只取+前面的部分 + // 计算分组startKm,确保是5的倍数且不大于km + int startKm = ((km / 10) * 10) + (km % 10 >= 5 ? 10 : 0); + startKm = startKm - startKm % 5; // 确保startKm是5的倍数 + if (startKm%5==0){ + if ((startKm / 5) % 2 == 0) { + startKm -= 5; + } + } + // 计算分组endKm,找到比startKm大、最接近的、以5结尾的数 + int endKm = startKm + 10; + while (endKm % 5 != 0) { + endKm++; + } + // 构造分组key + String groupKey = "K" + startKm + "-" + "K" + endKm; + long differenceInMilliseconds = event.getEndTime().getTime() - event.getStartTime().getTime(); + long differenceInMinutes = differenceInMilliseconds / 60000;//时间分钟 + Integer differenceInMinute = (int)differenceInMinutes; + + if (averageMap.get(groupKey)==null){ //事件还为存入map + averageMap.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1 + }else { + Integer currentSum = averageMap.get(groupKey); + averageMap.put(groupKey, currentSum +differenceInMinute ); + } + if (map.get(groupKey)==null){ //事件还为存入map + map.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1 + }else { + Integer currentSum = map.get(groupKey); + map.put(groupKey, currentSum +1 ); + } + + } + for (String key:averageMap.keySet()){ + if (map.containsKey(key)){ + double average = (double) averageMap.get(key) / map.get(key); + DecimalFormat df = new DecimalFormat("#.00"); + String formattedAverage = df.format(average); + groupCountMap.put(key, formattedAverage); + }else { + continue; + } + } + List> entries = new ArrayList<>(groupCountMap.entrySet()); + entries.sort(Comparator.comparingInt(e -> { + String[] parts = e.getKey().split("-"); + int start = Integer.parseInt(parts[0].substring(1)); // 去掉'K'并解析为整数 + int end = Integer.parseInt(parts[1].substring(1)); // 去掉'K'并解析为整数 + return start + end; // 返回两个数字之和 + })); + // 将排序后的 List 转换回 LinkedHashMap 以保持顺序 + LinkedHashMap sortedMap = new LinkedHashMap<>(); + for (Map.Entry entry : entries) { + sortedMap.put(entry.getKey(), entry.getValue()); + } + return sortedMap; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //事故多发路段分析导出 + @Override + public void sectionAnalysisExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery) { + + Map map =accidentSectionAnalysis(dcSdhsEventQuery); +// String direction = dcSdhsEventQuery.getDirection();//方向 + String title="事故路段分布图"; +// if ("广州方向".equals(direction)){ +// title="事故路段分布图-广州方向"; +// }else { +// title="事故路段分布图-济南方向"; +// } + PoiUtil.createHeading2(doc, title); + XWPFTable table = doc.createTable(map.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(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "路段"); + setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "事故发生数量"); + + List> entries = new ArrayList<>(map.entrySet()); + //excel + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); + setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); + } + try{ + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CHAR_SECTION.getValue()); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + //获取word中所有图表对象 + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + //系列信息 + String[] singleBarSeriesNames = {"数量"}; + //分类信息 + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(entries.get(i).getKey()); + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString())); + } + for (int i = sheet.getLastRowNum(); i > entries.size();i--){ + sheet.removeRow(sheet.getRow(i)); + } + PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); + // 追加到同一个Word文档中 + mergeChart(chart,doc); + // 关闭复制的模板文档 + copiedTemplate.close(); + + }catch (Exception e){ + e.printStackTrace(); + } + } + //事故类型分析导出 + @Override + public void accidentTypeAnalysisExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { + Map map =accidentTypeAnalysis(dcSdhsEventQuery); +// String direction = dcSdhsEventQuery.getDirection();//方向 + String title="事件类型分布图"; +// if ("广州方向".equals(direction)){ +// title="事件类型分布图-广州方向"; +// }else { +// title="事件类型分布图-济南方向"; +// } + PoiUtil.createHeading2(doc, title); + XWPFTable table = doc.createTable(map.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(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "类型"); + setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "数量"); + + List> entries = new ArrayList<>(map.entrySet()); + //excel + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); + setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); + } + try{ + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.TYPE_ANALYSIS.getValue()); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + + //获取word中所有图表对象 + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + //系列信息 + String[] singleBarSeriesNames = {"事件类型"}; + //分类信息 + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(entries.get(i).getKey()); + sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString())); + } + for (int i = sheet.getLastRowNum(); i > entries.size();i--){ + sheet.removeRow(sheet.getRow(i)); + } + PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); + // 追加到同一个Word文档中 + mergeChart(chart,doc); + // 关闭复制的模板文档 + copiedTemplate.close(); + + }catch (Exception e){ + e.printStackTrace(); + } + } + //事故拥堵时间导出 + @Override + public void accidentCongestedTimeExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { + Map map =accidentCongestedTime(dcSdhsEventQuery); + String title="事故拥堵时长分布图"; + PoiUtil.createHeading2(doc, title); + XWPFTable table = doc.createTable(map.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(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "路段"); + setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "时长(分钟)"); + + List> entries = new ArrayList<>(map.entrySet()); + //excel + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); + setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); + } + try{ + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CONGESTION_TIME.getValue()); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + + //获取word中所有图表对象 + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + //系列信息 + String[] singleBarSeriesNames = {"事故拥堵时长"}; + //分类信息 + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(0).setCellValue(entries.get(i).getKey()); + sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(1).setCellValue(Double.valueOf(entries.get(i).getValue())); + } + for (int i = sheet.getLastRowNum(); i > entries.size();i--){ + sheet.removeRow(sheet.getRow(i)); + } + PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); + // 追加到同一个Word文档中 + mergeChart(chart,doc); + // 关闭复制的模板文档 + copiedTemplate.close(); + + }catch (Exception e){ + e.printStackTrace(); + } + } + //事故拥堵地点导出 + @Override + public void accidentCongestedLocationExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { + Map map =accidentCongestedLocation(dcSdhsEventQuery); + String title="事故拥堵地点分布图"; + PoiUtil.createHeading2(doc, title); + XWPFTable table = doc.createTable(map.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(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "地点"); + setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "数量"); + + List> entries = new ArrayList<>(map.entrySet()); + //excel + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); + setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); + } + try{ + // 复制Word模板 + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CONGESTED_LOCATION.getValue()); + XWPFDocument copiedTemplate = new XWPFDocument(inputStream); + + //获取word中所有图表对象 + List charts = copiedTemplate.getCharts(); + XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); + XSSFWorkbook workbook = chart.getWorkbook(); + XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); + //系列信息 + String[] singleBarSeriesNames = {"事故拥堵地点"}; + //分类信息 + for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ + sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(0).setCellValue(entries.get(i).getKey()); + sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(1).setCellValue(entries.get(i).getValue()); + } + for (int i = sheet.getLastRowNum(); i > entries.size();i--){ + sheet.removeRow(sheet.getRow(i)); + } + PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); + // 追加到同一个Word文档中 + mergeChart(chart,doc); + // 关闭复制的模板文档 + copiedTemplate.close(); + + }catch (Exception e){ + e.printStackTrace(); + } + } /*public AjaxResult importData(MultipartFile file) throws IOException { List importData = new ArrayList<>(); diff --git a/zc-business/src/main/resources/wordTemplate/charSection.docx b/zc-business/src/main/resources/wordTemplate/charSection.docx index e189db73..f2338f4d 100644 Binary files a/zc-business/src/main/resources/wordTemplate/charSection.docx and b/zc-business/src/main/resources/wordTemplate/charSection.docx differ diff --git a/zc-business/src/main/resources/wordTemplate/congestedLocation.docx b/zc-business/src/main/resources/wordTemplate/congestedLocation.docx new file mode 100644 index 00000000..430f32d5 Binary files /dev/null and b/zc-business/src/main/resources/wordTemplate/congestedLocation.docx differ diff --git a/zc-business/src/main/resources/wordTemplate/congestionTime.docx b/zc-business/src/main/resources/wordTemplate/congestionTime.docx new file mode 100644 index 00000000..8137ba30 Binary files /dev/null and b/zc-business/src/main/resources/wordTemplate/congestionTime.docx differ diff --git a/zc-business/src/main/resources/wordTemplate/typeAnalysis.docx b/zc-business/src/main/resources/wordTemplate/typeAnalysis.docx index db896b4e..ef78289a 100644 Binary files a/zc-business/src/main/resources/wordTemplate/typeAnalysis.docx and b/zc-business/src/main/resources/wordTemplate/typeAnalysis.docx differ