角色管理
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.controller;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleAddReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleBindFunReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleEditReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleQueryReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.res.role.RoleQueryRes;
|
||||||
|
import com.cczsa.xinghe.codegen.service.RoleService;
|
||||||
|
import com.cczsa.xinghe.codegen.util.XResult;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色管理 控制层。
|
||||||
|
*
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Tag(name = "角色管理")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/role")
|
||||||
|
public class RoleController {
|
||||||
|
|
||||||
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "获取角色列表", description = "获取角色列表")
|
||||||
|
@PostMapping("/query")
|
||||||
|
public XResult<List<RoleQueryRes>> query(@RequestBody @Valid RoleQueryReq req) {
|
||||||
|
return roleService.query(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "创建角色", description = "创建角色")
|
||||||
|
@PutMapping("/add")
|
||||||
|
public XResult<Void> add(@RequestBody @Valid RoleAddReq req) {
|
||||||
|
return roleService.add(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改角色", description = "修改角色")
|
||||||
|
@PostMapping("/edit")
|
||||||
|
public XResult<Void> edit(@RequestBody @Valid RoleEditReq req) {
|
||||||
|
return roleService.edit(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除角色", description = "删除角色")
|
||||||
|
@DeleteMapping("/delete/{roleId}")
|
||||||
|
public XResult<Void> delete(@PathVariable Long roleId) {
|
||||||
|
return roleService.delete(roleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "角色设置权限", description = "角色设置权限")
|
||||||
|
@PostMapping("/bind/fun")
|
||||||
|
public XResult<Void> bindFun(@RequestBody @Valid RoleBindFunReq req) {
|
||||||
|
return roleService.bindFun(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除角色权限", description = "删除角色权限")
|
||||||
|
@DeleteMapping("/delete/fun/{roleBindFunId}")
|
||||||
|
public XResult<Void> deleteFun(@PathVariable Long roleBindFunId) {
|
||||||
|
return roleService.deleteFun(roleBindFunId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.RoleTypeEnum;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色表 实体类。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Table("cg_role")
|
||||||
|
public class RoleEntity extends BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称
|
||||||
|
*/
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色类型 0平台 1套餐
|
||||||
|
*/
|
||||||
|
private RoleTypeEnum roleType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||||
|
import com.cczsa.xinghe.codegen.handler.PostgreSQLJsonTypeHandler;
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import org.postgresql.util.PGobject;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限表 实体类。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Table("cg_role_fun")
|
||||||
|
public class RoleFunEntity extends BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色ID
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限ID
|
||||||
|
*/
|
||||||
|
private Long funId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限
|
||||||
|
*/
|
||||||
|
private UsableConfigEnum dataScope;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定的数据权限范围
|
||||||
|
*/
|
||||||
|
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||||
|
private List<Long> assignDataScope;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除的字段
|
||||||
|
*/
|
||||||
|
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||||
|
private List<String> excludeField;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.mybatisflex.annotation.EnumValue;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色类型枚举
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
*/
|
||||||
|
@Schema(description = "角色类型",
|
||||||
|
example = "0",
|
||||||
|
allowableValues = {"0: 平台", "1: 套餐"})
|
||||||
|
@Getter
|
||||||
|
public enum RoleTypeEnum {
|
||||||
|
|
||||||
|
PLATFORM(0, "平台"),
|
||||||
|
PACKAGE(1, "套餐");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String desc;
|
||||||
|
|
||||||
|
RoleTypeEnum(int code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
@EnumValue
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.req.role;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.RoleTypeEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建角色 请求参数
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "创建角色-参数")
|
||||||
|
public class RoleAddReq implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Min(value = 100, message = "id必须大于等于100小于等于999")
|
||||||
|
@Max(value = 999, message = "id必须大于等于100小于等于999")
|
||||||
|
@NotNull(message = "角色id不能为空")
|
||||||
|
@Schema(description = "角色id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank(message = "角色名称不能为空")
|
||||||
|
@Schema(description = "角色名称")
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@NotNull(message = "角色类型不能为空")
|
||||||
|
@Schema(description = "角色类型")
|
||||||
|
private RoleTypeEnum roleType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.req.role;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色设置权限 请求参数
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "角色设置权限-参数")
|
||||||
|
public class RoleBindFunReq implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@NotNull(message = "角色不能为空")
|
||||||
|
@Schema(description = "角色id")
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
@NotNull(message = "权限不能为空")
|
||||||
|
@Schema(description = "权限id")
|
||||||
|
private Long funId;
|
||||||
|
|
||||||
|
@Schema(description = "数据权限")
|
||||||
|
private UsableConfigEnum dataScope;
|
||||||
|
|
||||||
|
@Schema(description = "指定的部门ids")
|
||||||
|
private List<Long> deptDataScope;
|
||||||
|
|
||||||
|
@Schema(description = "指定的用户ids")
|
||||||
|
private List<Long> userDataScope;
|
||||||
|
|
||||||
|
@Schema(description = "排除的字段 根据 fieldConfig 进行设置")
|
||||||
|
private List<String> excludeField;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.req.role;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.RoleTypeEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改角色 请求参数
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "修改角色-参数")
|
||||||
|
public class RoleEditReq implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Min(value = 100, message = "id必须大于等于100小于等于999")
|
||||||
|
@Max(value = 999, message = "id必须大于等于100小于等于999")
|
||||||
|
@NotNull(message = "角色id不能为空")
|
||||||
|
@Schema(description = "角色id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank(message = "角色名称不能为空")
|
||||||
|
@Schema(description = "角色名称")
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@NotNull(message = "角色类型不能为空")
|
||||||
|
@Schema(description = "角色类型")
|
||||||
|
private RoleTypeEnum roleType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.req.role;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.RoleTypeEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色列表 请求参数
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "获取角色列表-参数")
|
||||||
|
public class RoleQueryReq implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "角色名称")
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@Schema(description = "角色类型")
|
||||||
|
private RoleTypeEnum roleType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.entity.res.role;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.RoleTypeEnum;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色列表 响应参数
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Schema(description = "获取角色列表-响应")
|
||||||
|
public class RoleQueryRes implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "角色id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "角色名称")
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@Schema(description = "角色类型")
|
||||||
|
private RoleTypeEnum roleType;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.RoleFunEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限表 映射层。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RoleFunMapper extends BaseMapper<RoleFunEntity> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.RoleEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色表 映射层。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RoleMapper extends BaseMapper<RoleEntity> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.mapper.def;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色表 表定义层。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
public class RoleDef extends TableDef {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色表
|
||||||
|
*/
|
||||||
|
public static final RoleDef ROLE_ENTITY = new RoleDef();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称
|
||||||
|
*/
|
||||||
|
public final QueryColumn ROLE_NAME = new QueryColumn(this, "role_name");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色类型 0平台 1套餐
|
||||||
|
*/
|
||||||
|
public final QueryColumn ROLE_TYPE = new QueryColumn(this, "role_type");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, ROLE_NAME, ROLE_TYPE};
|
||||||
|
|
||||||
|
public RoleDef() {
|
||||||
|
super("", "cg_role");
|
||||||
|
}
|
||||||
|
|
||||||
|
private RoleDef(String schema, String name, String alisa) {
|
||||||
|
super(schema, name, alisa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleDef as(String alias) {
|
||||||
|
String key = getNameWithSchema() + "." + alias;
|
||||||
|
return getCache(key, k -> new RoleDef("", "cg_role", alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.mapper.def;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限表 表定义层。
|
||||||
|
*
|
||||||
|
* @author My
|
||||||
|
* @since 0.0.1
|
||||||
|
*/
|
||||||
|
public class RoleFunDef extends TableDef {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限表
|
||||||
|
*/
|
||||||
|
public static final RoleFunDef ROLE_FUN_ENTITY = new RoleFunDef();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限ID
|
||||||
|
*/
|
||||||
|
public final QueryColumn FUN_ID = new QueryColumn(this, "fun_id");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色ID
|
||||||
|
*/
|
||||||
|
public final QueryColumn ROLE_ID = new QueryColumn(this, "role_id");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限默认:0无
|
||||||
|
*/
|
||||||
|
public final QueryColumn DATA_SCOPE = new QueryColumn(this, "data_scope");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除的字段
|
||||||
|
*/
|
||||||
|
public final QueryColumn EXCLUDE_FIELD = new QueryColumn(this, "exclude_field");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定的数据权限范围
|
||||||
|
*/
|
||||||
|
public final QueryColumn ASSIGN_DATA_SCOPE = new QueryColumn(this, "assign_data_scope");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||||
|
*/
|
||||||
|
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, ROLE_ID, FUN_ID, DATA_SCOPE, ASSIGN_DATA_SCOPE, EXCLUDE_FIELD};
|
||||||
|
|
||||||
|
public RoleFunDef() {
|
||||||
|
super("", "cg_role_fun");
|
||||||
|
}
|
||||||
|
|
||||||
|
private RoleFunDef(String schema, String name, String alisa) {
|
||||||
|
super(schema, name, alisa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleFunDef as(String alias) {
|
||||||
|
String key = getNameWithSchema() + "." + alias;
|
||||||
|
return getCache(key, k -> new RoleFunDef("", "cg_role_fun", alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.service;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleAddReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleBindFunReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleEditReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleQueryReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.res.role.RoleQueryRes;
|
||||||
|
import com.cczsa.xinghe.codegen.util.XResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色管理 服务层接口。
|
||||||
|
*
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
public interface RoleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色列表
|
||||||
|
*/
|
||||||
|
XResult<List<RoleQueryRes>> query(RoleQueryReq req);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建角色
|
||||||
|
*/
|
||||||
|
XResult<Void> add(RoleAddReq req);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改角色
|
||||||
|
*/
|
||||||
|
XResult<Void> edit(RoleEditReq req);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
*/
|
||||||
|
XResult<Void> delete(Long roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色设置权限
|
||||||
|
*/
|
||||||
|
XResult<Void> bindFun(RoleBindFunReq req);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色权限
|
||||||
|
*/
|
||||||
|
XResult<Void> deleteFun(Long roleBindFunId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
package com.cczsa.xinghe.codegen.service.impl;
|
||||||
|
|
||||||
|
import com.cczsa.xinghe.codegen.entity.FunOperationEntity;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.RoleEntity;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.RoleFunEntity;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleAddReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleBindFunReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleEditReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.req.role.RoleQueryReq;
|
||||||
|
import com.cczsa.xinghe.codegen.entity.res.role.RoleQueryRes;
|
||||||
|
import com.cczsa.xinghe.codegen.mapper.FunOperationMapper;
|
||||||
|
import com.cczsa.xinghe.codegen.mapper.RoleFunMapper;
|
||||||
|
import com.cczsa.xinghe.codegen.mapper.RoleMapper;
|
||||||
|
import com.cczsa.xinghe.codegen.mapper.def.RoleDef;
|
||||||
|
import com.cczsa.xinghe.codegen.mapper.def.RoleFunDef;
|
||||||
|
import com.cczsa.xinghe.codegen.service.RoleService;
|
||||||
|
import com.cczsa.xinghe.codegen.util.XResult;
|
||||||
|
import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色管理 服务层实现。
|
||||||
|
*
|
||||||
|
* @author xia
|
||||||
|
* @version 0.0.1
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RoleServiceImpl implements RoleService {
|
||||||
|
|
||||||
|
private final RoleMapper roleMapper;
|
||||||
|
private final RoleFunMapper roleFunMapper;
|
||||||
|
private final FunOperationMapper funOperationMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XResult<List<RoleQueryRes>> query(RoleQueryReq req) {
|
||||||
|
RoleDef roleDef = RoleDef.ROLE_ENTITY;
|
||||||
|
QueryWrapper query = new QueryWrapper();
|
||||||
|
query.select(roleDef.ALL_COLUMNS)
|
||||||
|
.from(roleDef)
|
||||||
|
.like(RoleEntity::getRoleName, req.getRoleName(), StrUtil.isNotBlank(req.getRoleName()))
|
||||||
|
.eq(RoleEntity::getRoleType, req.getRoleType(), req.getRoleType() != null);
|
||||||
|
List<RoleQueryRes> roleQueryRes = roleMapper.selectListByQueryAs(query, RoleQueryRes.class);
|
||||||
|
return XResult.ok(roleQueryRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建角色
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XResult<Void> add(RoleAddReq req) {
|
||||||
|
// 角色是否存在
|
||||||
|
QueryWrapper queryRole = new QueryWrapper();
|
||||||
|
queryRole.eq(RoleEntity::getRoleName, req.getRoleName());
|
||||||
|
queryRole.eq(RoleEntity::getRoleType, req.getRoleType());
|
||||||
|
if (roleMapper.selectCountByQuery(queryRole) > 0) {
|
||||||
|
return XResult.failed("角色已存在");
|
||||||
|
}
|
||||||
|
RoleEntity role = new RoleEntity();
|
||||||
|
role.setId(req.getId());
|
||||||
|
role.setRoleName(req.getRoleName());
|
||||||
|
role.setRoleType(req.getRoleType());
|
||||||
|
roleMapper.insertSelective(role);
|
||||||
|
return XResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改角色
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XResult<Void> edit(RoleEditReq req) {
|
||||||
|
RoleEntity role = roleMapper.selectOneById(req.getId());
|
||||||
|
if (role == null) {
|
||||||
|
return XResult.failed("角色不存在");
|
||||||
|
}
|
||||||
|
// 角色是否存在
|
||||||
|
QueryWrapper queryRole = new QueryWrapper();
|
||||||
|
queryRole.eq(RoleEntity::getRoleName, req.getRoleName());
|
||||||
|
queryRole.eq(RoleEntity::getRoleType, req.getRoleType());
|
||||||
|
queryRole.ne(RoleEntity::getId, req.getId());
|
||||||
|
if (roleMapper.selectCountByQuery(queryRole) > 0) {
|
||||||
|
return XResult.failed("角色已存在");
|
||||||
|
}
|
||||||
|
BeanUtils.copyProperties(req, role);
|
||||||
|
roleMapper.update(role);
|
||||||
|
return XResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public XResult<Void> delete(Long roleId) {
|
||||||
|
// 删除角色
|
||||||
|
QueryWrapper deleteRole = new QueryWrapper();
|
||||||
|
deleteRole.eq(RoleEntity::getId, roleId);
|
||||||
|
roleMapper.deleteByQuery(deleteRole);
|
||||||
|
// 删除角色权限
|
||||||
|
QueryWrapper deleteRoleFun = new QueryWrapper();
|
||||||
|
deleteRoleFun.eq(RoleFunEntity::getRoleId, roleId);
|
||||||
|
roleFunMapper.deleteByQuery(deleteRoleFun);
|
||||||
|
return XResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色设置权限
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XResult<Void> bindFun(RoleBindFunReq req) {
|
||||||
|
FunOperationEntity funOperationEntity = funOperationMapper.selectOneById(req.getFunId());
|
||||||
|
if (funOperationEntity == null) {
|
||||||
|
return XResult.failed("权限不存在");
|
||||||
|
}
|
||||||
|
List<UsableConfigEnum> usableConfig = funOperationEntity.getUsableConfig();
|
||||||
|
List<String> fieldConfig = funOperationEntity.getFieldConfig();
|
||||||
|
// 校验assignDataScope中的值是否都在usableConfig中存在
|
||||||
|
UsableConfigEnum dataScope = req.getDataScope();
|
||||||
|
if (dataScope != null && dataScope != UsableConfigEnum.NO_PROCESSING) {
|
||||||
|
if (!usableConfig.contains(dataScope)) {
|
||||||
|
return XResult.failed("可配置数据类型不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> excludeField = req.getExcludeField();
|
||||||
|
// 校验excludeField中的值是否都在fieldConfig中存在
|
||||||
|
if (excludeField != null && !excludeField.isEmpty()) {
|
||||||
|
if (fieldConfig == null || fieldConfig.isEmpty()) {
|
||||||
|
return XResult.failed("可配置字段不存在");
|
||||||
|
}
|
||||||
|
for (String field : excludeField) {
|
||||||
|
if (!fieldConfig.contains(field)) {
|
||||||
|
return XResult.failed("可配置字段不存在:" + field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 新增权限
|
||||||
|
RoleFunEntity roleFunEntity = new RoleFunEntity();
|
||||||
|
if (dataScope == UsableConfigEnum.SPECIFIED_DEPARTMENT) {
|
||||||
|
if (req.getDeptDataScope() == null || req.getDeptDataScope().isEmpty()) {
|
||||||
|
return XResult.failed("请选择指定的部门");
|
||||||
|
}
|
||||||
|
roleFunEntity.setAssignDataScope(req.getDeptDataScope());
|
||||||
|
// 用户
|
||||||
|
} else if (dataScope == UsableConfigEnum.SPECIFIED_USER) {
|
||||||
|
if (req.getUserDataScope() == null || req.getUserDataScope().isEmpty()) {
|
||||||
|
return XResult.failed("请选择指定的用户");
|
||||||
|
}
|
||||||
|
roleFunEntity.setAssignDataScope(req.getUserDataScope());
|
||||||
|
} else {
|
||||||
|
roleFunEntity.setAssignDataScope(new ArrayList<>());
|
||||||
|
}
|
||||||
|
roleFunEntity.setRoleId(req.getRoleId());
|
||||||
|
roleFunEntity.setFunId(req.getFunId());
|
||||||
|
roleFunEntity.setDataScope(req.getDataScope());
|
||||||
|
roleFunEntity.setExcludeField(req.getExcludeField());
|
||||||
|
if (req.getExcludeField() == null || !req.getExcludeField().isEmpty()) {
|
||||||
|
roleFunEntity.setExcludeField(new ArrayList<>());
|
||||||
|
}
|
||||||
|
// 删除旧权限
|
||||||
|
QueryWrapper deleteRoleFun = new QueryWrapper();
|
||||||
|
deleteRoleFun.eq(RoleFunEntity::getRoleId, req.getRoleId());
|
||||||
|
deleteRoleFun.eq(RoleFunEntity::getFunId, req.getFunId());
|
||||||
|
roleFunMapper.deleteByQuery(deleteRoleFun);
|
||||||
|
// 获取最大ID
|
||||||
|
RoleFunDef roleFunDef = RoleFunDef.ROLE_FUN_ENTITY;
|
||||||
|
QueryWrapper queryRoleFun = new QueryWrapper();
|
||||||
|
queryRoleFun.select(roleFunDef.ID)
|
||||||
|
.from(roleFunDef)
|
||||||
|
.orderBy(roleFunDef.ID, false);
|
||||||
|
Long maxId = roleFunMapper.selectOneByQueryAs(queryRoleFun, Long.class);
|
||||||
|
if (maxId == null) {
|
||||||
|
maxId = 10000L;
|
||||||
|
} else {
|
||||||
|
maxId++;
|
||||||
|
}
|
||||||
|
roleFunEntity.setId(maxId);
|
||||||
|
// 新增权限
|
||||||
|
roleFunMapper.insertSelective(roleFunEntity);
|
||||||
|
return XResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色权限
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public XResult<Void> deleteFun(Long roleBindFunId) {
|
||||||
|
QueryWrapper deleteRoleFun = new QueryWrapper();
|
||||||
|
deleteRoleFun.eq(RoleFunEntity::getId, roleBindFunId);
|
||||||
|
roleFunMapper.deleteByQuery(deleteRoleFun);
|
||||||
|
return XResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user