Browse Source

高速云事件导出

develop
lau572 3 months ago
parent
commit
a6bf875413
  1. 5
      zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java
  2. 43
      zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java
  3. 5
      zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java
  4. 96
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

5
zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java

@ -58,4 +58,9 @@ public class RedisKeyConstants
* 高速云导入事件列表
*/
public static final String SDHS_EVENT = "sdhsEvent";
/**
* 高速云导入事件列表
*/
public static final String SDHS_EVENT_FILE = "sdhsEventFile";
}

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

@ -8,6 +8,7 @@ import com.zc.business.service.IDcSdhsEventService;
import com.zc.business.utils.PoiUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
@ -43,12 +44,21 @@ public class DcSdhsEventController {
@Autowired
private IDcSdhsEventService dcSdhsEventService;
@Autowired
private WordController wordController;
@ApiOperation("导入数据")
/*@ApiOperation("导入数据")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception
{
return dcSdhsEventService.importData(file);
}*/
@ApiOperation("导入数据")
@PostMapping("/importData")
public AjaxResult importData(@ApiParam(value="文件名称", name="fileName", required=true) @RequestParam("fileName") String fileName,
@ApiParam(value="文件路径", name="fileUrl", required=true) @RequestParam("fileUrl") String fileUrl) throws Exception
{
return dcSdhsEventService.importData(fileName,fileUrl);
}
@PostMapping("/export")
@ -97,6 +107,37 @@ public class DcSdhsEventController {
dcSdhsEventService.exportStationAnalysis(newDoc,dcSdhsEventQuery);
}
}
} else if (exportKey.contains("7")){
PoiUtil.createHeading1(newDoc,"天气情况统计");
wordController.weather(newDoc);
} else if (exportKey.contains("8") || exportKey.contains("9")){
PoiUtil.createHeading1(newDoc,"交通量统计");
for (String trafficIncidentType : exportKey) {
if ("8".equals(trafficIncidentType)){
//门架车流量
} else if ("9".equals(trafficIncidentType)){
//收费站车流量
}
}
} else if (exportKey.contains("10")){
PoiUtil.createHeading1(newDoc,"交通事故情况");
//交通事故类型统计
} else if (exportKey.contains("11") || exportKey.contains("12")){
PoiUtil.createHeading1(newDoc,"交通量统计");
for (String trafficIncidentType : exportKey) {
if ("11".equals(trafficIncidentType)){
//拥堵地点统计
} else if ("12".equals(trafficIncidentType)){
//路段拥堵时长
}
}
}

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

@ -16,12 +16,13 @@ import javax.servlet.http.HttpServletResponse;
*/
public interface IDcSdhsEventService
{
AjaxResult importData(MultipartFile file) throws Exception;
// AjaxResult importData(MultipartFile file) throws Exception;
AjaxResult importData(String fileName,String fileUrl) throws Exception;
AjaxResult selectRegionAnalysis(DcSdhsEventQuery dcSdhsEventQuery);
void exportRegionAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery);
AjaxResult selectStationAnalysis(DcSdhsEventQuery dcSdhsEventQuery);
void exportStationAnalysis(XWPFDocument doc, DcSdhsEventQuery dcSdhsEventQuery);

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

@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
@ -50,11 +51,15 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
@Override
public AjaxResult importData(MultipartFile file) throws IOException {
public AjaxResult importData(String fileName,String fileUrl) throws IOException {
List<DcSdhsEvent> importData = new ArrayList<>();
try {
//本地路径
String newFileUrl = fileUrl.replace("/profile/upload","");
String filePath = RuoYiConfig.getUploadPath() + newFileUrl;
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class);
importData = util.importExcel(file.getInputStream());
importData = util.importExcel(new FileInputStream(filePath));
} catch (Exception e){
e.printStackTrace();
return AjaxResult.error("导入失败,请检查数据是否有误");
@ -126,9 +131,96 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
//不入数据库, 放入缓存
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT,eventList);
Map<String,Object> fileInfo = new HashMap<>();
fileInfo.put("fileName",fileName);
fileInfo.put("fileUrl",fileUrl);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String updateTime = simpleDateFormat.format(new Date());
fileInfo.put("uploadTime",updateTime);
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,updateTime,fileInfo);
return AjaxResult.success("导入成功");
}
/*public AjaxResult importData(MultipartFile file) throws IOException {
List<DcSdhsEvent> importData = new ArrayList<>();
try {
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class);
importData = util.importExcel(file.getInputStream());
} catch (Exception e){
e.printStackTrace();
return AjaxResult.error("导入失败,请检查数据是否有误");
}
redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT);
List<DcSdhsEvent> eventList = new ArrayList<>();
if (importData != null && importData.size() > 0){
int id = 1;
for (DcSdhsEvent dcSdhsEvent : importData) {
//插入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("否");
}
String stakeMark = dcSdhsEvent.getStakeMark();
if (StringUtils.isNotEmpty(stakeMark) && !"无".equals(stakeMark) && !StakeMarkUtils.checkStakeMark(stakeMark)){
//尝试桩号补零
List<String> numbers = new ArrayList<>();
// 匹配大小桩号数字
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(stakeMark);
while (matcher.find()) {
numbers.add(matcher.group()); // 将匹配到的数字字符串添加到列表中
}
List<String> formattedNumbers = new ArrayList<>();
for (String number : numbers) {
while (number.length() < 3) {
number = "0" + number;
}
formattedNumbers.add(number);
}
stakeMark = "K" + String.join("+",formattedNumbers);
//如果还验证不通过 则此条信息作废
if (!StakeMarkUtils.checkStakeMark(stakeMark)){
continue;
}
dcSdhsEvent.setStakeMark(stakeMark);
}
eventList.add(dcSdhsEvent);
id++;
}
}
//不入数据库, 放入缓存
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT,eventList);
return AjaxResult.success("导入成功");
}*/
/**
* @Description 提取文字中的数字
*

Loading…
Cancel
Save