【8.3.3】【role】初始化角色分类的基础类

dev-8.3.3
stylefeng 2025-01-22 17:40:37 +08:00
parent 17c3ed0f88
commit 107dbdb529
9 changed files with 605 additions and 0 deletions

View File

@ -0,0 +1,114 @@
package cn.stylefeng.roses.kernel.sys.modular.role.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleCategoryRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.service.RoleCategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@RestController
@ApiResource(name = "角色分类")
public class RoleCategoryController {
@Resource
private RoleCategoryService roleCategoryService;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@PostResource(name = "添加角色分类", path = "/roleCategory/add")
public ResponseData<RoleCategory> add(@RequestBody @Validated(RoleCategoryRequest.add.class) RoleCategoryRequest roleCategoryRequest) {
roleCategoryService.add(roleCategoryRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@PostResource(name = "删除角色分类", path = "/roleCategory/delete")
public ResponseData<?> delete(@RequestBody @Validated(RoleCategoryRequest.delete.class) RoleCategoryRequest roleCategoryRequest) {
roleCategoryService.del(roleCategoryRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@PostResource(name = "批量删除角色分类", path = "/roleCategory/batchDelete")
public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) RoleCategoryRequest roleCategoryRequest) {
roleCategoryService.batchDelete(roleCategoryRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@PostResource(name = "编辑角色分类", path = "/roleCategory/edit")
public ResponseData<?> edit(@RequestBody @Validated(RoleCategoryRequest.edit.class) RoleCategoryRequest roleCategoryRequest) {
roleCategoryService.edit(roleCategoryRequest);
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@GetResource(name = "查看角色分类详情", path = "/roleCategory/detail")
public ResponseData<RoleCategory> detail(@Validated(RoleCategoryRequest.detail.class) RoleCategoryRequest roleCategoryRequest) {
return new SuccessResponseData<>(roleCategoryService.detail(roleCategoryRequest));
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@GetResource(name = "获取角色分类列表", path = "/roleCategory/list")
public ResponseData<List<RoleCategory>> list(RoleCategoryRequest roleCategoryRequest) {
return new SuccessResponseData<>(roleCategoryService.findList(roleCategoryRequest));
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@GetResource(name = "获取角色分类列表(带分页)", path = "/roleCategory/page")
public ResponseData<PageResult<RoleCategory>> page(RoleCategoryRequest roleCategoryRequest) {
return new SuccessResponseData<>(roleCategoryService.findPage(roleCategoryRequest));
}
}

View File

@ -0,0 +1,70 @@
package cn.stylefeng.roses.kernel.sys.modular.role.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@TableName("sys_role_category")
@Data
@EqualsAndHashCode(callSuper = true)
public class RoleCategory extends BaseEntity {
/**
* id
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
@ChineseDescription("主键id")
private Long id;
/**
* id
*/
@TableField("category_parent_id")
@ChineseDescription("父级角色分类id")
private Long categoryParentId;
/**
* id
*/
@TableField("category_pids")
@ChineseDescription("父级角色分类id集合")
private String categoryPids;
/**
*
*/
@TableField("role_category_name")
@ChineseDescription("角色分类名称")
private String roleCategoryName;
/**
* 15-20-
*/
@TableField("category_type")
@ChineseDescription("角色分类类型15-业务角色20-公司角色")
private Integer categoryType;
/**
* Y-N-
*/
@TableField(value = "del_flag", fill = FieldFill.INSERT)
@ChineseDescription("删除标记Y-已删除N-未删除")
@TableLogic
private String delFlag;
/**
*
*/
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
@ChineseDescription("租户号")
private Long tenantId;
}

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.sys.modular.role.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@Getter
public enum RoleCategoryExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
ROLE_CATEGORY_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
RoleCategoryExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,28 @@
package cn.stylefeng.roses.kernel.sys.modular.role.mapper;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleCategoryRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleCategoryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
public interface RoleCategoryMapper extends BaseMapper<RoleCategory> {
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
List<RoleCategoryVo> customFindList(@Param("page") Page page, @Param("param")RoleCategoryRequest request);
}

View File

@ -0,0 +1,70 @@
<?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.stylefeng.roses.kernel.sys.modular.role.mapper.RoleCategoryMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory">
<id column="id" property="id" />
<result column="category_parent_id" property="categoryParentId" />
<result column="category_pids" property="categoryPids" />
<result column="role_category_name" property="roleCategoryName" />
<result column="category_type" property="categoryType" />
<result column="del_flag" property="delFlag" />
<result column="create_time" property="createTime" />
<result column="create_user" property="createUser" />
<result column="update_time" property="updateTime" />
<result column="update_user" property="updateUser" />
<result column="tenant_id" property="tenantId" />
</resultMap>
<sql id="Base_Column_List">
id,category_parent_id,category_pids,role_category_name,category_type,del_flag,create_time,create_user,update_time,update_user,tenant_id
</sql>
<resultMap id="customResultMap" type="cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleCategoryVo" extends="BaseResultMap">
</resultMap>
<select id="customFindList" resultMap="customResultMap">
SELECT
*
FROM
sys_role_category tbl
WHERE
<where>
<if test="param.id != null and param.id != ''">
and tbl.id like concat('%',#{param.id},'%')
</if>
<if test="param.categoryParentId != null and param.categoryParentId != ''">
and tbl.category_parent_id like concat('%',#{param.categoryParentId},'%')
</if>
<if test="param.categoryPids != null and param.categoryPids != ''">
and tbl.category_pids like concat('%',#{param.categoryPids},'%')
</if>
<if test="param.roleCategoryName != null and param.roleCategoryName != ''">
and tbl.role_category_name like concat('%',#{param.roleCategoryName},'%')
</if>
<if test="param.categoryType != null and param.categoryType != ''">
and tbl.category_type like concat('%',#{param.categoryType},'%')
</if>
<if test="param.delFlag != null and param.delFlag != ''">
and tbl.del_flag like concat('%',#{param.delFlag},'%')
</if>
<if test="param.createTime != null and param.createTime != ''">
and tbl.create_time like concat('%',#{param.createTime},'%')
</if>
<if test="param.createUser != null and param.createUser != ''">
and tbl.create_user like concat('%',#{param.createUser},'%')
</if>
<if test="param.updateTime != null and param.updateTime != ''">
and tbl.update_time like concat('%',#{param.updateTime},'%')
</if>
<if test="param.updateUser != null and param.updateUser != ''">
and tbl.update_user like concat('%',#{param.updateUser},'%')
</if>
<if test="param.tenantId != null and param.tenantId != ''">
and tbl.tenant_id like concat('%',#{param.tenantId},'%')
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,70 @@
package cn.stylefeng.roses.kernel.sys.modular.role.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RoleCategoryRequest extends BaseRequest {
/**
* id
*/
@NotNull(message = "主键id不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键id")
private Long id;
/**
* id
*/
@NotNull(message = "父级角色分类id不能为空", groups = {add.class, edit.class})
@ChineseDescription("父级角色分类id")
private Long categoryParentId;
/**
* id
*/
@NotBlank(message = "父级角色分类id集合不能为空", groups = {add.class, edit.class})
@ChineseDescription("父级角色分类id集合")
private String categoryPids;
/**
*
*/
@NotBlank(message = "角色分类名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("角色分类名称")
private String roleCategoryName;
/**
* 15-20-
*/
@NotNull(message = "角色分类类型15-业务角色20-公司角色不能为空", groups = {add.class, edit.class})
@ChineseDescription("角色分类类型15-业务角色20-公司角色")
private Integer categoryType;
/**
*
*/
@ChineseDescription("租户号")
private Long tenantId;
/**
* id
*/
@NotNull(message = "批量删除id集合不能为空", groups = batchDelete.class)
@ChineseDescription("批量删除用的id集合")
private List<Long> batchDeleteIdList;
}

View File

@ -0,0 +1,17 @@
package cn.stylefeng.roses.kernel.sys.modular.role.pojo.response;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RoleCategoryVo extends RoleCategory {
}

View File

@ -0,0 +1,83 @@
package cn.stylefeng.roses.kernel.sys.modular.role.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleCategoryRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
public interface RoleCategoryService extends IService<RoleCategory> {
/**
*
*
* @param roleCategoryRequest
* @author fengshuonan
* @since 2025/01/22 17:40
*/
void add(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @author fengshuonan
* @since 2025/01/22 17:40
*/
void del(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @author fengshuonan
* @since 2025/01/22 17:40
*/
void batchDelete(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @author fengshuonan
* @since 2025/01/22 17:40
*/
void edit(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @author fengshuonan
* @since 2025/01/22 17:40
*/
RoleCategory detail(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @return List<RoleCategory>
* @author fengshuonan
* @since 2025/01/22 17:40
*/
List<RoleCategory> findList(RoleCategoryRequest roleCategoryRequest);
/**
*
*
* @param roleCategoryRequest
* @return PageResult<RoleCategory>
* @author fengshuonan
* @since 2025/01/22 17:40
*/
PageResult<RoleCategory> findPage(RoleCategoryRequest roleCategoryRequest);
}

View File

@ -0,0 +1,117 @@
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.RoleCategory;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.RoleCategoryExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.role.mapper.RoleCategoryMapper;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleCategoryRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.service.RoleCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
@Service
public class RoleCategoryServiceImpl extends ServiceImpl<RoleCategoryMapper, RoleCategory> implements RoleCategoryService {
@Override
public void add(RoleCategoryRequest roleCategoryRequest) {
RoleCategory roleCategory = new RoleCategory();
BeanUtil.copyProperties(roleCategoryRequest, roleCategory);
this.save(roleCategory);
}
@Override
public void del(RoleCategoryRequest roleCategoryRequest) {
RoleCategory roleCategory = this.queryRoleCategory(roleCategoryRequest);
this.removeById(roleCategory.getId());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchDelete(RoleCategoryRequest roleCategoryRequest) {
this.removeByIds(roleCategoryRequest.getBatchDeleteIdList());
}
@Override
public void edit(RoleCategoryRequest roleCategoryRequest) {
RoleCategory roleCategory = this.queryRoleCategory(roleCategoryRequest);
BeanUtil.copyProperties(roleCategoryRequest, roleCategory);
this.updateById(roleCategory);
}
@Override
public RoleCategory detail(RoleCategoryRequest roleCategoryRequest) {
return this.queryRoleCategory(roleCategoryRequest);
}
@Override
public PageResult<RoleCategory> findPage(RoleCategoryRequest roleCategoryRequest) {
LambdaQueryWrapper<RoleCategory> wrapper = createWrapper(roleCategoryRequest);
Page<RoleCategory> pageList = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(pageList);
}
@Override
public List<RoleCategory> findList(RoleCategoryRequest roleCategoryRequest) {
LambdaQueryWrapper<RoleCategory> wrapper = this.createWrapper(roleCategoryRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
private RoleCategory queryRoleCategory(RoleCategoryRequest roleCategoryRequest) {
RoleCategory roleCategory = this.getById(roleCategoryRequest.getId());
if (ObjectUtil.isEmpty(roleCategory)) {
throw new ServiceException(RoleCategoryExceptionEnum.ROLE_CATEGORY_NOT_EXISTED);
}
return roleCategory;
}
/**
* wrapper
*
* @author fengshuonan
* @since 2025/01/22 17:40
*/
private LambdaQueryWrapper<RoleCategory> createWrapper(RoleCategoryRequest roleCategoryRequest) {
LambdaQueryWrapper<RoleCategory> queryWrapper = new LambdaQueryWrapper<>();
Long id = roleCategoryRequest.getId();
queryWrapper.eq(ObjectUtil.isNotNull(id), RoleCategory::getId, id);
Long categoryParentId = roleCategoryRequest.getCategoryParentId();
queryWrapper.eq(ObjectUtil.isNotNull(categoryParentId), RoleCategory::getCategoryParentId, categoryParentId);
String categoryPids = roleCategoryRequest.getCategoryPids();
queryWrapper.like(ObjectUtil.isNotEmpty(categoryPids), RoleCategory::getCategoryPids, categoryPids);
String roleCategoryName = roleCategoryRequest.getRoleCategoryName();
queryWrapper.like(ObjectUtil.isNotEmpty(roleCategoryName), RoleCategory::getRoleCategoryName, roleCategoryName);
Integer categoryType = roleCategoryRequest.getCategoryType();
queryWrapper.eq(ObjectUtil.isNotNull(categoryType), RoleCategory::getCategoryType, categoryType);
return queryWrapper;
}
}