Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
wangsixiang 3 months ago
parent
commit
e9deeea709
  1. 36
      zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java
  2. 6
      zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java
  3. 152
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java
  4. BIN
      zc-business/src/main/resources/wordTemplate/sdhsEventChart.docx

36
zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java

@ -92,12 +92,16 @@ public class DcSdhsEventController {
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)){
//事故地市分布
@ -108,10 +112,12 @@ public class DcSdhsEventController {
}
}
} else if (exportKey.contains("7")){
}
if (exportKey.contains("7")){
PoiUtil.createHeading1(newDoc,"天气情况统计");
wordController.weather(newDoc);
} else if (exportKey.contains("8") || exportKey.contains("9")){
}
if (exportKey.contains("8") || exportKey.contains("9")){
PoiUtil.createHeading1(newDoc,"交通量统计");
for (String trafficIncidentType : exportKey) {
if ("8".equals(trafficIncidentType)){
@ -123,18 +129,21 @@ public class DcSdhsEventController {
}
}
} else if (exportKey.contains("10")){
}
if (exportKey.contains("10")){
PoiUtil.createHeading1(newDoc,"交通事故情况");
//交通事故类型统计
dcSdhsEventService.exportAccidentType(newDoc,dcSdhsEventQuery);
} else if (exportKey.contains("11") || exportKey.contains("12")){
PoiUtil.createHeading1(newDoc,"交通量统计");
}
if (exportKey.contains("11") || exportKey.contains("12")){
PoiUtil.createHeading1(newDoc,"拥堵情况");
for (String trafficIncidentType : exportKey) {
if ("11".equals(trafficIncidentType)){
//拥堵地点统计
} else if ("12".equals(trafficIncidentType)){
//路段拥堵时长
//路段平均拥堵时长
}
@ -160,6 +169,13 @@ public class DcSdhsEventController {
}
}
@ApiOperation("查询上次上传的文件信息")
@GetMapping("/getFileInfo")
public AjaxResult getFileInfo()
{
return dcSdhsEventService.getFileInfo();
}
@ApiOperation("查询事故地市分布")
@PostMapping("/selectRegionAnalysis")
public AjaxResult selectRegionAnalysis(@RequestBody DcSdhsEventQuery dcSdhsEventQuery)
@ -175,5 +191,13 @@ public class DcSdhsEventController {
return dcSdhsEventService.selectStationAnalysis(dcSdhsEventQuery);
}
@ApiOperation("查询交通事故类型统计")
@PostMapping("/selectAccidentType")
public AjaxResult selectAccidentType(@RequestBody DcSdhsEventQuery dcSdhsEventQuery)
{
return dcSdhsEventService.selectAccidentType(dcSdhsEventQuery);
}
}

6
zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java

@ -19,6 +19,8 @@ public interface IDcSdhsEventService
// AjaxResult importData(MultipartFile file) throws Exception;
AjaxResult importData(String fileName,String fileUrl) throws Exception;
AjaxResult getFileInfo();
AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery);
void exportRegionAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery);
@ -26,4 +28,8 @@ public interface IDcSdhsEventService
AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery);
void exportStationAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery);
AjaxResult selectAccidentType(DcSdhsEventQuery dcSdhsEventQuery);
void exportAccidentType(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery);
}

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

@ -134,11 +134,13 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
Map<String,Object> fileInfo = new HashMap<>();
fileInfo.put("fileName",fileName);
fileInfo.put("fileUrl",fileUrl);
Date now = new Date();
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);
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,updateTime,fileInfo);
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,now.getTime(),fileInfo);
return AjaxResult.success("导入成功");
}
@ -242,6 +244,26 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
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 事故地市分布
@ -462,21 +484,28 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
List<Map<String,Object>> list = new ArrayList<>();
for (String stationName : stationSet) {
Map<String,Object> map = new HashMap<>();
Long allNum = 0L;
map.put("stationName",stationName);
if (closeStation.containsKey(stationName)){
map.put("close",closeStation.get(stationName));
allNum += closeStation.get(stationName);
} else {
map.put("close",0);
}
if (restrictionStation.containsKey(stationName)){
map.put("restriction",restrictionStation.get(stationName));
allNum += restrictionStation.get(stationName);
} else {
map.put("restriction",0);
}
map.put("allNum",allNum);
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);
}
@ -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());
}
}
}

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

Binary file not shown.
Loading…
Cancel
Save