mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 05:29:29 +08:00
refactor: 删除无用接口、修改变量命名
This commit is contained in:
parent
291116755c
commit
65d60bc182
@ -110,15 +110,9 @@ public class UserController {
|
||||
userService.updateCurrentUserByResourceId(resourceId);
|
||||
}
|
||||
|
||||
@PostMapping("/switch/source/org/{sourceId}")
|
||||
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("organization", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/switch/source/ws/{sourceId}")
|
||||
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("workspace", sourceId);
|
||||
userService.switchUserResource("workspace", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
|
@ -24,18 +24,18 @@ public class UserGroupService {
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserGroup> userGroups = userGroupMapper.selectByExample(userRoleExample);
|
||||
List<String> collect = userGroups.stream()
|
||||
.map(userRole -> userRole.getGroupId())
|
||||
.map(UserGroup::getGroupId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
for (int i = 0; i < collect.size(); i++) {
|
||||
for (String id : collect) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("id", collect.get(i));
|
||||
map.put("id", id);
|
||||
map.put("ids", new ArrayList<>());
|
||||
for (int j = 0; j < userGroups.size(); j++) {
|
||||
String role = userGroups.get(j).getGroupId();
|
||||
if (StringUtils.equals(role, collect.get(i))) {
|
||||
for (UserGroup userGroup : userGroups) {
|
||||
String groupId = userGroup.getGroupId();
|
||||
if (StringUtils.equals(groupId, id)) {
|
||||
List ids = (List) map.get("ids");
|
||||
ids.add(userGroups.get(j).getSourceId());
|
||||
ids.add(userGroup.getSourceId());
|
||||
}
|
||||
}
|
||||
list.add(map);
|
||||
|
@ -107,22 +107,20 @@ public class UserService {
|
||||
return extUserMapper.queryName();
|
||||
}
|
||||
|
||||
public UserDTO insert(UserRequest user) {
|
||||
checkUserParam(user);
|
||||
//
|
||||
String id = user.getId();
|
||||
User user1 = userMapper.selectByPrimaryKey(id);
|
||||
if (user1 != null) {
|
||||
public UserDTO insert(UserRequest userRequest) {
|
||||
checkUserParam(userRequest);
|
||||
String id = userRequest.getId();
|
||||
User user = userMapper.selectByPrimaryKey(id);
|
||||
if (user != null) {
|
||||
MSException.throwException(Translator.get("user_id_already_exists"));
|
||||
} else {
|
||||
createUser(user);
|
||||
createUser(userRequest);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> groups = user.getGroups();
|
||||
List<Map<String, Object>> groups = userRequest.getGroups();
|
||||
if (!groups.isEmpty()) {
|
||||
insertUserGroup(groups, user.getId());
|
||||
insertUserGroup(groups, userRequest.getId());
|
||||
}
|
||||
return getUserDTO(user.getId());
|
||||
return getUserDTO(userRequest.getId());
|
||||
}
|
||||
|
||||
public void insertUserGroup(List<Map<String, Object>> groups, String userId) {
|
||||
@ -385,14 +383,13 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
public void switchUserRole(String sign, String sourceId) {
|
||||
public void switchUserResource(String sign, String sourceId) {
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
// 获取最新UserDTO
|
||||
UserDTO user = getUserDTO(sessionUser.getId());
|
||||
User newUser = new User();
|
||||
|
||||
if (StringUtils.equals("workspace", sign)) {
|
||||
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);
|
||||
user.setLastWorkspaceId(sourceId);
|
||||
List<Project> projects = getProjectListByWsAndUserId(sourceId);
|
||||
if (projects.size() > 0) {
|
||||
@ -417,15 +414,13 @@ public class UserService {
|
||||
userGroupExample.createCriteria().andUserIdEqualTo(useId);
|
||||
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
|
||||
List<Project> projectList = new ArrayList<>();
|
||||
userGroups.forEach(userGroup -> {
|
||||
projects.forEach(project -> {
|
||||
if (StringUtils.equals(userGroup.getSourceId(), project.getId())) {
|
||||
if (!projectList.contains(project)) {
|
||||
projectList.add(project);
|
||||
}
|
||||
userGroups.forEach(userGroup -> projects.forEach(project -> {
|
||||
if (StringUtils.equals(userGroup.getSourceId(), project.getId())) {
|
||||
if (!projectList.contains(project)) {
|
||||
projectList.add(project);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
return projectList;
|
||||
}
|
||||
|
||||
@ -632,7 +627,7 @@ public class UserService {
|
||||
.collect(Collectors.toList());
|
||||
if (workspaces.size() > 0) {
|
||||
String wsId = workspaces.get(0).getSourceId();
|
||||
switchUserRole("workspace", wsId);
|
||||
switchUserResource("workspace", wsId);
|
||||
}
|
||||
} else {
|
||||
UserGroup userGroup = project.stream().filter(p -> StringUtils.isNotBlank(p.getSourceId()))
|
||||
@ -952,7 +947,6 @@ public class UserService {
|
||||
if (CollectionUtils.isEmpty(userGroups)) {
|
||||
return userGroupPermissionDTO;
|
||||
}
|
||||
// 设置 user_role
|
||||
userGroupPermissionDTO.setUserGroups(userGroups);
|
||||
|
||||
List<String> groupId = userGroups.stream().map(UserGroup::getGroupId).collect(Collectors.toList());
|
||||
@ -1088,24 +1082,27 @@ public class UserService {
|
||||
}
|
||||
|
||||
public void addProjectMember(AddMemberRequest request) {
|
||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
UserGroupExample userGroupExample = new UserGroupExample();
|
||||
userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getProjectId());
|
||||
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
|
||||
if (userGroups.size() > 0) {
|
||||
MSException.throwException(Translator.get("user_already_exists"));
|
||||
} else {
|
||||
for (String groupId : request.getGroupIds()) {
|
||||
UserGroup userGroup = new UserGroup();
|
||||
userGroup.setGroupId(groupId);
|
||||
userGroup.setSourceId(request.getProjectId());
|
||||
userGroup.setUserId(userId);
|
||||
userGroup.setId(UUID.randomUUID().toString());
|
||||
userGroup.setUpdateTime(System.currentTimeMillis());
|
||||
userGroup.setCreateTime(System.currentTimeMillis());
|
||||
userGroupMapper.insertSelective(userGroup);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
LogUtil.info("add project member warning, request param user id list empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String userId : request.getUserIds()) {
|
||||
UserGroupExample userGroupExample = new UserGroupExample();
|
||||
userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getProjectId());
|
||||
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
|
||||
if (userGroups.size() > 0) {
|
||||
MSException.throwException(Translator.get("user_already_exists"));
|
||||
} else {
|
||||
for (String groupId : request.getGroupIds()) {
|
||||
UserGroup userGroup = new UserGroup();
|
||||
userGroup.setGroupId(groupId);
|
||||
userGroup.setSourceId(request.getProjectId());
|
||||
userGroup.setUserId(userId);
|
||||
userGroup.setId(UUID.randomUUID().toString());
|
||||
userGroup.setUpdateTime(System.currentTimeMillis());
|
||||
userGroup.setCreateTime(System.currentTimeMillis());
|
||||
userGroupMapper.insertSelective(userGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user