@@ -46,6 +46,14 @@ public final class CommonConstant { | |||
public static final String BARS = "-"; | |||
/** | |||
* 下划线 | |||
*/ | |||
public static final String UNDERLINE = "_"; | |||
} |
@@ -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); | |||
} | |||
} |
@@ -34,4 +34,5 @@ public interface ClientUserMapper { | |||
Integer getUserRoleIdByUserName(String username); | |||
List<UserPo> getUserByRoleId(Integer id); | |||
} |
@@ -3,16 +3,24 @@ 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 | |||
*/ | |||
* @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); | |||
} | |||
@@ -3,16 +3,22 @@ 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 | |||
*/ | |||
* @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,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; | |||
} |
@@ -4,9 +4,13 @@ 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 lombok.Data; | |||
import java.util.List; | |||
/** | |||
* 菜单表 | |||
@@ -16,7 +20,7 @@ import lombok.Data; | |||
@Data | |||
public class Menus implements Serializable { | |||
/** | |||
* | |||
* id | |||
*/ | |||
@TableId(type = IdType.AUTO) | |||
private Integer id; | |||
@@ -24,11 +28,15 @@ public class Menus implements Serializable { | |||
/** | |||
* 创建时间 | |||
*/ | |||
@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; | |||
/** | |||
@@ -75,6 +83,10 @@ public class Menus implements Serializable { | |||
* 组件路径 | |||
*/ | |||
private String component; | |||
/** | |||
* 1 启用 2禁用 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 页面跳转方式 | |||
@@ -93,4 +105,28 @@ public class Menus implements Serializable { | |||
@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; | |||
} |
@@ -42,7 +42,7 @@ public class Permissions implements Serializable { | |||
private Integer updateUser; | |||
/** | |||
* 0:初始化;-1:删除 | |||
* 1:初始化;0:删除 | |||
*/ | |||
private Integer mark; | |||
@@ -83,4 +83,16 @@ public class Permissions implements Serializable { | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 是否选中 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean checked; | |||
/** | |||
* 是否打开 | |||
*/ | |||
@TableField(exist = false) | |||
private boolean open; | |||
} |
@@ -6,7 +6,10 @@ 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; | |||
/** | |||
* | |||
@@ -24,11 +27,15 @@ public class Roles implements Serializable { | |||
/** | |||
* 创建时间 | |||
*/ | |||
@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; | |||
/** | |||
@@ -49,18 +56,16 @@ public class Roles implements Serializable { | |||
/** | |||
* 角色备注 | |||
*/ | |||
private String mark; | |||
private String remark; | |||
/** | |||
* 0:初始化;-1:删除 | |||
* 1 正常 0删除 | |||
*/ | |||
private Integer status; | |||
private Integer mark; | |||
/** | |||
* 租户id | |||
* 1 启用;2:禁用 | |||
*/ | |||
private Integer tanentId; | |||
private Integer status; | |||
@TableField(exist = false) | |||
private static final long serialVersionUID = 1L; | |||
} |
@@ -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; | |||
} |
@@ -1,19 +1,119 @@ | |||
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 | |||
*/ | |||
* @author 小影 | |||
* @description 针对表【op_menus(菜单表)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:50:28 | |||
*/ | |||
@Service | |||
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus> | |||
implements MenusService{ | |||
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(); | |||
} | |||
} | |||
@@ -1,20 +1,119 @@ | |||
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.mapper.op.PermissionsMapper; | |||
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 | |||
*/ | |||
* @author 小影 | |||
* @description 针对表【op_permissions(权限配置表)】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:07 | |||
*/ | |||
@Service | |||
public class PermissionsServiceImpl extends ServiceImpl<PermissionsMapper, Permissions> | |||
implements PermissionsService{ | |||
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); | |||
} | |||
} | |||
} | |||
@@ -1,20 +1,255 @@ | |||
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.model.entity.Roles; | |||
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.mapper.op.RolesMapper; | |||
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 | |||
*/ | |||
* @author 小影 | |||
* @description 针对表【op_roles】的数据库操作Service实现 | |||
* @createDate 2023-03-20 14:55:52 | |||
*/ | |||
@Service | |||
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> | |||
implements RolesService{ | |||
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(); | |||
} | |||
} | |||
@@ -1,7 +1,10 @@ | |||
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 小影 | |||
@@ -10,4 +13,7 @@ import com.baomidou.mybatisplus.extension.service.IService; | |||
*/ | |||
public interface MenusService extends IService<Menus> { | |||
JsonResult getList(MenuQuery menuQuery); | |||
JsonResult edit(Menus entity, LoginUser loginUser); | |||
} |
@@ -1,13 +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 | |||
*/ | |||
* @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); | |||
} |
@@ -1,7 +1,12 @@ | |||
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 小影 | |||
@@ -10,4 +15,18 @@ import com.baomidou.mybatisplus.extension.service.IService; | |||
*/ | |||
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); | |||
} |
@@ -65,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 |
@@ -5,21 +5,22 @@ | |||
<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"/> | |||
<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"> | |||
@@ -27,6 +28,26 @@ | |||
create_user,update_user,mark, | |||
parent_id,name,client_id, | |||
menu_icon,path,component, | |||
target,is_hidden,sort | |||
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> |
@@ -5,19 +5,19 @@ | |||
<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"/> | |||
<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"> | |||
@@ -27,4 +27,15 @@ | |||
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> |
@@ -11,14 +11,14 @@ | |||
<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="mark" column="mark" jdbcType="VARCHAR"/> | |||
<result property="remark" column="mark" jdbcType="VARCHAR"/> | |||
<result property="status" column="status" jdbcType="TINYINT"/> | |||
<result property="tanentId" column="tanent_id" jdbcType="INTEGER"/> | |||
<result property="mark" column="mark" jdbcType="TINYINT"/> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id,create_time,update_time, | |||
create_user,update_user,role_name, | |||
mark,status,tanent_id | |||
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 |