5 changed files with 390 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.zc.business.service.IDcSdhsEventService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
/** |
|||
* @Description 高速云事件分析Controller |
|||
* |
|||
* @author liuwenge |
|||
* @date 2024/08/15 16:38 |
|||
*/ |
|||
@Api(tags = "高速云事件分析") |
|||
@RestController |
|||
@RequestMapping("/business/sdhsEvent") |
|||
public class DcSdhsEventController { |
|||
|
|||
|
|||
@Autowired |
|||
private IDcSdhsEventService dcSdhsEventService; |
|||
|
|||
@ApiOperation("导入数据") |
|||
@PostMapping("/importData") |
|||
public AjaxResult importData(MultipartFile file) throws Exception |
|||
{ |
|||
return dcSdhsEventService.importData(file); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,232 @@ |
|||
package com.zc.business.domain; |
|||
|
|||
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.ToStringStyle; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 预警信息对象 dc_warning |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-01-13 |
|||
*/ |
|||
public class DcSdhsEvent extends BaseEntity |
|||
{ |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** 预警编号 */ |
|||
private Integer id; |
|||
|
|||
/** 所属路线 */ |
|||
@Excel(name = "所属路线") |
|||
private String road; |
|||
|
|||
/** 机构 */ |
|||
@Excel(name = "机构") |
|||
private String dept; |
|||
|
|||
/** 事件类型 */ |
|||
@Excel(name = "事件类型") |
|||
private String eventType; |
|||
|
|||
/** 开始时间 */ |
|||
@Excel(name = "开始时间", dateFormat = "yyyy-MM-dd HH:mm:ss") |
|||
private Date startTime; |
|||
|
|||
/** 结束时间 */ |
|||
@Excel(name = "结束时间", dateFormat = "yyyy-MM-dd HH:mm:ss") |
|||
private Date endTime; |
|||
|
|||
/** 状态 */ |
|||
@Excel(name = "状态") |
|||
private String status; |
|||
|
|||
/** 事件来源 */ |
|||
@Excel(name = "事件来源") |
|||
private String source; |
|||
|
|||
/** 标题 */ |
|||
@Excel(name = "标题") |
|||
private String title; |
|||
|
|||
/** 详细类型 */ |
|||
@Excel(name = "详细类型") |
|||
private String eventSubclass; |
|||
|
|||
/** 车辆类型 */ |
|||
@Excel(name = "车辆类型") |
|||
private String carType; |
|||
|
|||
/** 车辆数量 */ |
|||
@Excel(name = "车数量") |
|||
private String carNum; |
|||
|
|||
/** 是否多车事故 */ |
|||
private String multiVehicle; |
|||
|
|||
/** 方向 */ |
|||
@Excel(name = "方向") |
|||
private String direction; |
|||
|
|||
/** 桩号 */ |
|||
@Excel(name = "桩号") |
|||
private String stakeMark; |
|||
|
|||
/** 天气 */ |
|||
@Excel(name = "天气") |
|||
private String weather; |
|||
|
|||
public Integer getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(Integer id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getRoad() { |
|||
return road; |
|||
} |
|||
|
|||
public void setRoad(String road) { |
|||
this.road = road; |
|||
} |
|||
|
|||
public String getDept() { |
|||
return dept; |
|||
} |
|||
|
|||
public void setDept(String dept) { |
|||
this.dept = dept; |
|||
} |
|||
|
|||
public String getEventType() { |
|||
return eventType; |
|||
} |
|||
|
|||
public void setEventType(String eventType) { |
|||
this.eventType = eventType; |
|||
} |
|||
|
|||
public Date getStartTime() { |
|||
return startTime; |
|||
} |
|||
|
|||
public void setStartTime(Date startTime) { |
|||
this.startTime = startTime; |
|||
} |
|||
|
|||
public Date getEndTime() { |
|||
return endTime; |
|||
} |
|||
|
|||
public void setEndTime(Date endTime) { |
|||
this.endTime = endTime; |
|||
} |
|||
|
|||
public String getStatus() { |
|||
return status; |
|||
} |
|||
|
|||
public void setStatus(String status) { |
|||
this.status = status; |
|||
} |
|||
|
|||
public String getSource() { |
|||
return source; |
|||
} |
|||
|
|||
public void setSource(String source) { |
|||
this.source = source; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getEventSubclass() { |
|||
return eventSubclass; |
|||
} |
|||
|
|||
public void setEventSubclass(String eventSubclass) { |
|||
this.eventSubclass = eventSubclass; |
|||
} |
|||
|
|||
public String getCarType() { |
|||
return carType; |
|||
} |
|||
|
|||
public void setCarType(String carType) { |
|||
this.carType = carType; |
|||
} |
|||
|
|||
public String getCarNum() { |
|||
return carNum; |
|||
} |
|||
|
|||
public void setCarNum(String carNum) { |
|||
this.carNum = carNum; |
|||
} |
|||
|
|||
public String getMultiVehicle() { |
|||
return multiVehicle; |
|||
} |
|||
|
|||
public void setMultiVehicle(String multiVehicle) { |
|||
this.multiVehicle = multiVehicle; |
|||
} |
|||
|
|||
public String getDirection() { |
|||
return direction; |
|||
} |
|||
|
|||
public void setDirection(String direction) { |
|||
this.direction = direction; |
|||
} |
|||
|
|||
public String getStakeMark() { |
|||
return stakeMark; |
|||
} |
|||
|
|||
public void setStakeMark(String stakeMark) { |
|||
this.stakeMark = stakeMark; |
|||
} |
|||
|
|||
public String getWeather() { |
|||
return weather; |
|||
} |
|||
|
|||
public void setWeather(String weather) { |
|||
this.weather = weather; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return new ToStringBuilder(this) |
|||
.append("id", id) |
|||
.append("road", road) |
|||
.append("dept", dept) |
|||
.append("eventType", eventType) |
|||
.append("startTime", startTime) |
|||
.append("endTime", endTime) |
|||
.append("status", status) |
|||
.append("source", source) |
|||
.append("title", title) |
|||
.append("eventSubclass", eventSubclass) |
|||
.append("carType", carType) |
|||
.append("carNum", carNum) |
|||
.append("multiVehicle", multiVehicle) |
|||
.append("direction", direction) |
|||
.append("stakeMark", stakeMark) |
|||
.append("weather", weather) |
|||
.toString(); |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.zc.business.service; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
/** |
|||
* 高速云事件分析Service接口 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-08-15 |
|||
*/ |
|||
public interface IDcSdhsEventService |
|||
{ |
|||
AjaxResult importData(MultipartFile file) throws Exception; |
|||
|
|||
} |
@ -0,0 +1,102 @@ |
|||
package com.zc.business.service.impl; |
|||
|
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.core.domain.entity.SysUser; |
|||
import com.ruoyi.common.core.redis.RedisCache; |
|||
import com.ruoyi.common.utils.StringUtils; |
|||
import com.ruoyi.common.utils.poi.ExcelUtil; |
|||
import com.zc.business.constant.RedisKeyConstants; |
|||
import com.zc.business.domain.DcSdhsEvent; |
|||
import com.zc.business.service.IDcSdhsEventService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* 高速云事件分析Service业务层处理 |
|||
* |
|||
* @author ruoyi |
|||
* @date 2024-08-15 |
|||
*/ |
|||
@Service |
|||
public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|||
|
|||
@Autowired |
|||
private RedisCache redisCache; |
|||
|
|||
|
|||
@Override |
|||
public AjaxResult importData(MultipartFile file) throws IOException { |
|||
List<DcSdhsEvent> eventList = new ArrayList<>(); |
|||
try { |
|||
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class); |
|||
eventList = util.importExcel(file.getInputStream()); |
|||
} catch (Exception e){ |
|||
e.printStackTrace(); |
|||
return AjaxResult.error("导入失败,请检查数据是否有误"); |
|||
} |
|||
|
|||
redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT); |
|||
if (eventList != null && eventList.size() > 0){ |
|||
int id = 1; |
|||
for (DcSdhsEvent dcSdhsEvent : eventList) { |
|||
|
|||
//插入id备用
|
|||
dcSdhsEvent.setId(id); |
|||
|
|||
//是否多车事故
|
|||
String carNum = dcSdhsEvent.getCarNum(); |
|||
if (StringUtils.isNotEmpty(carNum)){ |
|||
List<Integer> numbers = extractNumbers(carNum); |
|||
Integer carNumbers = 0; |
|||
for (Integer number : numbers) { |
|||
carNumbers += number; |
|||
} |
|||
|
|||
if (carNumbers > 0){ |
|||
dcSdhsEvent.setMultiVehicle("是"); |
|||
} else { |
|||
dcSdhsEvent.setMultiVehicle("否"); |
|||
} |
|||
} else { |
|||
dcSdhsEvent.setMultiVehicle("否"); |
|||
} |
|||
|
|||
id++; |
|||
} |
|||
|
|||
} |
|||
|
|||
//不入数据库, 放入缓存
|
|||
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT,eventList); |
|||
|
|||
return AjaxResult.success("导入成功"); |
|||
} |
|||
|
|||
/** |
|||
* @Description 提取文字中的数字 |
|||
* |
|||
* @author liuwenge |
|||
* @date 2024/8/15 17:05 |
|||
* @param input |
|||
* @return java.util.List<java.lang.Integer> |
|||
*/ |
|||
private static List<Integer> extractNumbers(String input) { |
|||
List<Integer> numbers = new ArrayList<>(); |
|||
Pattern pattern = Pattern.compile("\\d+"); // 匹配一个或多个数字
|
|||
Matcher matcher = pattern.matcher(input); |
|||
|
|||
while (matcher.find()) { |
|||
numbers.add(Integer.parseInt(matcher.group())); // 将匹配到的数字字符串转换为整数并添加到列表中
|
|||
} |
|||
|
|||
|
|||
return numbers; |
|||
} |
|||
} |
Loading…
Reference in new issue