parent
814ca633aa
commit
16d33b25be
@ -1,22 +1,72 @@
|
||||
package cn.iocoder.mall.admin.application.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.admin.api.ResourceService;
|
||||
import cn.iocoder.mall.admin.api.bo.ResourceBO;
|
||||
import cn.iocoder.mall.admin.api.constant.ResourceConstants;
|
||||
import cn.iocoder.mall.admin.application.convert.ResourceConvert;
|
||||
import cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO;
|
||||
import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder;
|
||||
import cn.iocoder.mall.admin.application.convert.AdminConvert;
|
||||
import cn.iocoder.mall.admin.application.vo.AdminInfoVO;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admin/admin")
|
||||
@Api("管理员模块")
|
||||
public class AdminController {
|
||||
|
||||
@Reference(validation = "true")
|
||||
private ResourceService resourceService;
|
||||
|
||||
@GetMapping("/info")
|
||||
public CommonResult<AdminInfoVO> info() {
|
||||
return CommonResult.success(AdminConvert.INSTANCE.convert(AdminSecurityContextHolder.getContext()));
|
||||
}
|
||||
|
||||
// =========== 当前管理员相关的资源 API ===========
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@GetMapping("/menu_resource_tree")
|
||||
@ApiOperation(value = "获得当前登陆的管理员拥有的菜单权限", notes = "以树结构返回")
|
||||
public CommonResult<List<AdminMenuTreeNodeVO>> menuResourceTree() {
|
||||
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds());
|
||||
// 创建 AdminMenuTreeNodeVO Map
|
||||
Map<Integer, AdminMenuTreeNodeVO> treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream()
|
||||
.filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||
.forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
AdminMenuTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
if (parentNode.getChildren() == null) { // 初始化 children 数组
|
||||
parentNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
// 将自己添加到父节点中
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
List<AdminMenuTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
||||
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||
.sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return CommonResult.success(rootNodes);
|
||||
}
|
||||
|
||||
@GetMapping("/url_resource_list")
|
||||
@ApiOperation(value = "获得当前登陆的管理员拥有的 URL 权限列表")
|
||||
// @ApiModelProperty(value = "data", example = "['/admin/role/add', '/admin/role/update']") 没效果
|
||||
public CommonResult<Set<String>> urlResourceList() {
|
||||
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_URL, AdminSecurityContextHolder.getContext().getRoleIds());
|
||||
return CommonResult.success(resources.stream().map(ResourceBO::getHandler).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
package cn.iocoder.mall.admin.application.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.admin.api.ResourceService;
|
||||
import cn.iocoder.mall.admin.api.RoleService;
|
||||
import cn.iocoder.mall.admin.api.bo.ResourceBO;
|
||||
import cn.iocoder.mall.admin.api.bo.RolePageBO;
|
||||
import cn.iocoder.mall.admin.api.constant.ResourceConstants;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleAddDTO;
|
||||
import cn.iocoder.mall.admin.api.dto.RolePageDTO;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO;
|
||||
import cn.iocoder.mall.admin.application.convert.ResourceConvert;
|
||||
import cn.iocoder.mall.admin.application.convert.RoleConvert;
|
||||
import cn.iocoder.mall.admin.application.vo.RolePageVO;
|
||||
import cn.iocoder.mall.admin.application.vo.RoleResourceTreeNodeVO;
|
||||
import cn.iocoder.mall.admin.application.vo.RoleVO;
|
||||
import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admin/role")
|
||||
public class RoleController {
|
||||
|
||||
@Reference(validation = "true")
|
||||
private RoleService roleService;
|
||||
@Reference(validation = "true")
|
||||
private ResourceService resourceService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation(value = "角色分页")
|
||||
public CommonResult<RolePageVO> page(@RequestParam(value = "name", required = false) String name,
|
||||
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
CommonResult<RolePageBO> result = roleService.getRolePage(new RolePageDTO().setName(name).setPageNo(pageNo).setPageSize(pageSize));
|
||||
return RoleConvert.INSTANCE.convert2(result);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "创建角色")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "角色", required = true, example = "系统管理员"),
|
||||
})
|
||||
public CommonResult<RoleVO> add(@RequestParam("name") String name) {
|
||||
RoleAddDTO roleAddDTO = new RoleAddDTO().setName(name);
|
||||
return RoleConvert.INSTANCE.convert(roleService.addRole(AdminSecurityContextHolder.getContext().getAdminId(), roleAddDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "更新角色")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "name", value = "角色名", required = true, example = "系统管理员"),
|
||||
})
|
||||
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
|
||||
@RequestParam("name") String name) {
|
||||
RoleUpdateDTO roleUpdateDTO = new RoleUpdateDTO().setId(id).setName(name);
|
||||
return roleService.updateRole(AdminSecurityContextHolder.getContext().getAdminId(), roleUpdateDTO);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "删除角色")
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
|
||||
return roleService.deleteRole(AdminSecurityContextHolder.getContext().getAdminId(), id);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@GetMapping("/resource_tree")
|
||||
@ApiOperation(value = "获得角色拥有的菜单权限", notes = "以树结构返回")
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1")
|
||||
public CommonResult<List<RoleResourceTreeNodeVO>> resourceTree(@RequestParam("id") Integer id) {
|
||||
// 芋艿:此处,严格来说可以在校验下角色是否存在。不过呢,校验了也没啥意义,因为一般不存在这个情况,且不会有业务上的影响。并且,反倒多了一次 rpc 调用。
|
||||
Set<Integer> roleIds = new HashSet<>();
|
||||
roleIds.add(id);
|
||||
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(null, roleIds);
|
||||
// 创建 AdminMenuTreeNodeVO Map
|
||||
Map<Integer, RoleResourceTreeNodeVO> treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert4));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream()
|
||||
.filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||
.forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
RoleResourceTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
if (parentNode.getChildren() == null) { // 初始化 children 数组
|
||||
parentNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
// 将自己添加到父节点中
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
List<RoleResourceTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
||||
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||
.sorted(Comparator.comparing(RoleResourceTreeNodeVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return CommonResult.success(rootNodes);
|
||||
}
|
||||
|
||||
@PostMapping("/assign_resource")
|
||||
@ApiOperation(value = "分配角色资源")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "resourceIds", value = "资源数组", required = true, example = "1,2,3"),
|
||||
})
|
||||
public CommonResult<Boolean> assignResource(@RequestParam("id") Integer id,
|
||||
@RequestParam(value = "resourceIds", required = false) Set<Integer> resourceIds) {
|
||||
return roleService.assignResource(AdminSecurityContextHolder.getContext().getAdminId(), id, resourceIds);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.admin.application.convert;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.admin.api.bo.RoleBO;
|
||||
import cn.iocoder.mall.admin.api.bo.RolePageBO;
|
||||
import cn.iocoder.mall.admin.application.vo.RolePageVO;
|
||||
import cn.iocoder.mall.admin.application.vo.RoleVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface RoleConvert {
|
||||
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
RoleVO convert(RoleBO roleBO);
|
||||
|
||||
@Mappings({})
|
||||
CommonResult<RoleVO> convert(CommonResult<RoleBO> resourceBO);
|
||||
|
||||
@Mappings({})
|
||||
CommonResult<RolePageVO> convert2(CommonResult<RolePageBO> resourceBO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.mall.admin.application.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("角色分页 VO")
|
||||
public class RolePageVO {
|
||||
|
||||
@ApiModelProperty(value = "角色数组")
|
||||
private List<RoleVO> roles;
|
||||
@ApiModelProperty(value = "角色总数")
|
||||
private Integer count;
|
||||
|
||||
public List<RoleVO> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public RolePageVO setRoles(List<RoleVO> roles) {
|
||||
this.roles = roles;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public RolePageVO setCount(Integer count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package cn.iocoder.mall.admin.application.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("角色拥有的资源 VO")
|
||||
public class RoleResourceTreeNodeVO {
|
||||
|
||||
@ApiModelProperty(value = "菜单编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
// @ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
|
||||
// private String name;
|
||||
@ApiModelProperty(value = "菜单操作", required = true, example = "/order/list")
|
||||
private String handler;
|
||||
@ApiModelProperty(value = "父菜单编号", required = true, example = "1", notes = "如果无父菜单,则值为 0")
|
||||
private Integer pid;
|
||||
@ApiModelProperty(value = "排序", required = true, example = "1")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "菜单展示名", required = true, example = "商品管理")
|
||||
private String displayName;
|
||||
@ApiModelProperty(value = "子节点数组")
|
||||
private List<RoleResourceTreeNodeVO> children;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setHandler(String handler) {
|
||||
this.handler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setPid(Integer pid) {
|
||||
this.pid = pid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<RoleResourceTreeNodeVO> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public RoleResourceTreeNodeVO setChildren(List<RoleResourceTreeNodeVO> children) {
|
||||
this.children = children;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.admin.application.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("角色 VO")
|
||||
public class RoleVO {
|
||||
|
||||
@ApiModelProperty(value = "角色编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "角色名字", required = true, example = "系统管理员")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RoleVO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public RoleVO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public RoleVO setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,24 @@
|
||||
package cn.iocoder.mall.admin.api;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.admin.api.bo.RoleBO;
|
||||
import cn.iocoder.mall.admin.api.bo.RolePageBO;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleAddDTO;
|
||||
import cn.iocoder.mall.admin.api.dto.RolePageDTO;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface RoleService {
|
||||
}
|
||||
|
||||
CommonResult<RolePageBO> getRolePage(RolePageDTO rolePageDTO);
|
||||
|
||||
CommonResult<RoleBO> addRole(Integer adminId, RoleAddDTO roleAddDTO);
|
||||
|
||||
CommonResult<Boolean> updateRole(Integer adminId, RoleUpdateDTO roleUpdateDTO);
|
||||
|
||||
CommonResult<Boolean> deleteRole(Integer adminId, Integer roleId);
|
||||
|
||||
CommonResult<Boolean> assignResource(Integer adminId, Integer roleId, Set<Integer> resourceIds);
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.mall.admin.api.bo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 角色 BO
|
||||
*/
|
||||
public class RoleBO {
|
||||
|
||||
/**
|
||||
* 角色编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 角色名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 添加时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RoleBO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public RoleBO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public RoleBO setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.mall.admin.api.bo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RolePageBO {
|
||||
|
||||
/**
|
||||
* 角色数组
|
||||
*/
|
||||
private List<RoleBO> roles;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private Integer count;
|
||||
|
||||
public List<RoleBO> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public RolePageBO setRoles(List<RoleBO> roles) {
|
||||
this.roles = roles;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public RolePageBO setCount(Integer count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.admin.api.dto;
|
||||
|
||||
public class RolePageDTO {
|
||||
|
||||
private Integer pageNo;
|
||||
private Integer pageSize;
|
||||
private String name;
|
||||
|
||||
public Integer getPageNo() {
|
||||
return pageNo;
|
||||
}
|
||||
|
||||
public RolePageDTO setPageNo(Integer pageNo) {
|
||||
this.pageNo = pageNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public RolePageDTO setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public RolePageDTO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.mall.admin.convert;
|
||||
|
||||
import cn.iocoder.mall.admin.api.bo.RoleBO;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleAddDTO;
|
||||
import cn.iocoder.mall.admin.api.dto.RoleUpdateDTO;
|
||||
import cn.iocoder.mall.admin.dataobject.RoleDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RoleConvert {
|
||||
|
||||
RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
RoleDO convert(RoleAddDTO roleAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
RoleDO convert(RoleUpdateDTO roleUpdateDTO);
|
||||
|
||||
@Mappings({})
|
||||
RoleBO convert(RoleDO roleDO);
|
||||
|
||||
@Mappings({})
|
||||
List<RoleBO> convert(List<RoleDO> roleDOs);
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.admin.dao;
|
||||
|
||||
import cn.iocoder.mall.admin.dataobject.RoleDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface RoleMapper {
|
||||
|
||||
void insert(RoleDO roleDO);
|
||||
|
||||
int update(RoleDO roleDO);
|
||||
|
||||
RoleDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<RoleDO> selectListByNameLike(@Param("name") String name,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
Integer selectCountByNameLike(@Param("name") String name);
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
<?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="cn.iocoder.mall.admin.dao.RoleMapper">
|
||||
|
||||
<insert id="insert" parameterType="RoleDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO role (
|
||||
name, create_time, deleted
|
||||
) VALUES (
|
||||
#{name}, #{createTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="RoleDO">
|
||||
UPDATE role
|
||||
<set>
|
||||
<if test="name != null">
|
||||
, name = #{name}
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
, deleted = #{deleted}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="RoleDO">
|
||||
SELECT
|
||||
id, name, create_time
|
||||
FROM role
|
||||
WHERE id = #{id}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectListByNameLike" resultType="RoleDO">
|
||||
SELECT
|
||||
id, name, create_time
|
||||
FROM role
|
||||
<where>
|
||||
<if test="name != null">
|
||||
name LIKE "%"#{name}"%"
|
||||
</if>
|
||||
</where>
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectCountByNameLike" resultType="RoleDO">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM role
|
||||
<where>
|
||||
<if test="name != null">
|
||||
name LIKE "%"#{name}"%"
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in new issue