2026-4-30添加更新
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.rczn.config;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class Knife4jConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
// 1. 声明JWT认证规则
|
||||
String securitySchemeName = "Authorization";
|
||||
return new OpenAPI()
|
||||
// 2. 文档基础信息(可选)
|
||||
.info(new Info()
|
||||
.title("XX自动化编程系统API")
|
||||
.version("1.0.0")
|
||||
.description("集成JWT认证的Knife4j接口文档"))
|
||||
// 3. 配置全局认证规则(所有接口默认需要Token)
|
||||
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
|
||||
// 4. 定义Token的传递方式(请求头+Bearer格式)
|
||||
.components(new Components()
|
||||
.addSecuritySchemes(securitySchemeName,
|
||||
new SecurityScheme()
|
||||
.name(securitySchemeName)
|
||||
.type(SecurityScheme.Type.HTTP) // HTTP认证
|
||||
.scheme("bearer") // Bearer格式
|
||||
.bearerFormat("JWT") // Token类型为JWT
|
||||
.in(SecurityScheme.In.HEADER) // 放在请求头
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.rczn.config;
|
||||
|
||||
import com.rczn.interceptors.LoginInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
// 必须启用@Configuration,让Spring扫描到
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
// 必须注入拦截器(取消注释)
|
||||
@Autowired
|
||||
LoginInterceptor loginInterceptor;
|
||||
|
||||
// 注册拦截器
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(loginInterceptor)
|
||||
// 拦截所有请求
|
||||
.addPathPatterns("/**")
|
||||
// 放行Swagger/Knife4j所有相关路径(关键补充/doc.html)
|
||||
.excludePathPatterns(
|
||||
// Knife4j自定义UI路径(核心!)
|
||||
"/doc.html",
|
||||
// Swagger UI页面相关
|
||||
"/swagger-ui/**",
|
||||
"/webjars/**",
|
||||
// SpringDoc接口文档数据相关
|
||||
"/v3/api-docs/**",
|
||||
"/v3/api-docs.yaml",
|
||||
// 旧版Swagger兼容
|
||||
"/swagger-resources/**",
|
||||
"/swagger-ui.html"
|
||||
)
|
||||
// 放行登录/注册接口
|
||||
.excludePathPatterns("/user/login", "/user/register");
|
||||
}
|
||||
|
||||
// 静态资源映射(适配Knife4j+SpringDoc)
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// Knife4j静态资源(核心补充)
|
||||
registry.addResourceHandler("/doc.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
// Swagger UI静态资源
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springdoc-openapi-ui/");
|
||||
// Webjars通用资源
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.system.domain.RolePermission;
|
||||
import com.rczn.system.domain.query.RolePermissionQuery;
|
||||
import com.rczn.system.service.RolePermissionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/rolePermission")
|
||||
@Tag(name = "角色权限管理", description = "角色权限关联接口")
|
||||
public class RolePermissionController {
|
||||
|
||||
@Autowired
|
||||
RolePermissionService rolePermissionService;
|
||||
|
||||
@GetMapping("/listByRoleId/{roleId}")
|
||||
@Operation(summary = "根据角色ID查询权限ID列表")
|
||||
public Result getListByRoleId(
|
||||
@Parameter(name = "roleId", required = true) @PathVariable Integer roleId) {
|
||||
List<RolePermission> list = rolePermissionService.selectListByRoleId(roleId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "给角色添加权限")
|
||||
public Result add(@RequestBody RolePermissionQuery rolePermission) {
|
||||
if (rolePermission.getRoleId() == null || rolePermission.getPermissionId() == null) {
|
||||
return Result.error("角色ID和权限ID不能为空");
|
||||
}
|
||||
try {
|
||||
RolePermission rolePermissionEntity = new RolePermission();
|
||||
rolePermissionEntity.setRoleId(rolePermission.getRoleId());
|
||||
rolePermissionEntity.setPermissionId(rolePermission.getPermissionId());
|
||||
rolePermissionService.insert(rolePermissionEntity);
|
||||
return Result.success("添加成功");
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/del")
|
||||
@Operation(summary = "删除角色权限关联")
|
||||
public Result delete(
|
||||
@RequestParam Integer roleId,
|
||||
@RequestParam(required = false) Integer permissionId) {
|
||||
boolean success = rolePermissionService.delete(roleId, permissionId);
|
||||
return success ? Result.success("删除成功") : Result.error("删除失败");
|
||||
}
|
||||
|
||||
@DeleteMapping("/clearByRoleId/{roleId}")
|
||||
@Operation(summary = "清空某个角色的所有权限")
|
||||
public Result clearByRoleId(
|
||||
@Parameter(name = "roleId", required = true) @PathVariable Integer roleId) {
|
||||
rolePermissionService.deleteByRoleId(roleId);
|
||||
return Result.success("清空成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.system.domain.SysDicData;
|
||||
import com.rczn.system.service.SysDicDataService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sysDicData")
|
||||
@Tag(name = "字典数据管理", description = "字典数据增删改查+分页查询+按类型查询接口")
|
||||
public class SysDicDataController {
|
||||
|
||||
@Autowired
|
||||
private SysDicDataService sysDicDataService;
|
||||
|
||||
@GetMapping(value = "/listPage", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "分页查询字典数据", description = "支持字典类型ID、标签、值查询")
|
||||
@Parameters({
|
||||
@Parameter(name = "pageNum", description = "页码(必填)", required = true, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "pageSize", description = "每页条数(必填)", required = true, example = "10", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicId", description = "字典类型ID(可选)", required = false, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicLabel", description = "数据标签(可选,模糊查询)", required = false, example = "运行", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicValue", description = "数据值(可选,模糊查询)", required = false, example = "1", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result getDicDataPage(
|
||||
@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam(required = false) Integer dicId,
|
||||
@RequestParam(required = false) String dicLabel,
|
||||
@RequestParam(required = false) String dicValue) {
|
||||
PageInfo<SysDicData> pageBean = sysDicDataService.selectPage(pageNum, pageSize, dicId, dicLabel, dicValue);
|
||||
return Result.success(pageBean);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "查询字典数据", description = "支持字典类型ID、标签、值查询")
|
||||
@Parameters({
|
||||
@Parameter(name = "dicId", description = "字典类型ID(可选)", required = false, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicLabel", description = "数据标签(可选,模糊查询)", required = false, example = "运行", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicValue", description = "数据值(可选,模糊查询)", required = false, example = "1", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result getList(
|
||||
@RequestParam(required = false) Integer dicId,
|
||||
@RequestParam(required = false) String dicLabel,
|
||||
@RequestParam(required = false) String dicValue) {
|
||||
List<SysDicData> list = sysDicDataService.selectList( dicId, dicLabel, dicValue);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "查询单个字典数据", description = "根据字典数据ID查询详情")
|
||||
public Result getDicDataById(@PathVariable Long id) {
|
||||
SysDicData sysDicData = sysDicDataService.selectById(id);
|
||||
return sysDicData != null ? Result.success(sysDicData) : Result.error("字典数据不存在");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/listByDicId/{dicId}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "按字典类型ID查询数据列表", description = "查询指定字典类型下的所有有效数据")
|
||||
public Result getDicDataByDicId(@PathVariable Integer dicId) {
|
||||
try {
|
||||
List<SysDicData> list = sysDicDataService.selectByDicId(dicId);
|
||||
return Result.success(list);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "新增字典数据", description = "字典类型ID、数据标签为必填项")
|
||||
public Result addDicData(@RequestBody SysDicData sysDicData) {
|
||||
try {
|
||||
Long dicDataId = sysDicDataService.insert(sysDicData);
|
||||
return Result.success(dicDataId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "修改字典数据", description = "需传入字典数据ID,其他字段可选(非空则更新)")
|
||||
public Result updateDicData(@RequestBody SysDicData sysDicData) {
|
||||
try {
|
||||
Boolean success = sysDicDataService.update(sysDicData);
|
||||
return success ? Result.success(true) : Result.error("修改失败(字典数据不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/del/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "删除字典数据", description = "逻辑删除(设置delSign=1,不物理删除数据)")
|
||||
public Result deleteDicData(@PathVariable Long id) {
|
||||
try {
|
||||
Boolean success = sysDicDataService.deleteById(id);
|
||||
return success ? Result.success(true) : Result.error("删除失败(字典数据不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.system.domain.SysDicType;
|
||||
import com.rczn.system.service.SysDicTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sysDicType")
|
||||
@Tag(name = "字典类型管理", description = "字典类型增删改查+分页查询接口")
|
||||
public class SysDicTypeController {
|
||||
|
||||
@Autowired
|
||||
private SysDicTypeService sysDicTypeService;
|
||||
|
||||
@GetMapping(value = "/listPage", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "分页查询字典类型", description = "支持字典名称、编码模糊查询")
|
||||
@Parameters({
|
||||
@Parameter(name = "pageNum", description = "页码(必填)", required = true, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "pageSize", description = "每页条数(必填)", required = true, example = "10", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicName", description = "字典名称(可选,模糊查询)", required = false, example = "设备状态", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicCode", description = "字典编码(可选,模糊查询)", required = false, example = "DEV_STATUS", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result getDicTypePage(
|
||||
@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam(required = false) String dicName,
|
||||
@RequestParam(required = false) String dicCode) {
|
||||
PageInfo<SysDicType> pageBean = sysDicTypeService.selectPage(pageNum, pageSize, dicName, dicCode);
|
||||
return Result.success(pageBean);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "查询字典类型列表", description = "支持字典名称、编码模糊查询")
|
||||
@Parameters({
|
||||
@Parameter(name = "dicName", description = "字典名称(可选,模糊查询)", required = false, example = "设备状态", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "dicCode", description = "字典编码(可选,模糊查询)", required = false, example = "DEV_STATUS", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result getList(
|
||||
@RequestParam(required = false) String dicName,
|
||||
@RequestParam(required = false) String dicCode) {
|
||||
List<SysDicType> list = sysDicTypeService.selectList( dicName, dicCode);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "查询单个字典类型", description = "根据字典类型ID查询详情")
|
||||
public Result getDicTypeById(@PathVariable Long id) {
|
||||
SysDicType sysDicType = sysDicTypeService.selectById(id);
|
||||
return sysDicType != null ? Result.success(sysDicType) : Result.error("字典类型不存在");
|
||||
}
|
||||
|
||||
@PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "新增字典类型", description = "字典名称为必填项")
|
||||
public Result addDicType(@RequestBody SysDicType sysDicType) {
|
||||
try {
|
||||
Long dicTypeId = sysDicTypeService.insert(sysDicType);
|
||||
return Result.success(dicTypeId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "修改字典类型", description = "需传入字典类型ID,其他字段可选(非空则更新)")
|
||||
public Result updateDicType(@RequestBody SysDicType sysDicType) {
|
||||
try {
|
||||
Boolean success = sysDicTypeService.update(sysDicType);
|
||||
return success ? Result.success(true) : Result.error("修改失败(字典类型不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/del/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "删除字典类型", description = "逻辑删除(设置delSign=1,不物理删除数据)")
|
||||
public Result deleteDicType(@PathVariable Long id) {
|
||||
try {
|
||||
Boolean success = sysDicTypeService.deleteById(id);
|
||||
return success ? Result.success(true) : Result.error("删除失败(字典类型不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.Role;
|
||||
import com.rczn.system.service.SysPermissionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限管理 API(MyBatis 树形结构实现)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/permission")
|
||||
@Tag(name = "权限管理", description = "权限增删改查接口(树形结构)")
|
||||
public class SysPermissionController {
|
||||
|
||||
@Autowired
|
||||
private SysPermissionService sysPermissionService;
|
||||
|
||||
/**
|
||||
* 1. 分页查询权限(多条件模糊查询)
|
||||
*/
|
||||
@GetMapping("/listPage")
|
||||
@Operation(summary = "分页查询权限", description = "支持角色名、角色编码模糊查询,页码从1开始")
|
||||
@Parameters({
|
||||
@Parameter(name = "pageNum", description = "页码(必填,从1开始)", required = true, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "pageSize", description = "每页条数(必填)", required = true, example = "10", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "parentId", description = "父级ID(可选)", required = false, example = "0", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "permissionName", description = "权限名称(模糊查询,可选)", required = false, example = "用户添加", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result<PageBean<Permission>> getRolePage(
|
||||
@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam(required = false) Integer parentId,
|
||||
@RequestParam(required = false) String permissionName) {
|
||||
|
||||
PageBean<Permission> pageBean = sysPermissionService.selectRolePage(pageNum, pageSize, parentId,permissionName);
|
||||
return Result.success(pageBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 查询权限树形结构列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询权限树形列表", description = "返回权限树形结构(parentId为0或null为顶级)")
|
||||
public Result<List<Permission>> getPermissionList() {
|
||||
List<Permission> treeList = sysPermissionService.getPermissionList();
|
||||
return Result.success(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 查询权限树形结构列表
|
||||
*/
|
||||
// @GetMapping("/listByParentId/{parentId}")
|
||||
// @Operation(summary = "查询权限树形列表", description = "返回权限树形结构(parentId为0或null为顶级)")
|
||||
// public Result<List<Permission>> getPermissionListByParentId(@PathVariable Integer parentId) {
|
||||
// List<Permission> treeList = sysPermissionService.getPermissionListByParentId(parentId);
|
||||
// return Result.success(treeList);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 2. 根据ID查询单个权限
|
||||
*/
|
||||
@GetMapping("/getById/{id}")
|
||||
@Operation(summary = "查询单个权限", description = "根据权限ID查询详情")
|
||||
public Result getPermissionById(
|
||||
@Parameter(name = "id", description = "权限ID", required = true, example = "1", in = ParameterIn.PATH)
|
||||
@PathVariable Integer id) {
|
||||
|
||||
Permission permission = sysPermissionService.getPermissionById(id);
|
||||
if (permission == null) {
|
||||
return Result.error("权限ID:" + id + " 不存在");
|
||||
}
|
||||
return Result.success(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. 新增权限
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增权限", description = "提交权限信息创建新权限")
|
||||
public Result addPermission(
|
||||
@Parameter(name = "permission", description = "权限信息", required = true)
|
||||
@RequestBody Permission permission) {
|
||||
|
||||
boolean success = sysPermissionService.addPermission(permission);
|
||||
return success ? Result.success("新增权限成功") : Result.error("新增失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 4. 修改权限
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改权限", description = "传入权限ID和需要修改的字段")
|
||||
public Result updatePermission(
|
||||
@Parameter(name = "permission", description = "权限信息(必须包含ID)", required = true)
|
||||
@RequestBody Permission permission) {
|
||||
|
||||
try {
|
||||
boolean success = sysPermissionService.updatePermission(permission);
|
||||
return success ? Result.success("修改权限成功") : Result.error("修改失败(权限不存在)");
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 5. 根据ID删除权限(逻辑删除)
|
||||
*/
|
||||
@DeleteMapping("/del/{id}")
|
||||
@Operation(summary = "删除权限", description = "根据权限ID逻辑删除")
|
||||
public Result deletePermission(
|
||||
@Parameter(name = "id", description = "权限ID", required = true, example = "1", in = ParameterIn.PATH)
|
||||
@PathVariable Integer id) {
|
||||
|
||||
boolean success = sysPermissionService.deletePermission(id);
|
||||
return success ? Result.success("删除权限成功") : Result.error("删除失败(权限不存在)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.rczn.system.domain;
|
||||
|
||||
import com.rczn.domain.BaseBean;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 字典数据实体类
|
||||
* 对应表:sys_dic_data
|
||||
*/
|
||||
public class SysDicData extends BaseBean {
|
||||
|
||||
// 字典类型id(外键)
|
||||
private Integer dicId;
|
||||
|
||||
// 数据标签
|
||||
private String dicLabel;
|
||||
|
||||
// 数据字典值
|
||||
private String dicValue;
|
||||
|
||||
public SysDicData() {
|
||||
}
|
||||
|
||||
public SysDicData(Long id, Long createId, LocalDateTime createTime, Long updateId, LocalDateTime updateTime, boolean delSign, String remark) {
|
||||
super(id, createId, createTime, updateId, updateTime, delSign, remark);
|
||||
}
|
||||
|
||||
// getter/setter
|
||||
public Integer getDicId() {
|
||||
return dicId;
|
||||
}
|
||||
|
||||
public void setDicId(Integer dicId) {
|
||||
this.dicId = dicId;
|
||||
}
|
||||
|
||||
public String getDicLabel() {
|
||||
return dicLabel;
|
||||
}
|
||||
|
||||
public void setDicLabel(String dicLabel) {
|
||||
this.dicLabel = dicLabel;
|
||||
}
|
||||
|
||||
public String getDicValue() {
|
||||
return dicValue;
|
||||
}
|
||||
|
||||
public void setDicValue(String dicValue) {
|
||||
this.dicValue = dicValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.rczn.system.domain;
|
||||
|
||||
import com.rczn.domain.BaseBean;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 字典类型实体类
|
||||
* 对应表:sys_dic_type
|
||||
*/
|
||||
public class SysDicType extends BaseBean {
|
||||
|
||||
// 字典名称(必填)
|
||||
private String dicName;
|
||||
|
||||
// 字典编码
|
||||
private String dicCode;
|
||||
|
||||
public SysDicType() {
|
||||
}
|
||||
|
||||
public SysDicType(Long id, Long createId, LocalDateTime createTime, Long updateId, LocalDateTime updateTime, boolean delSign, String remark) {
|
||||
super(id, createId, createTime, updateId, updateTime, delSign, remark);
|
||||
}
|
||||
|
||||
// getter/setter
|
||||
public String getDicName() {
|
||||
return dicName;
|
||||
}
|
||||
|
||||
public void setDicName(String dicName) {
|
||||
this.dicName = dicName;
|
||||
}
|
||||
|
||||
public String getDicCode() {
|
||||
return dicCode;
|
||||
}
|
||||
|
||||
public void setDicCode(String dicCode) {
|
||||
this.dicCode = dicCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.rczn.system.domain.query;
|
||||
|
||||
public class RolePermissionQuery {
|
||||
|
||||
//角色id
|
||||
private Integer roleId;
|
||||
|
||||
//权限id
|
||||
private Integer permissionId;
|
||||
|
||||
public RolePermissionQuery(Integer roleId, Integer permissionId) {
|
||||
this.roleId = roleId;
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
|
||||
public RolePermissionQuery() {
|
||||
}
|
||||
|
||||
public Integer getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Integer roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Integer getPermissionId() {
|
||||
return permissionId;
|
||||
}
|
||||
|
||||
public void setPermissionId(Integer permissionId) {
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
import com.rczn.system.domain.RolePermission;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RolePermissionMapper {
|
||||
|
||||
List<RolePermission> selectListByRoleId(@Param("roleId") Integer roleId);
|
||||
|
||||
int insert(RolePermission rolePermission);
|
||||
|
||||
int delete(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);
|
||||
|
||||
int deleteByRoleId(@Param("roleId") Integer roleId);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
import com.rczn.system.domain.SysDicData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysDicDataMapper {
|
||||
|
||||
/**
|
||||
* 新增字典数据
|
||||
*/
|
||||
int insert(SysDicData sysDicData);
|
||||
|
||||
/**
|
||||
* 修改字典数据
|
||||
*/
|
||||
int update(SysDicData sysDicData);
|
||||
|
||||
/**
|
||||
* 逻辑删除字典数据
|
||||
*/
|
||||
int deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询字典数据
|
||||
*/
|
||||
SysDicData selectById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询字典数据(参数可选)
|
||||
*/
|
||||
List<SysDicData> selectPage(SysDicData sysDicData);
|
||||
|
||||
/**
|
||||
* 根据字典类型ID查询字典数据列表
|
||||
*/
|
||||
List<SysDicData> selectByDicId(Integer dicId);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
import com.rczn.system.domain.SysDicType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysDicTypeMapper {
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
int insert(SysDicType sysDicType);
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
int update(SysDicType sysDicType);
|
||||
|
||||
/**
|
||||
* 逻辑删除字典类型
|
||||
*/
|
||||
int deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID查询字典类型
|
||||
*/
|
||||
SysDicType selectById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询字典类型(参数可选)
|
||||
*/
|
||||
List<SysDicType> selectPage(SysDicType sysDicType);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.Role;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysPermissionMapper {
|
||||
|
||||
/**
|
||||
* 分页查询角色(支持角色名/角色编码模糊查询)
|
||||
*/
|
||||
List<Permission> selectPermissionPage(
|
||||
@Param("parentId") Integer parentId,
|
||||
@Param("permissionName") String permissionName);
|
||||
|
||||
/**
|
||||
* 查询总条数(支持模糊查询条件)
|
||||
*/
|
||||
Long selectTotal(
|
||||
@Param("parentId") Integer parentId,
|
||||
@Param("permissionName") String permissionName);
|
||||
|
||||
/**
|
||||
* 查询所有权限(未删除)
|
||||
*/
|
||||
List<Permission> selectPermissionList();
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
Permission selectPermissionById(Integer id);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
int insertPermission(Permission permission);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
int updatePermission(Permission permission);
|
||||
|
||||
/**
|
||||
* 逻辑删除
|
||||
*/
|
||||
int deletePermissionById(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
import com.rczn.system.domain.RolePermission;
|
||||
import java.util.List;
|
||||
|
||||
public interface RolePermissionService {
|
||||
|
||||
List<RolePermission> selectListByRoleId(Integer roleId);
|
||||
|
||||
void insert(RolePermission rolePermission);
|
||||
|
||||
boolean delete(Integer roleId, Integer permissionId);
|
||||
|
||||
void deleteByRoleId(Integer roleId);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.system.domain.SysDicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysDicDataService {
|
||||
|
||||
/**
|
||||
* 分页查询字典数据
|
||||
*/
|
||||
PageInfo<SysDicData> selectPage(Integer pageNum, Integer pageSize, Integer dicId, String dicLabel, String dicValue);
|
||||
|
||||
/**
|
||||
* 查询字典数据列表
|
||||
*/
|
||||
List<SysDicData> selectList(Integer dicId, String dicLabel, String dicValue);
|
||||
|
||||
/**
|
||||
* 根据ID查询字典数据
|
||||
*/
|
||||
SysDicData selectById(Long id);
|
||||
|
||||
/**
|
||||
* 根据字典类型ID查询字典数据列表
|
||||
*/
|
||||
List<SysDicData> selectByDicId(Integer dicId);
|
||||
|
||||
/**
|
||||
* 新增字典数据
|
||||
*/
|
||||
Long insert(SysDicData sysDicData);
|
||||
|
||||
/**
|
||||
* 修改字典数据
|
||||
*/
|
||||
Boolean update(SysDicData sysDicData);
|
||||
|
||||
/**
|
||||
* 逻辑删除字典数据
|
||||
*/
|
||||
Boolean deleteById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.system.domain.SysDicType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysDicTypeService {
|
||||
|
||||
/**
|
||||
* 分页查询字典类型
|
||||
*/
|
||||
PageInfo<SysDicType> selectPage(Integer pageNum, Integer pageSize, String dicName, String dicCode);
|
||||
|
||||
/**
|
||||
* 查询字典类型列表
|
||||
*/
|
||||
List<SysDicType> selectList( String dicName, String dicCode);
|
||||
|
||||
/**
|
||||
* 根据ID查询字典类型
|
||||
*/
|
||||
SysDicType selectById(Long id);
|
||||
|
||||
/**
|
||||
* 新增字典类型
|
||||
*/
|
||||
Long insert(SysDicType sysDicType);
|
||||
|
||||
/**
|
||||
* 修改字典类型
|
||||
*/
|
||||
Boolean update(SysDicType sysDicType);
|
||||
|
||||
/**
|
||||
* 逻辑删除字典类型
|
||||
*/
|
||||
Boolean deleteById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysPermissionService {
|
||||
List<Permission> getPermissionList();
|
||||
//根据父ID查询权限列表:
|
||||
List<Permission> getPermissionListByParentId(Integer parentId);
|
||||
Permission getPermissionById(Integer id);
|
||||
boolean addPermission(Permission permission);
|
||||
boolean updatePermission(Permission permission);
|
||||
boolean deletePermission(Integer id);
|
||||
|
||||
/**
|
||||
* 1. 分页查询角色(多条件模糊查询)
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @param permissionName
|
||||
* @return
|
||||
*/
|
||||
PageBean<Permission> selectRolePage(Integer pageNum, Integer pageSize,Integer parentId, String permissionName);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.rczn.system.service.impl;
|
||||
|
||||
import com.rczn.system.domain.RolePermission;
|
||||
import com.rczn.system.mapper.RolePermissionMapper;
|
||||
import com.rczn.system.service.RolePermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class RolePermissionServiceImpl implements RolePermissionService {
|
||||
|
||||
@Autowired
|
||||
RolePermissionMapper rolePermissionMapper;
|
||||
|
||||
@Override
|
||||
public List<RolePermission> selectListByRoleId(Integer roleId) {
|
||||
return rolePermissionMapper.selectListByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void insert(RolePermission rolePermission) {
|
||||
rolePermission.setCreateTime(LocalDateTime.now());
|
||||
rolePermissionMapper.insert(rolePermission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean delete(Integer roleId, Integer permissionId) {
|
||||
return rolePermissionMapper.delete(roleId, permissionId) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteByRoleId(Integer roleId) {
|
||||
rolePermissionMapper.deleteByRoleId(roleId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.rczn.system.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.system.domain.SysDicData;
|
||||
import com.rczn.system.mapper.SysDicDataMapper;
|
||||
import com.rczn.system.service.SysDicDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SysDicDataServiceImpl implements SysDicDataService {
|
||||
|
||||
@Autowired
|
||||
private SysDicDataMapper sysDicDataMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<SysDicData> selectPage(Integer pageNum, Integer pageSize, Integer dicId, String dicLabel, String dicValue) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
SysDicData query = new SysDicData();
|
||||
query.setDicId(dicId);
|
||||
query.setDicLabel(dicLabel);
|
||||
query.setDicValue(dicValue);
|
||||
return new PageInfo<>(sysDicDataMapper.selectPage(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询字典数据列表
|
||||
*
|
||||
* @param dicId
|
||||
* @param dicLabel
|
||||
* @param dicValue
|
||||
*/
|
||||
@Override
|
||||
public List<SysDicData> selectList(Integer dicId, String dicLabel, String dicValue) {
|
||||
SysDicData query = new SysDicData();
|
||||
query.setDicId(dicId);
|
||||
query.setDicLabel(dicLabel);
|
||||
query.setDicValue(dicValue);
|
||||
return sysDicDataMapper.selectPage(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDicData selectById(Long id) {
|
||||
return sysDicDataMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDicData> selectByDicId(Integer dicId) {
|
||||
if (dicId == null) {
|
||||
throw new IllegalArgumentException("字典类型ID不能为空");
|
||||
}
|
||||
return sysDicDataMapper.selectByDicId(dicId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long insert(SysDicData sysDicData) {
|
||||
// 校验必填项
|
||||
if (sysDicData.getDicId() == null) {
|
||||
throw new IllegalArgumentException("字典类型ID不能为空");
|
||||
}
|
||||
if (sysDicData.getDicLabel() == null || sysDicData.getDicLabel().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("数据标签不能为空");
|
||||
}
|
||||
int count = sysDicDataMapper.insert(sysDicData);
|
||||
return count > 0 ? sysDicData.getId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(SysDicData sysDicData) {
|
||||
if (sysDicData.getId() == null) {
|
||||
throw new IllegalArgumentException("字典数据ID不能为空");
|
||||
}
|
||||
// 校验是否存在
|
||||
SysDicData exist = sysDicDataMapper.selectById(sysDicData.getId());
|
||||
if (exist == null) {
|
||||
return false;
|
||||
}
|
||||
int count = sysDicDataMapper.update(sysDicData);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteById(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("字典数据ID不能为空");
|
||||
}
|
||||
// 校验是否存在
|
||||
SysDicData exist = sysDicDataMapper.selectById(id);
|
||||
if (exist == null) {
|
||||
return false;
|
||||
}
|
||||
int count = sysDicDataMapper.deleteById(id);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.rczn.system.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rczn.system.domain.SysDicType;
|
||||
import com.rczn.system.mapper.SysDicTypeMapper;
|
||||
import com.rczn.system.service.SysDicTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SysDicTypeServiceImpl implements SysDicTypeService {
|
||||
|
||||
@Autowired
|
||||
private SysDicTypeMapper sysDicTypeMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<SysDicType> selectPage(Integer pageNum, Integer pageSize, String dicName, String dicCode) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
SysDicType query = new SysDicType();
|
||||
query.setDicName(dicName);
|
||||
query.setDicCode(dicCode);
|
||||
return new PageInfo<>(sysDicTypeMapper.selectPage(query));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询字典类型列表
|
||||
*
|
||||
* @param dicName
|
||||
* @param dicCode
|
||||
*/
|
||||
@Override
|
||||
public List<SysDicType> selectList(String dicName, String dicCode) {
|
||||
SysDicType query = new SysDicType();
|
||||
query.setDicName(dicName);
|
||||
query.setDicCode(dicCode);
|
||||
return sysDicTypeMapper.selectPage(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDicType selectById(Long id) {
|
||||
return sysDicTypeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long insert(SysDicType sysDicType) {
|
||||
// 校验必填项
|
||||
if (sysDicType.getDicName() == null || sysDicType.getDicName().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("字典名称不能为空");
|
||||
}
|
||||
int count = sysDicTypeMapper.insert(sysDicType);
|
||||
return count > 0 ? sysDicType.getId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(SysDicType sysDicType) {
|
||||
if (sysDicType.getId() == null) {
|
||||
throw new IllegalArgumentException("字典类型ID不能为空");
|
||||
}
|
||||
// 校验是否存在
|
||||
SysDicType exist = sysDicTypeMapper.selectById(sysDicType.getId());
|
||||
if (exist == null) {
|
||||
return false;
|
||||
}
|
||||
int count = sysDicTypeMapper.update(sysDicType);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteById(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("字典类型ID不能为空");
|
||||
}
|
||||
// 校验是否存在
|
||||
SysDicType exist = sysDicTypeMapper.selectById(id);
|
||||
if (exist == null) {
|
||||
return false;
|
||||
}
|
||||
int count = sysDicTypeMapper.deleteById(id);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.rczn.system.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.Role;
|
||||
import com.rczn.system.mapper.SysPermissionMapper;
|
||||
import com.rczn.system.service.SysPermissionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
|
||||
@Autowired
|
||||
private SysPermissionMapper sysPermissionMapper;
|
||||
|
||||
@Override
|
||||
public Permission getPermissionById(Integer id) {
|
||||
return sysPermissionMapper.selectPermissionById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPermission(Permission permission) {
|
||||
return sysPermissionMapper.insertPermission(permission) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePermission(Permission permission) {
|
||||
return sysPermissionMapper.updatePermission(permission) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePermission(Integer id) {
|
||||
return sysPermissionMapper.deletePermissionById(id) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 分页查询角色(多条件模糊查询)
|
||||
*
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @param permissionName
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageBean<Permission> selectRolePage(Integer pageNum, Integer pageSize,Integer parentId, String permissionName) {
|
||||
// 1. PageHelper 设置分页参数
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
//加一层过滤:
|
||||
if(parentId == 0){
|
||||
parentId = null;
|
||||
}
|
||||
// 2. 执行查询
|
||||
List<Permission> permissionList = sysPermissionMapper.selectPermissionPage(parentId,permissionName);
|
||||
// 3. 查询总条数
|
||||
Long total = sysPermissionMapper.selectTotal(parentId,permissionName);
|
||||
// 4. 封装分页结果
|
||||
return new PageBean<Permission>() {{
|
||||
setTotal(total);
|
||||
setItems(permissionList);
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> getPermissionList() {
|
||||
// 1. 查询所有平级权限
|
||||
List<Permission> allPermissions = sysPermissionMapper.selectPermissionList();
|
||||
|
||||
// 2. 找到顶层节点(parentId = null 或 0)
|
||||
List<Permission> topNodes = new ArrayList<>();
|
||||
for (Permission p : allPermissions) {
|
||||
if (p.getParentId() == null || p.getParentId() == 0) {
|
||||
topNodes.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 循环给每个顶层节点设置子节点(递归)
|
||||
for (Permission node : topNodes) {
|
||||
node.setChildren(findChildren(node, allPermissions));
|
||||
}
|
||||
|
||||
return topNodes;
|
||||
}
|
||||
|
||||
/***
|
||||
* 根据父ID查询权限列表
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Permission> getPermissionListByParentId(Integer parentId) {
|
||||
// 1. 查询所有平级权限
|
||||
List<Permission> allPermissions = sysPermissionMapper.selectPermissionList();
|
||||
|
||||
// 2. 找到顶层节点(parentId = null 或 0)
|
||||
List<Permission> topNodes = new ArrayList<>();
|
||||
for (Permission p : allPermissions) {
|
||||
if(parentId == null || parentId == 0){
|
||||
if (p.getParentId() == null || p.getParentId() == 0) {
|
||||
topNodes.add(p);
|
||||
}
|
||||
}else {
|
||||
if (p.getParentId() == parentId) {
|
||||
topNodes.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 3. 循环给每个顶层节点设置子节点(递归)
|
||||
for (Permission node : topNodes) {
|
||||
node.setChildren(findChildren(node, allPermissions));
|
||||
}
|
||||
|
||||
return topNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找子节点(最稳妥、最清晰、不会漏)
|
||||
*/
|
||||
private List<Permission> findChildren(Permission parent, List<Permission> allList) {
|
||||
List<Permission> children = new ArrayList<>();
|
||||
|
||||
for (Permission p : allList) {
|
||||
// 子节点的 parentId == 父节点 id
|
||||
if (parent.getId().equals(p.getParentId()==null?0:p.getParentId().longValue())) {
|
||||
children.add(p);
|
||||
// 递归给子节点设置孙子节点
|
||||
p.setChildren(findChildren(p, allList));
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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="com.rczn.system.mapper.RolePermissionMapper">
|
||||
|
||||
<resultMap id="RolePermissionResultMap" type="com.rczn.system.domain.RolePermission">
|
||||
<id column="id" property="id"/>
|
||||
<result column="role_id" property="roleId"/>
|
||||
<result column="permission_id" property="permissionId"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="baseColumn">
|
||||
id, role_id, permission_id
|
||||
</sql>
|
||||
|
||||
<select id="selectListByRoleId" resultMap="RolePermissionResultMap">
|
||||
SELECT <include refid="baseColumn"/>
|
||||
FROM sys_role_permission
|
||||
WHERE role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
INSERT INTO sys_role_permission (role_id, permission_id)
|
||||
VALUES (#{roleId}, #{permissionId})
|
||||
</insert>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM sys_role_permission
|
||||
<where>
|
||||
<if test="roleId != null">
|
||||
role_id = #{roleId}
|
||||
</if>
|
||||
<if test="permissionId != null">
|
||||
AND permission_id = #{permissionId}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByRoleId">
|
||||
DELETE FROM sys_role_permission
|
||||
WHERE role_id = #{roleId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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="com.rczn.system.mapper.SysDicDataMapper">
|
||||
<sql id="baseColumn">
|
||||
id, create_by, create_time, update_by, update_time, del_sign, remark
|
||||
</sql>
|
||||
|
||||
<sql id="dicDataColumn">
|
||||
dic_id, dic_label, dic_value
|
||||
</sql>
|
||||
|
||||
<!-- 新增字典数据 -->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO sys_dic_data (
|
||||
<include refid="dicDataColumn"/>,
|
||||
create_by, create_time, update_by, update_time, del_sign
|
||||
) VALUES (
|
||||
#{dicId}, #{dicLabel}, #{dicValue},
|
||||
#{createId}, NOW(), #{updateId}, NOW(), 0
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 修改字典数据 -->
|
||||
<update id="update">
|
||||
UPDATE sys_dic_data
|
||||
<set>
|
||||
<if test="dicId != null">dic_id = #{dicId},</if>
|
||||
<if test="dicLabel != null and dicLabel != ''">dic_label = #{dicLabel},</if>
|
||||
<if test="dicValue != null and dicValue != ''">dic_value = #{dicValue},</if>
|
||||
<if test="updateId != null">update_by = #{updateId},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除字典数据 -->
|
||||
<update id="deleteById">
|
||||
UPDATE sys_dic_data
|
||||
SET del_sign = 1, update_time = NOW()
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID查询字典数据 -->
|
||||
<select id="selectById" resultType="com.rczn.system.domain.SysDicData">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="dicDataColumn"/>
|
||||
FROM sys_dic_data
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</select>
|
||||
|
||||
<!-- 分页查询字典数据(支持按字典类型ID、标签、值查询) -->
|
||||
<select id="selectPage" resultType="com.rczn.system.domain.SysDicData">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="dicDataColumn"/>
|
||||
FROM sys_dic_data
|
||||
WHERE del_sign = 0
|
||||
<if test="dicId != null">AND dic_id = #{dicId}</if>
|
||||
<if test="dicLabel != null and dicLabel != ''">AND dic_label LIKE CONCAT('%', #{dicLabel}, '%')</if>
|
||||
<if test="dicValue != null and dicValue != ''">AND dic_value LIKE CONCAT('%', #{dicValue}, '%')</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据字典类型ID查询字典数据列表 -->
|
||||
<select id="selectByDicId" resultType="com.rczn.system.domain.SysDicData">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="dicDataColumn"/>
|
||||
FROM sys_dic_data
|
||||
WHERE dic_id = #{dicId} AND del_sign = 0
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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="com.rczn.system.mapper.SysDicTypeMapper">
|
||||
<sql id="baseColumn">
|
||||
id, create_by, create_time, update_by, update_time, del_sign, remark
|
||||
</sql>
|
||||
|
||||
<sql id="dicTypeColumn">
|
||||
dic_name, dic_code
|
||||
</sql>
|
||||
|
||||
<!-- 新增字典类型 -->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO sys_dic_type (
|
||||
<include refid="dicTypeColumn"/>,
|
||||
create_by, create_time, update_by, update_time, del_sign
|
||||
) VALUES (
|
||||
#{dicName}, #{dicCode},
|
||||
#{createId}, NOW(), #{updateId}, NOW(), 0
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 修改字典类型 -->
|
||||
<update id="update">
|
||||
UPDATE sys_dic_type
|
||||
<set>
|
||||
<if test="dicName != null and dicName != ''">dic_name = #{dicName},</if>
|
||||
<if test="dicCode != null and dicCode != ''">dic_code = #{dicCode},</if>
|
||||
<if test="updateId != null">update_by = #{updateId},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除字典类型 -->
|
||||
<update id="deleteById">
|
||||
UPDATE sys_dic_type
|
||||
SET del_sign = 1, update_time = NOW()
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID查询字典类型 -->
|
||||
<select id="selectById" resultType="com.rczn.system.domain.SysDicType">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="dicTypeColumn"/>
|
||||
FROM sys_dic_type
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</select>
|
||||
|
||||
<!-- 分页查询字典类型 -->
|
||||
<select id="selectPage" resultType="com.rczn.system.domain.SysDicType">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="dicTypeColumn"/>
|
||||
FROM sys_dic_type
|
||||
WHERE del_sign = 0
|
||||
<if test="dicName != null and dicName != ''">AND dic_name LIKE CONCAT('%', #{dicName}, '%')</if>
|
||||
<if test="dicCode != null and dicCode != ''">AND dic_code LIKE CONCAT('%', #{dicCode}, '%')</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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="com.rczn.system.mapper.SysPermissionMapper">
|
||||
|
||||
<resultMap id="PermissionResultMap" type="com.rczn.system.domain.Permission">
|
||||
<id column="id" property="id"/>
|
||||
<result column="parent_id" property="parentId"/>
|
||||
<result column="permission_name" property="permissionName"/>
|
||||
<result column="permission_code" property="permissionCode"/>
|
||||
<result column="create_id" property="createId"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_id" property="updateId"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_sign" property="delSign"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询所有 -->
|
||||
<select id="selectPermissionList" resultMap="PermissionResultMap">
|
||||
SELECT * FROM sys_permission
|
||||
WHERE del_sign = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据ID查询 -->
|
||||
<select id="selectPermissionById" resultMap="PermissionResultMap">
|
||||
SELECT * FROM sys_permission
|
||||
WHERE id = #{id} AND del_sign = 0
|
||||
</select>
|
||||
<!-- 查询总数量 -->
|
||||
<select id="selectTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(*) FROM sys_permission
|
||||
WHERE del_sign = 0
|
||||
<if test="parentId != null "> and parent_id = #{parentId}</if>
|
||||
<if test="permissionName != null and permissionName != ''"> AND permission_name LIKE CONCAT('%', #{permissionName}, '%')</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据条件分页查询权限数据: -->
|
||||
<select id="selectPermissionPage" resultType="com.rczn.system.domain.Permission">
|
||||
SELECT * FROM sys_permission
|
||||
WHERE del_sign = 0
|
||||
<if test="parentId != null "> and parent_id = #{parentId}</if>
|
||||
<if test="permissionName != null and permissionName != ''"> AND permission_name LIKE CONCAT('%', #{permissionName}, '%')</if>
|
||||
</select>
|
||||
|
||||
<!-- 新增 -->
|
||||
<insert id="insertPermission">
|
||||
INSERT INTO sys_permission
|
||||
(parent_id, permission_name, permission_code, create_id, remark, del_sign)
|
||||
VALUES
|
||||
(#{parentId}, #{permissionName}, #{permissionCode}, #{createId}, #{remark}, 0)
|
||||
</insert>
|
||||
|
||||
<!-- 修改 -->
|
||||
<update id="updatePermission">
|
||||
UPDATE sys_permission
|
||||
SET
|
||||
parent_id = #{parentId},
|
||||
permission_name = #{permissionName},
|
||||
permission_code = #{permissionCode},
|
||||
update_id = #{updateId},
|
||||
remark = #{remark}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除 -->
|
||||
<update id="deletePermissionById">
|
||||
UPDATE sys_permission SET del_sign = 1 WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.rczn;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class RcznAdminApplicationTests {
|
||||
|
||||
// @Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user