From a6bf87541345df8412cc4c2b766ef78d99d2be81 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Wed, 21 Aug 2024 09:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E9=80=9F=E4=BA=91=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/constant/RedisKeyConstants.java | 5 + .../controller/DcSdhsEventController.java | 43 ++++++++- .../business/service/IDcSdhsEventService.java | 5 +- .../service/impl/DcSdhsEventServiceImpl.java | 96 ++++++++++++++++++- 4 files changed, 144 insertions(+), 5 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java index ff54d824..5c501d5c 100644 --- a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java +++ b/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"; } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java b/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java index ec37b6db..e5c0062e 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcSdhsEventController.java +++ b/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)){ + //路段拥堵时长 + + } + } } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java b/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java index 6f72eb33..32afb38d 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcSdhsEventService.java +++ b/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); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java index 2962026a..084072c2 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java +++ b/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 importData = new ArrayList<>(); try { + //本地路径 + String newFileUrl = fileUrl.replace("/profile/upload",""); + String filePath = RuoYiConfig.getUploadPath() + newFileUrl; + ExcelUtil util = new ExcelUtil(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 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 importData = new ArrayList<>(); + try { + ExcelUtil util = new ExcelUtil(DcSdhsEvent.class); + importData = util.importExcel(file.getInputStream()); + } catch (Exception e){ + e.printStackTrace(); + return AjaxResult.error("导入失败,请检查数据是否有误"); + } + + redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT); + + List 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 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 numbers = new ArrayList<>(); + + // 匹配大小桩号数字 + Pattern pattern = Pattern.compile("\\d+"); + Matcher matcher = pattern.matcher(stakeMark); + while (matcher.find()) { + numbers.add(matcher.group()); // 将匹配到的数字字符串添加到列表中 + } + List 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 提取文字中的数字 *