Browse Source

高速通行情况快报

develop
lau572 8 months ago
parent
commit
da67d78e98
  1. 25
      zc-business/pom.xml
  2. 1050
      zc-business/src/main/java/com/zc/business/controller/WordController.java
  3. 93
      zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java
  4. 369
      zc-business/src/main/java/com/zc/business/utils/PoiUtil.java
  5. 229
      zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml
  6. BIN
      zc-business/src/main/resources/wordTemplate/chartTemplate.docx
  7. BIN
      zc-business/src/main/resources/wordTemplate/chartTemplate2.docx
  8. BIN
      zc-business/src/main/resources/wordTemplate/wordTemplate.docx

25
zc-business/pom.xml

@ -47,6 +47,31 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!--2.poi官网指出需要poi4.x.x版本抛弃了jdk1.7之前的版本,所以适应此版本需要将jdk升级,如果不想升级还有另一种办法就是,
使用springBoot单独做一个服务为你的主项目提供一个接口,让主项目去调用生成word流让主项目去接收即可。-->
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
<groupId>com.zc</groupId>
<version>1.0.0</version>

1050
zc-business/src/main/java/com/zc/business/controller/WordController.java

File diff suppressed because it is too large

93
zc-business/src/main/java/com/zc/business/mapper/DcTrafficIncidentsMapper.java

@ -236,4 +236,97 @@ public interface DcTrafficIncidentsMapper {
*/
List<Map<String,Object>> selectEventTypeAnalysis(@Param("direction") String direction,@Param("type") String type,@Param("startTime") String startTime);
/**
* @Description 交通管制情况
*
* @author liuwenge
* @date 2024/3/27 18:32
* @param startTime
* @param endTime
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectTrafficControlAnalysis(@Param("startTime") String startTime,@Param("endTime") String endTime);
/**
* @Description 交通事故统计
*
* @author liuwenge
* @date 2024/3/27 20:04
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectTrafficAccidentAnalysis();
/**
* @Description 封闭原因统计
*
* @author liuwenge
* @date 2024/3/28 14:47
* @param controlType
* @param startTime
* @param endTime
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectTrafficControlReasons(@Param("controlType") String controlType,@Param("startTime") String startTime,@Param("endTime") String endTime);
/**
* @Description 封闭数量统计
*
* @author liuwenge
* @date 2024/3/28 14:51
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectClosedQuantity();
/**
* @Description 事故类型统计--当月按类型
*
* @author liuwenge
* @date 2024/3/28 15:19
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectAccidentTypeStatistics();
/**
* @Description 事故类型统计--当天按小时
*
* @author liuwenge
* @date 2024/3/28 16:28
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectTrafficAccidents();
/**
* @Description 拥堵地点
*
* @author liuwenge
* @date 2024/3/28 16:55
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectCongestionLocation();
/**
* @Description 拥堵时长
*
* @author liuwenge
* @date 2024/3/28 17:23
* @param
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectCongestionDuration(@Param("startTime") String startTime,@Param("endTime") String endTime);
/**
* @Description 拥堵长度
*
* @author liuwenge
* @date 2024/3/28 19:30
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
*/
List<Map<String,Object>> selectCongestionMileage();
}

369
zc-business/src/main/java/com/zc/business/utils/PoiUtil.java

