feat(material): 新增生成编号接口
This commit is contained in:
@@ -132,4 +132,27 @@ public class MaterialController {
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(data).build();
|
||||
}
|
||||
|
||||
@ApiOperation("生成编号")
|
||||
@PostMapping("/id")
|
||||
public HttpResponse createId (
|
||||
@ApiParam(value = "父 id") @RequestParam(value="parent_id") String parentId
|
||||
) throws Exception {
|
||||
var query = new LambdaQueryWrapper<Material>();
|
||||
query.eq(Material::getParentId, parentId);
|
||||
query.orderByDesc(Material::getId);
|
||||
var data = materialService.list(query);
|
||||
String maxBrotherId;
|
||||
if (data == null) {
|
||||
maxBrotherId = null;
|
||||
} else {
|
||||
maxBrotherId = data.get(0).getId();
|
||||
}
|
||||
|
||||
String materialId = materialService.createNewMaterialId(parentId, maxBrotherId);
|
||||
var result = Map.of("material_id", materialId);
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,36 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MaterialService extends ServiceImpl<BaseMapper<Material>, Material> {
|
||||
public String createNewMaterialId(String parentId, String maxBrotherId) {
|
||||
String prefix;
|
||||
String suffix;
|
||||
String previous;
|
||||
if (parentId.contains("00.00.00.00")) {
|
||||
prefix = "";
|
||||
suffix = ".00.00.00";
|
||||
previous = maxBrotherId.substring(0, 2);
|
||||
} else if (parentId.contains("00.00.00")) {
|
||||
prefix = parentId.substring(0, 3);
|
||||
suffix = ".00.00";
|
||||
previous = maxBrotherId.substring(3, 5);
|
||||
} else if (parentId.contains("00.00")) {
|
||||
prefix = parentId.substring(0, 6);
|
||||
suffix = ".00";
|
||||
previous = maxBrotherId.substring(6, 8);
|
||||
} else if (parentId.contains("00")) {
|
||||
prefix = parentId.substring(0, 9);
|
||||
suffix = "";
|
||||
previous = maxBrotherId.substring(9, 11);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
var current = Integer.valueOf(previous) + 1;
|
||||
if (current < 60) {
|
||||
current = 60;
|
||||
}
|
||||
|
||||
return prefix + String.format("%02d", current) + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user