|
|
@ -20,6 +20,17 @@ import com.zc.business.utils.PoiUtil; |
|
|
|
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 com.zc.business.utils.PoiUtil; |
|
|
|
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.XSSFCell; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
@ -34,6 +45,16 @@ import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
@ -48,6 +69,9 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.zc.business.utils.PoiUtil.*; |
|
|
|
|
|
|
|
import static com.zc.business.utils.PoiUtil.mergeChart; |
|
|
|
import static com.zc.business.utils.PoiUtil.setTableFonts; |
|
|
|
|
|
|
|
/** |
|
|
|
* 高速云事件分析Service业务层处理 |
|
|
|
* |
|
|
@ -160,6 +184,440 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
|
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE, now.getTime(), fileInfo); |
|
|
|
return AjaxResult.success("导入成功"); |
|
|
|
} |
|
|
|
//事故多发路段分析
|
|
|
|
@Override |
|
|
|
public Map<String, Integer> accidentSectionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); |
|
|
|
Map<String, Integer> groupCountMap = new HashMap<>(); |
|
|
|
try { |
|
|
|
long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); |
|
|
|
long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); |
|
|
|
// String direction = dcSdhsEventQuery.getDirection();//方向
|
|
|
|
for (DcSdhsEvent event : cacheList) { |
|
|
|
if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
int km = Integer.parseInt(kmStr.split("\\+")[0]); // 假设+后面还有其他内容,我们只取+前面的部分
|
|
|
|
|
|
|
|
// 计算分组startKm,确保是5的倍数且不大于km
|
|
|
|
int startKm = ((km / 10) * 10) + (km % 10 >= 5 ? 10 : 0); |
|
|
|
startKm = startKm - startKm % 5; // 确保startKm是5的倍数
|
|
|
|
if (startKm%5==0){ |
|
|
|
if ((startKm / 5) % 2 == 0) { |
|
|
|
startKm -= 5; |
|
|
|
} |
|
|
|
} |
|
|
|
// 计算分组endKm,找到比startKm大、最接近的、以5结尾的数
|
|
|
|
int endKm = startKm + 10; |
|
|
|
while (endKm % 5 != 0) { |
|
|
|
endKm++; |
|
|
|
} |
|
|
|
// 构造分组key
|
|
|
|
String groupKey = "K" + startKm + "-" + "K" + endKm; |
|
|
|
//groupCountMap.put(groupKey, groupCountMap.getOrDefault(groupKey, 0) + 1);
|
|
|
|
if (groupCountMap.get(groupKey)==null){ //事件还为存入map
|
|
|
|
groupCountMap.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1
|
|
|
|
}else { |
|
|
|
Integer currentSum = groupCountMap.get(groupKey); |
|
|
|
groupCountMap.put(groupKey, currentSum +1 ); |
|
|
|
} |
|
|
|
} |
|
|
|
List<Map.Entry<String, Integer>> entries = new ArrayList<>(groupCountMap.entrySet()); |
|
|
|
entries.sort(Comparator.comparingInt(e -> { |
|
|
|
String[] parts = e.getKey().split("-"); |
|
|
|
int start = Integer.parseInt(parts[0].substring(1)); // 去掉'K'并解析为整数
|
|
|
|
int end = Integer.parseInt(parts[1].substring(1)); // 去掉'K'并解析为整数
|
|
|
|
return start + end; // 返回两个数字之和
|
|
|
|
})); |
|
|
|
// 将排序后的 List 转换回 LinkedHashMap 以保持顺序
|
|
|
|
LinkedHashMap<String, Integer> sortedMap = new LinkedHashMap<>(); |
|
|
|
for (Map.Entry<String, Integer> entry : entries) { |
|
|
|
sortedMap.put(entry.getKey(), entry.getValue()); |
|
|
|
} |
|
|
|
return sortedMap; |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return groupCountMap; |
|
|
|
} |
|
|
|
//事故类型分析
|
|
|
|
@Override |
|
|
|
public Map<String, Integer> accidentTypeAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); |
|
|
|
Map<String, Integer> groupCountMap = new HashMap<>(); |
|
|
|
try { |
|
|
|
long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); |
|
|
|
long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); |
|
|
|
// String direction = dcSdhsEventQuery.getDirection();//方向
|
|
|
|
for (DcSdhsEvent event : cacheList) { |
|
|
|
if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String eventType = event.getEventType();//事件类型
|
|
|
|
if (groupCountMap.get(eventType)==null){ //事件还为存入map
|
|
|
|
groupCountMap.putIfAbsent(eventType, UniversalEnum.ONE.getNumber());//事件类型不存在存1
|
|
|
|
}else { |
|
|
|
Integer currentSum = groupCountMap.get(eventType); |
|
|
|
groupCountMap.put(eventType, currentSum +1 ); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return groupCountMap; |
|
|
|
} |
|
|
|
|
|
|
|
//事故拥堵地点
|
|
|
|
@Override |
|
|
|
public Map<String, Integer> accidentCongestedLocation(DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); |
|
|
|
Map<String, Integer> groupCountMap = new HashMap<>(); |
|
|
|
try { |
|
|
|
long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); |
|
|
|
long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); |
|
|
|
for (DcSdhsEvent event : cacheList) { |
|
|
|
if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String eventType = event.getEventType();//事件类型
|
|
|
|
if (!"交通拥堵".equals(eventType)){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String eventSubclass = event.getEventSubclass();//事件子类型
|
|
|
|
if (groupCountMap.get(eventSubclass)==null){ //事件还为存入map
|
|
|
|
groupCountMap.putIfAbsent(eventSubclass, UniversalEnum.ONE.getNumber());//事件类型不存在存1
|
|
|
|
}else { |
|
|
|
Integer currentSum = Integer.valueOf(groupCountMap.get(eventSubclass).toString()); |
|
|
|
groupCountMap.put(eventSubclass, currentSum +1 ); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return groupCountMap; |
|
|
|
} |
|
|
|
//事故拥堵时间
|
|
|
|
@Override |
|
|
|
public Map<String, String> accidentCongestedTime(DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
List<DcSdhsEvent> cacheList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); |
|
|
|
Map<String, Integer> averageMap = new HashMap<>(); |
|
|
|
Map<String, Integer> map = new HashMap<>(); |
|
|
|
Map<String, String> groupCountMap = new HashMap<>(); |
|
|
|
try { |
|
|
|
long startTimeMillis = dcSdhsEventQuery.getStartTime().getTime(); |
|
|
|
long endTimeMillis = dcSdhsEventQuery.getEndTime().getTime(); |
|
|
|
for (DcSdhsEvent event : cacheList) { |
|
|
|
if (event.getStartTime() == null || event.getEndTime() == null || event.getStakeMark() == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!(event.getStartTime().getTime() >= startTimeMillis && event.getEndTime().getTime() <= endTimeMillis)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String eventType = event.getEventType();//事件类型
|
|
|
|
if (!"交通拥堵".equals(eventType)){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
String kmStr = event.getStakeMark().substring(1); // 假设总是以"K"开头
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(kmStr)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
int km = Integer.parseInt(kmStr.split("\\+")[0]); // 假设+后面还有其他内容,我们只取+前面的部分
|
|
|
|
// 计算分组startKm,确保是5的倍数且不大于km
|
|
|
|
int startKm = ((km / 10) * 10) + (km % 10 >= 5 ? 10 : 0); |
|
|
|
startKm = startKm - startKm % 5; // 确保startKm是5的倍数
|
|
|
|
if (startKm%5==0){ |
|
|
|
if ((startKm / 5) % 2 == 0) { |
|
|
|
startKm -= 5; |
|
|
|
} |
|
|
|
} |
|
|
|
// 计算分组endKm,找到比startKm大、最接近的、以5结尾的数
|
|
|
|
int endKm = startKm + 10; |
|
|
|
while (endKm % 5 != 0) { |
|
|
|
endKm++; |
|
|
|
} |
|
|
|
// 构造分组key
|
|
|
|
String groupKey = "K" + startKm + "-" + "K" + endKm; |
|
|
|
long differenceInMilliseconds = event.getEndTime().getTime() - event.getStartTime().getTime(); |
|
|
|
long differenceInMinutes = differenceInMilliseconds / 60000;//时间分钟
|
|
|
|
Integer differenceInMinute = (int)differenceInMinutes; |
|
|
|
|
|
|
|
if (averageMap.get(groupKey)==null){ //事件还为存入map
|
|
|
|
averageMap.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1
|
|
|
|
}else { |
|
|
|
Integer currentSum = averageMap.get(groupKey); |
|
|
|
averageMap.put(groupKey, currentSum +differenceInMinute ); |
|
|
|
} |
|
|
|
if (map.get(groupKey)==null){ //事件还为存入map
|
|
|
|
map.putIfAbsent(groupKey, UniversalEnum.ONE.getNumber());//事件类型不存在存1
|
|
|
|
}else { |
|
|
|
Integer currentSum = map.get(groupKey); |
|
|
|
map.put(groupKey, currentSum +1 ); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
for (String key:averageMap.keySet()){ |
|
|
|
if (map.containsKey(key)){ |
|
|
|
double average = (double) averageMap.get(key) / map.get(key); |
|
|
|
DecimalFormat df = new DecimalFormat("#.00"); |
|
|
|
String formattedAverage = df.format(average); |
|
|
|
groupCountMap.put(key, formattedAverage); |
|
|
|
}else { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
List<Map.Entry<String, String>> entries = new ArrayList<>(groupCountMap.entrySet()); |
|
|
|
entries.sort(Comparator.comparingInt(e -> { |
|
|
|
String[] parts = e.getKey().split("-"); |
|
|
|
int start = Integer.parseInt(parts[0].substring(1)); // 去掉'K'并解析为整数
|
|
|
|
int end = Integer.parseInt(parts[1].substring(1)); // 去掉'K'并解析为整数
|
|
|
|
return start + end; // 返回两个数字之和
|
|
|
|
})); |
|
|
|
// 将排序后的 List 转换回 LinkedHashMap 以保持顺序
|
|
|
|
LinkedHashMap<String, String> sortedMap = new LinkedHashMap<>(); |
|
|
|
for (Map.Entry<String, String> entry : entries) { |
|
|
|
sortedMap.put(entry.getKey(), entry.getValue()); |
|
|
|
} |
|
|
|
return sortedMap; |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
//事故多发路段分析导出
|
|
|
|
@Override |
|
|
|
public void sectionAnalysisExport(XWPFDocument doc,DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
|
|
|
|
Map<String, Integer> map =accidentSectionAnalysis(dcSdhsEventQuery); |
|
|
|
// String direction = dcSdhsEventQuery.getDirection();//方向
|
|
|
|
String title="事故路段分布图"; |
|
|
|
// if ("广州方向".equals(direction)){
|
|
|
|
// title="事故路段分布图-广州方向";
|
|
|
|
// }else {
|
|
|
|
// title="事故路段分布图-济南方向";
|
|
|
|
// }
|
|
|
|
PoiUtil.createHeading2(doc, title); |
|
|
|
XWPFTable table = doc.createTable(map.size()+1,2); |
|
|
|
//列宽自动分割
|
|
|
|
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); |
|
|
|
infoTableWidth.setType(STTblWidth.DXA); |
|
|
|
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); |
|
|
|
//插入表头
|
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "路段"); |
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "事故发生数量"); |
|
|
|
|
|
|
|
List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet()); |
|
|
|
//excel
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); |
|
|
|
setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); |
|
|
|
} |
|
|
|
try{ |
|
|
|
// 复制Word模板
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CHAR_SECTION.getValue()); |
|
|
|
XWPFDocument copiedTemplate = new XWPFDocument(inputStream); |
|
|
|
//获取word中所有图表对象
|
|
|
|
List<XWPFChart> charts = copiedTemplate.getCharts(); |
|
|
|
XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
XSSFWorkbook workbook = chart.getWorkbook(); |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); |
|
|
|
//系列信息
|
|
|
|
String[] singleBarSeriesNames = {"数量"}; |
|
|
|
//分类信息
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(entries.get(i).getKey()); |
|
|
|
sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString())); |
|
|
|
} |
|
|
|
for (int i = sheet.getLastRowNum(); i > entries.size();i--){ |
|
|
|
sheet.removeRow(sheet.getRow(i)); |
|
|
|
} |
|
|
|
PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); |
|
|
|
// 追加到同一个Word文档中
|
|
|
|
mergeChart(chart,doc); |
|
|
|
// 关闭复制的模板文档
|
|
|
|
copiedTemplate.close(); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//事故类型分析导出
|
|
|
|
@Override |
|
|
|
public void accidentTypeAnalysisExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
Map<String, Integer> map =accidentTypeAnalysis(dcSdhsEventQuery); |
|
|
|
// String direction = dcSdhsEventQuery.getDirection();//方向
|
|
|
|
String title="事件类型分布图"; |
|
|
|
// if ("广州方向".equals(direction)){
|
|
|
|
// title="事件类型分布图-广州方向";
|
|
|
|
// }else {
|
|
|
|
// title="事件类型分布图-济南方向";
|
|
|
|
// }
|
|
|
|
PoiUtil.createHeading2(doc, title); |
|
|
|
XWPFTable table = doc.createTable(map.size()+1,2); |
|
|
|
//列宽自动分割
|
|
|
|
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); |
|
|
|
infoTableWidth.setType(STTblWidth.DXA); |
|
|
|
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); |
|
|
|
//插入表头
|
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "类型"); |
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "数量"); |
|
|
|
|
|
|
|
List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet()); |
|
|
|
//excel
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); |
|
|
|
setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); |
|
|
|
} |
|
|
|
try{ |
|
|
|
// 复制Word模板
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.TYPE_ANALYSIS.getValue()); |
|
|
|
XWPFDocument copiedTemplate = new XWPFDocument(inputStream); |
|
|
|
|
|
|
|
//获取word中所有图表对象
|
|
|
|
List<XWPFChart> charts = copiedTemplate.getCharts(); |
|
|
|
XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
XSSFWorkbook workbook = chart.getWorkbook(); |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); |
|
|
|
//系列信息
|
|
|
|
String[] singleBarSeriesNames = {"事件类型"}; |
|
|
|
//分类信息
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ZERO.getNumber()).setCellValue(entries.get(i).getKey()); |
|
|
|
sheet.getRow(i+UniversalEnum.ONE.getNumber()).getCell(UniversalEnum.ONE.getNumber()).setCellValue(Long.parseLong(entries.get(i).getValue().toString())); |
|
|
|
} |
|
|
|
for (int i = sheet.getLastRowNum(); i > entries.size();i--){ |
|
|
|
sheet.removeRow(sheet.getRow(i)); |
|
|
|
} |
|
|
|
PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); |
|
|
|
// 追加到同一个Word文档中
|
|
|
|
mergeChart(chart,doc); |
|
|
|
// 关闭复制的模板文档
|
|
|
|
copiedTemplate.close(); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//事故拥堵时间导出
|
|
|
|
@Override |
|
|
|
public void accidentCongestedTimeExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
Map<String, String> map =accidentCongestedTime(dcSdhsEventQuery); |
|
|
|
String title="事故拥堵时长分布图"; |
|
|
|
PoiUtil.createHeading2(doc, title); |
|
|
|
XWPFTable table = doc.createTable(map.size()+1,2); |
|
|
|
//列宽自动分割
|
|
|
|
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); |
|
|
|
infoTableWidth.setType(STTblWidth.DXA); |
|
|
|
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); |
|
|
|
//插入表头
|
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "路段"); |
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "时长(分钟)"); |
|
|
|
|
|
|
|
List<Map.Entry<String, String>> entries = new ArrayList<>(map.entrySet()); |
|
|
|
//excel
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); |
|
|
|
setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); |
|
|
|
} |
|
|
|
try{ |
|
|
|
// 复制Word模板
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CONGESTION_TIME.getValue()); |
|
|
|
XWPFDocument copiedTemplate = new XWPFDocument(inputStream); |
|
|
|
|
|
|
|
//获取word中所有图表对象
|
|
|
|
List<XWPFChart> charts = copiedTemplate.getCharts(); |
|
|
|
XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
XSSFWorkbook workbook = chart.getWorkbook(); |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); |
|
|
|
//系列信息
|
|
|
|
String[] singleBarSeriesNames = {"事故拥堵时长"}; |
|
|
|
//分类信息
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(0).setCellValue(entries.get(i).getKey()); |
|
|
|
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(1).setCellValue(Double.valueOf(entries.get(i).getValue())); |
|
|
|
} |
|
|
|
for (int i = sheet.getLastRowNum(); i > entries.size();i--){ |
|
|
|
sheet.removeRow(sheet.getRow(i)); |
|
|
|
} |
|
|
|
PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); |
|
|
|
// 追加到同一个Word文档中
|
|
|
|
mergeChart(chart,doc); |
|
|
|
// 关闭复制的模板文档
|
|
|
|
copiedTemplate.close(); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//事故拥堵地点导出
|
|
|
|
@Override |
|
|
|
public void accidentCongestedLocationExport(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery) { |
|
|
|
Map<String, Integer> map =accidentCongestedLocation(dcSdhsEventQuery); |
|
|
|
String title="事故拥堵地点分布图"; |
|
|
|
PoiUtil.createHeading2(doc, title); |
|
|
|
XWPFTable table = doc.createTable(map.size()+1,2); |
|
|
|
//列宽自动分割
|
|
|
|
CTTblWidth infoTableWidth = table.getCTTbl().addNewTblPr().addNewTblW(); |
|
|
|
infoTableWidth.setType(STTblWidth.DXA); |
|
|
|
infoTableWidth.setW(BigInteger.valueOf(UniversalEnum.NINE_THOUSAND_AND_SEVENTY_TWO.getNumber())); |
|
|
|
//插入表头
|
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ZERO.getNumber()), "地点"); |
|
|
|
setTableFonts(table.getRow(UniversalEnum.ZERO.getNumber()).getCell(UniversalEnum.ONE.getNumber()), "数量"); |
|
|
|
|
|
|
|
List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet()); |
|
|
|
//excel
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
setTableFonts(table.getRow(i+1).getCell(0), entries.get(i).getKey()); |
|
|
|
setTableFonts(table.getRow(i+1).getCell(1), entries.get(i).getValue().toString()); |
|
|
|
} |
|
|
|
try{ |
|
|
|
// 复制Word模板
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(UniversalEnum.CONGESTED_LOCATION.getValue()); |
|
|
|
XWPFDocument copiedTemplate = new XWPFDocument(inputStream); |
|
|
|
|
|
|
|
//获取word中所有图表对象
|
|
|
|
List<XWPFChart> charts = copiedTemplate.getCharts(); |
|
|
|
XWPFChart chart = charts.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
XSSFWorkbook workbook = chart.getWorkbook(); |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); |
|
|
|
//系列信息
|
|
|
|
String[] singleBarSeriesNames = {"事故拥堵地点"}; |
|
|
|
//分类信息
|
|
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < entries.size(); i++){ |
|
|
|
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(0).setCellValue(entries.get(i).getKey()); |
|
|
|
sheet.getRow(i + UniversalEnum.ONE.getNumber()).getCell(1).setCellValue(entries.get(i).getValue()); |
|
|
|
} |
|
|
|
for (int i = sheet.getLastRowNum(); i > entries.size();i--){ |
|
|
|
sheet.removeRow(sheet.getRow(i)); |
|
|
|
} |
|
|
|
PoiUtil.wordExportChar(chart, title, singleBarSeriesNames,sheet ); |
|
|
|
// 追加到同一个Word文档中
|
|
|
|
mergeChart(chart,doc); |
|
|
|
// 关闭复制的模板文档
|
|
|
|
copiedTemplate.close(); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*public AjaxResult importData(MultipartFile file) throws IOException { |
|
|
|
List<DcSdhsEvent> importData = new ArrayList<>(); |
|
|
|