成员管理后端接口
This commit is contained in:
parent
dac30f47a5
commit
a086e80574
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.base.mapper.ext;
|
||||
|
||||
import io.metersphere.base.domain.User;
|
||||
import io.metersphere.controller.request.member.QueryMemberRequest;
|
||||
import io.metersphere.dto.UserRoleHelpDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -8,4 +10,6 @@ import java.util.List;
|
|||
public interface ExtUserRoleMapper {
|
||||
|
||||
List<UserRoleHelpDTO> getUserRoleHelpList(@Param("userId") String userId);
|
||||
|
||||
List<User> getMemberList(@Param("member") QueryMemberRequest request);
|
||||
}
|
||||
|
|
|
@ -27,4 +27,9 @@
|
|||
WHERE user_role.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="getMemberList" resultType="io.metersphere.base.domain.User">
|
||||
SELECT `user`.* FROM user_role JOIN `user` ON user_role.user_id = `user`.id
|
||||
WHERE user_role.source_id = #{member.workspaceId} AND user_role.role_id = #{member.roleId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,14 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum RoleConstants {
|
||||
ADMIN("admin"), ORGADMIN("org_admin"), TESTUSER("test_user"), TESTVIEWER("test_viewer"), TESTMANAGER("test_manager");
|
||||
private String value;
|
||||
|
||||
RoleConstants(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,19 @@
|
|||
package io.metersphere.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.base.domain.Role;
|
||||
import io.metersphere.base.domain.User;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.controller.request.member.AddMemberRequest;
|
||||
import io.metersphere.controller.request.member.QueryMemberRequest;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.dto.UserRoleDTO;
|
||||
import io.metersphere.service.UserService;
|
||||
import io.metersphere.user.SessionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -23,13 +30,19 @@ public class UserController {
|
|||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public List<User> getUserList() { return userService.getUserList(); }
|
||||
public List<User> getUserList() {
|
||||
return userService.getUserList();
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{userId}")
|
||||
public void deleteUser(@PathVariable(value = "userId") String userId) { userService.deleteUser(userId); }
|
||||
public void deleteUser(@PathVariable(value = "userId") String userId) {
|
||||
userService.deleteUser(userId);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public void updateUser(@RequestBody User user) { userService.updateUser(user); }
|
||||
public void updateUser(@RequestBody User user) {
|
||||
userService.updateUser(user);
|
||||
}
|
||||
|
||||
@GetMapping("/role/list/{userId}")
|
||||
public List<Role> getUserRolesList(@PathVariable(value = "userId") String userId) {
|
||||
|
@ -42,7 +55,7 @@ public class UserController {
|
|||
}
|
||||
|
||||
@PostMapping("/switch/source/{sourceId}")
|
||||
public void switchUserRole(@PathVariable (value = "sourceId") String sourceId) {
|
||||
public void switchUserRole(@PathVariable(value = "sourceId") String sourceId) {
|
||||
UserDTO user = SessionUtils.getUser();
|
||||
userService.switchUserRole(user, sourceId);
|
||||
}
|
||||
|
@ -51,4 +64,30 @@ public class UserController {
|
|||
public User getUserInfo(@PathVariable(value = "userId") String userId) {
|
||||
return userService.getUserInfo(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取成员用户
|
||||
*/
|
||||
@PostMapping("/member/list/{goPage}/{pageSize}")
|
||||
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加成员
|
||||
*/
|
||||
@PostMapping("/member/add")
|
||||
public void addMember(@RequestBody AddMemberRequest request) {
|
||||
userService.addMember(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除成员
|
||||
*/
|
||||
@GetMapping("/member/delete/{workspaceId}/{userId}")
|
||||
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||
userService.deleteMember(workspaceId, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package io.metersphere.controller.request.member;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddMemberRequest {
|
||||
|
||||
private String workspaceId;
|
||||
|
||||
private List<String> userIds;
|
||||
|
||||
public String getWorkspaceId() {
|
||||
return workspaceId;
|
||||
}
|
||||
|
||||
public void setWorkspaceId(String workspaceId) {
|
||||
this.workspaceId = workspaceId;
|
||||
}
|
||||
|
||||
public List<String> getUserIds() {
|
||||
return userIds;
|
||||
}
|
||||
|
||||
public void setUserIds(List<String> userIds) {
|
||||
this.userIds = userIds;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.controller.request.member;
|
||||
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
|
||||
public class QueryMemberRequest {
|
||||
private String workspaceId;
|
||||
private String roleId = RoleConstants.TESTMANAGER.getValue();
|
||||
|
||||
public String getWorkspaceId() {
|
||||
return workspaceId;
|
||||
}
|
||||
|
||||
public void setWorkspaceId(String workspaceId) {
|
||||
this.workspaceId = workspaceId;
|
||||
}
|
||||
}
|
|
@ -6,9 +6,11 @@ import io.metersphere.base.mapper.RoleMapper;
|
|||
import io.metersphere.base.mapper.UserMapper;
|
||||
import io.metersphere.base.mapper.UserRoleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.controller.request.member.AddMemberRequest;
|
||||
import io.metersphere.controller.request.member.QueryMemberRequest;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.dto.UserOperateDTO;
|
||||
import io.metersphere.dto.UserRoleDTO;
|
||||
import io.metersphere.dto.UserRoleHelpDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -223,4 +225,31 @@ public class UserService {
|
|||
public User getUserInfo(String userId) {
|
||||
return userMapper.selectByPrimaryKey(userId);
|
||||
}
|
||||
|
||||
public List<User> getMemberList(QueryMemberRequest request) {
|
||||
return extUserRoleMapper.getMemberList(request);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addMember(AddMemberRequest request) {
|
||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setRoleId(RoleConstants.TESTMANAGER.getValue());
|
||||
userRole.setSourceId(request.getWorkspaceId());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteMember(String workspaceId, String userId) {
|
||||
UserRoleExample example = new UserRoleExample();
|
||||
example.createCriteria().andRoleIdEqualTo(RoleConstants.TESTMANAGER.getValue())
|
||||
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
|
||||
userRoleMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue