济菏高速数据中心代码
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.

139 lines
5.0 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 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;
@ApiOperation("导入数据")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception
{
return dcSdhsEventService.importData(file);
}
@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)){
} else if ("2".equals(trafficIncidentType)){
} else if ("3".equals(trafficIncidentType)){
} else if ("4".equals(trafficIncidentType)){
} else if ("5".equals(trafficIncidentType)){
//事故地市分布
dcSdhsEventService.exportRegionAnalysis(newDoc,dcSdhsEventQuery);
} else if ("6".equals(trafficIncidentType)){
//交通管制情况统计
dcSdhsEventService.exportStationAnalysis(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("查询事故地市分布")
@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);
}
}