|
@@ -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;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -2945,51 +2946,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 +3799,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 +6227,48 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg fixParticipators(Integer companyId, HttpServletRequest request) {
|
|
|
+ //获取全部的分组参与人
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private List<Department> getSubDepts(Department dp, List<Department> list) {
|
|
|
List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());
|