Browse Source

高速云事件导出

develop
lau572 3 months ago
parent
commit
10e9ea4053
  1. 99
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java
  2. 2
      zc-business/src/main/resources/mapper/business/DcSdhsEventMapper.xml
  3. BIN
      zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx

99
zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

@ -1292,9 +1292,10 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){
return AjaxResult.error("参数错误");
}
List<Map<String,Object>> thisTimeData = dcSdhsEventMapper.selectRegionAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime());
return AjaxResult.success(thisTimeData);
}
@ -1368,11 +1369,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber());
//系列信息
String[] singleBarSeriesNames = {"数量"};
String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()};
//分类信息
for (int i = 0; i < data.size(); i++) {
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(data.get(i).get("regionName").toString());
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(data.get(i).get("num").toString()));
sheet.getRow(i + 1).getCell(0).setCellValue(data.get(i).get("city").toString());
sheet.getRow(i + 1).getCell(1).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()).toString()));
sheet.getRow(i + 1).getCell(2).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()).toString()));
}
for (int i = sheet.getLastRowNum(); i > data.size(); i--) {
sheet.removeRow(sheet.getRow(i));
@ -1397,17 +1400,19 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//插入表格
XWPFTable table = doc.createTable(data.size() + 1, 2);
XWPFTable table = doc.createTable(data.size() + 1, 3);
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
setTableFonts(table.getRow(0).getCell(0), "地市");
setTableFonts(table.getRow(0).getCell(1), "数量");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime());
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getLastTime());
for (int i = 0; i < data.size(); i++) {
setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("regionName").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get("num").toString());
setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("city").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get(dcSdhsEventQuery.getThisTime()).toString());
setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get(dcSdhsEventQuery.getLastTime()).toString());
}
} else {
addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue());
@ -1430,6 +1435,10 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){
return AjaxResult.error("参数错误");
}
//本期数据
List<DcSdhsEvent> thisTimeList = dcSdhsEventMapper.selectStationAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime());
Set<String> stationSet = new HashSet<>();
@ -1476,29 +1485,29 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
List<Map<String, Object>> list = new ArrayList<>();
for (String stationName : stationSet) {
Map<String, Object> map = new HashMap<>();
map.put("站点名称", stationName);
map.put("stationName", stationName);
if (thisTimeCloseStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getThisTime() + "封闭", thisTimeCloseStation.get(stationName));
map.put(dcSdhsEventQuery.getThisTime() + "close", thisTimeCloseStation.get(stationName));
} else {
map.put(dcSdhsEventQuery.getThisTime() + "封闭", 0);
map.put(dcSdhsEventQuery.getThisTime() + "close", 0);
}
if (thisTimeRestrictionStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getThisTime() + "限行", thisTimeRestrictionStation.get(stationName));
map.put(dcSdhsEventQuery.getThisTime() + "restriction", thisTimeRestrictionStation.get(stationName));
} else {
map.put(dcSdhsEventQuery.getThisTime() + "限行", 0);
map.put(dcSdhsEventQuery.getThisTime() + "restriction", 0);
}
if (lastTimeCloseStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getLastTime() + "封闭", lastTimeCloseStation.get(stationName));
map.put(dcSdhsEventQuery.getLastTime() + "close", lastTimeCloseStation.get(stationName));
} else {
map.put(dcSdhsEventQuery.getLastTime() + "封闭", 0);
map.put(dcSdhsEventQuery.getLastTime() + "close", 0);
}
if (lastTimeRestrictionStation.containsKey(stationName)) {
map.put(dcSdhsEventQuery.getLastTime() + "限行", lastTimeRestrictionStation.get(stationName));
map.put(dcSdhsEventQuery.getLastTime() + "restriction", lastTimeRestrictionStation.get(stationName));
} else {
map.put(dcSdhsEventQuery.getLastTime() + "限行", 0);
map.put(dcSdhsEventQuery.getLastTime() + "restriction", 0);
}
list.add(map);
@ -1553,23 +1562,30 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
try {
// 复制Word模板
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.DRAWING_TEMPLATE.getValue());
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/sdhsEventChart.docx");
XWPFDocument copiedTemplate = new XWPFDocument(inputStream);
//获取word中所有图表对象
List<XWPFChart> charts = copiedTemplate.getCharts();
XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber());
XWPFChart chart = charts.get(2);
XSSFWorkbook workbook = chart.getWorkbook();
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber());
//系列信息
String[] singleBarSeriesNames = {UniversalEnum.CLOSE.getValue(), UniversalEnum.TRAFFIC_RESTRICTION.getValue()};
String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime()+"封闭", dcSdhsEventQuery.getThisTime()+"限行",dcSdhsEventQuery.getLastTime()+"封闭", dcSdhsEventQuery.getLastTime()+"限行"};
sheet.getRow(0).getCell(1).setCellValue(dcSdhsEventQuery.getThisTime()+"封闭");
sheet.getRow(0).getCell(2).setCellValue(dcSdhsEventQuery.getThisTime()+"限行");
sheet.getRow(0).getCell(3).setCellValue(dcSdhsEventQuery.getLastTime()+"封闭");
sheet.getRow(0).getCell(4).setCellValue(dcSdhsEventQuery.getLastTime()+"限行");
//分类信息
for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) {
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(data.get(i).get("stationName").toString());
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(data.get(i).get("close").toString()));
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.TWO.getNumber()).setCellValue(Long.parseLong(data.get(i).get("restriction").toString()));
sheet.getRow(i + 1).getCell(0).setCellValue(data.get(i).get("stationName").toString());
sheet.getRow(i + 1).getCell(1).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()+"close").toString()));
sheet.getRow(i + 1).getCell(2).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()+"restriction").toString()));
sheet.getRow(i + 1).getCell(3).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()+"close").toString()));
sheet.getRow(i + 1).getCell(4).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()+"restriction").toString()));
}
for (int i = sheet.getLastRowNum(); i > data.size(); i--) {
@ -1595,20 +1611,24 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//插入表格
XWPFTable table = doc.createTable(data.size() + 1, 3);
XWPFTable table = doc.createTable(data.size() + 1, 5);
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
setTableFonts(table.getRow(0).getCell(1), "封闭");
setTableFonts(table.getRow(0).getCell(2), "限行");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime()+"封闭");
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getThisTime()+"限行");
setTableFonts(table.getRow(0).getCell(3), dcSdhsEventQuery.getLastTime()+"封闭");
setTableFonts(table.getRow(0).getCell(4), dcSdhsEventQuery.getLastTime()+"限行");
//excel
for (int i = 0; i < data.size(); i++) {
setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("stationName").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get("close").toString());
setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get("restriction").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get(dcSdhsEventQuery.getThisTime()+"close").toString());
setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get(dcSdhsEventQuery.getThisTime()+"restriction").toString());
setTableFonts(table.getRow(i + 1).getCell(3), data.get(i).get(dcSdhsEventQuery.getLastTime()+"close").toString());
setTableFonts(table.getRow(i + 1).getCell(4), data.get(i).get(dcSdhsEventQuery.getLastTime()+"restriction").toString());
}
} else {
addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue());
@ -1630,6 +1650,10 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery) {
if (StringUtils.isEmpty(dcSdhsEventQuery.getType()) || StringUtils.isEmpty(dcSdhsEventQuery.getThisTime()) || StringUtils.isEmpty(dcSdhsEventQuery.getLastTime())){
return AjaxResult.error("参数错误");
}
List<Map<String,Object>> list = dcSdhsEventMapper.selectAccidentType(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime());
return AjaxResult.success(list);
@ -1665,11 +1689,12 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber());
//系列信息
String[] singleBarSeriesNames = {"数量"};
String[] singleBarSeriesNames = {dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime()};
//分类信息
for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) {
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(data.get(i).get("subclassName").toString());
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(data.get(i).get("num").toString()));
sheet.getRow(i + 1).getCell(0).setCellValue(data.get(i).get("eventSubclass").toString());
sheet.getRow(i + 1).getCell(1).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getThisTime()).toString()));
sheet.getRow(i + 1).getCell(2).setCellValue(Long.parseLong(data.get(i).get(dcSdhsEventQuery.getLastTime()).toString()));
}
for (int i = sheet.getLastRowNum(); i > data.size(); i--) {
@ -1695,19 +1720,21 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//插入表格
XWPFTable table = doc.createTable(data.size() + 1, 2);
XWPFTable table = doc.createTable(data.size() + 1, 3);
//列宽自动分割
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber()));
setTableFonts(table.getRow(0).getCell(0), "事故类型");
setTableFonts(table.getRow(0).getCell(1), "数量");
setTableFonts(table.getRow(0).getCell(1), dcSdhsEventQuery.getThisTime());
setTableFonts(table.getRow(0).getCell(2), dcSdhsEventQuery.getLastTime());
//excel
for (int i = 0; i < data.size(); i++) {
setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("subclassName").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get("num").toString());
setTableFonts(table.getRow(i + 1).getCell(0), data.get(i).get("eventSubclass").toString());
setTableFonts(table.getRow(i + 1).getCell(1), data.get(i).get(dcSdhsEventQuery.getThisTime()).toString());
setTableFonts(table.getRow(i + 1).getCell(2), data.get(i).get(dcSdhsEventQuery.getLastTime()).toString());
}
} else {
addDescription(doc, UniversalEnum.NO_DATA_AVAILABLE.getValue());

2
zc-business/src/main/resources/mapper/business/DcSdhsEventMapper.xml

@ -126,7 +126,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAccidentType" resultType="java.util.Map">
SELECT t1.event_subclass,IFNULL(t2.num,0) as #{thisTime},IFNULL(t3.num,0) as #{lastTime}
SELECT t1.event_subclass eventSubclass,IFNULL(t2.num,0) as #{thisTime},IFNULL(t3.num,0) as #{lastTime}
from
(select '追尾' event_subclass
union all select '撞护栏' event_subclass

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

Binary file not shown.
Loading…
Cancel
Save