Преглед изворни кода

修复导入项目的参与人BUG

seyason пре 2 година
родитељ
комит
fa6af6bc4c

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -991,5 +991,10 @@ public class ProjectController {
     public HttpRespMsg batchExchangeIncharger(String projectIds,String inchargerId,HttpServletRequest request){
         return projectService.batchExchangeIncharger(projectIds,inchargerId,request);
     }
+
+    @RequestMapping("/fixParticipators")
+    public HttpRespMsg fixParticipators(Integer companyId, HttpServletRequest request){
+        return projectService.fixParticipators(companyId,request);
+    }
 }
 

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectService.java

@@ -184,4 +184,6 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg importPersonnelWithGroup(MultipartFile file, HttpServletRequest request);
 
     HttpRespMsg batchExchangeIncharger(String projectIds, String inchargerId, HttpServletRequest request);
+
+    HttpRespMsg fixParticipators(Integer companyId, HttpServletRequest request);
 }

+ 71 - 54
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -2945,51 +2945,54 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                             }
                         }
                     }
-                    //参与人
+                    //导入项目参与人,遵守只增不减的原则, 避免误删
+                    List<Participation> oldPartList = new ArrayList<>();
+                    if (!flag) {
+                        //更新的项目,检查已经存在的项目参与人
+                        oldPartList = participationMapper.selectList(new QueryWrapper<Participation>().eq("project_id", project.getId()));
+                    }
+                    List<Participation> participationList = new ArrayList<>();
                     if(inchargerCell!=null){
-                        if(participatorCell==null||StringUtils.isEmpty(participatorCell.getStringCellValue())){
-                            String value = inchargerCell.getStringCellValue();
-                            Participation p = new Participation();
-                            Optional<User> first = userList.stream().filter(u -> u.getName().equals(value)).findFirst();
-                            if (first.isPresent()) {
-                                //避免更新操作 想清楚之前存在的参与人
-                                participationMapper.delete(new QueryWrapper<Participation>().eq("project_id",project.getId()));
-                                p.setUserId(first.get().getId());
-                                p.setProjectId(project.getId());
-                                participationMapper.insert(p);
-                            } else {
-                                throw new Exception("参与人["+value+"]不存在");
-                            }
+                        String value = inchargerCell.getStringCellValue();
+                        Participation p = new Participation();
+                        Optional<User> first = userList.stream().filter(u -> u.getName().equals(value)).findFirst();
+                        if (first.isPresent()) {
+                            p.setUserId(first.get().getId());
+                            p.setProjectId(project.getId());
+                            participationList.add(p);
+                        } else {
+                            throw new Exception("参与人["+value+"]不存在");
                         }
                     }
                     if (participatorCell != null) {
                         String part = participatorCell.getStringCellValue().trim();
-                        //将项目负责人也添加到参与人当中来
-                        String incharger = inchargerCell.getStringCellValue().trim();
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
-                            if(!StringUtils.isEmpty(incharger)){
-                                String[] inchargerSplit = incharger.split("\\,|\\,");
-                                int strLen1 = partSplit.length;// 保存第一个数组长度
-                                int strLen2 = inchargerSplit.length;
-                                partSplit=Arrays.copyOf(partSplit, strLen1+strLen2);
-                                System.arraycopy(inchargerSplit, 0, partSplit, strLen1, strLen2);
-                            }
                             for (String str : partSplit) {
                                 Participation p = new Participation();
                                 Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
                                 if (first.isPresent()) {
-                                    participationMapper.delete(new QueryWrapper<Participation>().eq("project_id",project.getId()));
-                                    p.setUserId(first.get().getId());
-                                    p.setProjectId(project.getId());
-                                    participationMapper.insert(p);
+                                    User partMemb = first.get();
+//                                    System.out.println("参与人:"+partMemb.getName());
+                                    if (!participationList.stream().anyMatch(partOne->partOne.getUserId().equals(partMemb.getId()))) {
+                                        p.setUserId(partMemb.getId());
+                                        p.setProjectId(project.getId());
+                                        participationList.add(p);
+                                    }
                                 } else {
-                                    projectMapper.deleteById(project.getId());
                                     throw new Exception("参与人["+str+"]不存在");
                                 }
                             }
                         }
                     }
