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; import com.zc.business.domain.DcSdhsEvent; import com.zc.business.domain.DcSdhsEventQuery; import com.zc.business.enums.UniversalEnum; 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; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType; import org.apache.catalina.security.SecurityUtil; import org.apache.poi.xssf.usermodel.XSSFSheet; 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; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import static com.zc.business.utils.PoiUtil.insertTOC; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import static com.zc.business.utils.PoiUtil.*; import static com.zc.business.utils.PoiUtil.createLineBreak; /** * @Description 高速云事件分析Controller * * @author liuwenge * @date 2024/08/15 16:38 */ @Api(tags = "高速云事件分析") @RestController @RequestMapping("/business/sdhsEvent") public class DcSdhsEventController { @Autowired private IDcSdhsEventService dcSdhsEventService; @Autowired private WordController wordController; /*@ApiOperation("导入数据") @PostMapping("/importData") public AjaxResult importData(MultipartFile file) throws Exception { return dcSdhsEventService.importData(file); }*/ @ApiOperation("导入数据") @PostMapping("/importData") public AjaxResult importData(@ApiParam(value="文件名称", name="fileName", required=true) @RequestParam("fileName") String fileName, @ApiParam(value="文件路径", name="fileUrl", required=true) @RequestParam("fileUrl") String fileUrl) throws Exception { return dcSdhsEventService.importData(fileName,fileUrl); } //事故多发路段分析 @ApiOperation("查询事故多发路段分析") @PostMapping("/sectionAnalysis") public AjaxResult sectionAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ if (dcSdhsEventQuery.getStartTime()==null||dcSdhsEventQuery.getEndTime()==null){ return AjaxResult.error("参数异常"); } return AjaxResult.success(dcSdhsEventService.accidentSectionAnalysis(dcSdhsEventQuery)); } //事件类型分析 @ApiOperation("查询事件类型分析") @PostMapping("/typeAnalysis") public AjaxResult accidentTypeAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ if (dcSdhsEventQuery.getStartTime()==null||dcSdhsEventQuery.getEndTime()==null){ return AjaxResult.error("参数异常"); } return AjaxResult.success(dcSdhsEventService.accidentTypeAnalysis(dcSdhsEventQuery)); } //事故拥堵时间 @ApiOperation("查询事故拥堵时间分析") @PostMapping("/congestedTime") public AjaxResult accidentCongestedTime(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ if (dcSdhsEventQuery.getStartTime()==null||dcSdhsEventQuery.getEndTime()==null){ return AjaxResult.error("参数异常"); } return AjaxResult.success(dcSdhsEventService.accidentCongestedTime(dcSdhsEventQuery)); } //事故拥堵地点 @ApiOperation("查询事故拥堵地点分析") @PostMapping("/congestedLocation") public AjaxResult accidentCongestedLocation(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ if (dcSdhsEventQuery.getStartTime()==null||dcSdhsEventQuery.getEndTime()==null){ return AjaxResult.error("参数异常"); } 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,DcSdhsEventQuery dcSdhsEventQuery) throws Exception { try { SimpleDateFormat df = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); String date = df.format(new Date()); String outputPath = RuoYiConfig.getDownloadPath() +"/高速云事件分析报告" + date + ".docx"; // 读取Word模板 InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/wordTemplate2.docx"); XWPFDocument newDoc = new XWPFDocument(inputStream); // 创建并插入带超链接的目录 insertTOC(newDoc); //换页 XWPFParagraph breakPara = newDoc.createParagraph(); breakPara.setAlignment(ParagraphAlignment.CENTER); CTP ctP = breakPara.getCTP(); CTR ctr = ctP.addNewR(); CTBr ctBr = ctr.addNewBr(); ctBr.setType(STBrType.PAGE); List exportKey = dcSdhsEventQuery.getExportKey(); if (exportKey != null && exportKey.size() > 0){ //交通事件 if (exportKey.contains("1") || exportKey.contains("2") || exportKey.contains("3") || exportKey.contains("4") || exportKey.contains("5") || exportKey.contains("6")){ PoiUtil.createHeading1(newDoc,"交通事件"); 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)){ //事故车型分析 //事故车型 dcSdhsEventService.exportAccidentModelAnalysis(newDoc, dcSdhsEventQuery); } else if ("4".equals(trafficIncidentType)){ //事故时间分析 //事故时间 dcSdhsEventService.exportAccidentTimeAnalysis(newDoc, dcSdhsEventQuery); } else if ("5".equals(trafficIncidentType)){ //事故地市分布 dcSdhsEventService.exportRegionAnalysis(newDoc,dcSdhsEventQuery); } else if ("6".equals(trafficIncidentType)){ //交通管制情况统计 dcSdhsEventService.exportStationAnalysis(newDoc,dcSdhsEventQuery); } } } if (exportKey.contains("7")){ PoiUtil.createHeading1(newDoc,"天气情况统计"); wordController.weather(newDoc); } if (exportKey.contains("8") || exportKey.contains("9")){ PoiUtil.createHeading1(newDoc,"交通量统计"); for (String trafficIncidentType : exportKey) { if ("8".equals(trafficIncidentType)){ //门架车流量 dcSdhsEventService.exporFrameDataAnalysis(newDoc,dcSdhsEventQuery); } else if ("9".equals(trafficIncidentType)){ //收费站车流量 dcSdhsEventService.exporttollGateEntrance(newDoc,dcSdhsEventQuery); } } } if (exportKey.contains("10")){ PoiUtil.createHeading1(newDoc,"交通事故情况"); //交通事故类型统计 dcSdhsEventService.exportAccidentType(newDoc,dcSdhsEventQuery); } if (exportKey.contains("11") || exportKey.contains("12")){ PoiUtil.createHeading1(newDoc,"拥堵情况"); for (String trafficIncidentType : exportKey) { if ("11".equals(trafficIncidentType)){ //拥堵地点统计 dcSdhsEventService.accidentCongestedLocationExport(newDoc,dcSdhsEventQuery); } else if ("12".equals(trafficIncidentType)){ //路段平均拥堵时长 dcSdhsEventService.accidentCongestedTimeExport(newDoc,dcSdhsEventQuery); } } } } // 保存新生成的Word文件 /*FileOutputStream out = new FileOutputStream(outputPath); newDoc.write(out); out.close();*/ // 不保存直接返回文件流 newDoc.write(response.getOutputStream()); // 关闭文档 newDoc.close(); } catch (Exception e) { e.printStackTrace(); } } @ApiOperation("查询上次上传的文件信息") @GetMapping("/getFileInfo") public AjaxResult getFileInfo() { return dcSdhsEventService.getFileInfo(); } @ApiOperation("查询事故地市分布") @PostMapping("/selectRegionAnalysis") public AjaxResult selectRegionAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery) { return dcSdhsEventService.selectRegionAnalysis(dcSdhsEventQuery); } /** * 事故时间分析 * @param dcSdhsEventQuery * @return */ @PostMapping("/accidentTimeAnalysis") @ApiOperation("事故时间分析") public AjaxResult accidentTimeAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ return AjaxResult.success( dcSdhsEventService.accidentTimeAnalysis(dcSdhsEventQuery)); } /** * 事故车型分析 * @param dcSdhsEventQuery * @return */ @PostMapping("/accidentModelAnalysis") @ApiOperation("事故车型分析") public AjaxResult accidentModelAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ return AjaxResult.success( dcSdhsEventService.accidentModelAnalysis(dcSdhsEventQuery)); } /** * 收费站出入口分析 * @param dcSdhsEventQuery * @return */ @PostMapping("/TollBoothStatisticsList") @ApiOperation("收费站出入口分析") public AjaxResult TollBoothStatisticsList(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ return AjaxResult.success( dcSdhsEventService.TollBoothStatisticsList(dcSdhsEventQuery)); } /** * 门架分析 * @param dcSdhsEventQuery * @return */ @PostMapping("/gantryAnalysis") @ApiOperation("门架分析") public AjaxResult gantryAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery){ return AjaxResult.success( dcSdhsEventService.trafficFlowStatistics(dcSdhsEventQuery)); } @ApiOperation("查询交通管制情况分析") @PostMapping("/selectStationAnalysis") public AjaxResult selectStationAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery) { return dcSdhsEventService.selectStationAnalysis(dcSdhsEventQuery); } @ApiOperation("查询交通事故类型统计") @PostMapping("/selectAccidentType") public AjaxResult selectAccidentType(@RequestBody DcSdhsEventQuery dcSdhsEventQuery) { return dcSdhsEventService.selectAccidentType(dcSdhsEventQuery); } @ApiOperation("查询天气情况统计") @PostMapping("/selectWeather") public AjaxResult selectWeather() { return dcSdhsEventService.selectWeather(); } }