From 90dad7fa18a51cef5a9ef3c5450c94beefa0c0d1 Mon Sep 17 00:00:00 2001 From: sunyugang Date: Fri, 22 Aug 2025 16:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=9F=A5=E9=97=AE=E5=8D=B7=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dw/controller/DwQuestionController.java | 2 ++ .../service/impl/DwQuestionServiceImpl.java | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java index 2063b44..a2e1aae 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/controller/DwQuestionController.java @@ -182,6 +182,8 @@ public class DwQuestionController extends BaseController int successNum = dwQuestionService.importData(file, dwInfo); if (successNum > 0) { return AjaxResult.success(); + }else if (successNum == 0){ + return AjaxResult.success("导入数据为0"); }else { return AjaxResult.error("导入失败,请检查调查问卷内容是否正确"); } diff --git a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/DwQuestionServiceImpl.java b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/DwQuestionServiceImpl.java index 2b7fc85..5ca130e 100644 --- a/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/DwQuestionServiceImpl.java +++ b/ruoyi-dw/src/main/java/com/ruoyi/dw/service/impl/DwQuestionServiceImpl.java @@ -123,15 +123,16 @@ public class DwQuestionServiceImpl implements IDwQuestionService return -1; } List answers = new ArrayList(); + List answerIds = new ArrayList<>(); for (int i = 1; i <= rows; i++) { //第一个调查问卷问题 Row row = sheet.getRow(i); Cell idCell = row.getCell(0); idCell.setCellType(CellType.STRING); String id = idCell.getStringCellValue(); -// if (redisCache.hasKey(id)){ -// continue; -// } + if (redisCache.hasKey(id)){ + continue; + } if (dwInfo.getId().intValue() == 1) { Cell cell15 = row.getCell(15); DwAnswer answer110 = new DwAnswer(); @@ -2023,10 +2024,17 @@ public class DwQuestionServiceImpl implements IDwQuestionService }else { return -2; } - redisCache.setCacheObject(id, true); + answerIds.add(id); } - dwAnswerMapper.insertDwAnswerBatch(answers); - return rows; + if (answers.size() > 0){ + int result = dwAnswerMapper.insertDwAnswerBatch(answers); + if (result > 0){ + for(String id : answerIds){ + redisCache.setCacheObject(id, true); + } + } + } + return answers.size(); }catch (Exception ex){ ex.printStackTrace(); return -1;