|
@ -134,11 +134,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
Map<String,Object> fileInfo = new HashMap<>(); |
|
|
Map<String,Object> fileInfo = new HashMap<>(); |
|
|
fileInfo.put("fileName",fileName); |
|
|
fileInfo.put("fileName",fileName); |
|
|
fileInfo.put("fileUrl",fileUrl); |
|
|
fileInfo.put("fileUrl",fileUrl); |
|
|
|
|
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
String updateTime = simpleDateFormat.format(new Date()); |
|
|
String updateTime = simpleDateFormat.format(now); |
|
|
fileInfo.put("uploadTime",updateTime); |
|
|
fileInfo.put("uploadTime",updateTime); |
|
|
|
|
|
|
|
|
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,updateTime,fileInfo); |
|
|
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,now.getTime(),fileInfo); |
|
|
return AjaxResult.success("导入成功"); |
|
|
return AjaxResult.success("导入成功"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -242,6 +244,26 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
return numbers; |
|
|
return numbers; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public AjaxResult getFileInfo(){ |
|
|
|
|
|
Map<String,Map<String,Object>> allFileInfo = redisCache.getCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE); |
|
|
|
|
|
Map<String, Object> lastFile = new HashMap<>(); |
|
|
|
|
|
if (allFileInfo != null && allFileInfo.size() > 0){ |
|
|
|
|
|
String maxKeyNumerically = Collections.max(allFileInfo.keySet(), new Comparator<String>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public int compare(String o1, String o2) { |
|
|
|
|
|
try { |
|
|
|
|
|
return Long.compare(Long.parseLong(o1), Long.parseLong(o2)); |
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
throw new IllegalArgumentException("Keys cannot be parsed as numbers", e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
lastFile = allFileInfo.get(maxKeyNumerically); |
|
|
|
|
|
} |
|
|
|
|
|
return AjaxResult.success(lastFile); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description 事故地市分布 |
|
|
* @Description 事故地市分布 |
|
@ -462,21 +484,28 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
for (String stationName : stationSet) { |
|
|
for (String stationName : stationSet) { |
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
|
Long allNum = 0L; |
|
|
map.put("stationName",stationName); |
|
|
map.put("stationName",stationName); |
|
|
if (closeStation.containsKey(stationName)){ |
|
|
if (closeStation.containsKey(stationName)){ |
|
|
map.put("close",closeStation.get(stationName)); |
|
|
map.put("close",closeStation.get(stationName)); |
|
|
|
|
|
allNum += closeStation.get(stationName); |
|
|
} else { |
|
|
} else { |
|
|
map.put("close",0); |
|
|
map.put("close",0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (restrictionStation.containsKey(stationName)){ |
|
|
if (restrictionStation.containsKey(stationName)){ |
|
|
map.put("restriction",restrictionStation.get(stationName)); |
|
|
map.put("restriction",restrictionStation.get(stationName)); |
|
|
|
|
|
allNum += restrictionStation.get(stationName); |
|
|
} else { |
|
|
} else { |
|
|
map.put("restriction",0); |
|
|
map.put("restriction",0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
map.put("allNum",allNum); |
|
|
list.add(map); |
|
|
list.add(map); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据总数排序
|
|
|
|
|
|
list = list.stream().sorted(Comparator.comparing(item -> Long.parseLong(((Map<String, Object>) item).get("allNum").toString())).reversed()).collect(Collectors.toList()); |
|
|
return AjaxResult.success(list); |
|
|
return AjaxResult.success(list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -594,4 +623,123 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 查询交通事故类型统计 |
|
|
|
|
|
* |
|
|
|
|
|
* @author liuwenge |
|
|
|
|
|
* @date 2024/8/21 10:56 |
|
|
|
|
|
* @param dcSdhsEventQuery |
|
|
|
|
|
* @return com.ruoyi.common.core.domain.AjaxResult |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery){ |
|
|
|
|
|
List<DcSdhsEvent> eventList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); |
|
|
|
|
|
if (eventList == null || eventList.size() == 0){ |
|
|
|
|
|
return AjaxResult.error("请先导入数据"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eventList = eventList.stream().filter(item -> item.getStartTime() != null |
|
|
|
|
|
&& item.getStartTime().getTime() >= dcSdhsEventQuery.getStartTime().getTime() |
|
|
|
|
|
&& item.getStartTime().getTime() <= dcSdhsEventQuery.getEndTime().getTime() |
|
|
|
|
|
&& "交通事故".equals(item.getEventType())) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
if(eventList.size() > 0){ |
|
|
|
|
|
//根据详细类型 分组计数
|
|
|
|
|
|
Map<String, Long> subclass = eventList.stream().collect(Collectors.groupingBy(DcSdhsEvent::getEventSubclass,Collectors.counting())); |
|
|
|
|
|
subclass.forEach((key,count)->{ |
|
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
|
map.put("subclassName",key); |
|
|
|
|
|
map.put("num",count); |
|
|
|
|
|
list.add(map); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 导出交通事故类型统计 |
|
|
|
|
|
* |
|
|
|
|
|
* @author liuwenge |
|
|
|
|
|
* @date 2024/8/21 11:07 |
|
|
|
|
|
* @param doc |
|
|
|
|
|
* @param dcSdhsEventQuery |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void exportAccidentType(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery){ |
|
|
|
|
|
AjaxResult ajaxResult = selectAccidentType(dcSdhsEventQuery); |
|
|
|
|
|
if (ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) { |
|
|
|
|
|
|
|
|
|
|
|
PoiUtil.createHeading2(doc,"事故类型统计"); |
|
|
|
|
|
List<Map<String,Object>> data = (List<Map<String,Object>>) ajaxResult.get("data"); |
|
|
|
|
|
if (data != null && data.size() != UniversalEnum.ZERO.getNumber()){ |
|
|
|
|
|
//插入图表
|
|
|
|
|
|
try { |
|
|
|
|
|
// 复制Word模板
|
|
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("wordTemplate/sdhsEventChart.docx"); |
|
|
|
|
|
|
|
|
|
|
|
XWPFDocument copiedTemplate = new XWPFDocument(inputStream); |
|
|
|
|
|
|
|
|
|
|
|
//获取word中所有图表对象
|
|
|
|
|
|
List<XWPFChart> charts = copiedTemplate.getCharts(); |
|
|
|
|
|
XWPFChart chart = charts.get(1); |
|
|
|
|
|
XSSFWorkbook workbook = chart.getWorkbook(); |
|
|
|
|
|
XSSFSheet sheet = workbook.getSheetAt(UniversalEnum.ZERO.getNumber()); |
|
|
|
|
|
|
|
|
|
|
|
//系列信息
|
|
|
|
|
|
String[] singleBarSeriesNames = {"数量"}; |
|
|
|
|
|
//分类信息
|
|
|
|
|
|
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())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = sheet.getLastRowNum(); i > data.size();i--){ |
|
|
|
|
|
sheet.removeRow(sheet.getRow(i)); |
|
|
|
|
|
} |
|
|
|
|
|
PoiUtil.wordExportChar(chart, "事故类型统计", singleBarSeriesNames,sheet ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 追加到同一个Word文档中
|
|
|
|
|
|
mergeChart(chart,doc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭复制的模板文档
|
|
|
|
|
|
copiedTemplate.close(); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//换行
|
|
|
|
|
|
createLineBreak(doc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//插入表格
|
|
|
|
|
|
XWPFTable table = doc.createTable(data.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(0).getCell(0), "事故类型"); |
|
|
|
|
|
setTableFonts(table.getRow(0).getCell(1), "数量"); |
|
|
|
|
|
|
|
|
|
|
|
//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()); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
addDescription(doc,UniversalEnum.NO_DATA_AVAILABLE.getValue()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
addDescription(doc,UniversalEnum.NO_DATA_AVAILABLE.getValue()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|