济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
7.6 KiB

package com.zc.business.controller;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
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 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
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;
/**
* @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);
}
@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<String> 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)){
8 months ago
//事故多发路段
} else if ("2".equals(trafficIncidentType)){
8 months ago
//事件类型分析
} else if ("3".equals(trafficIncidentType)){
8 months ago
//事故车型分析
} else if ("4".equals(trafficIncidentType)){
8 months ago
//事故时间分析
} 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)){
//门架车流量
} else if ("9".equals(trafficIncidentType)){
//收费站车流量
}
}
}
if (exportKey.contains("10")){
PoiUtil.createHeading1(newDoc,"交通事故情况");
//交通事故类型统计
dcSdhsEventService.exportAccidentType(newDoc,dcSdhsEventQuery);
}
if (exportKey.contains("11") || exportKey.contains("12")){
8 months ago
PoiUtil.createHeading1(newDoc,"拥堵情况");
for (String trafficIncidentType : exportKey) {
if ("11".equals(trafficIncidentType)){
//拥堵地点统计
} else if ("12".equals(trafficIncidentType)){
8 months ago
//路段平均拥堵时长
}
}
}
}
// 保存新生成的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);
}
@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);
}
}