1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
public void updatePdmProjMemberGroups(
String userId, String tenantId, UpdatePdmProjMemberGroupsRequest request) {
// todo 检查projectId是否存在
Map<String, PdmProjMemberGroup> projectGroupIdToProjectMemberGroupMap =
getProjectGroupIdToProjectMemberGroupMap(request.getProjectId(), tenantId);
List<CreatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO> toAdd = new ArrayList<>();
List<UpdatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO> toUpdate = new ArrayList<>();
List<String> toDelete = new ArrayList<>(projectGroupIdToProjectMemberGroupMap.keySet());
// 如果传递的请求中包含Id则进行更新, 否则进行添加
for (UpdatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO groupInfo : request.getGroupInfos()) {
if (StringUtils.isBlank(groupInfo.getProjectGroupId())) {
// 完成参数转换,方便接下来复用已有方法
toAdd.add(BeanUtil.copyProperties(groupInfo,
CreatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO.class));
} else {
// 查看用户传递的Id是否已经在数据库中存在
if (!projectGroupIdToProjectMemberGroupMap.containsKey(groupInfo.getProjectGroupId())) {
throw new RuntimeException("Wrong");
}
toUpdate.add(groupInfo);
toDelete.remove(groupInfo.getProjectGroupId());
}
}
// 新增
if (toAdd.size() != 0) {
createPdmProjMemberGroups(userId, tenantId, request.getProjectId(), toAdd);
}
// 删除
if (toDelete.size() != 0) {
// 删除成员信息
deleteProjectMembersByProjectIdAndTenantId(
request.getProjectId(), toDelete, tenantId);
// 删除分组信息
deleteProjectMemberGroupsByProjectIdAndTenantId(
request.getProjectId(), toDelete, tenantId);
}
// 修改(成员信息直接删除重建,分组信息进行更新)
if (toUpdate.size() != 0) {
deleteProjectMembersByProjectIdAndTenantId(
request.getProjectId(),
toUpdate.stream()
.map(UpdatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO::getProjectGroupId)
.collect(Collectors.toList()),
tenantId);
for (UpdatePdmProjMemberGroupsRequest.PdmProjMemberGroupDTO groupInfo : toUpdate) {
PdmProjMemberGroup pdmProjMemberGroup =
projectGroupIdToProjectMemberGroupMap.get(groupInfo.getProjectGroupId());
PdmProjMemberGroup pdmProjMemberGroupUpdate = PdmProjMemberGroup.builder()
.id(pdmProjMemberGroup.getId())
.modifier(userId)
.gmtModifyTime(LocalDateTime.now())
.name((JSONObject) JSONObject.toJSON(groupInfo.getName()))
.build();
pdmProjMemberGroupMapper.updateById(pdmProjMemberGroupUpdate);
// 重新插入成员信息
createProjectMembersBatch(userId, tenantId,
request.getProjectId(), groupInfo.getProjectGroupId(),
groupInfo.getUserIds());
}
}
}
|