|
@@ -21,6 +21,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
@@ -218,6 +219,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@Resource
|
|
|
private UserReportDeptService userReportDeptService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProjectDeptRelateMapper projectDeptRelateMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private LdapTemplate ldapTemplate;
|
|
|
@Resource
|
|
@@ -1434,6 +1438,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
});
|
|
|
userReportDeptService.saveBatch(userReportDeptList);
|
|
|
}
|
|
|
+ //新增用户,查看项目部门关联表,若存在有直属部门,直接加入
|
|
|
+ if(null != departmentId && 0 != departmentId){
|
|
|
+ List<ProjectDeptRelate> projectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, departmentId)
|
|
|
+ );
|
|
|
+ if(CollectionUtils.isNotEmpty(projectDeptRelates)){
|
|
|
+ List<Participation> toAddList = new ArrayList<>(projectDeptRelates.size());
|
|
|
+ for (ProjectDeptRelate relate : projectDeptRelates) {
|
|
|
+ Participation participation = new Participation();
|
|
|
+ participation.setProjectId(relate.getProjectId());
|
|
|
+ participation.setUserId(String.valueOf(id));
|
|
|
+ toAddList.add(participation);
|
|
|
+ }
|
|
|
+ participationMapper.insertBatch(toAddList);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -1473,6 +1493,33 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
superiorChange = true;
|
|
|
}
|
|
|
|
|
|
+ //更新操作,判断前后部门是否变化,有变化则删除原部门关联项目下的该用户,新增到新部门关联的项目下
|
|
|
+ if(oldUser.getDepartmentId() != (departmentId == null ? 0 : departmentId)){
|
|
|
+ List<ProjectDeptRelate> oldProjectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, oldUser.getDepartmentId())
|
|
|
+ );
|
|
|
+ List<ProjectDeptRelate> newProjectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, departmentId)
|
|
|
+ );
|
|
|
+ List<Integer> originalProjectIds = oldProjectDeptRelates.stream().map(ProjectDeptRelate::getProjectId).collect(Collectors.toList());
|
|
|
+ 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();
|
|
|
+ participation.setProjectId(relate.getProjectId());
|
|
|
+ participation.setUserId(targetId);
|
|
|
+ toAddList.add(participation);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(toAddList)){
|
|
|
+ participationMapper.insertBatch(toAddList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
userMapper.updateById(oldUser
|
|
|
.setName(name)
|
|
|
.setPhone(phone)
|
|
@@ -1813,7 +1860,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
httpRespMsg.setError(MessageUtils.message("register.phoneUsed")+":" + userPhoneList.stream().filter(u->!u.getCompanyId().equals(companyId)).map(User::getPhone).collect(Collectors.joining(",")));
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
-
|
|
|
+ List<User> existUsers= new ArrayList<>();
|
|
|
+ List<User> unExistUsers = new ArrayList<>();
|
|
|
for (User oldUser : userPhoneList) {
|
|
|
for (User newUser : userList) {
|
|
|
if (oldUser.getPhone().equals(newUser.getPhone())) {
|
|
@@ -1825,12 +1873,75 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
.setMonthCost(null)
|
|
|
.setCost(null)
|
|
|
.setSalaryType(null);
|
|
|
+ existUsers.add(newUser);
|
|
|
break;
|
|
|
+ }else{
|
|
|
+ if(null != newUser.getDepartmentId() && 0 != newUser.getDepartmentId()){
|
|
|
+ unExistUsers.add(newUser);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //已存在的用户中查看部门是否有变化,变化则删除原部门关联项目的参与人,新增新部门关联项目
|
|
|
+ List<Participation> toAddList = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(existUsers)){
|
|
|
+ List<Integer> collect = existUsers.stream().map(User::getDepartmentId).collect(Collectors.toList());
|
|
|
+ Map<String, User> existMap = existUsers.stream().collect(Collectors.toMap(User::getId, t -> t));
|
|
|
+ List<User> oldDeptCheckUsers = userMapper.selectList(new LambdaQueryWrapper<User>().in(User::getId, collect)
|
|
|
+ .ne(User::getDepartmentId,0)
|
|
|
+ );
|
|
|
+ for (User oldDeptCheckUser : oldDeptCheckUsers) {
|
|
|
+ User user = existMap.get(oldDeptCheckUser.getId());
|
|
|
+ if(null != user && null != user.getDepartmentId() && 0!= user.getDepartmentId()){
|
|
|
+ if(!Objects.equals(oldDeptCheckUser.getDepartmentId(), user.getDepartmentId())){
|
|
|
+ List<ProjectDeptRelate> oldProjectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, oldDeptCheckUser.getDepartmentId())
|
|
|
+ );
|
|
|
+ List<ProjectDeptRelate> newProjectDeptRelates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, user.getDepartmentId())
|
|
|
+ );
|
|
|
+ List<Integer> originalProjectIds = oldProjectDeptRelates.stream().map(ProjectDeptRelate::getProjectId).collect(Collectors.toList());
|
|
|
+ participationMapper.delete(new LambdaQueryWrapper<Participation>()
|
|
|
+ .eq(Participation::getUserId,user.getId())
|
|
|
+ .in(Participation::getProjectId,originalProjectIds)
|
|
|
+ );
|
|
|
+ for (ProjectDeptRelate relate : newProjectDeptRelates) {
|
|
|
+ Participation participation = new Participation();
|
|
|
+ participation.setProjectId(relate.getProjectId());
|
|
|
+ participation.setUserId(user.getId());
|
|
|
+ toAddList.add(participation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //原先不存在用户直接往新部门关联项目中添加
|
|
|
+ if(CollectionUtils.isNotEmpty(unExistUsers)){
|
|
|
+ for (User unExistUser : unExistUsers) {
|
|
|
+ List<ProjectDeptRelate> relates = projectDeptRelateMapper.selectList(new LambdaQueryWrapper<ProjectDeptRelate>()
|
|
|
+ .eq(ProjectDeptRelate::getDepartmentId, unExistUser.getDepartmentId())
|
|
|
+ );
|
|
|
+ for (ProjectDeptRelate relate : relates) {
|
|
|
+ Participation participation = new Participation();
|
|
|
+ participation.setUserId(unExistUser.getId());
|
|
|
+ participation.setProjectId(relate.getProjectId());
|
|
|
+ toAddList.add(participation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(toAddList)){
|
|
|
+ toAddList = toAddList.stream().distinct().collect(Collectors.toList());
|
|
|
+ participationMapper.insertBatch(toAddList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
saveOrUpdateBatch(userList);
|
|
|
+
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -2374,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("人员不能为空");
|