+                    if (participationList.size() > 0) {
+                        //批量保存
+                        List<Participation> finalOldPartList = oldPartList;
+                        List<Participation> addPartList = participationList.stream().filter(newP-> finalOldPartList.stream().anyMatch(oldP->oldP.getUserId().equals(newP.getUserId()))).collect(Collectors.toList());
+                        if (addPartList.size() > 0) {
+                            participationService.saveBatch(addPartList);
+                        }
+                    }
                 }
                 msg.data = "成功导入"+importCount+"条数据。";
                 if (existCodeList.size() > 0) {
@@ -3795,49 +3798,54 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         }
                     }
                     importCount++;
-                    //参与人
+                    //导入项目参与人,遵守只增不减的原则, 避免误删
+                    List<Participation> oldPartList = new ArrayList<>();
+                    if (!flag) {
+                        //更新的项目,检查已经存在的项目参与人
+                        oldPartList = participationMapper.selectList(new QueryWrapper<Participation>().eq("project_id", project.getId()));
+                    }
+                    List<Participation> participationList = new ArrayList<>();
                     if(inchargerCell!=null){
-                        if(participatorCell==null||StringUtils.isEmpty(participatorCell.getStringCellValue())){
-                            String value = inchargerCell.getStringCellValue();
-                            Participation p = new Participation();
-                            Optional<User> first = userList.stream().filter(u -> u.getName().equals(value)).findFirst();
-                            if (first.isPresent()) {
-                                participationMapper.delete(new QueryWrapper<Participation>().eq("project_id",project.getId()));
-                                p.setUserId(first.get().getId());
-                                p.setProjectId(project.getId());
-                                participationMapper.insert(p);
-                            } else {
-                                throw new Exception("参与人["+value+"]不存在");
-                            }
+                        String value = inchargerCell.getStringCellValue();
+                        Participation p = new Participation();
+                        Optional<User> first = userList.stream().filter(u -> u.getName().equals(value)).findFirst();
+                        if (first.isPresent()) {
+                            p.setUserId(first.get().getId());
+                            p.setProjectId(project.getId());
+                            participationList.add(p);
+                        } else {
+                            throw new Exception("参与人["+value+"]不存在");
                         }
                     }
                     if (participatorCell != null) {
                         String part = participatorCell.getStringCellValue().trim();
-                        //将项目负责人也添加到参与人当中来
-                        String incharger = inchargerCell.getStringCellValue().trim();
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
-                            if(!StringUtils.isEmpty(incharger)){
-                                String[] inchargerSplit = incharger.split("\\,|\\,");
-                                int strLen1 = partSplit.length;// 保存第一个数组长度
-                                int strLen2 = inchargerSplit.length;
-                                partSplit=Arrays.copyOf(partSplit, strLen1+strLen2);
-                                System.arraycopy(inchargerSplit, 0, partSplit, strLen1, strLen2);
-                            }
                             for (String str : partSplit) {
                                 Participation p = new Participation();
                                 Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
                                 if (first.isPresent()) {
-                                    participationMapper.delete(new QueryWrapper<Participation>().eq("project_id",project.getId()));
-                                    p.setUserId(first.get().getId());
-                                    p.setProjectId(project.getId());
-                                    participationMapper.insert(p);
+                                    User partMemb = first.get();
+//                                    System.out.println("参与人:"+partMemb.getName());
+                                    if (!participationList.stream().anyMatch(partOne->partOne.getUserId().equals(partMemb.getId()))) {
+                                        p.setUserId(partMemb.getId());
+                                        p.setProjectId(project.getId());
+                                        participationList.add(p);
+                                    }
                                 } else {
                                     throw new Exception("参与人["+str+"]不存在");
                                 }
                             }
                         }
                     }
+                    if (participationList.size() > 0) {
+                        //批量保存
+                        List<Participation> finalOldPartList = oldPartList;
+                        List<Participation> addPartList = participationList.stream().filter(newP-> !finalOldPartList.stream().anyMatch(oldP->oldP.getUserId().equals(newP.getUserId()))).collect(Collectors.toList());
+                        if (addPartList.size() > 0) {
+                            participationService.saveBatch(addPartList);
+                        }
+                    }
                 }
                 msg.data = "成功导入"+importCount+"条数据。";
                 if (existCodeList.size() > 0) {
@@ -6218,6 +6226,15 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return httpRespMsg;
     }
 
+    @Override
+    public HttpRespMsg fixParticipators(Integer companyId, HttpServletRequest request) {
+        //获取全部的分组参与人
+
+        groupParticipatorMapper.selectList(new QueryWrapper<>());
+
+        return null;
+    }
+
 
     private List<Department> getSubDepts(Department dp, List<Department> list) {
         List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());