From 2ef54f1439fdae5edcc645618f336a5d0965113c Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Mon, 9 Sep 2024 10:58:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E9=80=9F=E4=BA=91=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=AA=8C=E9=87=8D=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DcSdhsEventServiceImpl.java | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) 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 9bbeb028..a598f939 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 @@ -100,22 +100,42 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { String filePath = RuoYiConfig.getUploadPath() + newFileUrl; ExcelUtil util = new ExcelUtil(DcSdhsEvent.class); - importData = util.importExcel(new FileInputStream(filePath)); + InputStream inputStream = new FileInputStream(filePath); + importData = util.importExcel(inputStream); + inputStream.close(); } catch (Exception e) { e.printStackTrace(); return AjaxResult.error("导入失败,请检查数据是否有误"); } - redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT); + //redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT); + + //根据开始事件验重,如果有时间重复的则本次不导入 + List eventCache = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT); + if (eventCache != null && eventCache.size() > 0){ + Set oldStartTime = new HashSet<>(); + eventCache.forEach(item -> { + oldStartTime.add(item.getStartTime()); + }); + if (importData != null && importData.size() > 0) { + + List duplicateData = new ArrayList<>(); + for (DcSdhsEvent importDatum : importData) { + if (oldStartTime.contains(importDatum.getStartTime())){ + duplicateData.add(importDatum.getStartTime()); + } + } + + if (duplicateData.size() > 0){ + return AjaxResult.error("本次导入含有重复数据",duplicateData); + } + } + } 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)) { @@ -164,13 +184,15 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { } eventList.add(dcSdhsEvent); - id++; + } } //不入数据库, 放入缓存 - redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT, eventList); + if (eventList.size() > 0) { + redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT, eventList); + } Map fileInfo = new HashMap<>(); fileInfo.put("fileName", fileName);