Browse Source

高速云事件入库

查询事故地市分布
develop
lau572 3 months ago
parent
commit
00dbca3abf
  1. 51
      zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java
  2. 12
      zc-business/src/main/java/com/zc/business/domain/DcSdhsEvent.java
  3. 24
      zc-business/src/main/java/com/zc/business/domain/DcSdhsEventQuery.java
  4. 7
      zc-business/src/main/java/com/zc/business/mapper/DcSdhsEventMapper.java
  5. 12
      zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java
  6. 72
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java
  7. 58
      zc-business/src/main/resources/mapper/business/DcSdhsEventMapper.xml

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

@ -8,26 +8,10 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.domain.DcSdhsEvent; import com.zc.business.domain.DcSdhsEvent;
import com.zc.business.domain.DcSdhsEventQuery; import com.zc.business.domain.DcSdhsEventQuery;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.domain.DcSdhsEventQuery;
import com.zc.business.enums.UniversalEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.zc.business.domain.DcSdhsEvent;
import com.zc.business.domain.DcSdhsEventQuery;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcSdhsEventService; import com.zc.business.service.IDcSdhsEventService;
import com.zc.business.utils.PoiUtil; import com.zc.business.utils.PoiUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
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 io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment; import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -36,53 +20,18 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
import org.apache.catalina.security.SecurityUtil;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.reflect.generics.tree.VoidDescriptor;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.ruoyi.common.utils.PageUtils.startPage;
import static com.zc.business.utils.PoiUtil.mergeChart;
import static com.zc.business.utils.PoiUtil.setTableFonts;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import static com.zc.business.utils.PoiUtil.insertTOC; import static com.zc.business.utils.PoiUtil.insertTOC;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.zc.business.utils.PoiUtil.*;
import static com.zc.business.utils.PoiUtil.createLineBreak;
/** /**
* @Description 高速云事件分析Controller * @Description 高速云事件分析Controller
* *

12
zc-business/src/main/java/com/zc/business/domain/DcSdhsEvent.java

@ -80,6 +80,10 @@ public class DcSdhsEvent extends BaseEntity
@Excel(name = "天气") @Excel(name = "天气")
private String weather; private String weather;
/** 桩号里程 */
@Excel(name = "桩号里程")
private Long mileage;
public Long getId() { public Long getId() {
return id; return id;
} }
@ -208,6 +212,14 @@ public class DcSdhsEvent extends BaseEntity
this.weather = weather; this.weather = weather;
} }
public Long getMileage() {
return mileage;
}
public void setMileage(Long mileage) {
this.mileage = mileage;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this) return new ToStringBuilder(this)

24
zc-business/src/main/java/com/zc/business/domain/DcSdhsEventQuery.java

@ -1,14 +1,10 @@
package com.zc.business.domain; package com.zc.business.domain;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 高速云事件分析查询对象 * 高速云事件分析查询对象
@ -37,6 +33,10 @@ public class DcSdhsEventQuery
/** 需要导出的键 */ /** 需要导出的键 */
private List<String> exportKey; private List<String> exportKey;
private String thisTime;
private String lastTime;
public String getDirection() { public String getDirection() {
return direction; return direction;
} }
@ -77,6 +77,22 @@ public class DcSdhsEventQuery
this.exportKey = exportKey; this.exportKey = exportKey;
} }
public String getThisTime() {
return thisTime;
}
public void setThisTime(String thisTime) {
this.thisTime = thisTime;
}
public String getLastTime() {
return lastTime;
}
public void setLastTime(String lastTime) {
this.lastTime = lastTime;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this) return new ToStringBuilder(this)

7
zc-business/src/main/java/com/zc/business/mapper/DcSdhsEventMapper.java

@ -2,9 +2,10 @@ package com.zc.business.mapper;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import com.ruoyi.system.domain.SysUserPost;
import com.zc.business.domain.DcSdhsEvent; import com.zc.business.domain.DcSdhsEvent;
import org.apache.ibatis.annotations.Param;
/** /**
* 高速云事件Mapper接口 * 高速云事件Mapper接口
@ -72,5 +73,7 @@ public interface DcSdhsEventMapper
*/ */
public boolean batchInsert(List<DcSdhsEvent> dcSdhsEventList); public boolean batchInsert(List<DcSdhsEvent> dcSdhsEventList);
boolean deleteByTimeRange(String startTime, String endTime); boolean deleteByTimeRange(@Param("startTime") String startTime,@Param("endTime") String endTime);
List<Map<String,Object>> selectRegionAnalysis(@Param("type") String type,@Param("thisTime") String thisTime, @Param("lastTime") String lastTime);
} }

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

