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;