feat: 项目编码自动生成
- 新增项目时自动生成编码,格式: C{赛事ID}-P{序号}
- 移除手动输入项目编码
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
+24
@@ -1,5 +1,6 @@
|
||||
package org.springblade.modules.martial.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -78,9 +79,32 @@ public class MartialProjectController extends BladeController {
|
||||
@PostMapping("/submit")
|
||||
@Operation(summary = "新增或修改", description = "传入实体")
|
||||
public R submit(@RequestBody MartialProject project) {
|
||||
// Auto-generate project code for new projects
|
||||
if (project.getId() == null && StringUtil.isBlank(project.getProjectCode())) {
|
||||
String projectCode = generateProjectCode(project.getCompetitionId());
|
||||
project.setProjectCode(projectCode);
|
||||
}
|
||||
return R.status(projectService.saveOrUpdate(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate project code: competition prefix + sequence number
|
||||
* Format: C{competitionId}-P{sequence}, e.g., C1-P001
|
||||
*/
|
||||
private String generateProjectCode(Long competitionId) {
|
||||
if (competitionId == null) {
|
||||
return "P" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// Count existing projects for this competition
|
||||
LambdaQueryWrapper<MartialProject> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MartialProject::getCompetitionId, competitionId);
|
||||
long count = projectService.count(wrapper);
|
||||
|
||||
// Generate code: C{competitionId}-P{sequence}
|
||||
return String.format("C%d-P%03d", competitionId, count + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user