feat(新增): 新增权限内容,修改部分缺陷
This commit is contained in:
parent
5dec36899d
commit
bf1c466ccf
|
@ -3,11 +3,11 @@ package cn.bunny.common.generator.generator;
|
||||||
import cn.bunny.common.generator.entity.BaseField;
|
import cn.bunny.common.generator.entity.BaseField;
|
||||||
import cn.bunny.common.generator.entity.BaseResultMap;
|
import cn.bunny.common.generator.entity.BaseResultMap;
|
||||||
import cn.bunny.common.generator.utils.GeneratorCodeUtils;
|
import cn.bunny.common.generator.utils.GeneratorCodeUtils;
|
||||||
import cn.bunny.dao.dto.system.role.RoleAddDto;
|
import cn.bunny.dao.dto.system.rolePower.PowerAddDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.PowerDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleUpdateDto;
|
import cn.bunny.dao.dto.system.rolePower.PowerUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Power;
|
||||||
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
import cn.bunny.dao.vo.system.rolePower.PowerVo;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
@ -51,11 +51,11 @@ public class WebGeneratorCode {
|
||||||
public static String resourceMapperPath = "D:\\Project\\web\\PC\\auth\\auth-server-java\\service\\src\\main\\resources\\mapper\\";
|
public static String resourceMapperPath = "D:\\Project\\web\\PC\\auth\\auth-server-java\\service\\src\\main\\resources\\mapper\\";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Class<?> originalClass = Role.class;
|
Class<?> originalClass = Power.class;
|
||||||
Class<?> dtoClass = RoleDto.class;
|
Class<?> dtoClass = PowerDto.class;
|
||||||
Class<?> addDtoClass = RoleAddDto.class;
|
Class<?> addDtoClass = PowerAddDto.class;
|
||||||
Class<?> updateDtoClass = RoleUpdateDto.class;
|
Class<?> updateDtoClass = PowerUpdateDto.class;
|
||||||
Class<?> voClass = RoleVo.class;
|
Class<?> voClass = PowerVo.class;
|
||||||
|
|
||||||
// 设置velocity资源加载器
|
// 设置velocity资源加载器
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
|
@ -109,10 +109,16 @@ public class WebGeneratorCode {
|
||||||
// 是否必须字段设置
|
// 是否必须字段设置
|
||||||
List<BaseField> baseFieldList = Arrays.stream(addDtoClass.getDeclaredFields()).map(field -> {
|
List<BaseField> baseFieldList = Arrays.stream(addDtoClass.getDeclaredFields()).map(field -> {
|
||||||
try {
|
try {
|
||||||
|
String message = "";
|
||||||
|
boolean hasMessage = false;
|
||||||
// 验证消息
|
// 验证消息
|
||||||
String message = field.getAnnotation(NotBlank.class).message();
|
NotBlank messageAnnotation = field.getAnnotation(NotBlank.class);
|
||||||
boolean hasMessage = StringUtils.hasText(message);
|
if (messageAnnotation != null) {
|
||||||
if (!hasMessage) message = field.getAnnotation(NotNull.class).message();
|
message = messageAnnotation.message();
|
||||||
|
hasMessage = StringUtils.hasText(message);
|
||||||
|
if (!hasMessage) message = field.getAnnotation(NotNull.class).message();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 设置基础字段注解和是否必填项
|
// 设置基础字段注解和是否必填项
|
||||||
BaseField baseField = new BaseField();
|
BaseField baseField = new BaseField();
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "PowerAddDto对象", title = "权限", description = "权限管理")
|
||||||
|
public class PowerAddDto {
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "父级id")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "权限编码")
|
||||||
|
@NotBlank(message = "权限编码 不能为空")
|
||||||
|
private String powerCode;
|
||||||
|
|
||||||
|
@Schema(name = "powerName", title = "权限名称")
|
||||||
|
@NotBlank(message = "权限名称 不能为空")
|
||||||
|
private String powerName;
|
||||||
|
|
||||||
|
@Schema(name = "requestUrl", title = "请求路径")
|
||||||
|
@NotBlank(message = "请求路径 不能为空")
|
||||||
|
private String requestUrl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "PowerDto对象", title = "权限", description = "权限管理")
|
||||||
|
public class PowerDto {
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "父级id")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@ApiModelProperty("权限编码")
|
||||||
|
@Schema(name = "parentId", title = "权限编码")
|
||||||
|
private String powerCode;
|
||||||
|
|
||||||
|
@Schema(name = "powerName", title = "权限名称")
|
||||||
|
private String powerName;
|
||||||
|
|
||||||
|
@Schema(name = "requestUrl", title = "请求路径")
|
||||||
|
private String requestUrl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "PowerUpdateDto对象", title = "权限", description = "权限管理")
|
||||||
|
public class PowerUpdateDto {
|
||||||
|
|
||||||
|
@Schema(name = "id", title = "主键")
|
||||||
|
@NotNull(message = "id不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "父级id")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "权限编码")
|
||||||
|
@NotBlank(message = "权限编码 不能为空")
|
||||||
|
private String powerCode;
|
||||||
|
|
||||||
|
@Schema(name = "powerName", title = "权限名称")
|
||||||
|
@NotBlank(message = "权限名称 不能为空")
|
||||||
|
private String powerName;
|
||||||
|
|
||||||
|
@Schema(name = "requestUrl", title = "请求路径")
|
||||||
|
@NotBlank(message = "请求路径 不能为空")
|
||||||
|
private String requestUrl;
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.bunny.dao.dto.system.role;
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.bunny.dao.dto.system.role;
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.bunny.dao.dto.system.role;
|
package cn.bunny.dao.dto.system.rolePower;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
|
@ -2,7 +2,6 @@ package cn.bunny.dao.entity.system;
|
||||||
|
|
||||||
import cn.bunny.dao.entity.BaseEntity;
|
import cn.bunny.dao.entity.BaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -16,7 +15,6 @@ public class Power extends BaseEntity {
|
||||||
@Schema(name = "parentId", title = "父级id")
|
@Schema(name = "parentId", title = "父级id")
|
||||||
private Long parentId;
|
private Long parentId;
|
||||||
|
|
||||||
@ApiModelProperty("权限编码")
|
|
||||||
@Schema(name = "parentId", title = "权限编码")
|
@Schema(name = "parentId", title = "权限编码")
|
||||||
private String powerCode;
|
private String powerCode;
|
||||||
|
|
||||||
|
@ -26,4 +24,5 @@ public class Power extends BaseEntity {
|
||||||
@Schema(name = "requestUrl", title = "请求路径")
|
@Schema(name = "requestUrl", title = "请求路径")
|
||||||
private String requestUrl;
|
private String requestUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||||
@TableName("sys_router_power")
|
@TableName("sys_router_power")
|
||||||
@Schema(name = "RouterPower对象", title = "路由和权限关系表", description = "路由和权限关系表")
|
@Schema(name = "RouterPower对象", title = "路由和权限关系表", description = "路由和权限关系表")
|
||||||
public class RouterPower extends BaseEntity {
|
public class RouterPower extends BaseEntity {
|
||||||
|
|
||||||
@Schema(name = "routerId", title = "路由ID")
|
@Schema(name = "routerId", title = "路由ID")
|
||||||
private Long routerId;
|
private Long routerId;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package cn.bunny.dao.vo.system.rolePower;
|
||||||
|
|
||||||
|
import cn.bunny.dao.vo.BaseVo;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "PowerVo对象", title = "权限", description = "权限管理")
|
||||||
|
public class PowerVo extends BaseVo {
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "父级id")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "权限编码")
|
||||||
|
private String powerCode;
|
||||||
|
|
||||||
|
@Schema(name = "powerName", title = "权限名称")
|
||||||
|
private String powerName;
|
||||||
|
|
||||||
|
@Schema(name = "requestUrl", title = "请求路径")
|
||||||
|
private String requestUrl;
|
||||||
|
|
||||||
|
}
|
|
@ -18,4 +18,6 @@ public class RoleVo extends BaseVo {
|
||||||
@Schema(name = "description", title = "描述")
|
@Schema(name = "description", title = "描述")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,72 @@
|
||||||
package cn.bunny.services.controller;
|
package cn.bunny.services.controller;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import cn.bunny.dao.dto.system.rolePower.PowerAddDto;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import cn.bunny.dao.dto.system.rolePower.PowerDto;
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerUpdateDto;
|
||||||
|
import cn.bunny.dao.entity.system.Power;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
|
import cn.bunny.dao.pojo.result.Result;
|
||||||
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
|
import cn.bunny.dao.vo.system.rolePower.PowerVo;
|
||||||
|
import cn.bunny.services.service.PowerService;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 前端控制器
|
* 权限表 前端控制器
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-09-26
|
* @since 2024-10-03 16:00:52
|
||||||
*/
|
*/
|
||||||
|
@Tag(name = "权限", description = "权限相关接口")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/power")
|
@RequestMapping("admin/power")
|
||||||
public class PowerController {
|
public class PowerController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PowerService powerService;
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询权限", description = "分页查询权限")
|
||||||
|
@GetMapping("getPowerList/{page}/{limit}")
|
||||||
|
public Mono<Result<PageResult<PowerVo>>> getPowerList(
|
||||||
|
@Parameter(name = "page", description = "当前页", required = true)
|
||||||
|
@PathVariable("page") Integer page,
|
||||||
|
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||||
|
@PathVariable("limit") Integer limit,
|
||||||
|
PowerDto dto) {
|
||||||
|
Page<Power> pageParams = new Page<>(page, limit);
|
||||||
|
PageResult<PowerVo> pageResult = powerService.getPowerList(pageParams, dto);
|
||||||
|
return Mono.just(Result.success(pageResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加权限", description = "添加权限")
|
||||||
|
@PostMapping("addPower")
|
||||||
|
public Mono<Result<String>> addPower(@Valid @RequestBody PowerAddDto dto) {
|
||||||
|
powerService.addPower(dto);
|
||||||
|
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新权限", description = "更新权限")
|
||||||
|
@PutMapping("updatePower")
|
||||||
|
public Mono<Result<String>> updatePower(@Valid @RequestBody PowerUpdateDto dto) {
|
||||||
|
powerService.updatePower(dto);
|
||||||
|
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除权限", description = "删除权限")
|
||||||
|
@DeleteMapping("deletePower")
|
||||||
|
public Mono<Result<String>> deletePower(@RequestBody List<Long> ids) {
|
||||||
|
powerService.deletePower(ids);
|
||||||
|
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.bunny.services.controller;
|
package cn.bunny.services.controller;
|
||||||
|
|
||||||
import cn.bunny.dao.dto.system.role.RoleAddDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleAddDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleUpdateDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Role;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.Result;
|
import cn.bunny.dao.pojo.result.Result;
|
||||||
|
|
|
@ -1,22 +1,43 @@
|
||||||
package cn.bunny.services.mapper;
|
package cn.bunny.services.mapper;
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerDto;
|
||||||
import cn.bunny.dao.entity.system.Power;
|
import cn.bunny.dao.entity.system.Power;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Mapper 接口
|
* 权限 Mapper 接口
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-09-26
|
* @since 2024-10-03 16:00:52
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PowerMapper extends BaseMapper<Power> {
|
public interface PowerMapper extends BaseMapper<Power> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 分页查询权限内容
|
||||||
|
*
|
||||||
|
* @param pageParams 权限分页参数
|
||||||
|
* @param dto 权限查询表单
|
||||||
|
* @return 权限分页结果
|
||||||
|
*/
|
||||||
|
IPage<Power> selectListByPage(@Param("page") Page<Power> pageParams, @Param("dto") PowerDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物理删除权限
|
||||||
|
*
|
||||||
|
* @param ids 删除 id 列表
|
||||||
|
*/
|
||||||
|
void deleteBatchIdsWithPhysics(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 根据用户id查询当前用户所有角色
|
* * 根据用户id查询当前用户所有角色
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package cn.bunny.services.mapper;
|
package cn.bunny.services.mapper;
|
||||||
|
|
||||||
import cn.bunny.dao.dto.system.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleDto;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Role;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
|
|
@ -1,16 +1,52 @@
|
||||||
package cn.bunny.services.service;
|
package cn.bunny.services.service;
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerAddDto;
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerDto;
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Power;
|
import cn.bunny.dao.entity.system.Power;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
|
import cn.bunny.dao.vo.system.rolePower.PowerVo;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 服务类
|
* 权限 服务类
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-09-26
|
* @since 2024-10-03 16:00:52
|
||||||
*/
|
*/
|
||||||
public interface PowerService extends IService<Power> {
|
public interface PowerService extends IService<Power> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 获取权限列表
|
||||||
|
*
|
||||||
|
* @return 权限返回列表
|
||||||
|
*/
|
||||||
|
PageResult<PowerVo> getPowerList(Page<Power> pageParams, PowerDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 添加权限
|
||||||
|
*
|
||||||
|
* @param dto 添加表单
|
||||||
|
*/
|
||||||
|
void addPower(@Valid PowerAddDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 更新权限
|
||||||
|
*
|
||||||
|
* @param dto 更新表单
|
||||||
|
*/
|
||||||
|
void updatePower(@Valid PowerUpdateDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 删除|批量删除权限类型
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
void deletePower(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.bunny.services.service;
|
package cn.bunny.services.service;
|
||||||
|
|
||||||
import cn.bunny.dao.dto.system.role.RoleAddDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleAddDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleUpdateDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Role;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
||||||
|
|
|
@ -1,20 +1,92 @@
|
||||||
package cn.bunny.services.service.impl;
|
package cn.bunny.services.service.impl;
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerAddDto;
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerDto;
|
||||||
|
import cn.bunny.dao.dto.system.rolePower.PowerUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Power;
|
import cn.bunny.dao.entity.system.Power;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
|
import cn.bunny.dao.vo.system.rolePower.PowerVo;
|
||||||
import cn.bunny.services.mapper.PowerMapper;
|
import cn.bunny.services.mapper.PowerMapper;
|
||||||
import cn.bunny.services.service.PowerService;
|
import cn.bunny.services.service.PowerService;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 服务实现类
|
* 权限 服务实现类
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-09-26
|
* @since 2024-10-03 16:00:52
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements PowerService {
|
public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements PowerService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 权限 服务实现类
|
||||||
|
*
|
||||||
|
* @param pageParams 权限分页查询page对象
|
||||||
|
* @param dto 权限分页查询对象
|
||||||
|
* @return 查询分页权限返回对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<PowerVo> getPowerList(Page<Power> pageParams, PowerDto dto) {
|
||||||
|
// 分页查询菜单图标
|
||||||
|
IPage<Power> page = baseMapper.selectListByPage(pageParams, dto);
|
||||||
|
|
||||||
|
List<PowerVo> voList = page.getRecords().stream().map(Power -> {
|
||||||
|
PowerVo PowerVo = new PowerVo();
|
||||||
|
BeanUtils.copyProperties(Power, PowerVo);
|
||||||
|
return PowerVo;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
return PageResult.<PowerVo>builder()
|
||||||
|
.list(voList)
|
||||||
|
.pageNo(page.getCurrent())
|
||||||
|
.pageSize(page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加权限
|
||||||
|
*
|
||||||
|
* @param dto 权限添加
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addPower(@Valid PowerAddDto dto) {
|
||||||
|
// 保存数据
|
||||||
|
Power power = new Power();
|
||||||
|
BeanUtils.copyProperties(dto, power);
|
||||||
|
save(power);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新权限
|
||||||
|
*
|
||||||
|
* @param dto 权限更新
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updatePower(@Valid PowerUpdateDto dto) {
|
||||||
|
// 更新内容
|
||||||
|
Power power = new Power();
|
||||||
|
BeanUtils.copyProperties(dto, power);
|
||||||
|
updateById(power);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除|批量删除权限
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deletePower(List<Long> ids) {
|
||||||
|
baseMapper.deleteBatchIdsWithPhysics(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cn.bunny.services.service.impl;
|
package cn.bunny.services.service.impl;
|
||||||
|
|
||||||
import cn.bunny.dao.dto.system.role.RoleAddDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleAddDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleDto;
|
||||||
import cn.bunny.dao.dto.system.role.RoleUpdateDto;
|
import cn.bunny.dao.dto.system.rolePower.RoleUpdateDto;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Role;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
||||||
|
|
|
@ -5,22 +5,54 @@
|
||||||
<!-- 通用查询映射结果 -->
|
<!-- 通用查询映射结果 -->
|
||||||
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Power">
|
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Power">
|
||||||
<id column="id" property="id"/>
|
<id column="id" property="id"/>
|
||||||
<result column="parent_id" property="parentId"/>
|
<id column="create_time" property="createTime"/>
|
||||||
<result column="power_code" property="powerCode"/>
|
<id column="update_time" property="updateTime"/>
|
||||||
<result column="power_name" property="powerName"/>
|
<id column="create_user" property="createUser"/>
|
||||||
<result column="request_url" property="requestUrl"/>
|
<id column="update_user" property="updateUser"/>
|
||||||
<result column="create_time" property="createTime"/>
|
<id column="is_deleted" property="isDeleted"/>
|
||||||
<result column="update_time" property="updateTime"/>
|
<id column="parent_id" property="parentId"/>
|
||||||
<result column="create_user" property="createUser"/>
|
<id column="power_code" property="powerCode"/>
|
||||||
<result column="update_user" property="updateUser"/>
|
<id column="power_name" property="powerName"/>
|
||||||
<result column="is_deleted" property="isDeleted"/>
|
<id column="request_url" property="requestUrl"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<!-- 通用查询结果列 -->
|
<!-- 通用查询结果列 -->
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, parent_id, power_code, power_name, request_url, create_time, update_time, create_user, update_user, is_deleted
|
id, create_time, update_time, create_user, update_user, is_deleted, parent_id, power_code, power_name, request_url
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<!-- 分页查询权限内容 -->
|
||||||
|
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.Power">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
from sys_power
|
||||||
|
<where>
|
||||||
|
<if test="dto.parentId != null and dto.parentId != ''">
|
||||||
|
parent_id like CONCAT('%',#{dto.parentId},'%')
|
||||||
|
</if>
|
||||||
|
<if test="dto.powerCode != null and dto.powerCode != ''">
|
||||||
|
power_code like CONCAT('%',#{dto.powerCode},'%')
|
||||||
|
</if>
|
||||||
|
<if test="dto.powerName != null and dto.powerName != ''">
|
||||||
|
power_name like CONCAT('%',#{dto.powerName},'%')
|
||||||
|
</if>
|
||||||
|
<if test="dto.requestUrl != null and dto.requestUrl != ''">
|
||||||
|
request_url like CONCAT('%',#{dto.requestUrl},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by update_time
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 物理删除权限 -->
|
||||||
|
<delete id="deleteBatchIdsWithPhysics">
|
||||||
|
delete
|
||||||
|
from sys_power
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<!-- 根据用户id查询当前用户所有角色 -->
|
<!-- 根据用户id查询当前用户所有角色 -->
|
||||||
<select id="selectListByUserId" resultType="cn.bunny.dao.entity.system.Power">
|
<select id="selectListByUserId" resultType="cn.bunny.dao.entity.system.Power">
|
||||||
SELECT p.*
|
SELECT p.*
|
||||||
|
@ -33,6 +65,8 @@
|
||||||
AND rp.power_id = p.id
|
AND rp.power_id = p.id
|
||||||
AND u.id = #{userId}
|
AND u.id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据权限码返回权限列表 -->
|
||||||
<select id="selectListByPowerCodes" resultType="cn.bunny.dao.entity.system.Power">
|
<select id="selectListByPowerCodes" resultType="cn.bunny.dao.entity.system.Power">
|
||||||
SELECT * FROM sys_power WHERE power_code IN
|
SELECT * FROM sys_power WHERE power_code IN
|
||||||
<foreach collection="powerCodes" separator="," item="code" open="(" close=")">
|
<foreach collection="powerCodes" separator="," item="code" open="(" close=")">
|
||||||
|
|
Loading…
Reference in New Issue