1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package cn.fateverse.admin.dto;
|
||||
|
||||
import cn.fateverse.common.core.entity.UserBase;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@@ -83,8 +83,8 @@ public class UserDto{
|
||||
private List<Long> roleIds;
|
||||
|
||||
|
||||
public UserBase toUser() {
|
||||
return UserBase.builder()
|
||||
public User toUser() {
|
||||
return User.builder()
|
||||
.userId(userId)
|
||||
.deptId(deptId)
|
||||
.userName(userName)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.fateverse.admin.dubbo;
|
||||
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,7 +18,7 @@ public interface DubboUserService {
|
||||
* @param username 用户名称
|
||||
* @return 用户信息
|
||||
*/
|
||||
User getUserByUsername(String username);
|
||||
UserVo getUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据用户id查询用户信息
|
||||
@@ -25,7 +26,7 @@ public interface DubboUserService {
|
||||
* @param userId 用户id
|
||||
* @return 用户信息
|
||||
*/
|
||||
User getUserByUserId(Long userId);
|
||||
UserVo getUserByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据roleId查询用户列表
|
||||
@@ -57,4 +58,12 @@ public interface DubboUserService {
|
||||
* @return 所有用户的id
|
||||
*/
|
||||
List<Long> searchAllUserIds();
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户详细信息
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return {@link UserDetails }
|
||||
*/
|
||||
UserDetail getUserDetailsByUserName(String userName);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.fateverse.admin.vo;
|
||||
|
||||
import cn.fateverse.admin.entity.Role;
|
||||
import cn.fateverse.admin.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.fateverse.admin.vo;
|
||||
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
@@ -14,11 +14,10 @@ import java.util.List;
|
||||
* @date 2022/11/4
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@ApiModel("用户详细信息")
|
||||
public class UserDetailVo {
|
||||
@ApiModelProperty("用户基本细腻系")
|
||||
private User user;
|
||||
private UserDetail user;
|
||||
|
||||
@ApiModelProperty("用户所在的岗位")
|
||||
private List<Long> postIds;
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.fateverse.admin.controller;
|
||||
import cn.fateverse.admin.dto.RoleDto;
|
||||
import cn.fateverse.admin.entity.Role;
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.admin.facade.RoleFacade;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.common.core.entity.IdWrapper;
|
||||
@@ -23,6 +24,7 @@ import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -38,30 +40,21 @@ import java.util.Set;
|
||||
@Api(tags = "角色管理")
|
||||
@RestController
|
||||
@RequestMapping("/role")
|
||||
@RequiredArgsConstructor
|
||||
public class RoleController {
|
||||
|
||||
|
||||
private final RoleService roleService;
|
||||
|
||||
private final RoleFacade roleFacade;
|
||||
private final UserService userService;
|
||||
|
||||
private final MenuService menuService;
|
||||
|
||||
private final TokenService tokenService;
|
||||
|
||||
public RoleController(RoleService roleService, UserService userService, MenuService menuService, TokenService tokenService) {
|
||||
this.roleService = roleService;
|
||||
this.userService = userService;
|
||||
this.menuService = menuService;
|
||||
this.tokenService = tokenService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取角色列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('admin:role:list')")
|
||||
public Result<TableDataInfo<RoleVo>> list(RoleQuery query) {
|
||||
TableDataInfo<RoleVo> dataInfo = roleService.searchList(query);
|
||||
TableDataInfo<RoleVo> dataInfo = roleFacade.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@@ -70,30 +63,30 @@ public class RoleController {
|
||||
@GetMapping("/{roleId}")
|
||||
@PreAuthorize("@ss.hasPermission('admin:role:info')")
|
||||
public Result<RoleVo> info(@PathVariable Long roleId) {
|
||||
checkRoleId(roleId);
|
||||
RoleVo vo = roleService.searchById(roleId);
|
||||
RoleVo vo = roleFacade.searchById(roleId);
|
||||
return Result.ok(vo);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据菜单id获取角色列表")
|
||||
@GetMapping("/menu/list")
|
||||
public Result<TableDataInfo<RoleVo>> roleExcludeMenuId(Long menuId, String roleName, String roleKey) {
|
||||
if (ObjectUtils.isEmpty(menuId)) {
|
||||
return Result.error("菜单id不能为空!");
|
||||
}
|
||||
TableDataInfo<RoleVo> dataInfo = roleService.searchListExcludeMenuId(menuId, roleName, roleKey);
|
||||
public Result<TableDataInfo<RoleVo>> roleExcludeMenuId(@RequestParam Long menuId,
|
||||
@RequestParam String roleName,
|
||||
@RequestParam String roleKey) {
|
||||
TableDataInfo<RoleVo> dataInfo = roleFacade.searchListExcludeMenuId(menuId, roleName, roleKey);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据菜单id获取分配的角色信息")
|
||||
@GetMapping("/menu")
|
||||
public Result<TableDataInfo<RoleVo>> menuRole(Long menuId, String roleName, String roleKey) {
|
||||
public Result<TableDataInfo<RoleVo>> menuRole(@RequestParam Long menuId,
|
||||
@RequestParam String roleName,
|
||||
@RequestParam String roleKey) {
|
||||
if (ObjectUtils.isEmpty(menuId)) {
|
||||
return Result.error("菜单id不能为空!");
|
||||
}
|
||||
TableDataInfo<RoleVo> dataInfo = roleService.searchListByMenuId(menuId, roleName, roleKey);
|
||||
TableDataInfo<RoleVo> dataInfo = roleFacade.searchListByMenuId(menuId, roleName, roleKey);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@@ -105,7 +98,7 @@ public class RoleController {
|
||||
public Result<Void> bindRole(@RequestBody IdWrapper wrapper) {
|
||||
checkRoleIds(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
|
||||
roleService.bindMenu(wrapper.getId(), wrapper.getIds());
|
||||
roleFacade.bindMenu(wrapper.getId(), wrapper.getIds());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -117,7 +110,7 @@ public class RoleController {
|
||||
public Result<Void> unBindMenu(@RequestBody IdWrapper wrapper) {
|
||||
checkRoleIds(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
|
||||
roleService.unBindMenu(wrapper.getId(), wrapper.getIds());
|
||||
roleFacade.unBindMenu(wrapper.getId(), wrapper.getIds());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -127,7 +120,7 @@ public class RoleController {
|
||||
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> unBindAllMenu(@RequestBody IdWrapper wrapper) {
|
||||
LongUtils.checkId(wrapper.getId(), "菜单id不能为空");
|
||||
roleService.unBindAllMenu(wrapper.getId());
|
||||
roleFacade.unBindAllMenu(wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -135,7 +128,7 @@ public class RoleController {
|
||||
@ApiOperation("查询角色信息")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option() {
|
||||
List<Option> option = roleService.searchOption();
|
||||
List<Option> option = roleFacade.searchOption();
|
||||
return Result.ok(option);
|
||||
}
|
||||
|
||||
@@ -146,7 +139,7 @@ public class RoleController {
|
||||
@PreAuthorize("@ss.hasPermission('admin:role:add')")
|
||||
public Result<Void> add(@RequestBody @Validated RoleDto role) {
|
||||
checkNameAndKey(role);
|
||||
roleService.save(role);
|
||||
roleFacade.save(role);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -157,7 +150,7 @@ public class RoleController {
|
||||
public Result<Void> edit(@NotNull @RequestBody @Validated RoleDto role) {
|
||||
checkRoleId(role.getRoleId());
|
||||
checkNameAndKey(role);
|
||||
roleService.edit(role);
|
||||
roleFacade.edit(role);
|
||||
checkUserRoleUpdate(role);
|
||||
return Result.ok();
|
||||
}
|
||||
@@ -173,7 +166,7 @@ public class RoleController {
|
||||
if (StrUtil.isEmpty(role.getState())) {
|
||||
return Result.error("状态不能为空!");
|
||||
}
|
||||
roleService.editState(role.getRoleId(), role.getState());
|
||||
roleFacade.editState(role.getRoleId(), role.getState());
|
||||
checkUserRoleUpdate(role);
|
||||
return Result.ok();
|
||||
}
|
||||
@@ -185,7 +178,7 @@ public class RoleController {
|
||||
@PreAuthorize("@ss.hasPermission('admin:role:del')")
|
||||
public Result<Void> delete(@PathVariable Long roleId) {
|
||||
checkRoleId(roleId);
|
||||
roleService.remove(roleId);
|
||||
roleFacade.remove(roleId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -213,10 +206,10 @@ public class RoleController {
|
||||
* 检查角色名称和角色关键词
|
||||
*/
|
||||
private void checkNameAndKey(RoleDto dto) {
|
||||
if (roleService.checkNameUnique(dto)) {
|
||||
if (roleFacade.checkNameUnique(dto)) {
|
||||
throw new CustomException("角色名称已存在!");
|
||||
}
|
||||
if (roleService.checkRoleKeyUnique(dto)) {
|
||||
if (roleFacade.checkRoleKeyUnique(dto)) {
|
||||
throw new CustomException("角色权限名称已存在!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
package cn.fateverse.admin.controller;
|
||||
|
||||
import cn.fateverse.admin.dto.UserDto;
|
||||
import cn.fateverse.admin.facade.RoleFacade;
|
||||
import cn.fateverse.admin.facade.UserFacade;
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.service.PostService;
|
||||
import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.IdWrapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.admin.service.PostService;
|
||||
import cn.fateverse.admin.service.RoleService;
|
||||
import cn.fateverse.admin.service.UserService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.security.annotation.Anonymity;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.security.annotation.Anonymity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -37,31 +38,20 @@ import java.util.regex.Pattern;
|
||||
@Api(tags = "用户管理")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final RoleService roleService;
|
||||
|
||||
private final UserFacade userFacade;
|
||||
private final RoleFacade roleFacade;
|
||||
private final PostService postService;
|
||||
|
||||
public UserController(UserService userService,
|
||||
RoleService roleService,
|
||||
PostService postService) {
|
||||
this.userService = userService;
|
||||
this.roleService = roleService;
|
||||
this.postService = postService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取用户列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('admin:user:list')")
|
||||
public Result<TableDataInfo<UserVo>> list(UserQuery userQuery) {
|
||||
PageUtils.startPage();
|
||||
List<UserVo> userVos = userService.searchList(userQuery);
|
||||
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userVos);
|
||||
TableDataInfo<UserVo> dataTable = userFacade.searchList(userQuery);
|
||||
return Result.ok(dataTable);
|
||||
}
|
||||
|
||||
@@ -72,7 +62,7 @@ public class UserController {
|
||||
if (null == type || null == chooseId || type > 1 || type < 0) {
|
||||
return Result.error("参数异常!");
|
||||
}
|
||||
List<UserChooseVo> userChooseList = userService.searchUserChooseRoleOrDept(type, chooseId);
|
||||
List<UserChooseVo> userChooseList = userFacade.searchUserChooseRoleOrDept(type, chooseId);
|
||||
return Result.ok(userChooseList);
|
||||
}
|
||||
|
||||
@@ -80,9 +70,8 @@ public class UserController {
|
||||
@GetMapping("/info/{userId}")
|
||||
@PreAuthorize("@ss.hasPermission('admin:user:info')")
|
||||
public Result<UserDetailVo> info(@PathVariable Long userId) {
|
||||
checkUserId(userId);
|
||||
UserDetailVo userDetail = userService.searchByUserId(userId);
|
||||
List<Option> roleOption = roleService.searchOption();
|
||||
UserDetailVo userDetail = userFacade.searchDetailByUserId(userId);
|
||||
List<Option> roleOption = roleFacade.searchOption();
|
||||
List<Option> postOption = postService.searchOption();
|
||||
userDetail.setRoleList(roleOption);
|
||||
userDetail.setPostList(postOption);
|
||||
@@ -94,7 +83,7 @@ public class UserController {
|
||||
public Result<TableDataInfo<UserVo>> role(@PathVariable Long roleId, String userName, String phoneNumber) {
|
||||
LongUtils.checkId(roleId, "角色id不能为空!");
|
||||
PageUtils.startPage();
|
||||
List<UserVo> userList = userService.searchListByRoleId(roleId, userName, phoneNumber);
|
||||
List<UserVo> userList = userFacade.searchListByRoleId(roleId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
|
||||
return Result.ok(dataTable);
|
||||
}
|
||||
@@ -103,7 +92,7 @@ public class UserController {
|
||||
@GetMapping("/role/exclude/{roleId}")
|
||||
public Result<TableDataInfo<UserVo>> excludeRole(@PathVariable Long roleId, String userName, String phoneNumber) {
|
||||
LongUtils.checkId(roleId, "角色id不能为空!");
|
||||
TableDataInfo<UserVo> table = userService.searchUserListByExcludeRoleId(roleId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> table = userFacade.searchUserListByExcludeRoleId(roleId, userName, phoneNumber);
|
||||
return Result.ok(table);
|
||||
}
|
||||
|
||||
@@ -114,7 +103,7 @@ public class UserController {
|
||||
public Result<Void> bindRole(@RequestBody IdWrapper wrapper) {
|
||||
checkUserId(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
|
||||
userService.bindRole(wrapper.getIds(), wrapper.getId());
|
||||
userFacade.bindRole(wrapper.getIds(), wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -125,7 +114,7 @@ public class UserController {
|
||||
public Result<Void> unBindRole(@RequestBody IdWrapper wrapper) {
|
||||
checkUserId(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
|
||||
userService.unBindRole(wrapper.getIds(), wrapper.getId());
|
||||
userFacade.unBindRole(wrapper.getIds(), wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -135,7 +124,7 @@ public class UserController {
|
||||
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> unBindAllRole(@RequestBody IdWrapper wrapper) {
|
||||
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
|
||||
userService.unBindAllRole(wrapper.getId());
|
||||
userFacade.unBindAllRole(wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -144,7 +133,7 @@ public class UserController {
|
||||
public Result<TableDataInfo<UserVo>> dept(@PathVariable Long deptId, String userName, String phoneNumber) {
|
||||
LongUtils.checkId(deptId, "角色id不能为空!");
|
||||
PageUtils.startPage();
|
||||
List<UserVo> userList = userService.searchListByDeptId(deptId, userName, phoneNumber);
|
||||
List<UserVo> userList = userFacade.searchListByDeptId(deptId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
|
||||
return Result.ok(dataTable);
|
||||
}
|
||||
@@ -153,7 +142,7 @@ public class UserController {
|
||||
// @GetMapping("/dept/exclude/{deptId}")
|
||||
public Result<TableDataInfo<UserVo>> excludeDept(@PathVariable Long deptId, String userName, String phoneNumber) {
|
||||
LongUtils.checkId(deptId, "角色id不能为空!");
|
||||
TableDataInfo<UserVo> table = userService.searchUserListByExcludeDeptId(deptId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> table = userFacade.searchUserListByExcludeDeptId(deptId, userName, phoneNumber);
|
||||
return Result.ok(table);
|
||||
}
|
||||
|
||||
@@ -164,7 +153,7 @@ public class UserController {
|
||||
public Result<Void> unBindDept(@PathVariable List<Long> userIds, @PathVariable Long deptId) {
|
||||
checkUserId(userIds);
|
||||
LongUtils.checkId(deptId, "角色id不能为空");
|
||||
userService.unBindDept(userIds, deptId);
|
||||
userFacade.unBindDept(userIds, deptId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -174,7 +163,7 @@ public class UserController {
|
||||
// @Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> unBindAllDept(@PathVariable Long deptId) {
|
||||
LongUtils.checkId(deptId, "角色id不能为空");
|
||||
userService.unBindAllDept(deptId);
|
||||
userFacade.unBindAllDept(deptId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -185,7 +174,7 @@ public class UserController {
|
||||
return Result.error("岗位id不能为空!");
|
||||
}
|
||||
PageUtils.startPage();
|
||||
List<UserVo> userList = userService.searchListByPostId(postId, userName, phoneNumber);
|
||||
List<UserVo> userList = userFacade.searchListByPostId(postId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> dataTable = PageUtils.getDataTable(userList);
|
||||
return Result.ok(dataTable);
|
||||
}
|
||||
@@ -195,7 +184,7 @@ public class UserController {
|
||||
@GetMapping("/post/exclude/{postId}")
|
||||
public Result<TableDataInfo<UserVo>> excludePost(@PathVariable Long postId, String userName, String phoneNumber) {
|
||||
LongUtils.checkId(postId, "角色id不能为空!");
|
||||
TableDataInfo<UserVo> table = userService.searchUserListByExcludePostId(postId, userName, phoneNumber);
|
||||
TableDataInfo<UserVo> table = userFacade.searchUserListByExcludePostId(postId, userName, phoneNumber);
|
||||
return Result.ok(table);
|
||||
}
|
||||
|
||||
@@ -207,7 +196,7 @@ public class UserController {
|
||||
public Result<Void> bindPost(@RequestBody IdWrapper wrapper) {
|
||||
checkUserId(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "角色id不能为空");
|
||||
userService.bindPost(wrapper.getIds(), wrapper.getId());
|
||||
userFacade.bindPost(wrapper.getIds(), wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -218,7 +207,7 @@ public class UserController {
|
||||
public Result<Void> unBindPost(@RequestBody IdWrapper wrapper) {
|
||||
checkUserId(wrapper.getIds());
|
||||
LongUtils.checkId(wrapper.getId(), "岗位id不能为空");
|
||||
userService.unBindPost(wrapper.getIds(), wrapper.getId());
|
||||
userFacade.unBindPost(wrapper.getIds(), wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -228,7 +217,7 @@ public class UserController {
|
||||
@Log(title = "解除当前角色对应的所有用户的绑定关系", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> unBindAllPost(@RequestBody IdWrapper wrapper) {
|
||||
LongUtils.checkId(wrapper.getId(), "岗位id不能为空");
|
||||
userService.unBindAllPost(wrapper.getId());
|
||||
userFacade.unBindAllPost(wrapper.getId());
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -241,7 +230,7 @@ public class UserController {
|
||||
return Result.error("初始密码不能为空");
|
||||
}
|
||||
checkPhone(user.getPhoneNumber());
|
||||
userService.save(user);
|
||||
userFacade.save(user);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -253,7 +242,7 @@ public class UserController {
|
||||
public Result<Void> edit(@NotNull @RequestBody @Validated UserDto user) {
|
||||
checkUserId(user.getUserId());
|
||||
checkPhone(user.getPhoneNumber());
|
||||
userService.edit(user);
|
||||
userFacade.edit(user);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -263,7 +252,7 @@ public class UserController {
|
||||
@Log(title = "删除用户", businessType = BusinessType.DELETE)
|
||||
public Result<Void> del(@PathVariable Long userId) {
|
||||
checkUserId(userId);
|
||||
userService.remove(userId);
|
||||
userFacade.remove(userId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.fateverse.admin.convert;
|
||||
|
||||
|
||||
import cn.fateverse.admin.dto.RoleDto;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.common.core.convert.BaseConvertDefine;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface RoleConvert extends BaseConvertDefine<RoleDto, Role, RoleVo> {
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.fateverse.admin.convert;
|
||||
|
||||
import cn.fateverse.admin.dto.UserDto;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.convert.BaseConvertDefine;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface UserConvert extends BaseConvertDefine<UserDto, User, UserVo> {
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
/**
|
||||
* 实体到细节
|
||||
*
|
||||
* @param user 用户
|
||||
* @return {@link UserDetail }
|
||||
*/
|
||||
UserDetail entityToDetail(User user);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.fateverse.admin.dubbo;
|
||||
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.admin.service.UserService;
|
||||
import cn.fateverse.admin.facade.UserFacade;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
@@ -15,24 +16,21 @@ import java.util.List;
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
@RequiredArgsConstructor
|
||||
public class DubboUserServiceImpl implements DubboUserService {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public DubboUserServiceImpl(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
private final UserFacade userFacade;
|
||||
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
public UserVo getUserByUsername(String username) {
|
||||
log.info("用户登录:{}", username);
|
||||
return userService.searchByUserName(username);
|
||||
return userFacade.searchByUserName(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUserId(Long userId) {
|
||||
return userService.searchUserInfoByUserId(userId);
|
||||
public UserVo getUserByUserId(Long userId) {
|
||||
return userFacade.searchByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +38,7 @@ public class DubboUserServiceImpl implements DubboUserService {
|
||||
if (roleIds.isEmpty()) {
|
||||
throw new CustomException("角色id不能为空");
|
||||
}
|
||||
return userService.searchListByRoleIds(roleIds);
|
||||
return userFacade.searchListByRoleIds(roleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +46,7 @@ public class DubboUserServiceImpl implements DubboUserService {
|
||||
if (userIds.isEmpty()) {
|
||||
throw new CustomException("用户id不能为空");
|
||||
}
|
||||
return userService.searchByUserIds(userIds);
|
||||
return userFacade.searchByUserIds(userIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,11 +54,16 @@ public class DubboUserServiceImpl implements DubboUserService {
|
||||
if (deptIds.isEmpty()) {
|
||||
throw new CustomException("部门id不能为空");
|
||||
}
|
||||
return userService.searchByDeptIds(deptIds);
|
||||
return userFacade.searchByDeptIds(deptIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> searchAllUserIds() {
|
||||
return userService.searchAllUserIds();
|
||||
return userFacade.searchAllUserIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetail getUserDetailsByUserName(String userName) {
|
||||
return userFacade.getUserDetailsByUserName(userName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package cn.fateverse.admin.facade;
|
||||
|
||||
import cn.fateverse.admin.convert.RoleConvert;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.service.RoleService;
|
||||
import cn.fateverse.admin.service.UserRoleService;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageConditionUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RoleFacade {
|
||||
|
||||
private final RoleService roleService;
|
||||
private final UserRoleService userRoleService;
|
||||
|
||||
/**
|
||||
* 搜索选项
|
||||
*
|
||||
* @return {@link List }<{@link Option }>
|
||||
*/
|
||||
public List<Option> searchOption() {
|
||||
List<Role> list = roleService.list();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索列表
|
||||
*
|
||||
* @param query 查询
|
||||
* @return {@link TableDataInfo }<{@link RoleVo }>
|
||||
*/
|
||||
public TableDataInfo<RoleVo> searchList(RoleQuery query) {
|
||||
IPage<Role> page = roleService.searchList(query);
|
||||
return PageConditionUtil.convertDataTable(page, RoleConvert.INSTANCE::entityToVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按id查询
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return {@link RoleVo }
|
||||
*/
|
||||
public RoleVo searchById(Long roleId) {
|
||||
Role role = roleService.getById(roleId);
|
||||
return RoleConvert.INSTANCE.entityToVo(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索列表排除菜单id
|
||||
*
|
||||
* @param menuId 菜单id
|
||||
* @param roleName 角色名
|
||||
* @param roleKey 关键角色
|
||||
* @return {@link TableDataInfo }<{@link RoleVo }>
|
||||
*/
|
||||
public TableDataInfo<RoleVo> searchListExcludeMenuId(Long menuId, String roleName, String roleKey) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package cn.fateverse.admin.facade;
|
||||
|
||||
import cn.fateverse.admin.convert.UserConvert;
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.service.*;
|
||||
import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageConditionUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserFacade {
|
||||
|
||||
private final UserService userService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final UserPostService userPostService;
|
||||
private final DeptService deptService;
|
||||
private final RoleService roleService;
|
||||
|
||||
|
||||
/**
|
||||
* 按用户名搜索
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return {@link UserVo }
|
||||
*/
|
||||
public UserVo searchByUserName(String username) {
|
||||
User user = userService.searchByUserName(username);
|
||||
return UserConvert.INSTANCE.entityToVo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按用户id搜索
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return {@link UserVo }
|
||||
*/
|
||||
public UserVo searchByUserId(Long userId) {
|
||||
User user = userService.getById(userId);
|
||||
return UserConvert.INSTANCE.entityToVo(user);
|
||||
}
|
||||
|
||||
public UserDetail getUserDetailsByUserName(String username) {
|
||||
User user = userService.searchByUserName(username);
|
||||
return buildUserDetail(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户细节
|
||||
*
|
||||
* @param user 用户
|
||||
* @return {@link UserDetail }
|
||||
*/
|
||||
private UserDetail buildUserDetail(User user) {
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
return null;
|
||||
}
|
||||
UserDetail userDetail = UserConvert.INSTANCE.entityToDetail(user);
|
||||
|
||||
Dept dept = deptService.getById(user.getDeptId());
|
||||
if (ObjectUtil.isNotNull(dept)) {
|
||||
userDetail.setDept(dept);
|
||||
}
|
||||
List<Role> roleList = userRoleService.selectRoleByUserId(user.getUserId());
|
||||
if (CollUtil.isNotEmpty(roleList)) {
|
||||
userDetail.setRoles(roleList);
|
||||
}
|
||||
return userDetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索列表
|
||||
*
|
||||
* @param userQuery 用户查询
|
||||
* @return {@link List }<{@link UserVo }>
|
||||
*/
|
||||
public TableDataInfo<UserVo> searchList(UserQuery userQuery) {
|
||||
IPage<UserVo> page = userService.searchList(userQuery);
|
||||
return PageConditionUtil.convertDataTable(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索用户选择角色或部门
|
||||
*
|
||||
* @param type 类型
|
||||
* @param chooseId 选择id
|
||||
* @return {@link List }<{@link UserChooseVo }>
|
||||
*/
|
||||
public List<UserChooseVo> searchUserChooseRoleOrDept(Integer type, Long chooseId) {
|
||||
switch (type) {
|
||||
// 0代表角色
|
||||
case 0:
|
||||
return chooseRole(chooseId);
|
||||
// 1代表部门
|
||||
case 1:
|
||||
return chooseDept(chooseId);
|
||||
default:
|
||||
throw new CustomException("参数异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择角色
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 选择成功的用户信息
|
||||
*/
|
||||
private List<UserChooseVo> chooseRole(Long roleId) {
|
||||
if (roleId.equals(0L)) {
|
||||
List<Role> roleList = roleService.list();
|
||||
return roleList.stream().map(UserChooseVo::toUserChooseByRole).collect(Collectors.toList());
|
||||
} else {
|
||||
List<UserVo> userList = userService.selectUserListByRoleId(roleId, null, null);
|
||||
return userList.stream().map(user ->
|
||||
UserChooseVo.toUserChooseByUser(user, roleId)
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 选择部门
|
||||
*
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
private List<UserChooseVo> chooseDept(Long deptId) {
|
||||
List<Dept> deptList = deptService.selectListByDeptParentId(deptId);
|
||||
List<UserChooseVo> result = deptList.stream().map(dept -> UserChooseVo.toUserChooseByDept(dept, deptId)).collect(Collectors.toList());
|
||||
List<UserVo> userList = userService.selectByDeptIds(Collections.singletonList(deptId));
|
||||
userList.forEach(user -> result.add(UserChooseVo.toUserChooseByUser(user, deptId)));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按用户id搜索详细信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return {@link UserDetailVo }
|
||||
*/
|
||||
public UserDetailVo searchDetailByUserId(Long userId) {
|
||||
User user = userService.getById(userId);
|
||||
UserDetail userDetail = buildUserDetail(user);
|
||||
UserDetailVo detailVo = new UserDetailVo();
|
||||
detailVo.setUser(userDetail);
|
||||
return detailVo;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.fateverse.admin.mapper;
|
||||
|
||||
import cn.fateverse.admin.entity.Role;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -10,7 +11,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/11/4
|
||||
*/
|
||||
public interface RoleMapper {
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,10 @@ package cn.fateverse.admin.mapper;
|
||||
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.UserBase;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,7 +14,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
public interface UserMapper extends BaseMapper<UserBase> {
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
@@ -32,10 +34,11 @@ public interface UserMapper extends BaseMapper<UserBase> {
|
||||
/**
|
||||
* 查询用户列表
|
||||
*
|
||||
* @param page 页面
|
||||
* @param query 用户查询信息
|
||||
* @return 用户信息
|
||||
*/
|
||||
List<UserVo> selectList(UserQuery query);
|
||||
IPage<UserVo> selectPage(@Param("page") IPage<User> page, @Param("query") UserQuery query);
|
||||
|
||||
/**
|
||||
* 排除角色id
|
||||
@@ -88,7 +91,7 @@ public interface UserMapper extends BaseMapper<UserBase> {
|
||||
* @param deptIds 部门id列表
|
||||
* @return 用户信息
|
||||
*/
|
||||
List<UserVo> selectUserByDeptIds(List<Long> deptIds);
|
||||
List<UserVo> selectByDeptIds(List<Long> deptIds);
|
||||
|
||||
/**
|
||||
* 根据岗位id查询用户信息
|
||||
@@ -104,7 +107,7 @@ public interface UserMapper extends BaseMapper<UserBase> {
|
||||
* @param userId 用户id
|
||||
* @return 用户信息
|
||||
*/
|
||||
User selectUserByUserId(Long userId);
|
||||
UserDetail selectUserByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 校验用户是否唯一
|
||||
@@ -136,7 +139,7 @@ public interface UserMapper extends BaseMapper<UserBase> {
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(UserBase user);
|
||||
int insert(User user);
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
@@ -144,7 +147,7 @@ public interface UserMapper extends BaseMapper<UserBase> {
|
||||
* @param user 用户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int update(UserBase user);
|
||||
int update(User user);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.fateverse.admin.mapper;
|
||||
|
||||
import cn.fateverse.admin.entity.UserPost;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -9,7 +10,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/11/26
|
||||
*/
|
||||
public interface UserPostMapper {
|
||||
public interface UserPostMapper extends BaseMapper<UserPost> {
|
||||
/**
|
||||
* 批量新增用户角色映射关系
|
||||
*
|
||||
|
||||
@@ -2,6 +2,8 @@ package cn.fateverse.admin.mapper;
|
||||
|
||||
|
||||
import cn.fateverse.admin.entity.UserRole;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -10,7 +12,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/11/6
|
||||
*/
|
||||
public interface UserRoleMapper {
|
||||
public interface UserRoleMapper extends BaseMapper<UserRole> {
|
||||
|
||||
/**
|
||||
* 批量新增用户角色映射关系
|
||||
@@ -54,4 +56,11 @@ public interface UserRoleMapper {
|
||||
*/
|
||||
int bind(@Param("userIds") List<Long> userIds, @Param("roleId") Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户id选择角色
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return {@link List }<{@link Role }>
|
||||
*/
|
||||
List<Role> selectRoleByUserId(Long userId);
|
||||
}
|
||||
|
||||
@@ -59,4 +59,12 @@ public interface DeptService extends IService<Dept> {
|
||||
*/
|
||||
List<Dept> selectChildrenById(Long deptId);
|
||||
|
||||
/**
|
||||
* 按部门父级id选择列表
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return {@link List }<{@link Dept }>
|
||||
*/
|
||||
List<Dept> selectListByDeptParentId(Long deptId);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import cn.fateverse.admin.dto.RoleDto;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,7 +15,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/11/4
|
||||
*/
|
||||
public interface RoleService {
|
||||
public interface RoleService extends IService<Role> {
|
||||
|
||||
/**
|
||||
* 查询角色列表
|
||||
@@ -20,7 +23,7 @@ public interface RoleService {
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
TableDataInfo<RoleVo> searchList(RoleQuery query);
|
||||
IPage<Role> searchList(RoleQuery query);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.fateverse.admin.service;
|
||||
|
||||
import cn.fateverse.admin.entity.UserPost;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface UserPostService extends IService<UserPost> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.fateverse.admin.service;
|
||||
|
||||
import cn.fateverse.admin.entity.UserRole;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRoleService extends IService<UserRole> {
|
||||
|
||||
List<Role> selectRoleByUserId(Long userId);
|
||||
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,7 +34,7 @@ public interface UserService extends IService<User> {
|
||||
* @param userId 用户ID
|
||||
* @return 用户对象
|
||||
*/
|
||||
User searchUserInfoByUserId(Long userId);
|
||||
UserDetail searchUserInfoByUserId(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,7 +43,7 @@ public interface UserService extends IService<User> {
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
List<UserVo> searchList(UserQuery user);
|
||||
IPage<UserVo> searchList(UserQuery user);
|
||||
|
||||
/**
|
||||
* 根据角色或者是部门获取到用户信息
|
||||
@@ -92,14 +94,14 @@ public interface UserService extends IService<User> {
|
||||
*
|
||||
* @param user@return
|
||||
*/
|
||||
boolean checkUserNameUnique(UserDto user);
|
||||
boolean checkUserNameUnique(User user);
|
||||
|
||||
/**
|
||||
* 校验手机号是否唯一
|
||||
*
|
||||
* @param user@return
|
||||
*/
|
||||
boolean checkPhoneNumberUnique(UserDto user);
|
||||
boolean checkPhoneNumberUnique(User user);
|
||||
|
||||
/**
|
||||
* 校验邮箱是否唯一
|
||||
@@ -272,4 +274,22 @@ public interface UserService extends IService<User> {
|
||||
* @return boolean
|
||||
*/
|
||||
boolean checkExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据角色id选择用户列表
|
||||
*
|
||||
* @param roleId
|
||||
* @param userName 用户名
|
||||
* @param phoneNumber 电话号码
|
||||
* @return {@link List }<{@link UserVo }>
|
||||
*/
|
||||
List<UserVo> selectUserListByRoleId(Long roleId, String userName, String phoneNumber);
|
||||
|
||||
/**
|
||||
* 按部门id选择
|
||||
*
|
||||
* @param deptIds 部门id
|
||||
* @return {@link List }<{@link UserVo }>
|
||||
*/
|
||||
List<UserVo> selectByDeptIds(List<Long> deptIds);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.dto.ConfigDto;
|
||||
import cn.fateverse.admin.query.ConfigQuery;
|
||||
import cn.fateverse.admin.vo.ConfigVo;
|
||||
import cn.fateverse.admin.entity.Config;
|
||||
import cn.fateverse.admin.mapper.ConfigMapper;
|
||||
import cn.fateverse.admin.query.ConfigQuery;
|
||||
import cn.fateverse.admin.service.ConfigService;
|
||||
import cn.fateverse.admin.vo.ConfigVo;
|
||||
import cn.fateverse.common.core.entity.PageInfo;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.core.utils.TableSupport;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageConditionUtil;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
@@ -48,7 +48,7 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
PageUtils.startPage();
|
||||
List<Config> list = configMapper.selectList(query);
|
||||
log.info("query time :{}", (System.currentTimeMillis() - startTime));
|
||||
return PageUtils.convertDataTable(list, ConfigVo::toConfigVo);
|
||||
return PageConditionUtil.convertDataTable(list, ConfigVo::toConfigVo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.mapper.DeptMapper;
|
||||
import cn.fateverse.admin.service.DeptService;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.utils.AssertUtil;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
@@ -73,4 +74,12 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept>
|
||||
.eq(Dept::getParentId, deptId)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dept> selectListByDeptParentId(Long deptId) {
|
||||
return this.lambdaQuery()
|
||||
.eq(Dept::getParentId, deptId)
|
||||
.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public List<RouterVo> searchRouterByUserId(Long userId) {
|
||||
List<Menu> menuList = null;
|
||||
if (User.isAdmin(userId)) {
|
||||
if (SecurityUtils.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectRouterMenuList();
|
||||
} else {
|
||||
menuList = menuMapper.selectRouterMenuListByUserId(userId);
|
||||
@@ -79,7 +79,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
public List<MenuSimpVo> searchTree(String menuName, String state) {
|
||||
List<Menu> menuList = null;
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
if (User.isAdmin(userId)) {
|
||||
if (SecurityUtils.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(menuName, state, null, false);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(userId, menuName, state, null, false);
|
||||
@@ -103,7 +103,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
public List<OptionTree> searchTreeOption(Long excludeId) {
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
List<Menu> menuList = null;
|
||||
if (User.isAdmin(userId)) {
|
||||
if (SecurityUtils.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(null, null, excludeId, true);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(userId, null, null, excludeId, true);
|
||||
@@ -123,7 +123,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
List<Menu> menuList = null;
|
||||
if (User.isAdmin(userId)) {
|
||||
if (SecurityUtils.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(null, null, null, true);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(userId, null, null, null, true);
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.dto.RoleDto;
|
||||
import cn.fateverse.admin.entity.Role;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.admin.entity.RoleMenu;
|
||||
import cn.fateverse.admin.mapper.MenuMapper;
|
||||
import cn.fateverse.admin.mapper.RoleMapper;
|
||||
import cn.fateverse.admin.mapper.RoleMenuMapper;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.service.RoleService;
|
||||
import cn.fateverse.admin.vo.RoleVo;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.core.utils.StateUtils;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageConditionUtil;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,7 +34,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RoleServiceImpl implements RoleService {
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>
|
||||
implements RoleService {
|
||||
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
@@ -47,25 +50,31 @@ public class RoleServiceImpl implements RoleService {
|
||||
|
||||
|
||||
@Override
|
||||
public TableDataInfo<RoleVo> searchList(RoleQuery query) {
|
||||
PageUtils.startPage();
|
||||
List<Role> list = roleMapper.selectList(query);
|
||||
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
|
||||
public IPage<Role> searchList(RoleQuery query) {
|
||||
IPage<Role> page = PageConditionUtil.getPage();
|
||||
return this.lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(query.getRoleName()), Role::getRoleName, query.getRoleName())
|
||||
.like(StrUtil.isNotBlank(query.getRoleKey()), Role::getRoleKey, query.getRoleKey())
|
||||
.eq(ObjectUtil.isNotNull(query.getState()), Role::getState, query.getState())
|
||||
.between(ObjectUtil.isNotNull(query.getStartTime()) && ObjectUtil.isNotNull(query.getEndTime()),
|
||||
Role::getCreateTime, query.getStartTime(), query.getEndTime())
|
||||
.page(page);
|
||||
return PageConditionUtil.convertDataTable(list, RoleVo::toRoleVo);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TableDataInfo<RoleVo> searchListByMenuId(Long menuId, String roleName, String roleKey) {
|
||||
PageUtils.startPage();
|
||||
PageConditionUtil.startPage();
|
||||
List<Role> list = roleMapper.selectListByMenuId(menuId, roleName, roleKey);
|
||||
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
|
||||
return PageConditionUtil.convertDataTable(list, RoleVo::toRoleVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<RoleVo> searchListExcludeMenuId(Long menuId, String roleName, String roleKey) {
|
||||
PageUtils.startPage();
|
||||
List<Role> list = roleMapper.searchListExcludeMenuId(menuId,roleName,roleKey);
|
||||
return PageUtils.convertDataTable(list, RoleVo::toRoleVo);
|
||||
PageConditionUtil.startPage();
|
||||
List<Role> list = roleMapper.searchListExcludeMenuId(menuId, roleName, roleKey);
|
||||
return PageConditionUtil.convertDataTable(list, RoleVo::toRoleVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,7 +165,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
public int bindMenu(Long menuId, List<Long> roleIds) {
|
||||
List<RoleMenu> roleMenuList = roleIds.stream().filter(LongUtils::isNotNull).map(roleId -> RoleMenu.builder().roleId(roleId)
|
||||
.menuId(menuId).build()).collect(Collectors.toList());
|
||||
if (roleMenuList.isEmpty()){
|
||||
if (roleMenuList.isEmpty()) {
|
||||
throw new CustomException("角色id不能为空");
|
||||
}
|
||||
return roleMenuMapper.batch(roleMenuList);
|
||||
@@ -175,7 +184,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
|
||||
public void checkRoleAllowed(Role role) {
|
||||
if (!ObjectUtils.isEmpty(role.getRoleId()) && role.isAdmin()) {
|
||||
if (!ObjectUtils.isEmpty(role.getRoleId()) && SecurityUtils.isAdmin(role.getRoleId())) {
|
||||
throw new CustomException("不允许操作超级管理员角色");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.entity.UserPost;
|
||||
import cn.fateverse.admin.mapper.UserPostMapper;
|
||||
import cn.fateverse.admin.service.UserPostService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserPostServiceImpl extends ServiceImpl<UserPostMapper, UserPost>
|
||||
implements UserPostService {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.entity.UserRole;
|
||||
import cn.fateverse.admin.mapper.UserRoleMapper;
|
||||
import cn.fateverse.admin.service.UserRoleService;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
|
||||
implements UserRoleService {
|
||||
|
||||
|
||||
@Override
|
||||
public List<Role> selectRoleByUserId(Long userId) {
|
||||
return baseMapper.selectRoleByUserId(userId);
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,17 @@ import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.Role;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserBase;
|
||||
import cn.fateverse.common.core.entity.UserDetail;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageUtils;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageConditionUtil;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -37,7 +39,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
@@ -63,17 +65,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
|
||||
@Override
|
||||
public User searchByUserName(String username) {
|
||||
return userMapper.selectByUserName(username);
|
||||
return this.lambdaQuery()
|
||||
.eq(User::getUserName, username)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User searchUserInfoByUserId(Long userId) {
|
||||
public UserDetail searchUserInfoByUserId(Long userId) {
|
||||
return userMapper.selectUserByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVo> searchList(UserQuery user) {
|
||||
return userMapper.selectList(user);
|
||||
public IPage<UserVo> searchList(UserQuery user) {
|
||||
IPage<User> page = PageConditionUtil.getPage();
|
||||
return userMapper.selectPage(page, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,39 +113,45 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
|
||||
@Override
|
||||
public List<UserVo> searchByDeptIds(List<Long> deptIds) {
|
||||
return userMapper.selectUserByDeptIds(deptIds);
|
||||
return userMapper.selectByDeptIds(deptIds);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetailVo searchByUserId(Long userId) {
|
||||
User user = userMapper.selectUserByUserId(userId);
|
||||
List<Long> roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
||||
user.setDept(null);
|
||||
user.setRoles(null);
|
||||
user.setPassword(null);
|
||||
UserDetail userDetail = userMapper.selectUserByUserId(userId);
|
||||
List<Long> roleIds = userDetail.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList());
|
||||
userDetail.setDept(null);
|
||||
userDetail.setRoles(null);
|
||||
userDetail.setPassword(null);
|
||||
List<Long> postIds = userPostMapper.selectPostIdListByUserId(userId);
|
||||
return UserDetailVo.builder()
|
||||
.user(user)
|
||||
.user(userDetail)
|
||||
.postIds(postIds)
|
||||
.roleIds(roleIds)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkUserNameUnique(UserDto user) {
|
||||
public boolean checkUserNameUnique(User user) {
|
||||
Long userId = getUserId(user);
|
||||
User info = userMapper.selectUserInfoByUserName(user.getUserName());
|
||||
User info = this.lambdaQuery()
|
||||
.eq(User::getUserName, user.getUserName())
|
||||
.last("limit 1")
|
||||
.one();
|
||||
return checkUser(info, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPhoneNumberUnique(UserDto user) {
|
||||
public boolean checkPhoneNumberUnique(User user) {
|
||||
if (StrUtil.isEmpty(user.getPhoneNumber())) {
|
||||
return false;
|
||||
}
|
||||
Long userId = getUserId(user);
|
||||
User info = userMapper.selectUserInfoByUserName(user.getPhoneNumber());
|
||||
User info = this.lambdaQuery()
|
||||
.eq(User::getPhoneNumber, user.getPhoneNumber())
|
||||
.last("limit 1")
|
||||
.one();
|
||||
return checkUser(info, userId);
|
||||
}
|
||||
|
||||
@@ -149,7 +161,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
return false;
|
||||
}
|
||||
Long userId = getUserId(user);
|
||||
User info = userMapper.selectByEmail(user.getEmail());
|
||||
UserDetail info = userMapper.selectByEmail(user.getEmail());
|
||||
return checkUser(info, userId);
|
||||
}
|
||||
|
||||
@@ -160,10 +172,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
|
||||
@Override
|
||||
public TableDataInfo<UserVo> searchUserListByExcludeRoleId(Long roleId, String userName, String phoneNumber) {
|
||||
PageUtils.startPage();
|
||||
PageConditionUtil.startPage();
|
||||
List<UserVo> list = userMapper.selectUserListByExcludeRoleId(roleId, userName, phoneNumber);
|
||||
Long total = PageUtils.getTotal(list);
|
||||
return PageUtils.convertDataTable(list, total);
|
||||
Long total = PageConditionUtil.getTotal(list);
|
||||
return PageConditionUtil.convertDataTable(list, total);
|
||||
}
|
||||
|
||||
|
||||
@@ -197,10 +209,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
|
||||
@Override
|
||||
public TableDataInfo<UserVo> searchUserListByExcludePostId(Long postId, String userName, String phoneNumber) {
|
||||
PageUtils.startPage();
|
||||
PageConditionUtil.startPage();
|
||||
List<UserVo> list = userMapper.selectUserListByExcludePostId(postId, userName, phoneNumber);
|
||||
Long total = PageUtils.getTotal(list);
|
||||
return PageUtils.convertDataTable(list, total);
|
||||
Long total = PageConditionUtil.getTotal(list);
|
||||
return PageConditionUtil.convertDataTable(list, total);
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +248,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
private List<UserChooseVo> chooseDept(Long deptId) {
|
||||
List<Dept> deptList = deptMapper.selectListByDeptParentId(deptId);
|
||||
List<UserChooseVo> result = deptList.stream().map(dept -> UserChooseVo.toUserChooseByDept(dept, deptId)).collect(Collectors.toList());
|
||||
List<UserVo> userList = userMapper.selectUserByDeptIds(Collections.singletonList(deptId));
|
||||
List<UserVo> userList = userMapper.selectByDeptIds(Collections.singletonList(deptId));
|
||||
userList.forEach(user -> result.add(UserChooseVo.toUserChooseByUser(user, deptId)));
|
||||
return result;
|
||||
}
|
||||
@@ -266,15 +278,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
|
||||
@Override
|
||||
public TableDataInfo<UserVo> searchUserListByExcludeDeptId(Long deptId, String userName, String phoneNumber) {
|
||||
PageUtils.startPage();
|
||||
PageConditionUtil.startPage();
|
||||
Dept dept = deptMapper.selectById(deptId);
|
||||
if (null == dept) {
|
||||
throw new CustomException("当前部门不存在");
|
||||
}
|
||||
// dept.getAncestors()
|
||||
List<UserVo> list = userMapper.searchUserListByExcludeDeptId(deptId, userName, phoneNumber);
|
||||
Long total = PageUtils.getTotal(list);
|
||||
return PageUtils.convertDataTable(list, total);
|
||||
Long total = PageConditionUtil.getTotal(list);
|
||||
return PageConditionUtil.convertDataTable(list, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,7 +304,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int save(UserDto dto) {
|
||||
checkUser(dto);
|
||||
UserBase user = insertInitUser(dto);
|
||||
User user = insertInitUser(dto);
|
||||
int result = userMapper.insert(user);
|
||||
dto.setUserId(user.getUserId());
|
||||
batchUserRole(dto, Boolean.FALSE);
|
||||
@@ -310,7 +322,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
batchUserRole(dto, Boolean.TRUE);
|
||||
batchUserPost(dto, Boolean.TRUE);
|
||||
dto.setPassword(null);
|
||||
UserBase user = dto.toUser();
|
||||
User user = dto.toUser();
|
||||
return userMapper.update(user);
|
||||
}
|
||||
|
||||
@@ -334,10 +346,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
@Override
|
||||
public boolean checkExistUser(Long deptId) {
|
||||
return this.lambdaQuery()
|
||||
.eq(UserBase::getDeptId, deptId)
|
||||
.eq(User::getDeptId, deptId)
|
||||
.exists();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserVo> selectUserListByRoleId(Long roleId, String userName, String phoneNumber) {
|
||||
return baseMapper.selectUserListByRoleId(roleId, userName, phoneNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVo> selectByDeptIds(List<Long> deptIds) {
|
||||
return baseMapper.selectByDeptIds(deptIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量处理用户与角色之间的对应关系
|
||||
*/
|
||||
@@ -381,8 +404,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
private UserBase insertInitUser(UserDto dto) {
|
||||
UserBase user = dto.toUser();
|
||||
private User insertInitUser(UserDto dto) {
|
||||
User user = dto.toUser();
|
||||
user.setPassword(SecurityUtils.encryptPassword(dto.getPassword()));
|
||||
return user;
|
||||
}
|
||||
@@ -393,7 +416,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
private Long getUserId(UserDto user) {
|
||||
private Long getUserId(User user) {
|
||||
return LongUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.fateverse.admin.mapper.UserMapper">
|
||||
|
||||
<resultMap type="cn.fateverse.common.core.entity.User" id="UserResult">
|
||||
<resultMap type="cn.fateverse.common.core.entity.UserDetail" id="UserResult">
|
||||
<id property="userId" column="user_id"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="userName" column="user_name"/>
|
||||
@@ -135,21 +135,21 @@
|
||||
where u.user_name = #{userName} limit 0,1
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultType="cn.fateverse.admin.vo.UserVo">
|
||||
<select id="selectPage" resultType="cn.fateverse.admin.vo.UserVo">
|
||||
<include refid="selectUserVo"/>
|
||||
<where>
|
||||
u.del_flag = '0'
|
||||
<if test="userName != null and userName != ''">and u.user_name like concat('%', #{userName}, '%')</if>
|
||||
<if test="phoneNumber != null and phoneNumber != ''">and u.phone_number like
|
||||
concat('%',#{phoneNumber},'%')
|
||||
<if test="query.userName != null and query.userName != ''">and u.user_name like concat('%', #{query.userName}, '%')</if>
|
||||
<if test="query.phoneNumber != null and query.phoneNumber != ''">and u.phone_number like
|
||||
concat('%',#{query.phoneNumber},'%')
|
||||
</if>
|
||||
<if test="state != null and state != ''">and u.state = #{state}</if>
|
||||
<if test="startTime != null and endTime != null">
|
||||
and u.create_time between #{startTime} and #{endTime}
|
||||
<if test="query.state != null">and u.state = #{query.state}</if>
|
||||
<if test="query.startTime != null and query.endTime != null">
|
||||
and u.create_time between #{query.startTime} and #{query.endTime}
|
||||
</if>
|
||||
<if test="deptId != null">
|
||||
and (u.dept_id = #{deptId} or u.dept_id in ( select t.dept_id from sys_dept t where
|
||||
find_in_set(#{deptId}, ancestors) ))
|
||||
<if test="query.deptId != null">
|
||||
and (u.dept_id = #{query.deptId} or u.dept_id in ( select t.dept_id from sys_dept t where
|
||||
find_in_set(#{query.deptId}, ancestors) ))
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
@@ -218,17 +218,17 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectUserInfoByUserName" resultType="cn.fateverse.common.core.entity.User">
|
||||
<select id="selectUserInfoByUserName" resultType="cn.fateverse.common.core.entity.UserDetail">
|
||||
<include refid="selectUser"/>
|
||||
where user_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="selectByPhoneNum" resultType="cn.fateverse.common.core.entity.User">
|
||||
<select id="selectByPhoneNum" resultType="cn.fateverse.common.core.entity.UserDetail">
|
||||
<include refid="selectUser"/>
|
||||
where phone_number = #{phoneNumber}
|
||||
</select>
|
||||
|
||||
<select id="selectByEmail" resultType="cn.fateverse.common.core.entity.User">
|
||||
<select id="selectByEmail" resultType="cn.fateverse.common.core.entity.UserDetail">
|
||||
<include refid="selectUser"/>
|
||||
where email = #{email} limit 0,1
|
||||
</select>
|
||||
@@ -243,7 +243,7 @@
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectUserByDeptIds" resultType="cn.fateverse.admin.vo.UserVo">
|
||||
<select id="selectByDeptIds" resultType="cn.fateverse.admin.vo.UserVo">
|
||||
select distinct u.user_id,u.user_name,u.nick_name,u.phone_number,u.state,u.create_time,
|
||||
d.dept_name,u.user_type,u.sex,u.avatar,d.dept_id as leaderDeptId
|
||||
from sys_user u
|
||||
@@ -260,7 +260,7 @@
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insert" parameterType="cn.fateverse.common.core.entity.UserBase" useGeneratedKeys="true" keyProperty="userId"
|
||||
<insert id="insert" parameterType="cn.fateverse.common.core.entity.User" useGeneratedKeys="true" keyProperty="userId"
|
||||
keyColumn="user_id">
|
||||
insert into sys_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
@@ -32,4 +32,22 @@
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<select id="selectRoleByUserId" resultType="cn.fateverse.common.core.entity.Role">
|
||||
select r.role_id,
|
||||
r.role_name,
|
||||
r.role_key,
|
||||
r.role_sort,
|
||||
r.data_scope,
|
||||
r.`state`,
|
||||
r.del_flag,
|
||||
r.create_by,
|
||||
r.create_time,
|
||||
r.update_by,
|
||||
r.update_time,
|
||||
r.remark,
|
||||
r.role_type
|
||||
from sys_role r
|
||||
left join sys_user_role ur on r.role_id = ur.role_id
|
||||
where ur.user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user