@ -3,21 +3,13 @@ package com.zc.business.service;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcSdhsEvent; import com.zc.business.domain.DcSdhsEvent;
import com.zc.business.domain.DcSdhsEventQuery; import com.zc.business.domain.DcSdhsEventQuery;
import org.apache.poi.xddf.usermodel.XDDFAdjustHandleXY; import com.zc.business.domain.DcTollStationStatisticsDataMap;
import com.zc.business.domain.TrafficFlowStatisticsMap;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import com.zc.business.domain.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import com.zc.business.domain.DcSdhsEventQuery;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse;
/** /**
* 高速云事件分析Service接口 * 高速云事件分析Service接口
* *

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

@ -21,17 +21,6 @@ import com.zc.business.utils.PoiUtil;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row; 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.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
@ -47,19 +36,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.DecimalFormat; 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.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
@ -70,9 +49,6 @@ import java.util.stream.Collectors;
import static com.zc.business.utils.PoiUtil.*; import static com.zc.business.utils.PoiUtil.*;
import static com.zc.business.utils.PoiUtil.mergeChart;
import static com.zc.business.utils.PoiUtil.setTableFonts;
/** /**
* 高速云事件分析Service业务层处理 * 高速云事件分析Service业务层处理
* *
@ -154,7 +130,9 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
String stakeMark = dcSdhsEvent.getStakeMark(); String stakeMark = dcSdhsEvent.getStakeMark();
if (StringUtils.isNotEmpty(stakeMark) && !"无".equals(stakeMark) && !StakeMarkUtils.checkStakeMark(stakeMark)) { if (StringUtils.isNotEmpty(stakeMark) && !"无".equals(stakeMark)) {
if (!StakeMarkUtils.checkStakeMark(stakeMark)){
//尝试桩号补零 //尝试桩号补零
List<String> numbers = new ArrayList<>(); List<String> numbers = new ArrayList<>();
@ -178,7 +156,11 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
if (!StakeMarkUtils.checkStakeMark(stakeMark)) { if (!StakeMarkUtils.checkStakeMark(stakeMark)) {
continue; continue;
} }
}
dcSdhsEvent.setStakeMark(stakeMark); dcSdhsEvent.setStakeMark(stakeMark);
dcSdhsEvent.setMileage(StakeMarkUtils.formatMetreLong(stakeMark));
} }
eventList.add(dcSdhsEvent); eventList.add(dcSdhsEvent);
@ -1310,46 +1292,10 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override @Override
public AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) { public AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery) {
List<DcSdhsEvent> eventList = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); List<Map<String,Object>> thisTimeData = dcSdhsEventMapper.selectRegionAnalysis(dcSdhsEventQuery.getType(),dcSdhsEventQuery.getThisTime(),dcSdhsEventQuery.getLastTime());
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()
&& item.getEventType().equals("交通事故"))
.collect(Collectors.toList());
//筛选方向
/*if (StringUtils.isNotEmpty(dcSdhsEventQuery.getDirection())){
if (dcSdhsEventQuery.getDirection().equals("1")){
//菏泽方向
eventList = eventList.stream()
.filter(item -> item.getDirection().equals("广州方向") || item.getDirection().equals("双向"))
.collect(Collectors.toList());
} else if (dcSdhsEventQuery.getDirection().equals("3")){
//济南方向
eventList = eventList.stream()
.filter(item -> item.getDirection().equals("济南方向") || item.getDirection().equals("双向"))
.collect(Collectors.toList());
}
}*/
//地市统计 return AjaxResult.success(thisTimeData);
Map<String, Long> region = eventList.stream()
.collect(Collectors.groupingBy(item -> getRange(item.getStakeMark()), Collectors.counting()));
List<Map<String, Object>> list = new ArrayList<>();
for (String key : region.keySet()) {
Map<String, Object> map = new HashMap<>();
map.put("regionName", key);
map.put("num", region.get(key));
list.add(map);
}
list = list.stream().sorted(Comparator.comparing(item -> getCitySorted(item.get("regionName").toString()))).collect(Collectors.toList());
return AjaxResult.success(list);
} }
private int getCitySorted(String city){ private int getCitySorted(String city){

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

@ -55,6 +55,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTimeList" resultType="java.util.Date"> <select id="selectTimeList" resultType="java.util.Date">
select DISTINCT(start_time) from dc_sdhs_event select DISTINCT(start_time) from dc_sdhs_event
</select> </select>
<select id="selectRegionAnalysis" resultType="java.util.Map">
select t1.city,IFNULL(t2.num,0) as #{thisTime}, IFNULL(t3.num,0) as #{lastTime}
from
(select '济南' city
union all select '泰安' city
union all select '济宁' city
union all select '菏泽' city) t1
left join
(SELECT
case when mileage >= 0 and mileage &lt;= 132469 then '济南'
when mileage > 132469 and mileage &lt;= 160708 then '泰安'
when mileage > 160708 and mileage &lt;= 200752 then '济宁'
when mileage > 200752 then '菏泽' else '其他' end city,
count(*) num
FROM `dc_sdhs_event`
<where>
event_type = '交通事故'
<if test="type != null and type == '0'.toString">
and DATE_FORMAT(start_time,'%Y') = #{thisTime}
</if>
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y-%m') = #{thisTime}
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y-%m-%d') = #{thisTime}
</if>
</where>
GROUP BY city order by mileage asc) t2
on t1.city = t2.city
left join
(SELECT
case when mileage >= 0 and mileage &lt;= 132469 then '济南'
when mileage > 132469 and mileage &lt;= 160708 then '泰安'
when mileage > 160708 and mileage &lt;= 200752 then '济宁'
when mileage > 200752 then '菏泽' else '其他' end city,
count(*) num
FROM `dc_sdhs_event`
<where>
event_type = '交通事故'
<if test="type != null and type == '0'.toString">
and DATE_FORMAT(start_time,'%Y') = #{lastTime}
</if>
<if test="type != null and type == '1'.toString">
and DATE_FORMAT(start_time,'%Y-%m') = #{lastTime}
</if>
<if test="type != null and type == '2'.toString">
and DATE_FORMAT(start_time,'%Y-%m-%d') = #{lastTime}
</if>
</where>
GROUP BY city order by mileage asc) t3
on t1.city = t3.city
</select>
<insert id="insertDcSdhsEvent" parameterType="DcSdhsEvent" useGeneratedKeys="true" keyProperty="id"> <insert id="insertDcSdhsEvent" parameterType="DcSdhsEvent" useGeneratedKeys="true" keyProperty="id">
insert into dc_sdhs_event insert into dc_sdhs_event
@ -95,9 +149,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert> </insert>
<insert id="batchInsert"> <insert id="batchInsert">
insert into dc_sdhs_event(road,dept,event_type,start_time,end_time,status,source,title,event_subclass,car_type,car_num,multi_vehicle,direction,stake_mark,weather) values insert into dc_sdhs_event(road,dept,event_type,start_time,end_time,status,source,title,event_subclass,car_type,car_num,multi_vehicle,direction,stake_mark,weather,mileage) values
<foreach item="item" index="index" collection="list" separator=","> <foreach item="item" index="index" collection="list" separator=",">
(#{item.road},#{item.dept},#{item.eventType},#{item.startTime},#{item.endTime},#{item.status},#{item.source},#{item.title},#{item.eventSubclass},#{item.carType},#{item.carNum},#{item.multiVehicle},#{item.direction},#{item.stakeMark},#{item.weather}) (#{item.road},#{item.dept},#{item.eventType},#{item.startTime},#{item.endTime},#{item.status},#{item.source},#{item.title},#{item.eventSubclass},#{item.carType},#{item.carNum},#{item.multiVehicle},#{item.direction},#{item.stakeMark},#{item.weather},#{item.mileage})
</foreach> </foreach>
</insert> </insert>

Loading…
Cancel
Save