mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 12:48:59 +08:00
feat: 系统功能优化;移除查询模式;一些已知BUG修复
This commit is contained in:
parent
29a3522564
commit
237e3aaab6
@ -1,8 +1,8 @@
|
||||
package com.youlai.mall.pms.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.common.pojo.vo.CascadeVO;
|
||||
import com.youlai.mall.pms.pojo.entity.PmsCategory;
|
||||
import com.youlai.mall.pms.pojo.vo.CascadeVO;
|
||||
import com.youlai.mall.pms.pojo.vo.CategoryVO;
|
||||
|
||||
import java.util.List;
|
||||
@ -41,7 +41,4 @@ public interface IPmsCategoryService extends IService<PmsCategory> {
|
||||
*/
|
||||
Long saveCategory(PmsCategory category);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import com.youlai.common.pojo.vo.CascadeVO;
|
||||
import com.youlai.mall.pms.pojo.entity.PmsCategory;
|
||||
import com.youlai.mall.pms.mapper.PmsCategoryMapper;
|
||||
import com.youlai.mall.pms.pojo.vo.CascadeVO;
|
||||
import com.youlai.mall.pms.service.IPmsCategoryService;
|
||||
import com.youlai.mall.pms.pojo.vo.CategoryVO;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -84,7 +84,7 @@ public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryMapper, PmsCa
|
||||
.forEach(category -> {
|
||||
CascadeVO categoryVO = new CascadeVO()
|
||||
.setLabel(category.getName())
|
||||
.setValue(category.getId().toString());
|
||||
.setValue(category.getId());
|
||||
BeanUtil.copyProperties(category, categoryVO);
|
||||
List<CascadeVO> children = recursionCascade(category.getId(), categoryList);
|
||||
categoryVO.setChildren(children);
|
||||
|
@ -35,8 +35,8 @@ public class SysUser extends BaseEntity {
|
||||
|
||||
private Long deptId;
|
||||
|
||||
@ApiModelProperty("逻辑删除标识 0-未删除 1-已删除")
|
||||
// @TableLogic(value = "0", delval = "1")
|
||||
@ApiModelProperty("逻辑删除标识: 0-未删除 1-已删除")
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer deleted;
|
||||
|
||||
@TableField(exist = false)
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.youlai.admin.component.security;
|
||||
package com.youlai.admin.component.cache;
|
||||
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -11,7 +10,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class InitPermissionRoles implements CommandLineRunner {
|
||||
public class InitPermissionRolesCache implements CommandLineRunner {
|
||||
|
||||
private ISysPermissionService iSysPermissionService;
|
||||
|
@ -2,7 +2,8 @@ package com.youlai.admin.controller;
|
||||
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.service.ISysDeptService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -39,10 +40,10 @@ public class DeptController {
|
||||
return Result.success(deptTableList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "部门下拉(Select)层级列表")
|
||||
@ApiOperation(value = "部门下拉(TreeSelect)层级列表")
|
||||
@GetMapping("/select")
|
||||
public Result getSelectList() {
|
||||
List<TreeVO> deptSelectList = deptService.listSelect();
|
||||
List<TreeSelectVO> deptSelectList = deptService.listTreeSelect();
|
||||
return Result.success(deptSelectList);
|
||||
}
|
||||
|
||||
|
@ -10,15 +10,12 @@ import com.youlai.admin.pojo.entity.SysDict;
|
||||
import com.youlai.admin.pojo.entity.SysDictItem;
|
||||
import com.youlai.admin.service.ISysDictItemService;
|
||||
import com.youlai.admin.service.ISysDictService;
|
||||
import com.youlai.common.enums.QueryModeEnum;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -7,16 +7,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.admin.pojo.entity.SysDictItem;
|
||||
import com.youlai.admin.service.ISysDictItemService;
|
||||
import com.youlai.common.enums.QueryModeEnum;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -4,8 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.RouteVO;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -30,6 +31,7 @@ import java.util.List;
|
||||
public class MenuController {
|
||||
|
||||
private final ISysMenuService menuService;
|
||||
private final ISysPermissionService permissionService;
|
||||
|
||||
@ApiOperation(value = "菜单表格(Table)层级列表")
|
||||
@ApiImplicitParam(name = "name", value = "菜单名称", paramType = "query", dataType = "String")
|
||||
@ -43,7 +45,7 @@ public class MenuController {
|
||||
@ApiOperation(value = "菜单下拉(Select)层级列表")
|
||||
@GetMapping("/select")
|
||||
public Result getMenuSelectList() {
|
||||
List<TreeVO> menuList = menuService.listSelect();
|
||||
List<SelectVO> menuList = menuService.listSelect();
|
||||
return Result.success(menuList);
|
||||
}
|
||||
|
||||
@ -64,38 +66,50 @@ public class MenuController {
|
||||
|
||||
@ApiOperation(value = "新增菜单")
|
||||
@PostMapping
|
||||
@CacheEvict(cacheNames = "admin",key = "'routeList'")
|
||||
@CacheEvict(cacheNames = "system",key = "'routeList'")
|
||||
public Result add(@RequestBody SysMenu menu) {
|
||||
boolean status = menuService.save(menu);
|
||||
return Result.judge(status);
|
||||
boolean result = menuService.save(menu);
|
||||
if(result){
|
||||
permissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改菜单")
|
||||
@PutMapping(value = "/{id}")
|
||||
@CacheEvict(cacheNames = "admin",key = "'routeList'")
|
||||
@CacheEvict(cacheNames = "system",key = "'routeList'")
|
||||
public Result update(
|
||||
@PathVariable Integer id,
|
||||
@PathVariable Long id,
|
||||
@RequestBody SysMenu menu) {
|
||||
boolean status = menuService.updateById(menu);
|
||||
return Result.judge(status);
|
||||
boolean result = menuService.updateById(menu);
|
||||
if(result){
|
||||
permissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除菜单")
|
||||
@ApiImplicitParam(name = "ids", value = "id集合字符串,以,分割", required = true, paramType = "query", dataType = "String")
|
||||
@DeleteMapping("/{ids}")
|
||||
@CacheEvict(cacheNames = "admin",key = "'routeList'")
|
||||
@CacheEvict(cacheNames = "system",key = "'routeList'")
|
||||
public Result delete(@PathVariable("ids") String ids) {
|
||||
boolean status = menuService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.judge(status);
|
||||
boolean result = menuService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
if(result){
|
||||
permissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "选择性修改菜单")
|
||||
@PatchMapping(value = "/{id}")
|
||||
@CacheEvict(cacheNames = "admin",key = "'routeList'")
|
||||
@CacheEvict(cacheNames = "system",key = "'routeList'")
|
||||
public Result patch(@PathVariable Integer id, @RequestBody SysMenu menu) {
|
||||
LambdaUpdateWrapper<SysMenu> updateWrapper = new LambdaUpdateWrapper<SysMenu>().eq(SysMenu::getId, id);
|
||||
updateWrapper.set(menu.getVisible() != null, SysMenu::getVisible, menu.getVisible());
|
||||
boolean result = menuService.update(updateWrapper);
|
||||
if(result){
|
||||
permissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,13 @@ import com.youlai.admin.service.ISysRoleMenuService;
|
||||
import com.youlai.admin.service.ISysRolePermissionService;
|
||||
import com.youlai.admin.service.ISysRoleService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import com.youlai.common.enums.QueryModeEnum;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import com.youlai.common.web.util.JwtUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -87,6 +83,9 @@ public class RoleController {
|
||||
);
|
||||
Assert.isTrue(count == 0, "角色名称或角色编码重复,请检查!");
|
||||
boolean result = iSysRoleService.save(role);
|
||||
if (result) {
|
||||
iSysPermissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ -125,7 +124,7 @@ public class RoleController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "选择性更新角色")
|
||||
@ApiOperation(value = "选择性修改角色")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "role", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysRole")
|
||||
@ -142,7 +141,7 @@ public class RoleController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "角色拥有的菜单ID集合")
|
||||
@ApiOperation(value = "获取角色拥有的菜单ID集合")
|
||||
@ApiImplicitParam(name = "id", value = "角色id", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping("/{id}/menus")
|
||||
public Result listRoleMenu(@PathVariable("id") Long roleId) {
|
||||
@ -150,7 +149,7 @@ public class RoleController {
|
||||
return Result.success(menuIds);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "角色拥有的权限ID集合")
|
||||
@ApiOperation(value = "获取角色拥有的权限ID集合")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "角色id", required = true, paramType = "path", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "menuId", value = "菜单ID", paramType = "query", dataType = "Integer"),
|
||||
@ -173,6 +172,9 @@ public class RoleController {
|
||||
|
||||
List<Long> menuIds = role.getMenuIds();
|
||||
boolean result = iSysRoleMenuService.update(roleId, menuIds);
|
||||
if (result) {
|
||||
iSysPermissionService.refreshPermRolesRules();
|
||||
}
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
|
@ -48,14 +48,7 @@ public class UserController {
|
||||
@ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataType = "Long"),
|
||||
})
|
||||
@GetMapping
|
||||
public Result list(
|
||||
Integer page,
|
||||
Integer limit,
|
||||
String nickname,
|
||||
String mobile,
|
||||
Integer status,
|
||||
Long deptId
|
||||
) {
|
||||
public Result list(Integer page, Integer limit, String nickname, String mobile, Integer status, Long deptId) {
|
||||
|
||||
SysUser user = new SysUser();
|
||||
user.setNickname(nickname);
|
||||
@ -70,9 +63,7 @@ public class UserController {
|
||||
@ApiOperation(value = "用户详情")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping("/{id}")
|
||||
public Result detail(
|
||||
@PathVariable Long id
|
||||
) {
|
||||
public Result detail(@PathVariable Long id) {
|
||||
SysUser user = iSysUserService.getById(id);
|
||||
if (user != null) {
|
||||
List<Long> roleIds = iSysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>()
|
||||
@ -85,7 +76,6 @@ public class UserController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增用户")
|
||||
@ApiImplicitParam(name = "user", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysUser")
|
||||
@PostMapping
|
||||
public Result add(@RequestBody SysUser user) {
|
||||
boolean result = iSysUserService.saveUser(user);
|
||||
@ -93,13 +83,10 @@ public class UserController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "user", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysUser")
|
||||
})
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update(
|
||||
@PathVariable Integer id,
|
||||
@PathVariable Long id,
|
||||
@RequestBody SysUser user) {
|
||||
boolean result = iSysUserService.updateUser(user);
|
||||
return Result.judge(result);
|
||||
@ -113,11 +100,8 @@ public class UserController {
|
||||
return Result.judge(status);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "选择性更新")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "user", value = "实体JSON对象", required = true, paramType = "body", dataType = "SysUser")
|
||||
})
|
||||
@ApiOperation(value = "选择性更新用户")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long")
|
||||
@PatchMapping(value = "/{id}")
|
||||
public Result patch(@PathVariable Long id, @RequestBody SysUser user) {
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>().eq(SysUser::getId, id);
|
||||
@ -146,8 +130,6 @@ public class UserController {
|
||||
@ApiOperation(value = "获取当前登陆的用户信息")
|
||||
@GetMapping("/me")
|
||||
public Result<UserVO> getCurrentUser() {
|
||||
log.info("获取当前登陆的用户信息 begin");
|
||||
|
||||
UserVO userVO = new UserVO();
|
||||
|
||||
// 用户基本信息
|
||||
|
@ -3,7 +3,9 @@ package com.youlai.admin.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -23,11 +25,11 @@ public interface ISysDeptService extends IService<SysDept> {
|
||||
List<DeptVO> listTable(Integer status, String name);
|
||||
|
||||
/**
|
||||
* 部门下拉(Select)层级列表
|
||||
* 部门树形下拉(TreeSelect)层级列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeVO> listSelect();
|
||||
List<TreeSelectVO> listTreeSelect();
|
||||
|
||||
/**
|
||||
* 新增/修改部门
|
||||
|
@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.RouteVO;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -30,7 +30,7 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeVO> listSelect();
|
||||
List<SelectVO> listSelect();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,12 @@ public interface ISysPermissionService extends IService<SysPermission> {
|
||||
|
||||
IPage<SysPermission> list(Page<SysPermission> page, SysPermission permission);
|
||||
|
||||
boolean refreshPermRolesRules();
|
||||
|
||||
List<String> listBtnPermByRoles(List<String> roles);
|
||||
|
||||
/**
|
||||
* 刷新Redis缓存中角色菜单的权限规则,角色和菜单信息变更调用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean refreshPermRolesRules();
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.youlai.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.admin.common.constant.SystemConstants;
|
||||
import com.youlai.admin.mapper.SysDeptMapper;
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.mapper.SysDeptMapper;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.service.ISysDeptService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
@ -72,12 +73,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TreeVO> listSelect() {
|
||||
public List<TreeSelectVO> listTreeSelect() {
|
||||
List<SysDept> deptList = this.list(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getStatus, GlobalConstants.STATUS_YES)
|
||||
.orderByAsc(SysDept::getSort)
|
||||
);
|
||||
List<TreeVO> deptSelectList = recursionSelectList(SystemConstants.ROOT_DEPT_ID, deptList);
|
||||
List<TreeSelectVO> deptSelectList = recursionTreeSelectList(SystemConstants.ROOT_DEPT_ID, deptList);
|
||||
return deptSelectList;
|
||||
}
|
||||
|
||||
@ -89,20 +90,20 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @param deptList
|
||||
* @return
|
||||
*/
|
||||
public static List<TreeVO> recursionSelectList(long parentId, List<SysDept> deptList) {
|
||||
List<TreeVO> deptSelectList = new ArrayList<>();
|
||||
public static List<TreeSelectVO> recursionTreeSelectList(long parentId, List<SysDept> deptList) {
|
||||
List<TreeSelectVO> deptTreeSelectList = new ArrayList<>();
|
||||
Optional.ofNullable(deptList).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.filter(dept -> dept.getParentId().equals(parentId))
|
||||
.forEach(dept -> {
|
||||
TreeVO treeVO = new TreeVO();
|
||||
treeVO.setId(dept.getId());
|
||||
treeVO.setLabel(dept.getName());
|
||||
List<TreeVO> children = recursionSelectList(dept.getId(), deptList);
|
||||
treeVO.setChildren(children);
|
||||
deptSelectList.add(treeVO);
|
||||
TreeSelectVO treeSelectVO = new TreeSelectVO(dept.getId(), dept.getName());
|
||||
List<TreeSelectVO> children = recursionTreeSelectList(dept.getId(), deptList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
treeSelectVO.setChildren(children);
|
||||
}
|
||||
deptTreeSelectList.add(treeSelectVO);
|
||||
});
|
||||
return deptSelectList;
|
||||
return deptTreeSelectList;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,13 +10,14 @@ import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.RouteVO;
|
||||
import com.youlai.admin.mapper.SysMenuMapper;
|
||||
import com.youlai.admin.pojo.vo.TreeVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -80,9 +81,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TreeVO> listSelect() {
|
||||
public List<SelectVO> listSelect() {
|
||||
List<SysMenu> menuList = this.list(new LambdaQueryWrapper<SysMenu>().orderByAsc(SysMenu::getSort));
|
||||
List<TreeVO> menuSelectList = recursionSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
List<SelectVO> menuSelectList = recursionSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
return menuSelectList;
|
||||
}
|
||||
|
||||
@ -94,20 +95,18 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @param menuList 菜单列表
|
||||
* @return
|
||||
*/
|
||||
private static List<TreeVO> recursionSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<TreeVO> menuSelectList = new ArrayList<>();
|
||||
private static List<SelectVO> recursionSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<SelectVO> menuSelectList = new ArrayList<>();
|
||||
Optional.ofNullable(menuList).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.filter(menu -> menu.getParentId().equals(parentId))
|
||||
.forEach(menu -> {
|
||||
TreeVO treeVO = new TreeVO();
|
||||
treeVO.setId(menu.getId());
|
||||
treeVO.setLabel(menu.getName());
|
||||
List<TreeVO> children = recursionSelectList(menu.getId(), menuList);
|
||||
SelectVO selectVO = new SelectVO(menu.getId(), menu.getName());
|
||||
List<SelectVO> children = recursionSelectList(menu.getId(), menuList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
treeVO.setChildren(children);
|
||||
selectVO.setChildren(children);
|
||||
}
|
||||
menuSelectList.add(treeVO);
|
||||
menuSelectList.add(selectVO);
|
||||
});
|
||||
return menuSelectList;
|
||||
}
|
||||
@ -122,7 +121,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @Cacheable cacheNames:缓存名称,不同缓存的数据是彼此隔离; key: 缓存Key。
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(cacheNames = "admin", key = "'routeList'")
|
||||
@Cacheable(cacheNames = "system", key = "'routeList'")
|
||||
public List<RouteVO> listRoute() {
|
||||
List<SysMenu> menuList = this.baseMapper.listRoute();
|
||||
List<RouteVO> list = recursionRoute(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
|
@ -11,7 +11,7 @@ import com.youlai.admin.pojo.entity.SysUserRole;
|
||||
import com.youlai.admin.service.ISysUserRoleService;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -19,15 +19,23 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*用户业务类
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
private final ISysUserRoleService iSysUserRoleService;
|
||||
|
||||
/**
|
||||
* 用户分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<SysUser> list(Page<SysUser> page, SysUser user) {
|
||||
List<SysUser> list = this.baseMapper.list(page, user);
|
||||
@ -35,6 +43,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean saveUser(SysUser user) {
|
||||
user.setPassword(passwordEncoder.encode(GlobalConstants.DEFAULT_USER_PASSWORD));
|
||||
@ -50,16 +64,26 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateUser(SysUser user) {
|
||||
|
||||
List<Long> dbRoleIds = iSysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, user.getId())).stream().map(item -> item.getRoleId()).collect(Collectors.toList());
|
||||
// 原来的用户角色ID集合
|
||||
List<Long> oldRoleIds = iSysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>()
|
||||
.eq(SysUserRole::getUserId, user.getId())).stream()
|
||||
.map(item -> item.getRoleId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Long> roleIds = user.getRoleIds();
|
||||
|
||||
List<Long> addRoleIds = roleIds.stream().filter(roleId -> !dbRoleIds.contains(roleId)).collect(Collectors.toList());
|
||||
List<Long> removeRoleIds = dbRoleIds.stream().filter(roleId -> !roleIds.contains(roleId)).collect(Collectors.toList());
|
||||
// 新的用户角色ID集合
|
||||
List<Long> newRoleIds = user.getRoleIds();
|
||||
|
||||
// 需要新增的用户角色ID集合
|
||||
List<Long> addRoleIds = newRoleIds.stream().filter(roleId -> !oldRoleIds.contains(roleId)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(addRoleIds)) {
|
||||
List<SysUserRole> addUserRoleList = new ArrayList<>();
|
||||
addRoleIds.forEach(roleId -> {
|
||||
@ -68,14 +92,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
iSysUserRoleService.saveBatch(addUserRoleList);
|
||||
}
|
||||
|
||||
// 需要删除的用户的角色ID集合
|
||||
List<Long> removeRoleIds = oldRoleIds.stream().filter(roleId -> !newRoleIds.contains(roleId)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(removeRoleIds)) {
|
||||
removeRoleIds.forEach(roleId -> {
|
||||
iSysUserRoleService.remove(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, user.getId()).eq(SysUserRole::getRoleId, roleId));
|
||||
});
|
||||
}
|
||||
|
||||
boolean result = this.updateById(user);
|
||||
return result;
|
||||
// 最后更新用户
|
||||
return this.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,5 +109,4 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return this.baseMapper.getByUsername(username);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
|
||||
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
|
||||
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
|
||||
<result property="deleted" column="deleted" jdbcType="BOOLEAN"/>
|
||||
<collection property="roles" ofType="string" javaType="list">
|
||||
<result column="roleCode"></result>
|
||||
@ -25,20 +25,43 @@
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,username,nickname,
|
||||
gender,password,dept_id,
|
||||
avatar,mobile,status,
|
||||
email,gmt_create,gmt_modified,
|
||||
deleted
|
||||
,username,nickname,
|
||||
gender,password,dept_id,
|
||||
avatar,mobile,status,
|
||||
email,gmt_create,gmt_modified,
|
||||
deleted
|
||||
</sql>
|
||||
<select id="getByUsername" resultMap="BaseResultMap">
|
||||
select t1.id, t1.username, t1.nickname, t1.password, t1.status, t3.code roleCode
|
||||
from sys_user t1,
|
||||
sys_user_role t2,
|
||||
sys_role t3
|
||||
where t1.username = #{username}
|
||||
and t1.deleted = 0
|
||||
and t1.id = t2.user_id
|
||||
and t2.role_id = t3.id
|
||||
from sys_user t1,
|
||||
sys_user_role t2,
|
||||
sys_role t3
|
||||
where t1.username = #{username}
|
||||
and t1.deleted = 0
|
||||
and t1.id = t2.user_id
|
||||
and t2.role_id = t3.id
|
||||
</select>
|
||||
|
||||
|
||||
<select id="list" resultType="com.youlai.admin.pojo.entity.SysUser">
|
||||
select u.*,d.name as dept_name , GROUP_CONCAT(r.name) as roleNames
|
||||
from sys_user u
|
||||
left join sys_dept d on u.dept_id= d.id
|
||||
left join sys_user_role ur on u.id=ur.user_id
|
||||
left join sys_role r on ur.role_id=r.id
|
||||
where 1=1
|
||||
<if test='user.username!=null and user.username.trim() neq ""'>
|
||||
and u.username like concat('%',#{user.username},'%')
|
||||
</if>
|
||||
<if test='user.mobile!=null and user.mobile.trim() neq ""'>
|
||||
and u.mobile like concat('%',#{user.mobile},'%')
|
||||
</if>
|
||||
<if test='user.status!=null'>
|
||||
and u.status = #{user.status}
|
||||
</if>
|
||||
<if test='user.deptId!=null'>
|
||||
and concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{user.deptId},',%')
|
||||
</if>
|
||||
GROUP BY u.id
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.youlai.admin.service.impl;
|
||||
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
|
||||
* @date 2021/8/28
|
||||
*/
|
||||
@SpringBootTest
|
||||
class SysUserServiceImplTest {
|
||||
|
||||
@Autowired
|
||||
private ISysUserService iSysUserService;
|
||||
|
||||
@Test
|
||||
public void saveUser() {
|
||||
SysUser user=new SysUser();
|
||||
user.setUsername("root");
|
||||
user.setNickname("有来技术");
|
||||
user.setMobile("17621590365");
|
||||
user.setEmail("youlaitech@163.com");
|
||||
iSysUserService.saveUser(user);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user