|
@@ -1502,10 +1502,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
.eq(ProjectDeptRelate::getDepartmentId, departmentId)
|
|
|
);
|
|
|
List<Integer> originalProjectIds = oldProjectDeptRelates.stream().map(ProjectDeptRelate::getProjectId).collect(Collectors.toList());
|
|
|
- participationMapper.delete(new LambdaQueryWrapper<Participation>()
|
|
|
- .eq(Participation::getUserId,targetId)
|
|
|
- .in(Participation::getProjectId,originalProjectIds)
|
|
|
- );
|
|
|
+ if(CollectionUtils.isNotEmpty(originalProjectIds)){
|
|
|
+ participationMapper.delete(new LambdaQueryWrapper<Participation>()
|
|
|
+ .eq(Participation::getUserId,targetId)
|
|
|
+ .in(Participation::getProjectId,originalProjectIds)
|
|
|
+ );
|
|
|
+ }
|
|
|
List<Participation> toAddList = new ArrayList<>(newProjectDeptRelates.size());
|
|
|
for (ProjectDeptRelate relate : newProjectDeptRelates) {
|
|
|
Participation participation = new Participation();
|
|
@@ -1513,7 +1515,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
participation.setUserId(targetId);
|
|
|
toAddList.add(participation);
|
|
|
}
|
|
|
- participationMapper.insertBatch(toAddList);
|
|
|
+ if(CollectionUtils.isNotEmpty(toAddList)){
|
|
|
+ participationMapper.insertBatch(toAddList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
userMapper.updateById(oldUser
|
|
@@ -2481,13 +2485,58 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
String deptCascade = deptId == null ?
|
|
|
convertDepartmentIdToCascade(0) :
|
|
|
convertDepartmentIdToCascade(deptId);
|
|
|
- for (String id : array) {
|
|
|
+ List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
+ .in(User::getId, array)
|
|
|
+ );
|
|
|
+ List<Integer> oldDeptIds = users.stream().map(User::getDepartmentId).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ProjectDeptRelate> projectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .in(ProjectDeptRelate::getDepartmentId, oldDeptIds)
|
|
|
+ );
|
|
|
+ Map<Integer, List<ProjectDeptRelate>> relateMap = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(projectDeptRelates)){
|
|
|
+ //涉及到项目关联的原部门相关的参与人要删除
|
|
|
+ relateMap = projectDeptRelates.stream()
|
|
|
+ .collect(Collectors.groupingBy(ProjectDeptRelate::getDepartmentId));
|
|
|
+ }
|
|
|
+ for (User user : users) {
|
|
|
+ //删除该员工原部门关联的项目
|
|
|
+ List<ProjectDeptRelate> tmpRelates = relateMap.get(user.getDepartmentId());
|
|
|
+ if(CollectionUtils.isNotEmpty(tmpRelates)){
|
|
|
+ participationMapper.delete(new LambdaQueryWrapper<Participation>()
|
|
|
+ .eq(Participation::getUserId,user.getId())
|
|
|
+ .in(Participation::getProjectId,tmpRelates.stream().map(ProjectDeptRelate::getProjectId).collect(Collectors.toList()))
|
|
|
+ );
|
|
|
+ }
|
|
|
User u = new User();
|
|
|
- u.setId(id);
|
|
|
+ u.setId(user.getId());
|
|
|
u.setDepartmentId(deptId==null?0:deptId);
|
|
|
u.setDepartmentCascade(deptCascade);
|
|
|
userList.add(u);
|
|
|
}
|
|
|
+ //查看新部门关联的项目,向这些项目中插入这些人
|
|
|
+ List<ProjectDeptRelate> newDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, deptId)
|
|
|
+ );
|
|
|
+ if(CollectionUtils.isNotEmpty(newDeptRelates)){
|
|
|
+ List<Participation> toAddList = new ArrayList<>();
|
|
|
+ for (ProjectDeptRelate newDeptRelate : newDeptRelates) {
|
|
|
+ users.forEach(tmpUser->{
|
|
|
+ Participation participation = new Participation();
|
|
|
+ participation.setUserId(tmpUser.getId());
|
|
|
+ participation.setProjectId(newDeptRelate.getProjectId());
|
|
|
+ toAddList.add(participation);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ participationMapper.insertBatch(toAddList);
|
|
|
+ }
|
|
|
+// for (String id : array) {
|
|
|
+// User u = new User();
|
|
|
+// u.setId(id);
|
|
|
+// u.setDepartmentId(deptId==null?0:deptId);
|
|
|
+// u.setDepartmentCascade(deptCascade);
|
|
|
+// userList.add(u);
|
|
|
+// }
|
|
|
updateBatchById(userList);
|
|
|
} else {
|
|
|
//msg.setError("人员不能为空");
|