feat: 新增编码规则管理Controller

This commit is contained in:
zhouz
2026-07-15 17:09:36 +08:00
parent ca8dfde35a
commit 2ace4ea21c

View File

@@ -0,0 +1,109 @@
package cn.code.nl.module.base.controller.admin.codegen;
import cn.code.nl.framework.common.pojo.CommonResult;
import cn.code.nl.framework.common.pojo.PageResult;
import cn.code.nl.framework.common.util.object.BeanUtils;
import cn.code.nl.module.base.controller.admin.codegen.vo.*;
import cn.code.nl.module.base.dal.dataobject.codegen.CodeRuleDO;
import cn.code.nl.module.base.service.codegen.CodeRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.code.nl.framework.common.pojo.CommonResult.success;
/**
* 管理后台 - 编码规则
*
* @author zhouz
*/
@Tag(name = "管理后台 - 编码规则")
@RestController
@RequestMapping("/base/code-rule")
@Validated
public class CodeRuleController {
@Resource
private CodeRuleService codeRuleService;
/**
* 创建编码规则
*/
@PostMapping("/create")
@Operation(summary = "创建编码规则")
@PreAuthorize("@ss.hasPermission('base:code-rule:create')")
public CommonResult<Long> createCodeRule(@Valid @RequestBody CodeRuleSaveReqVO createReqVO) {
return success(codeRuleService.createRule(createReqVO));
}
/**
* 更新编码规则
*/
@PutMapping("/update")
@Operation(summary = "更新编码规则")
@PreAuthorize("@ss.hasPermission('base:code-rule:update')")
public CommonResult<Boolean> updateCodeRule(@Valid @RequestBody CodeRuleSaveReqVO updateReqVO) {
codeRuleService.updateRule(updateReqVO);
return success(true);
}
/**
* 删除编码规则
*/
@DeleteMapping("/delete")
@Operation(summary = "删除编码规则")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('base:code-rule:delete')")
public CommonResult<Boolean> deleteCodeRule(@RequestParam("id") Long id) {
codeRuleService.deleteRule(id);
return success(true);
}
/**
* 获取编码规则详情
*/
@GetMapping("/get")
@Operation(summary = "获得编码规则")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('base:code-rule:query')")
public CommonResult<CodeRuleRespVO> getCodeRule(@RequestParam("id") Long id) {
CodeRuleDO rule = codeRuleService.getRule(id);
CodeRuleRespVO respVO = BeanUtils.toBean(rule, CodeRuleRespVO.class);
respVO.setSegments(rule.getSegmentConfig());
return success(respVO);
}
/**
* 分页查询编码规则
*/
@GetMapping("/page")
@Operation(summary = "获得编码规则分页")
@PreAuthorize("@ss.hasPermission('base:code-rule:query')")
public CommonResult<PageResult<CodeRuleRespVO>> getCodeRulePage(@Valid CodeRulePageReqVO pageReqVO) {
PageResult<CodeRuleDO> pageResult = codeRuleService.getRulePage(pageReqVO);
PageResult<CodeRuleRespVO> result = BeanUtils.toBean(pageResult, CodeRuleRespVO.class);
// 补充 segmentConfigBeanUtils.toBean 无法映射 JSON 字段)
for (int i = 0; i < pageResult.getList().size(); i++) {
result.getList().get(i).setSegments(pageResult.getList().get(i).getSegmentConfig());
}
return success(result);
}
/**
* 获取启用状态的编码规则精简列表(下拉选项)
*/
@GetMapping("/simple-list")
@Operation(summary = "获取编码规则精简列表")
public CommonResult<List<CodeRuleSimpleRespVO>> getSimpleCodeRuleList() {
List<CodeRuleDO> list = codeRuleService.getEnabledRuleList();
return success(BeanUtils.toBean(list, CodeRuleSimpleRespVO.class));
}
}