Browse Source

批量激活bug解决

dzx 3 months ago
parent
commit
65f9f6598a

+ 1 - 1
src/main/java/com/xjrsoft/module/base/controller/WhitelistManagementController.java

@@ -155,7 +155,7 @@ public class WhitelistManagementController {
     @PostMapping("/activate-import")
     @ApiOperation(value = "新生账号激活导入")
     public RT<List<Map<String, String>>> activateImport(@RequestParam MultipartFile file) throws IOException {
-        List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(2).doReadSync();
+        List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(3).doReadSync();
         List<Map<Integer, Object>> errorList = whitelistManagementService.activateImport(excelDataList);
         List<Map<String, String>> result = new ArrayList<>();
 

+ 20 - 9
src/main/java/com/xjrsoft/module/base/service/impl/WhitelistManagementServiceImpl.java

@@ -41,6 +41,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -221,14 +222,9 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
 
         Set<Long> whitelistUsers = this.baseMapper.selectList(new QueryWrapper<>()).stream().map(WhitelistManagement::getUserId).collect(Collectors.toSet());
 
-        List<User> updateList = new ArrayList<>();
-        List<BaseUserStudent> userStudentList = new ArrayList<>();
-        List<User> parentInsList = new ArrayList<>();
-        List<User> parentUpdList = new ArrayList<>();
-        List<UserRoleRelation> roleRelationList = new ArrayList<>();
-        List<WhitelistManagement> whitelist = new ArrayList();
-        LocalDateTime now = LocalDateTime.now();
-        Date createDate = new Date();
+
+        // 1、先把文件中的所有家长信息去重并提取出来
+        List<Map<Integer, Object>> dataList = new ArrayList<>();
         for (Map<Integer, Object> vo : savedDataList) {
             List<String> errorLogs = new ArrayList<>();
 
@@ -253,8 +249,23 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
             }
             if(!errorLogs.isEmpty()){
                 vo.put(5, errorLogs.toString().replace("[", "").replace("]", ""));
+                errorList.add(vo);
                 continue;
             }
+            dataList.add(vo);
+        }
+
+        List<User> updateList = new ArrayList<>();
+        List<BaseUserStudent> userStudentList = new ArrayList<>();
+        List<User> parentInsList = new ArrayList<>();
+        List<User> parentUpdList = new ArrayList<>();
+        List<UserRoleRelation> roleRelationList = new ArrayList<>();
+        List<WhitelistManagement> whitelist = new ArrayList();
+        LocalDateTime now = LocalDateTime.now();
+        Date createDate = new Date();
+
+        for (Map<Integer, Object> vo : dataList) {
+            String studentKey = vo.get(0).toString() + vo.get(1).toString();
             long parentId = IdUtil.getSnowflakeNextId();
             if(parentsMap.get(vo.get(4).toString()) != null){
                 User parent = parentsMap.get(vo.get(4).toString());
@@ -314,7 +325,7 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
             userService.updateBatchById(updateList);
         }
         if(!userStudentList.isEmpty()){
-            userStudentService.updateBatchById(userStudentList);
+            userStudentService.saveBatch(userStudentList);
         }
         if(!parentInsList.isEmpty()){
             userService.saveBatch(parentInsList);