Selaa lähdekoodia

修复任务分组的负责人+参与人不在项目参与人中的数据问题

seyason 2 vuotta sitten
vanhempi
commit
0716632cae

+ 38 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -47,6 +47,7 @@ import java.time.chrono.ChronoLocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 /**
@@ -6229,10 +6230,43 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     @Override
     public HttpRespMsg fixParticipators(Integer companyId, HttpServletRequest request) {
         //获取全部的分组参与人
-
-        groupParticipatorMapper.selectList(new QueryWrapper<>());
-
-        return null;
+        List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").eq("company_id", companyId));
+        List<Integer> collect = projectList.stream().map(Project::getId).collect(Collectors.toList());
+        List<TaskGroup> groupList = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().in("project_id", collect));
+        List<Integer> groupIds = groupList.stream().map(TaskGroup::getId).collect(Collectors.toList());
+        List<GroupParticipator> groupParticipatorList = groupParticipatorMapper.selectList(new QueryWrapper<GroupParticipator>().in("group_id", groupIds).isNotNull("user_id"));
+        List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().in("project_id", collect));
+        List<Participation> addPartList = new ArrayList<>();
+        //过滤出不在项目参与人中的分组参与人
+        for (Project p : projectList) {
+            List<TaskGroup> curGroups = groupList.stream().filter(g -> g.getProjectId().equals(p.getId())).collect(Collectors.toList());
+            List<String> groupInchargerList = curGroups.stream().map(TaskGroup::getInchargerId).collect(Collectors.toList());
+            List<Integer> curGroupIds = curGroups.stream().map(TaskGroup::getId).collect(Collectors.toList());
+            //取到当前这个项目的分组的参与人
+            List<GroupParticipator> curGParticipatorList = groupParticipatorList.stream().filter(gp -> curGroupIds.stream().anyMatch(curG -> curG.equals(gp.getGroupId()))).collect(Collectors.toList());
+            //当前这个项目的参与人
+            List<Participation> projectParticiList = participationList.stream().filter(part -> part.getProjectId().equals(p.getId())).collect(Collectors.toList());
+            //分组的参与人不在项目参与人中的
+            List<String> gpNotInList = curGParticipatorList.stream().filter(gp -> !StringUtils.isEmpty(gp.getUserId()) && !projectParticiList.stream().anyMatch(proPart -> proPart.getUserId().equals(gp.getUserId()))).map(GroupParticipator::getUserId).collect(Collectors.toList());
+            //分组负责人不在项目参与人里面的
+            List<String> inchargerNotInList = groupInchargerList.stream().filter(gi -> !StringUtils.isEmpty(gi) && !projectParticiList.stream().anyMatch(proPart -> proPart.getUserId().equals(gi))).collect(Collectors.toList());
+            //做个排重
+            gpNotInList.addAll(inchargerNotInList);
+            gpNotInList.stream().distinct().forEach(membId->{
+                Participation one = new Participation();
+                one.setProjectId(p.getId());
+                one.setUserId(membId);
+                System.out.println("添加="+one.getProjectId()+","+membId);
+                addPartList.add(one);
+            });
+        }
+        HttpRespMsg msg = new HttpRespMsg();
+        if (addPartList.size() > 0) {
+            msg.data = addPartList.size();
+            participationService.saveBatch(addPartList);
+            System.out.println("需要增加的参与人数量为"+addPartList.size());
+        }
+        return msg;
     }