@ -0,0 +1,369 @@
package com.zc.business.utils;
import com.aliyuncs.utils.IOUtils;
import com.google.common.base.Strings;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.util.StringUtils;
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author : LCheng
* @date : 2020-12-10 10:03
* description : poi工具
*/
public class PoiUtil {
public static int headingCount1 = 1;
public static int headingCount2 = 1;
/**
* 根据word模板导出 针对图表柱状图折线图饼图等的处理
*
* @param docChart 图表对象
* @param title 图表标题
* @param seriesNames 系列名称数组
* @return {@link XWPFChart}
* @author LCheng
* @date 2020/12/10 11:08
*/
public static XWPFChart wordExportChar(XWPFChart docChart, String title, String[] seriesNames, XSSFSheet sheet) {
//获取图表数据对象
XDDFChartData chartData = docChart.getChartSeries().get(0);
//word图表均对应一个内置的excel,用于保存图表对应的数据
//excel中 第一列第二行开始的数据为分类信息
//CellRangeAddress(1, categories.size(), 0, 0) 四个参数依次为 起始行 截止行 起始列 截止列。
//根据分类信息的范围创建分类信息的数据源
XDDFDataSource catDataSource = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1,sheet.getLastRowNum(),0,0));
//更新数据
for (int i = 0; i < seriesNames.length; i++) {
//excel中各系列对应的数据的范围
//根据数据的范围创建值的数据源
XDDFNumericalDataSource<Double> valDataSource = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1,sheet.getLastRowNum(),i+1,i+1));
//获取图表系列的数据对象
XDDFChartData.Series series = chartData.getSeries().get(i);
//替换系列数据对象中的分类和值
series.replaceData(catDataSource, valDataSource);
//修改系列数据对象中的标题
CellReference cellReference = docChart.setSheetTitle(seriesNames[i], 1);
series.setTitle(seriesNames[i], cellReference);
}
//更新图表数据对象
docChart.plot(chartData);
//图表整体的标题 传空值则不替换标题
if (!Strings.isNullOrEmpty(title)) {
docChart.setTitleText(title);
docChart.setTitleOverlay(false);
}
return docChart;
}
/**
* 合并docx文件
* @param srcDocxs 需要合并的目标docx文件
* @param destDocx 合并后的docx输出文件
*/
public static void mergeDoc(XWPFDocument srcDocxs, XWPFDocument destDocx) {
try {
//获取目标文件的CTDocument1对象
CTDocument1 ctDocument1 = srcDocxs.getDocument();
//获取第一个目标文件的CTBody对象
CTBody src1Body = ctDocument1.getBody();
//获取目标文件中的图表
List<XWPFChart> relations = srcDocxs.getCharts();
//判断是否有图表,没有图表的话,追加到之前的目标文件后面
if (relations.size() <= 0) {
CTBody src2Body = srcDocxs.getDocument().getBody();
//获取目标文件中的图片
List<XWPFPictureData> allPictures = srcDocxs.getAllPictures();
// 记录图片合并前及合并后的ID
Map<String,String> map = new HashMap();
//遍历图片
for (XWPFPictureData picture : allPictures) {
String before = srcDocxs.getRelationId(picture);
//将原文档中的图片加入到目标文档中
String after = destDocx.addPictureData(picture.getData(), Document.PICTURE_TYPE_PNG);
map.put(before, after);
}
//将当前文件的内容追加到之前的目标文件中
appendBody(src1Body, src2Body,map);
}
//遍历图表,
for (XWPFChart chart1 : relations) {
//是否是word中自带图表
if (chart1 instanceof XWPFChart) { // 如果是图表元素
XWPFChart chart = destDocx.createChart(5774310, 3076575);
CTPlotArea plotArea = chart1.getCTChart().getPlotArea();
chart.getCTChart().setPlotArea(plotArea);
chart.getCTChart().setLegend(chart1.getCTChart().getLegend());
}
}
//关闭流
srcDocxs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 合并chart
* @param chart 需要合并的目标chart
* @param destDocx 合并后的docx输出文件
*/
public static void mergeChart(XWPFChart chart, XWPFDocument destDocx) {
try {
XWPFChart docxChart = destDocx.createChart(5774310, 3076575);
CTPlotArea plotArea = chart.getCTChart().getPlotArea();
docxChart.getCTChart().setPlotArea(plotArea);
docxChart.getCTChart().setLegend(chart.getCTChart().getLegend());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 插入换行符
* @param destDocx 合并后的docx输出文件
*/
public static void createLineBreak(XWPFDocument destDocx) {
try {
XWPFParagraph paragraph = destDocx.createParagraph();
XWPFRun run = paragraph.createRun();
run.addBreak();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 合并文档内容
*
* @param src 目标文档
* @param append 要合并的文档
* @throws Exception
*/
private static void appendBody(CTBody src, CTBody append,Map<String,String> map) throws Exception {
XmlOptions optionsOuter = new XmlOptions();
optionsOuter.setSaveOuter();
//获取目标文件的字符内容
String srcString = src.xmlText();
//获取目标文件字符的开头
String prefix = srcString.substring(0, srcString.indexOf(">") + 1);
//获取目标文件字符的内容
String mainPart = srcString.substring(srcString.indexOf(">") + 1,
srcString.lastIndexOf("<"));
//获取目标文件字符的结尾
String sufix = srcString.substring(srcString.lastIndexOf("<"));
//获取需要追加的文件
String appendString = append.xmlText(optionsOuter);
//获取需要追加的文件内容(除去头和尾)
String addPart = appendString.substring(appendString.indexOf(">") + 1,
appendString.lastIndexOf("<"));
if (map != null && !map.isEmpty()) {
//对xml字符串中图片ID进行替换
for (Map.Entry<String, String> set : map.entrySet()) {
addPart = addPart.replace(set.getKey(), set.getValue());
}
}
//将获取到的文件内容合并成为新的CTBody
CTBody makeBody = CTBody.Factory.parse(prefix + mainPart + addPart
+ sufix);
//将新的CTBody重新设置到目标文件中
src.set(makeBody);
}
public static XWPFParagraph createHeading(XWPFDocument doc, String title) {
//段落
XWPFParagraph paragraph = doc.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(title);
// run.setColor("696969");
run.setFontSize(18);
run.setBold(true);//标题加粗
return paragraph;
}
/**
* 创建标题1
*
* @param doc
* @param title
*/
public static void createHeading1(XWPFDocument doc, String title) {
//段落
XWPFParagraph paragraph = doc.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(title);
// run.setColor("696969");
run.setFontSize(16);
run.setBold(true);//标题加粗
paragraph.setStyle("Heading1");
}
/**
* 创建标题2
*
* @param doc
* @param title
*/
public static void createHeading2(XWPFDocument doc, String title) {
XWPFParagraph paragraph = doc.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(title);
run.setFontSize(14);
run.setBold(true);//标题加粗
paragraph.setStyle("Heading2");
}
public static void createTable(XWPFDocument doc) {
XWPFTable table = doc.createTable(3, 3);
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
setTableFonts(table.getRow(0).getCell(0), "编号");
setTableFonts(table.getRow(0).getCell(1), "问题");
setTableFonts(table.getRow(0).getCell(2), "应答");
setTableFonts(table.getRow(1).getCell(0), "1");
setTableFonts(table.getRow(1).getCell(1), "陈述日期");
setTableFonts(table.getRow(1).getCell(2), "2017年02月17日");
setTableFonts(table.getRow(2).getCell(0), "2");
setTableFonts(table.getRow(2).getCell(1), "PICS序列号");
setTableFonts(table.getRow(2).getCell(2), "121313132131");
}
// word跨列合并单元格
public static void mergeCellsHorizontal(XWPFTable table, int row, int fromCell, int toCell) {
for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {
XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
if (cellIndex == fromCell) {
// The first merged cell is set with RESTART merge value
cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
}
}
}
// word跨行并单元格
public static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) {
for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
if (rowIndex == fromRow) {
// The first merged cell is set with RESTART merge value
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
} else {
// Cells which join (merge) the first one, are set with CONTINUE
cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
}
}
}
/**
* 设置表格中字体
*
* @param cell
* @param cellText
*/
public static void setTableFonts(XWPFTableCell cell, String cellText) {
CTP ctp = CTP.Factory.newInstance();
XWPFParagraph p = new XWPFParagraph(ctp, cell);
p.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = p.createRun();
run.setFontSize(8);
run.setText(cellText);
CTRPr rpr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr();
CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
fonts.setAscii("仿宋");
fonts.setEastAsia("仿宋");
fonts.setHAnsi("仿宋");
cell.setParagraph(p);
}
/**
* 添加描述信息
*
* @param doc
* @param description
*/
public static void addDescription(XWPFDocument doc, String description) {
if (StringUtils.isEmpty(description)) {
return;
}
XWPFParagraph title = doc.createParagraph();
XWPFRun run = title.createRun();
run.setText(description);
run.setBold(true);
title.setAlignment(ParagraphAlignment.CENTER);
}
/**
* 创建目录
* 创建并插入带超链接的目录
* @param document
*/
public static void insertTOC2(XWPFDocument document) {
// 定义 TOC 字段属性
CTSimpleField tocField = CTSimpleField.Factory.newInstance();
tocField.setInstr("TOC \\h \\z \\t \"Heading1,Heading2\""); // 包含 Heading1 和 Heading2 样式的目录
// 创建包含 TOC 字段的段落
XWPFParagraph tocPara = document.createParagraph();
tocPara.getCTP().addNewFldSimple().set(tocField);
// 更新文档字段以计算目录
document.enforceUpdateFields();
}
/**
* 创建目录
* 创建并插入带超链接的目录
* @param document
*/
public static void insertTOC(XWPFDocument document) {
// 创建目录所在的段落
XWPFParagraph tocPara = document.createParagraph();
// 添加 TOC 域代码
String tocFieldCode = "TOC \\o \"1-3\" \\h \\z \\u";
CTSimpleField tocField = tocPara.getCTP().addNewFldSimple();
tocField.setInstr(tocFieldCode);
tocField.setDirty(STOnOff.TRUE);
}
}

229
zc-business/src/main/resources/mapper/business/DcTrafficIncidentsMapper.xml

@ -398,4 +398,233 @@
group by event_subclass) t3 on t1.eventSubclass = t3.event_subclass
</select>
<select id="selectTrafficControlAnalysis" resultType="java.util.Map">
select t1.controlCause,t1.controlCauseName,IFNULL(t2.facilityClose,0) facilityClose,
IFNULL(t2.facilityRestriction,0) facilityRestriction,IFNULL(t2.facilityInterval,0) facilityInterval
from
(select '1' controlCause,'车流量大' controlCauseName
union all select '2' controlCause,'交通事故' controlCauseName
union all select '3' controlCause,'恶劣天气' controlCauseName
union all select '4' controlCause,'施工' controlCauseName
union all select '5' controlCause,'警备任务' controlCauseName
union all select '6' controlCause,'其他' controlCauseName
) t1
left join
(select
t2.control_cause,
SUM(case when t2.classify = '6' then 1 else 0 end) facilityClose,
SUM(case when t2.classify = '7' then 1 else 0 end) facilityRestriction,
SUM(case when t2.classify = '9' then 1 else 0 end) facilityInterval
from dc_event t1
LEFT JOIN dc_event_traffic_control t2 on t1.id = t2.id
where
t1.event_type = '3'
and date_format(t1.start_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
and (date_format(t1.end_time,'%Y-%m-%d %H:%i:%s') > date_format(#{startTime},'%Y-%m-%d %H:%i:%s') or ISNULL(t1.end_time))
and t2.classify in ('6','7','9')
GROUP BY t2.control_cause) t2
on t1.controlCause = t2.control_cause
</select>
<select id="selectTrafficAccidentAnalysis" resultType="java.util.Map">
select t1.eventStateLabel,IFNULL(t2.num,0) num
from
(select '0' eventState,'待确认' eventStateLabel
union all select '1' eventState,'处理中' eventStateLabel
union all select '2' eventState,'已完成' eventStateLabel) t1
left join
(select event_state,count(*) num from dc_event
where event_type = '1' and date_format(start_time,'%y%m') = date_format(now(),'%y%m')
group by event_state) t2
on t1.eventState = t2.event_state
</select>
<select id="selectTrafficControlReasons" resultType="java.util.Map">
select t3.control_cause controlCause,t3.cause_type causeType,controlCauseName,causeTypeName,IFNULL(t4.num,0) num
from
(select 1 control_cause,'' cause_type,'车流量大' controlCauseName,'车流量大' causeTypeName
UNION ALL select 2 control_cause,'' cause_type,'交通事故' controlCauseName,'交通事故' causeTypeName
UNION ALL select 3 control_cause,'3-1' cause_type,'恶劣天气' controlCauseName,'雨' causeTypeName
UNION ALL select 3 control_cause,'3-2' cause_type,'恶劣天气' controlCauseName,'雪' causeTypeName
UNION ALL select 3 control_cause,'3-3' cause_type,'恶劣天气' controlCauseName,'雾' causeTypeName
UNION ALL select 3 control_cause,'3-4' cause_type,'恶劣天气' controlCauseName,'道路积水' causeTypeName
UNION ALL select 3 control_cause,'3-5' cause_type,'恶劣天气' controlCauseName,'道路湿滑' causeTypeName
UNION ALL select 3 control_cause,'3-6' cause_type,'恶劣天气' controlCauseName,'道路结冰' causeTypeName
UNION ALL select 3 control_cause,'3-7' cause_type,'恶劣天气' controlCauseName,'沙尘暴' causeTypeName
UNION ALL select 4 control_cause,'' cause_type,'施工' controlCauseName,'施工' causeTypeName
UNION ALL select 5 control_cause,'' cause_type,'警备任务' controlCauseName,'警备任务' causeTypeName
UNION ALL select 6 control_cause,'' cause_type,'其他' controlCauseName,'其他' causeTypeName) t3
LEFT JOIN
(select t2.control_type,t2.control_cause,t2.cause_type,count(*) num
from dc_event t1 LEFT JOIN dc_event_traffic_control t2 on t1.id = t2.id
where
t1.event_type = '3' and t1.event_subclass = '3-2' and t2.control_type = #{controlType}
and date_format(t1.start_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
and (date_format(t1.end_time,'%Y-%m-%d %H:%i:%s') > date_format(#{startTime},'%Y-%m-%d %H:%i:%s') or ISNULL(t1.end_time))
GROUP BY t2.control_cause,t2.cause_type) t4
on t3.control_cause = t4.control_cause and t3.cause_type = t4.cause_type
ORDER BY t3.control_cause, t3.cause_type
</select>
<select id="selectClosedQuantity" resultType="java.util.Map">
SELECT CONCAT(t1.hours,'时') hours, ifnull(t2.num, 0) num
FROM
(SELECT 0 hours
UNION ALL SELECT 1 hours
UNION ALL SELECT 2 hours
UNION ALL SELECT 3 hours
UNION ALL SELECT 4 hours
UNION ALL SELECT 5 hours
UNION ALL SELECT 6 hours
UNION ALL SELECT 7 hours
UNION ALL SELECT 8 hours
UNION ALL SELECT 9 hours
UNION ALL SELECT 10 hours
UNION ALL SELECT 11 hours
UNION ALL SELECT 12 hours
UNION ALL SELECT 13 hours
UNION ALL SELECT 14 hours
UNION ALL SELECT 15 hours
UNION ALL SELECT 16 hours
UNION ALL SELECT 17 hours
UNION ALL SELECT 18 hours
UNION ALL SELECT 19 hours
UNION ALL SELECT 20 hours
UNION ALL SELECT 21 hours
UNION ALL SELECT 22 hours
UNION ALL SELECT 23 hours
) t1
LEFT JOIN
(SELECT
hour(create_time) hours,count(*) num
FROM dc_event
WHERE date_format(create_time, '%Y%m%d') = date_format(now(), '%Y%m%d')
and event_type = '3' and event_subclass = '3-2'
GROUP BY date_format(create_time, '%Y%m%d %H'), hours) t2
ON t1.hours = t2.hours;
</select>
<select id="selectAccidentTypeStatistics" resultType="java.util.Map">
select t1.eventSubclass,t1.eventSubclassName,IFNULL(t2.num,0) num
from
(select '1-1' eventSubclass, '追尾' eventSubclassName
UNION ALL select '1-2' eventSubclass, '侧翻' eventSubclassName
UNION ALL select '1-3' eventSubclass, '撞护栏' eventSubclassName
UNION ALL select '1-4' eventSubclass, '自燃' eventSubclassName
UNION ALL select '1-5' eventSubclass, '其他事故' eventSubclassName) t1
LEFT JOIN
(select event_subclass, count(*) num
from dc_event
where event_type = '1'
and DATE_FORMAT(start_time,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
group by event_subclass) t2
on t1.eventSubclass = t2.event_subclass
</select>
<select id="selectTrafficAccidents" resultType="java.util.Map">
SELECT CONCAT(t1.hours,'时') hours, ifnull(t2.num, 0) num
FROM
(SELECT 0 hours
UNION ALL SELECT 1 hours
UNION ALL SELECT 2 hours
UNION ALL SELECT 3 hours
UNION ALL SELECT 4 hours
UNION ALL SELECT 5 hours
UNION ALL SELECT 6 hours
UNION ALL SELECT 7 hours
UNION ALL SELECT 8 hours
UNION ALL SELECT 9 hours
UNION ALL SELECT 10 hours
UNION ALL SELECT 11 hours
UNION ALL SELECT 12 hours
UNION ALL SELECT 13 hours
UNION ALL SELECT 14 hours
UNION ALL SELECT 15 hours
UNION ALL SELECT 16 hours
UNION ALL SELECT 17 hours
UNION ALL SELECT 18 hours
UNION ALL SELECT 19 hours
UNION ALL SELECT 20 hours
UNION ALL SELECT 21 hours
UNION ALL SELECT 22 hours
UNION ALL SELECT 23 hours
) t1
LEFT JOIN
(SELECT
hour(create_time) hours,count(*) num
FROM dc_event
WHERE date_format(create_time, '%Y%m%d') = date_format(now(), '%Y%m%d')
and event_type = '1'
GROUP BY date_format(create_time, '%Y%m%d %H'), hours) t2
ON t1.hours = t2.hours;
</select>
<select id="selectCongestionLocation" resultType="java.util.Map">
select t1.eventSubclass,t1.eventSubclassLabel,IFNULL(t2.num,0) num
from
(select '4-1' eventSubclass,'道路拥堵' eventSubclassLabel
union all select '4-2' eventSubclass,'立交拥堵' eventSubclassLabel
union all select '4-3' eventSubclass,'收费站拥堵' eventSubclassLabel
union all select '4-4' eventSubclass,'服务区拥堵' eventSubclassLabel) t1
left join
(select event_type,event_subclass,count(*) num
from dc_event
where event_type = '4' and DATE_FORMAT(occurrence_time,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
GROUP BY event_subclass
) t2
on t1.eventSubclass = t2.event_subclass
</select>
<select id="selectCongestionDuration" resultType="java.util.Map">
select
IFNULL(
sum(
case when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') >= date_format(start_time,'%Y-%m-%d %H:%i:%s')
and (DATE_FORMAT(end_time,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s') or ISNULL(end_time))
then TIMESTAMPDIFF(MINUTE,start_time,now())
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') >= date_format(start_time,'%Y-%m-%d %H:%i:%s')
and DATE_FORMAT(end_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
then TIMESTAMPDIFF(MINUTE,#{startTime},end_time)
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') &lt;= date_format(start_time,'%Y-%m-%d %H:%i:%s')
and (DATE_FORMAT(end_time,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s') or ISNULL(end_time))
then TIMESTAMPDIFF(MINUTE,start_time,#{endTime})
when date_format(#{startTime},'%Y-%m-%d %H:%i:%s') &lt;= date_format(start_time,'%Y-%m-%d %H:%i:%s')
and DATE_FORMAT(end_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
then TIMESTAMPDIFF(MINUTE,start_time,end_time)
else 0 end
)
,0) minuteTime
from dc_event
where
event_type = '4' and date_format(start_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
and (date_format(end_time,'%Y-%m-%d %H:%i:%s') > date_format(#{startTime},'%Y-%m-%d %H:%i:%s') or ISNULL(end_time))
</select>
<select id="selectCongestionMileage" resultType="java.util.Map">
select t3.mileageType,IFNULL(t4.num,0) num
from
(select '0-2公里' mileageType
union all select '2-5公里' mileageType
union all select '5-8公里' mileageType
union all select '8-10公里' mileageType
union all select '10公里以上' mileageType) t3
left join
(select
case when t2.congestion_mileage &lt; 2 then '0-2公里'
when t2.congestion_mileage >= 2 and t2.congestion_mileage &lt; 5 then '2-5公里'
when t2.congestion_mileage >= 5 and t2.congestion_mileage &lt; 8 then '5-8公里'
when t2.congestion_mileage >= 8 and t2.congestion_mileage &lt; 10 then '8-10公里'
when t2.congestion_mileage >= 10 then '10公里以上'
else '' end mileageType,count(*) num
from dc_event t1
left join dc_event_traffic_congestion t2 on t1.id = t2.id
WHERE t1.event_type = '4' and DATE_FORMAT(t1.create_time,'%Y%m') = DATE_FORMAT(now(),'%Y%m')
GROUP BY mileageType
) t4
on t3.mileageType = t4.mileageType
</select>
</mapper>

BIN
zc-business/src/main/resources/wordTemplate/chartTemplate.docx

Binary file not shown.

BIN
zc-business/src/main/resources/wordTemplate/chartTemplate2.docx

Binary file not shown.

BIN
zc-business/src/main/resources/wordTemplate/wordTemplate.docx

Binary file not shown.
Loading…
Cancel
Save