Skip to content

Commit

Permalink
code optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
yuankang134 committed Mar 12, 2024
1 parent 775d4d5 commit b3f0d06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void insertUserRoleInWorkspace(@Param("workspaceId") long workspaceId, @Param("r

@Select({
"<script>",
"select created_by as creator, username as username, create_time as joinTime, workspace_id as workspaceId, group_concat(DISTINCT role_id) as roleIds, update_time as updateTime, update_user as updateUser " +
"select created_by as creator, username as username, create_time as joinTime, workspace_id as workspaceId, group_concat(role_id) as roleIds, update_time as updateTime, update_user as updateUser " +
"from dss_workspace_user_role where workspace_id = #{workspaceId} ",
"<if test='username != null'>and username like concat('%',#{username},'%')</if> " + "group by username " +
"<if test='username != null'>and username like concat('%',#{username},'%')</if> " + "group by username,created_by,create_time,workspace_id,update_time,update_user " +
"<if test='roleId != null'>HAVING FIND_IN_SET(#{roleId},roleIds)</if> " +
"order by id desc",
"</script>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,24 @@ private void joinWorkspaceForNewUser(String userName, Long userId) {
String userOrgName = staffInfoGetter.getFullOrgNameByUsername(userName);
String orgName = userOrgName.split("-")[0];
List<DSSWorkspaceAssociateDepartments> workspaceAssociateDepartments = dssWorkspaceMapper.getWorkspaceAssociateDepartments();
Set<ImmutablePair<Long, String>> needToAdd = new HashSet<>();
Set<Map<Long, String>> needToAdd = new HashSet<>();
for (DSSWorkspaceAssociateDepartments item : workspaceAssociateDepartments) {
String departments = item.getDepartments();
if (StringUtils.isNotBlank(departments) && StringUtils.isNotBlank(item.getRoleIds())) {
Arrays.stream(departments.split(",")).forEach(org -> {
if (org.equals(userOrgName) || orgName.equals(org)) {
needToAdd.add(new ImmutablePair<>(item.getWorkspaceId(), item.getRoleIds()));
Map<Long, String> pair = new HashMap<>();
pair.put(item.getWorkspaceId(), item.getRoleIds());
needToAdd.add(pair);
}
});
}
}
needToAdd.forEach(pair -> {
Arrays.stream(pair.getValue().split(",")).forEach(roleId -> {
dssWorkspaceUserMapper.insertUserRoleInWorkspace(pair.getKey().intValue(), Integer.parseInt(roleId),new Date(), userName, "system", userId, "system");
needToAdd.forEach(map -> {
map.forEach((key, value) -> {
Arrays.stream(value.split(",")).forEach(roleId -> {
dssWorkspaceUserMapper.insertUserRoleInWorkspace(key.intValue(), Integer.parseInt(roleId), new Date(), userName, "system", userId, "system");
});
});
});
}
Expand Down

0 comments on commit b3f0d06

Please sign in to comment.