@@ -16,6 +16,10 @@ public enum ServiceExceptionEnum implements ExceptionInterface { | |||
* 未查询到数据 | |||
*/ | |||
GET_NO_DATA(10001, "未查到该记录!"), | |||
/** | |||
* 获取不到当前用户信息 | |||
*/ | |||
NO_DATA_USER(10000,"获取不到当前用户信息!"), | |||
/** | |||
* 参数为空 | |||
*/ |
@@ -3,6 +3,8 @@ package com.tuoheng.config; | |||
import com.alibaba.druid.util.StringUtils; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.common.ServiceException; | |||
import com.tuoheng.common.ServiceExceptionEnum; | |||
import com.tuoheng.mapper.ClientUserMapper; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.po.UserPo; | |||
@@ -16,6 +18,9 @@ import org.springframework.web.context.request.NativeWebRequest; | |||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||
import org.springframework.web.method.support.ModelAndViewContainer; | |||
import javax.annotation.PostConstruct; | |||
import java.util.Optional; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
@@ -30,25 +35,38 @@ public class LoginUserHandler implements HandlerMethodArgumentResolver { | |||
parameter.getParameterType().isAssignableFrom(LoginUser.class); | |||
} | |||
@Autowired | |||
private ClientUserMapper clientUserMapper; | |||
private static LoginUserHandler handler; | |||
@PostConstruct | |||
public void init() { | |||
handler = this; | |||
handler.clientUserMapper = this.clientUserMapper; | |||
} | |||
@Override | |||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container, | |||
NativeWebRequest request, WebDataBinderFactory factory) { | |||
// header中获取用户token | |||
String token = request.getHeader("th-token"); | |||
String oUserJson = request.getHeader("o-user-json"); | |||
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(oUserJson)){ | |||
if (StringUtils.isEmpty(token) || StringUtils.isEmpty(oUserJson)) { | |||
return new LoginUser(); | |||
} | |||
String json = EncryptUtil.decodeUTF8StringBase64(oUserJson); | |||
JSONObject jsonObject = JSON.parseObject(json); | |||
String username = jsonObject.getString("username"); | |||
Integer roleId = handler.clientUserMapper.getUserRoleIdByUserName(username); | |||
Long oidcUserId = jsonObject.getLong("oUserId"); | |||
// 这里可以自定义封装自己的用户信息 | |||
//UserPo userPo = clientUserMapper.getUserByUserName(username); | |||
LoginUser user = new LoginUser() | |||
.setUsername(username) | |||
.setUserId(oidcUserId) | |||
.setThToken(token); | |||
.setThToken(token) | |||
.setRoleId(roleId); | |||
return user; | |||
} | |||
} |
@@ -46,6 +46,14 @@ public final class CommonConstant { | |||
public static final String BARS = "-"; | |||
/** | |||
* 下划线 | |||
*/ | |||
public static final String UNDERLINE = "_"; | |||
} |
@@ -1,7 +1,10 @@ | |||
package com.tuoheng.controller; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.service.CurrentUser; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
@@ -11,12 +14,12 @@ import org.springframework.web.bind.annotation.RestController; | |||
*/ | |||
@RestController | |||
@Slf4j | |||
@RequestMapping("/test") | |||
public class DemoController { | |||
@GetMapping("getHealth") | |||
public String getHealth(){ | |||
@GetMapping("/getHealth") | |||
public String getHealth(@CurrentUser LoginUser loginUser) { | |||
log.info("tuoheng-oidc-admin is ok~"); | |||
return "tuoheng-oidc-admin is ok~"; | |||
return null == loginUser.getRoleId() ? null : loginUser.getRoleId().toString(); | |||
} | |||
} |
@@ -0,0 +1,72 @@ | |||
package com.tuoheng.controller.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.tuoheng.model.query.MenuQuery; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.service.op.MenusService; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.java.Log; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/20 17:08 | |||
*/ | |||
@RestController | |||
@RequestMapping("/menu") | |||
public class MenuController { | |||
@Autowired | |||
private MenusService menuService; | |||
/** | |||
* 获取菜单列表 | |||
* | |||
* @param menuQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(MenuQuery menuQuery) { | |||
return menuService.getList(menuQuery); | |||
} | |||
/** | |||
* 添加菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Menus entity, @CurrentUser LoginUser loginUser) { | |||
return menuService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 编辑菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/edit") | |||
public JsonResult edit(@RequestBody Menus entity, @CurrentUser LoginUser loginUser) { | |||
return menuService.edit(entity, loginUser); | |||
} | |||
/** | |||
* 删除菜单 | |||
* | |||
* @param menuId 菜单ID | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{menuId}") | |||
public JsonResult delete(@PathVariable("menuId") Integer menuId) { | |||
boolean flag = menuService.update().eq("id", menuId).set("mark", 0).update(); | |||
if (flag) { | |||
return JsonResult.success(); | |||
} else { | |||
return JsonResult.error(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,73 @@ | |||
package com.tuoheng.controller.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Permissions; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.service.op.PermissionsService; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/11/11 14:33 | |||
*/ | |||
@RestController | |||
@Slf4j | |||
@RequestMapping("/permission") | |||
public class PermissionController { | |||
@Autowired | |||
private PermissionsService permissionService; | |||
/** | |||
* 根据 RoleId 获取用户权限 | |||
* | |||
* @return | |||
*/ | |||
@GetMapping("/getRolePermission") | |||
public JsonResult getMenuAndPermissionByRoleId(RoleClientQuery query) { | |||
return permissionService.getRolePermissionByRoleId(query); | |||
} | |||
/** | |||
* 添加权限(按钮) | |||
* | |||
* @param permissions | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Permissions permissions, @CurrentUser LoginUser loginUser) { | |||
return permissionService.edit(permissions,loginUser); | |||
} | |||
/** | |||
* 编辑权限(按钮) | |||
* | |||
* @param permissions | |||
* @return | |||
*/ | |||
@PostMapping("/edit") | |||
public JsonResult edit(@RequestBody Permissions permissions ,@CurrentUser LoginUser loginUser) { | |||
return permissionService.edit(permissions,loginUser); | |||
} | |||
/** | |||
* 删除权限按钮(更新) | |||
* @param id | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{id}") | |||
public JsonResult delete(@PathVariable("id") Integer id) { | |||
boolean flag = permissionService.update().eq("id",id).set("mark", 0).update(); | |||
if (flag) { | |||
return JsonResult.success(); | |||
} else { | |||
return JsonResult.error(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,97 @@ | |||
package com.tuoheng.controller.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.RoleMenuDto; | |||
import com.tuoheng.model.entity.Roles; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.model.query.RoleQuery; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.service.op.RolesService; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.java.Log; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/20 17:09 | |||
*/ | |||
@RestController | |||
@RequestMapping("/role") | |||
public class RoleController { | |||
@Autowired | |||
private RolesService rolesService; | |||
/** | |||
* 获取角色列表 | |||
* | |||
* @param roleQuery 查询条件 | |||
* @return | |||
*/ | |||
@GetMapping("/index") | |||
public JsonResult index(RoleQuery roleQuery) { | |||
return rolesService.getList(roleQuery); | |||
} | |||
/** | |||
* 添加角色 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public JsonResult add(@RequestBody Roles entity,@CurrentUser LoginUser loginUser) { | |||
return rolesService.edit(entity,loginUser); | |||
} | |||
/** | |||
* 编辑角色 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/edit") | |||
public JsonResult edit(@RequestBody Roles entity,@CurrentUser LoginUser loginUser) { | |||
return rolesService.edit(entity,loginUser); | |||
} | |||
/** | |||
* 删除角色 | |||
* | |||
* @param roleIds 角色ID | |||
* @return | |||
*/ | |||
@DeleteMapping("/delete/{roleIds}") | |||
public JsonResult delete(@PathVariable("roleIds") Integer[] roleIds) { | |||
return rolesService.deleteByList(roleIds); | |||
} | |||
/** | |||
* 获取角色菜单列表 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@GetMapping("/getMenuList") | |||
public JsonResult getMenuList(RoleClientQuery query) { | |||
return rolesService.getMenuList(query); | |||
} | |||
/** | |||
* 保存角色权限数据 | |||
* | |||
* @param roleMenuDto 角色菜单Dto | |||
* @return | |||
*/ | |||
@PostMapping("/savePermission") | |||
public JsonResult savePermission(@RequestBody RoleMenuDto roleMenuDto) { | |||
return rolesService.savePermission(roleMenuDto); | |||
} | |||
} |
@@ -31,4 +31,8 @@ public interface ClientUserMapper { | |||
List<UserPo> selectByTenantId(@Param("tenantId") Long id); | |||
IPage<UserVo> selectByTenantIdAndPage(UserQuery query, IPage<UserPo> page); | |||
Integer getUserRoleIdByUserName(String username); | |||
List<UserPo> getUserByRoleId(Integer id); | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.tuoheng.mapper.op; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
import org.apache.ibatis.annotations.Param; | |||
import java.util.List; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_menus(菜单表)】的数据库操作Mapper | |||
* @createDate 2023-03-20 14:50:28 | |||
* @Entity com.tuoheng.model.entity.Menus | |||
*/ | |||
@Mapper | |||
public interface MenusMapper extends BaseMapper<Menus> { | |||
List<Menus> getOpMenusByRoleId(@Param("roleId") Integer roleId); | |||
List<Menus> getChildrenMenuByPid(@Param("parentId") Integer parentId); | |||
} | |||
@@ -0,0 +1,26 @@ | |||
package com.tuoheng.mapper.op; | |||
import com.tuoheng.model.entity.Permissions; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
import org.apache.ibatis.annotations.Param; | |||
import java.util.List; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_permissions(权限配置表)】的数据库操作Mapper | |||
* @createDate 2023-03-20 14:55:07 | |||
* @Entity com.tuoheng.model.entity.Permissions | |||
*/ | |||
@Mapper | |||
public interface PermissionsMapper extends BaseMapper<Permissions> { | |||
List<Permissions> getOpPermissionsByRoleId(@Param("roleId") Integer roleId); | |||
} | |||
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper.op; | |||
import com.tuoheng.model.entity.RoleMenu; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_menu(角色可访问菜单表)】的数据库操作Mapper | |||
* @createDate 2023-03-20 14:55:25 | |||
* @Entity com.tuoheng.model.entity.RoleMenu | |||
*/ | |||
@Mapper | |||
public interface RoleMenuMapper extends BaseMapper<RoleMenu> { | |||
} | |||
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper.op; | |||
import com.tuoheng.model.entity.RolePermission; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_permission(角色可操作的permission)】的数据库操作Mapper | |||
* @createDate 2023-03-20 14:55:35 | |||
* @Entity com.tuoheng.model.entity.RolePermission | |||
*/ | |||
@Mapper | |||
public interface RolePermissionMapper extends BaseMapper<RolePermission> { | |||
} | |||
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.mapper.op; | |||
import com.tuoheng.model.entity.Roles; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import org.apache.ibatis.annotations.Mapper; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_roles】的数据库操作Mapper | |||
* @createDate 2023-03-20 14:55:52 | |||
* @Entity com.tuoheng.model.entity.Roles | |||
*/ | |||
@Mapper | |||
public interface RolesMapper extends BaseMapper<Roles> { | |||
} | |||
@@ -18,4 +18,6 @@ public class LoginUser { | |||
private String thToken; | |||
private Integer roleId; | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.tuoheng.model.dto; | |||
import lombok.Data; | |||
/** | |||
* 角色菜单Dto | |||
*/ | |||
@Data | |||
public class RoleMenuDto { | |||
/** | |||
* 角色ID | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 菜单ID或者权限 | |||
*/ | |||
private String[] ids; | |||
} |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.model.dto; | |||
import com.tuoheng.model.vo.MenusVo; | |||
import com.tuoheng.model.vo.OpPermissionsVo; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/28 13:16 | |||
*/ | |||
@Data | |||
public class RoleMenuPermissionDto { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
*对应的菜单集合->及子菜单(按钮) | |||
*/ | |||
private List<MenusVo> opMenusList; | |||
/** | |||
* 对应的权限集合 | |||
*/ | |||
private List<OpPermissionsVo> permissionsList; | |||
} |
@@ -0,0 +1,132 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import java.util.List; | |||
/** | |||
* 菜单表 | |||
* @TableName op_menus | |||
*/ | |||
@TableName(value ="op_menus") | |||
@Data | |||
public class Menus implements Serializable { | |||
/** | |||
* id | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 修改时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 修改人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 1初始化 0删除 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 父级菜单(0:无父级菜单) | |||
*/ | |||
private Integer parentId; | |||
/** | |||
* 菜单名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 菜单所属client | |||
*/ | |||
private String clientId; | |||
/** | |||
* icon图标 | |||
*/ | |||
private String menuIcon; | |||
/** | |||
* 路由地址 | |||
*/ | |||
private String path; | |||
/** | |||
* 组件路径 | |||
*/ | |||
private String component; | |||
/** | |||
* 1 启用 2禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 页面跳转方式 | |||
*/ | |||
private String target; | |||
/** | |||
* 0:显示;1:隐藏 | |||
*/ | |||
private Integer isHidden; | |||
/** | |||
* 排序字段 | |||
*/ | |||
private Integer sort; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 子级菜单 | |||
*/ | |||
@TableField(exist = false) | |||
private List<Menus> children; | |||
/** | |||
* 是否选中 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean checked; | |||
/** | |||
* 是否打开 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean open; | |||
/** | |||
* 权限节点参数 | |||
*/ | |||
@TableField(exist = false) | |||
private Integer[] checkedList; | |||
} |
@@ -0,0 +1,98 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import lombok.Data; | |||
/** | |||
* 权限配置表 | |||
* @TableName op_permissions | |||
*/ | |||
@TableName(value ="op_permissions") | |||
@Data | |||
public class Permissions implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createTime; | |||
/** | |||
* 修改时间 | |||
*/ | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 修改人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 1:初始化;0:删除 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 所属client | |||
*/ | |||
private String clientId; | |||
/** | |||
* code标识 | |||
*/ | |||
private String code; | |||
/** | |||
* 展示name | |||
*/ | |||
private String name; | |||
/** | |||
* 备注信息 | |||
*/ | |||
private String remark; | |||
/** | |||
* 0:菜单项action-permissions; | |||
*/ | |||
private Integer type; | |||
/** | |||
* 关联菜单id | |||
*/ | |||
private Integer menuId; | |||
/** | |||
* 接口路径 | |||
*/ | |||
private String apiUrl; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 是否选中 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean checked; | |||
/** | |||
* 是否打开 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean open; | |||
} |
@@ -0,0 +1,61 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import lombok.Data; | |||
/** | |||
* 角色可访问菜单表 | |||
* @TableName op_role_menu | |||
*/ | |||
@TableName(value ="op_role_menu") | |||
@Data | |||
public class RoleMenu implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createTime; | |||
/** | |||
* 修改时间 | |||
*/ | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 修改人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 0:初始化;-1:删除 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* 菜单id | |||
*/ | |||
private Integer menuId; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -0,0 +1,61 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import lombok.Data; | |||
/** | |||
* 角色可操作的permission | |||
* @TableName op_role_permission | |||
*/ | |||
@TableName(value ="op_role_permission") | |||
@Data | |||
public class RolePermission implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
private Date createTime; | |||
/** | |||
* 修改时间 | |||
*/ | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 修改人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 0:初始化;-1:删除 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
* | |||
*/ | |||
private Integer permissionId; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -0,0 +1,71 @@ | |||
package com.tuoheng.model.entity; | |||
import com.baomidou.mybatisplus.annotation.IdType; | |||
import com.baomidou.mybatisplus.annotation.TableField; | |||
import com.baomidou.mybatisplus.annotation.TableId; | |||
import com.baomidou.mybatisplus.annotation.TableName; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
/** | |||
* | |||
* @TableName op_roles | |||
*/ | |||
@TableName(value ="op_roles") | |||
@Data | |||
public class Roles implements Serializable { | |||
/** | |||
* | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
/** | |||
* 创建时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date createTime; | |||
/** | |||
* 修改时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | |||
private Date updateTime; | |||
/** | |||
* 创建人 | |||
*/ | |||
private Integer createUser; | |||
/** | |||
* 修改人 | |||
*/ | |||
private Integer updateUser; | |||
/** | |||
* 角色名称 | |||
*/ | |||
private String roleName; | |||
/** | |||
* 角色备注 | |||
*/ | |||
private String remark; | |||
/** | |||
* 1 正常 0删除 | |||
*/ | |||
private Integer mark; | |||
/** | |||
* 1 启用;2:禁用 | |||
*/ | |||
private Integer status; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -23,5 +23,9 @@ public class UserPo extends BasePo { | |||
private Long tenantId; | |||
private Integer isTenant; | |||
/** | |||
* 当前系统中的角色id | |||
*/ | |||
private Integer roleId; | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.model.query; | |||
import com.tuoheng.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* 菜单查询条件 | |||
*/ | |||
@Data | |||
public class MenuQuery extends BaseQuery { | |||
/** | |||
* 菜单名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 上级ID | |||
*/ | |||
private Integer parentId; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.model.query; | |||
import com.tuoheng.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/25 17:56 | |||
*/ | |||
@Data | |||
public class RoleClientQuery extends BaseQuery { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.model.query; | |||
import com.tuoheng.common.BaseQuery; | |||
import lombok.Data; | |||
/** | |||
* 角色查询条件 | |||
*/ | |||
@Data | |||
public class RoleQuery extends BaseQuery { | |||
/** | |||
* 角色名称 | |||
*/ | |||
private String roleName; | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.tuoheng.model.entity.Permissions; | |||
import lombok.Data; | |||
import java.util.List; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/28 15:31 | |||
*/ | |||
@Data | |||
public class MenuindexVo { | |||
/** | |||
* 菜单集合 | |||
*/ | |||
private List<MenusVo> menuListVoList; | |||
/** | |||
* 权限集合 | |||
*/ | |||
private List<Permissions> permissionList; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Menus; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/28 11:55 | |||
*/ | |||
@Data | |||
public class MenusVo extends Menus { | |||
/** | |||
* 标识id | |||
*/ | |||
private String identificationId; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Permissions; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2022/11/28 13:11 | |||
*/ | |||
@Data | |||
public class OpPermissionsVo extends Permissions { | |||
/** | |||
* 标识id | |||
*/ | |||
private String identificationId; | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Roles; | |||
import lombok.Data; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/3/21 10:03 | |||
*/ | |||
@Data | |||
public class RoleListVo extends Roles { | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.tuoheng.model.vo; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.tuoheng.model.entity.Permissions; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import lombok.experimental.Accessors; | |||
import java.util.List; | |||
@Data | |||
@AllArgsConstructor | |||
@NoArgsConstructor | |||
@Accessors(chain = true) | |||
public class RolePermissionVo { | |||
/** | |||
* 角色id | |||
*/ | |||
private Integer roleId; | |||
/** | |||
*对应的菜单集合->及子菜单(按钮) | |||
*/ | |||
private List<Menus> opMenusList; | |||
/** | |||
* 对应的权限集合 | |||
*/ | |||
private List<Permissions> permissionsList; | |||
} |
@@ -0,0 +1,122 @@ | |||
package com.tuoheng.service.op.Impl; | |||
import cn.hutool.core.date.DateUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.common.BaseQuery; | |||
import com.tuoheng.enums.MarkTypeEnum; | |||
import com.tuoheng.mapper.op.PermissionsMapper; | |||
import com.tuoheng.mapper.op.RoleMenuMapper; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.tuoheng.model.entity.Permissions; | |||
import com.tuoheng.model.entity.RoleMenu; | |||
import com.tuoheng.model.query.MenuQuery; | |||
import com.tuoheng.model.vo.MenuindexVo; | |||
import com.tuoheng.model.vo.MenusVo; | |||
import com.tuoheng.service.op.MenusService; | |||
import com.tuoheng.mapper.op.MenusMapper; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_menus(菜单表)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:50:28 | |||
*/ | |||
@Service | |||
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus> | |||
implements MenusService { | |||
@Autowired | |||
private PermissionsMapper permissionsMapper; | |||
@Autowired | |||
private MenusMapper menusMapper; | |||
@Autowired | |||
private RoleMenuMapper roleMenuMapper; | |||
/** | |||
* 获取菜单列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getList(MenuQuery query) { | |||
MenuindexVo vo = new MenuindexVo(); | |||
//获取权限/按钮列表 | |||
List<Permissions> permissions = permissionsMapper.selectList(Wrappers.<Permissions>lambdaQuery() | |||
.like(ObjectUtil.isNotEmpty(query.getName()), Permissions::getName, query.getName()) | |||
.eq(Permissions::getMark, MarkTypeEnum.VALID.getCode())); | |||
vo.setPermissionList(permissions); | |||
//获取菜单列表 | |||
List<Menus> menus = menusMapper.selectList(Wrappers.<Menus>lambdaQuery() | |||
.like(ObjectUtil.isNotEmpty(query.getName()), Menus::getName, query.getName()) | |||
.eq(Menus::getMark, MarkTypeEnum.VALID.getCode()) | |||
.orderByDesc(Menus::getSort)); | |||
//封装 | |||
List<MenusVo> collect = menus.stream().map(item -> { | |||
MenusVo menuListVo = new MenusVo(); | |||
BeanUtils.copyProperties(item, menuListVo); | |||
return menuListVo; | |||
}).collect(Collectors.toList()); | |||
vo.setMenuListVoList(collect); | |||
return JsonResult.success(vo); | |||
} | |||
/** | |||
* 添加或编辑菜单 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(Menus entity, LoginUser loginUser) { | |||
if (entity == null) { | |||
return JsonResult.error("实体对象不存在"); | |||
} | |||
boolean result = false; | |||
if (entity.getId() != null && entity.getId() > 0) { | |||
// 修改记录 | |||
entity.setUpdateUser(loginUser.getUserId().intValue()); | |||
entity.setUpdateTime(DateUtil.date()); | |||
result = this.updateById(entity); | |||
if (!result) { | |||
return JsonResult.error(); | |||
} | |||
} else { | |||
// 新增记录 | |||
entity.setCreateUser(loginUser.getUserId().intValue()); | |||
entity.setCreateTime(DateUtil.date()); | |||
entity.setMark(1); | |||
result = this.save(entity); | |||
if (!result) { | |||
return JsonResult.error(); | |||
} | |||
//新增菜单直接讲菜单跟当前用户的租户进行关联 | |||
RoleMenu roleMenu = new RoleMenu(); | |||
//查询出所有有效租户 | |||
roleMenu.setRoleId(loginUser.getRoleId()); | |||
roleMenu.setMenuId(entity.getId()); | |||
roleMenuMapper.insert(roleMenu); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} | |||
@@ -0,0 +1,121 @@ | |||
package com.tuoheng.service.op.Impl; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.mapper.op.MenusMapper; | |||
import com.tuoheng.mapper.op.PermissionsMapper; | |||
import com.tuoheng.mapper.op.RoleMenuMapper; | |||
import com.tuoheng.mapper.op.RolePermissionMapper; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.tuoheng.model.entity.Permissions; | |||
import com.tuoheng.model.entity.RoleMenu; | |||
import com.tuoheng.model.entity.RolePermission; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.model.vo.RolePermissionVo; | |||
import com.tuoheng.service.op.PermissionsService; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_permissions(权限配置表)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:07 | |||
*/ | |||
@Service | |||
public class PermissionsServiceImpl extends ServiceImpl<PermissionsMapper, Permissions> | |||
implements PermissionsService { | |||
@Autowired | |||
private MenusMapper menusMapper; | |||
@Autowired | |||
private PermissionsMapper permissionsMapper; | |||
@Autowired | |||
private RoleMenuMapper roleMenuMapper; | |||
@Autowired | |||
private RolePermissionMapper rolePermissionMapper; | |||
@Override | |||
@Transactional(readOnly = true) | |||
public JsonResult getRolePermissionByRoleId(RoleClientQuery query) { | |||
RolePermissionVo vo = new RolePermissionVo(); | |||
//根据角色id查询出对应的菜单列表 -> 无父级 | |||
List<Menus> opMenusDtoList = menusMapper.getOpMenusByRoleId(query.getRoleId()); | |||
for (Menus menus : opMenusDtoList) { | |||
//根据父级id查询出对应所属的菜单 | |||
extracted(query, menus); | |||
} | |||
vo.setRoleId(query.getRoleId()) | |||
.setOpMenusList(opMenusDtoList) | |||
//根据角色id查询出对应的权限集合 | |||
.setPermissionsList(permissionsMapper.getOpPermissionsByRoleId(query.getRoleId())); | |||
return JsonResult.success(vo); | |||
} | |||
/** | |||
* 添加或者编辑 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(Permissions opPermissions, LoginUser loginUser) { | |||
Integer opPermissionsId = opPermissions.getId(); | |||
//添加 | |||
if (null == opPermissionsId) { | |||
//默认 | |||
opPermissions.setCreateUser(1); | |||
permissionsMapper.insert(opPermissions); | |||
//添加对应创建权限时的关联关系 | |||
RolePermission opRolePermission = new RolePermission(); | |||
//新增权限直接讲菜单跟当前用户的租户进行关联 | |||
opRolePermission.setRoleId(loginUser.getRoleId()); | |||
opRolePermission.setPermissionId(opPermissions.getId()); | |||
rolePermissionMapper.insert(opRolePermission); | |||
} else { | |||
opPermissions.setUpdateUser(loginUser.getUserId().intValue()); | |||
permissionsMapper.updateById(opPermissions); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 封装方法 递归菜单 层级 | |||
* | |||
* @param query | |||
* @param item | |||
*/ | |||
private void extracted(RoleClientQuery query, Menus item) { | |||
List<Menus> list = menusMapper.getChildrenMenuByPid(item.getId()); | |||
if (ObjectUtil.isNotEmpty(list)) { | |||
// 获取角色菜单列表 | |||
List<RoleMenu> roleMenuList = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery() | |||
.eq(RoleMenu::getRoleId, query.getRoleId()) | |||
.select(RoleMenu::getMenuId)); | |||
List<Integer> menuIds = roleMenuList.stream().map(p -> p.getMenuId()).collect(Collectors.toList()); | |||
List<Menus> collect = list.stream().map(t -> { | |||
if (menuIds.contains(t.getId())) { | |||
t.setChecked(true); | |||
t.setOpen(true); | |||
} | |||
extracted(query, t); | |||
return t; | |||
}).filter(t -> t.isChecked() == true).collect(Collectors.toList()); | |||
item.setChildren(collect); | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.service.op.Impl; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.model.entity.RoleMenu; | |||
import com.tuoheng.service.op.RoleMenuService; | |||
import com.tuoheng.mapper.op.RoleMenuMapper; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_menu(角色可访问菜单表)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:25 | |||
*/ | |||
@Service | |||
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> | |||
implements RoleMenuService{ | |||
} | |||
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.service.op.Impl; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.model.entity.RolePermission; | |||
import com.tuoheng.service.op.RolePermissionService; | |||
import com.tuoheng.mapper.op.RolePermissionMapper; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_permission(角色可操作的permission)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:35 | |||
*/ | |||
@Service | |||
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> | |||
implements RolePermissionService{ | |||
} | |||
@@ -0,0 +1,257 @@ | |||
package com.tuoheng.service.op.Impl; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.convert.Convert; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.tuoheng.constant.CommonConstant; | |||
import com.tuoheng.enums.MarkTypeEnum; | |||
import com.tuoheng.mapper.ClientUserMapper; | |||
import com.tuoheng.mapper.op.*; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.RoleMenuDto; | |||
import com.tuoheng.model.dto.RoleMenuPermissionDto; | |||
import com.tuoheng.model.entity.*; | |||
import com.tuoheng.model.po.UserPo; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.model.query.RoleQuery; | |||
import com.tuoheng.model.vo.MenusVo; | |||
import com.tuoheng.model.vo.OpPermissionsVo; | |||
import com.tuoheng.model.vo.RoleListVo; | |||
import com.tuoheng.service.op.RoleMenuService; | |||
import com.tuoheng.service.op.RolePermissionService; | |||
import com.tuoheng.service.op.RolesService; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_roles】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:52 | |||
*/ | |||
@Service | |||
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> | |||
implements RolesService { | |||
@Autowired | |||
private RolesMapper rolesMapper; | |||
@Autowired | |||
private RoleMenuMapper roleMenuMapper; | |||
@Autowired | |||
private RolePermissionMapper rolePermissionMapper; | |||
@Autowired | |||
private ClientUserMapper clientUserMapper; | |||
@Autowired | |||
private MenusMapper menusMapper; | |||
@Autowired | |||
private PermissionsMapper permissionsMapper; | |||
@Autowired | |||
private RoleMenuService roleMenuService; | |||
@Autowired | |||
private RolePermissionService rolePermissionService; | |||
/** | |||
* 获取角色列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getList(RoleQuery query) { | |||
query.checkParam(); | |||
IPage<Roles> page = new Page<>(query.getPage(), query.getLimit()); | |||
// 查询条件 | |||
IPage<Roles> pageData = rolesMapper.selectPage(page, Wrappers.<Roles>lambdaQuery() | |||
.like(ObjectUtil.isNotEmpty(query.getRoleName()), Roles::getRoleName, query.getRoleName()) | |||
.eq(Roles::getMark, MarkTypeEnum.VALID.getCode()) | |||
.orderByDesc(Roles::getCreateTime)); | |||
pageData.convert(x -> { | |||
RoleListVo vo = Convert.convert(RoleListVo.class, x); | |||
// TODO... | |||
return vo; | |||
}); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
* 添加或编辑 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult edit(Roles entity, LoginUser loginUser) { | |||
//新增 | |||
boolean flag = false; | |||
if (ObjectUtil.isNull(entity.getId())) { | |||
entity.setCreateUser(loginUser.getUserId().intValue()); | |||
flag = this.save(entity); | |||
} else { | |||
entity.setUpdateUser(loginUser.getUserId().intValue()); | |||
flag = this.updateById(entity); | |||
} | |||
if (!flag) { | |||
return JsonResult.error(); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 删除角色,限制 | |||
* | |||
* @param roleIds | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult deleteByList(Integer[] roleIds) { | |||
for (Integer roleId : roleIds) { | |||
List<RoleMenu> roleMenus = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery() | |||
.eq(RoleMenu::getRoleId, roleId) | |||
.eq(RoleMenu::getMark, MarkTypeEnum.VALID.getCode())); | |||
if (CollectionUtil.isNotEmpty(roleMenus)) { | |||
return JsonResult.error("该角色已配置菜单不能删除!"); | |||
} | |||
List<RolePermission> opRolePermissionList = rolePermissionMapper.selectList(Wrappers.<RolePermission>lambdaQuery() | |||
.eq(RolePermission::getRoleId, roleId) | |||
.eq(RolePermission::getMark, MarkTypeEnum.VALID.getCode())); | |||
if (CollectionUtil.isNotEmpty(opRolePermissionList)) { | |||
return JsonResult.error("该角色已配置权限不能删除!"); | |||
} | |||
List<UserPo> list = clientUserMapper.getUserByRoleId(roleId); | |||
if (CollectionUtil.isNotEmpty(list)) { | |||
return JsonResult.error("该角色已经分配用户不能删除!"); | |||
} | |||
Roles role = rolesMapper.selectById(roleId); | |||
role.setMark(MarkTypeEnum.NOTVALID.getCode()); | |||
rolesMapper.updateById(role); | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 获取菜单列表 | |||
* | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getMenuList(RoleClientQuery query) { | |||
RoleMenuPermissionDto dto = new RoleMenuPermissionDto(); | |||
Integer roleId = query.getRoleId(); | |||
List<Menus> menuList = menusMapper.selectList(Wrappers.<Menus>lambdaQuery() | |||
.eq(Menus::getMark, MarkTypeEnum.VALID.getCode()) | |||
.eq(Menus::getStatus, CommonConstant.ONE) | |||
.orderByAsc(Menus::getSort)); | |||
if (!menuList.isEmpty()) { | |||
// 获取角色菜单列表 | |||
List<RoleMenu> roleMenuList = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery() | |||
.eq(RoleMenu::getRoleId, roleId) | |||
.select(RoleMenu::getMenuId)); | |||
List<Integer> menuIds = roleMenuList.stream().map(p -> p.getMenuId()).collect(Collectors.toList()); | |||
menuList.forEach(item -> { | |||
if (menuIds.contains(item.getId())) { | |||
item.setChecked(true); | |||
item.setOpen(true); | |||
} | |||
}); | |||
} | |||
List<MenusVo> collect = menuList.stream().map(t -> { | |||
MenusVo menusVo = new MenusVo(); | |||
BeanUtils.copyProperties(t, menusVo); | |||
menusVo.setIdentificationId(t.getId().toString()); | |||
return menusVo; | |||
}).collect(Collectors.toList()); | |||
dto.setOpMenusList(collect); | |||
//根据小程序或者pc标识 | |||
List<Permissions> permissions = permissionsMapper.selectList(Wrappers.<Permissions>lambdaQuery() | |||
.eq(Permissions::getMark, MarkTypeEnum.VALID.getCode())); | |||
if (!permissions.isEmpty()) { | |||
// 获取角色菜单列表 | |||
List<RolePermission> rolePermissions = rolePermissionMapper.selectList(Wrappers.<RolePermission>lambdaQuery() | |||
.eq(RolePermission::getRoleId, roleId) | |||
.select(RolePermission::getPermissionId)); | |||
List<Integer> permissionIds = rolePermissions.stream().map(p -> p.getPermissionId()).collect(Collectors.toList()); | |||
permissions.forEach(item -> { | |||
if (permissionIds.contains(item.getId())) { | |||
item.setChecked(true); | |||
item.setOpen(true); | |||
} | |||
}); | |||
} | |||
List<OpPermissionsVo> collect1 = permissions.stream().map(t -> { | |||
OpPermissionsVo vo = new OpPermissionsVo(); | |||
BeanUtils.copyProperties(t, vo); | |||
//用"_"进行区分 | |||
vo.setIdentificationId(t.getMenuId() + CommonConstant.UNDERLINE + t.getId()); | |||
return vo; | |||
}).collect(Collectors.toList()); | |||
dto.setPermissionsList(collect1); | |||
dto.setRoleId(roleId); | |||
return JsonResult.success(dto); | |||
} | |||
/** | |||
* 保存角色菜单权限数据 | |||
* | |||
* @param roleMenuDto 角色菜单Dto | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult savePermission(RoleMenuDto roleMenuDto) { | |||
// 角色ID校验 | |||
if (ObjectUtil.isNull(roleMenuDto.getRoleId())) { | |||
return JsonResult.error("角色ID不能位空"); | |||
} | |||
// 同步删除角色菜单,权限关系数据 | |||
roleMenuMapper.delete(Wrappers.<RoleMenu>lambdaQuery().eq(RoleMenu::getRoleId, roleMenuDto.getRoleId())); | |||
rolePermissionMapper.delete(Wrappers.<RolePermission>lambdaQuery().eq(RolePermission::getRoleId, roleMenuDto.getRoleId())); | |||
// 插入新的角色菜单关系数据and权限 | |||
List<RoleMenu> roleMenuList = new ArrayList<>(); | |||
List<RolePermission> permissions = new ArrayList<>(); | |||
if (roleMenuDto.getIds().length > 0) { | |||
for (String id : roleMenuDto.getIds()) { | |||
if (id.contains(CommonConstant.UNDERLINE)) { | |||
id = id.split(CommonConstant.UNDERLINE)[CommonConstant.ONE]; | |||
RolePermission opRolePermission = new RolePermission(); | |||
opRolePermission.setRoleId(roleMenuDto.getRoleId()); | |||
opRolePermission.setPermissionId(Integer.parseInt(id)); | |||
permissions.add(opRolePermission); | |||
} else { | |||
RoleMenu roleMenu = new RoleMenu(); | |||
//roleMenu.setTenantId(ShiroUtils.getTenantId()); | |||
roleMenu.setRoleId(roleMenuDto.getRoleId()); | |||
roleMenu.setMenuId(Integer.parseInt(id)); | |||
roleMenuList.add(roleMenu); | |||
} | |||
} | |||
} | |||
// 批量插入角色菜单关系数据 | |||
roleMenuService.saveBatch(roleMenuList); | |||
rolePermissionService.saveBatch(permissions); | |||
return JsonResult.success(); | |||
} | |||
} | |||
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.service.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Menus; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.query.MenuQuery; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_menus(菜单表)】的数据库操作Service | |||
* @createDate 2023-03-20 14:50:28 | |||
*/ | |||
public interface MenusService extends IService<Menus> { | |||
JsonResult getList(MenuQuery menuQuery); | |||
JsonResult edit(Menus entity, LoginUser loginUser); | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.tuoheng.service.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.entity.Permissions; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_permissions(权限配置表)】的数据库操作Service | |||
* @createDate 2023-03-20 14:55:07 | |||
*/ | |||
public interface PermissionsService extends IService<Permissions> { | |||
JsonResult getRolePermissionByRoleId(RoleClientQuery query); | |||
JsonResult edit(Permissions permissions, LoginUser loginUser); | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.service.op; | |||
import com.tuoheng.model.entity.RoleMenu; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_menu(角色可访问菜单表)】的数据库操作Service | |||
* @createDate 2023-03-20 14:55:25 | |||
*/ | |||
public interface RoleMenuService extends IService<RoleMenu> { | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.tuoheng.service.op; | |||
import com.tuoheng.model.entity.RolePermission; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_role_permission(角色可操作的permission)】的数据库操作Service | |||
* @createDate 2023-03-20 14:55:35 | |||
*/ | |||
public interface RolePermissionService extends IService<RolePermission> { | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.tuoheng.service.op; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.dto.RoleMenuDto; | |||
import com.tuoheng.model.entity.Roles; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.tuoheng.model.query.RoleClientQuery; | |||
import com.tuoheng.model.query.RoleQuery; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @author 小影 | |||
* @description 针对表【op_roles】的数据库操作Service | |||
* @createDate 2023-03-20 14:55:52 | |||
*/ | |||
public interface RolesService extends IService<Roles> { | |||
JsonResult getList(RoleQuery roleQuery); | |||
JsonResult edit(Roles entity, LoginUser loginUser); | |||
JsonResult deleteByList(Integer[] roleIds); | |||
/** | |||
* 获取角色菜单列表 | |||
* | |||
* @param query 角色ID | |||
* @return | |||
*/ | |||
JsonResult getMenuList(RoleClientQuery query); | |||
JsonResult savePermission(RoleMenuDto roleMenuDto); | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.tuoheng.third.vo; | |||
import com.tuoheng.model.entity.Menus; | |||
import lombok.Data; | |||
import java.util.List; | |||
@@ -17,5 +18,5 @@ public class RoleMenuVo { | |||
/** | |||
*对应的菜单集合->及子菜单(按钮) | |||
*/ | |||
private List<MenuVo> opMenusList; | |||
private List<Menus> opMenusList; | |||
} |
@@ -3,8 +3,8 @@ | |||
<mapper namespace="com.tuoheng.mapper.ClientUserMapper"> | |||
<insert id="insertClientUser" parameterType="com.tuoheng.model.po.UserPo" keyProperty="id" useGeneratedKeys="true"> | |||
insert into users (username, password, create_user, tenant_id, is_tenant) | |||
values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant}) | |||
insert into users (username, password, create_user, tenant_id, is_tenant, role_id) | |||
values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant}, #{roleId}) | |||
</insert> | |||
<select id="judgeCreateByUserName" parameterType="java.lang.String" resultType="int"> | |||
@@ -20,13 +20,20 @@ | |||
where username = #{username} | |||
and enabled = 1 | |||
</select> | |||
<select id="getUserRoleIdByUserName" parameterType="java.lang.String" resultType="int"> | |||
select role_id | |||
from users | |||
where username = #{username} | |||
and enabled = 1 | |||
</select> | |||
<select id="selectByUserId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT id, | |||
username, | |||
`password`, | |||
enabled, | |||
tenant_id, | |||
is_tenant | |||
is_tenant, | |||
role_id | |||
FROM users | |||
WHERE id = #{userId} | |||
</select> | |||
@@ -58,6 +65,13 @@ | |||
AND u.enabled = 1 | |||
GROUP BY u.username | |||
</select> | |||
<select id="getUserByRoleId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT * | |||
FROM users | |||
WHERE role_id = #{roleId} | |||
# 用户没有被删除 | |||
and enabled = 1 | |||
</select> | |||
<update id="updatePass" parameterType="com.tuoheng.model.po.UserPo"> | |||
update users |
@@ -0,0 +1,53 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.op.MenusMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.Menus"> | |||
<id property="id" column="id" jdbcType="INTEGER"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="INTEGER"/> | |||
<result property="updateUser" column="update_user" jdbcType="INTEGER"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="parentId" column="parent_id" jdbcType="INTEGER"/> | |||
<result property="name" column="name" jdbcType="VARCHAR"/> | |||
<result property="clientId" column="client_id" jdbcType="VARCHAR"/> | |||
<result property="menuIcon" column="menu_icon" jdbcType="VARCHAR"/> | |||
<result property="path" column="path" jdbcType="VARCHAR"/> | |||
<result property="component" column="component" jdbcType="VARCHAR"/> | |||
<result property="target" column="target" jdbcType="VARCHAR"/> | |||
<result property="isHidden" column="is_hidden" jdbcType="INTEGER"/> | |||
<result property="sort" column="sort" jdbcType="INTEGER"/> | |||
<result property="status" column="status" jdbcType="INTEGER"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,mark, | |||
parent_id,name,client_id, | |||
menu_icon,path,component, | |||
target,is_hidden,sort,status | |||
</sql> | |||
<!--根据角色id获取对应的菜单集合 无父级--> | |||
<select id="getOpMenusByRoleId" resultType="com.tuoheng.model.entity.Menus"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from op_menus | |||
where mark = 1 and parent_id = 0 | |||
and status = 1 | |||
and id in (select menu_id from op_role_menu where role_id = #{roleId} and mark = 1) | |||
order by sort asc | |||
</select> | |||
<!--根据父级id查询所属对应的菜单列表--> | |||
<select id="getChildrenMenuByPid" resultType="com.tuoheng.model.entity.Menus"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from op_menus | |||
where mark = 1 and status = 1 and parent_id = #{parentId} | |||
order by sort asc | |||
</select> | |||
</mapper> |
@@ -0,0 +1,41 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.op.PermissionsMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.Permissions"> | |||
<id property="id" column="id" jdbcType="INTEGER"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="INTEGER"/> | |||
<result property="updateUser" column="update_user" jdbcType="INTEGER"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="clientId" column="client_id" jdbcType="VARCHAR"/> | |||
<result property="code" column="code" jdbcType="VARCHAR"/> | |||
<result property="name" column="name" jdbcType="VARCHAR"/> | |||
<result property="remark" column="remark" jdbcType="VARCHAR"/> | |||
<result property="type" column="type" jdbcType="INTEGER"/> | |||
<result property="menuId" column="menu_id" jdbcType="INTEGER"/> | |||
<result property="apiUrl" column="api_url" jdbcType="VARCHAR"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,mark, | |||
client_id,code,name, | |||
remark,type,menu_id, | |||
api_url | |||
</sql> | |||
<!--根据role_id获取对应的权限集合--> | |||
<select id="getOpPermissionsByRoleId" resultType="com.tuoheng.model.entity.Permissions"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from op_permissions | |||
where mark = 1 | |||
and id in (select permission_id from op_role_permission where role_id = #{roleId} and mark = 1) | |||
</select> | |||
</mapper> |
@@ -0,0 +1,23 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.op.RoleMenuMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.RoleMenu"> | |||
<id property="id" column="id" jdbcType="INTEGER"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="INTEGER"/> | |||
<result property="updateUser" column="update_user" jdbcType="INTEGER"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="roleId" column="role_id" jdbcType="INTEGER"/> | |||
<result property="menuId" column="menu_id" jdbcType="INTEGER"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,mark, | |||
role_id,menu_id | |||
</sql> | |||
</mapper> |
@@ -0,0 +1,23 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.op.RolePermissionMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.RolePermission"> | |||
<id property="id" column="id" jdbcType="INTEGER"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="INTEGER"/> | |||
<result property="updateUser" column="update_user" jdbcType="INTEGER"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
<result property="roleId" column="role_id" jdbcType="INTEGER"/> | |||
<result property="permissionId" column="permission_id" jdbcType="INTEGER"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,mark, | |||
role_id,permission_id | |||
</sql> | |||
</mapper> |
@@ -0,0 +1,24 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper | |||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.op.RolesMapper"> | |||
<resultMap id="BaseResultMap" type="com.tuoheng.model.entity.Roles"> | |||
<id property="id" column="id" jdbcType="INTEGER"/> | |||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> | |||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> | |||
<result property="createUser" column="create_user" jdbcType="INTEGER"/> | |||
<result property="updateUser" column="update_user" jdbcType="INTEGER"/> | |||
<result property="roleName" column="role_name" jdbcType="VARCHAR"/> | |||
<result property="remark" column="mark" jdbcType="VARCHAR"/> | |||
<result property="status" column="status" jdbcType="TINYINT"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,role_name, | |||
remark,status,mark | |||
</sql> | |||
</mapper> |
@@ -3,8 +3,8 @@ | |||
<mapper namespace="com.tuoheng.mapper.ClientUserMapper"> | |||
<insert id="insertClientUser" parameterType="com.tuoheng.model.po.UserPo" keyProperty="id" useGeneratedKeys="true"> | |||
insert into users (username, password, create_user, tenant_id, is_tenant) | |||
values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant}) | |||
insert into users (username, password, create_user, tenant_id, is_tenant, role_id) | |||
values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant}, #{roleId}) | |||
</insert> | |||
<select id="judgeCreateByUserName" parameterType="java.lang.String" resultType="int"> | |||
@@ -20,13 +20,20 @@ | |||
where username = #{username} | |||
and enabled = 1 | |||
</select> | |||
<select id="getUserRoleIdByUserName" parameterType="java.lang.String" resultType="int"> | |||
select role_id | |||
from users | |||
where username = #{username} | |||
and enabled = 1 | |||
</select> | |||
<select id="selectByUserId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT id, | |||
username, | |||
`password`, | |||
enabled, | |||
tenant_id, | |||
is_tenant | |||
is_tenant, | |||
role_id | |||
FROM users | |||
WHERE id = #{userId} | |||
</select> | |||
@@ -58,6 +65,13 @@ | |||
AND u.enabled = 1 | |||
GROUP BY u.username | |||
</select> | |||
<select id="getUserByRoleId" resultType="com.tuoheng.model.po.UserPo"> | |||
SELECT * | |||
FROM users | |||
WHERE role_id = #{roleId} | |||
# 用户没有被删除 | |||
and enabled = 1 | |||
</select> | |||
<update id="updatePass" parameterType="com.tuoheng.model.po.UserPo"> | |||
update users |