diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java index aa32fcc..f6ea38f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java @@ -51,31 +51,7 @@ public class GenerateProjectCodeUtil { String currentCode = areaCode + year + projectType; // 16-20 项目序号00001 //要查询 两边的项目序号 - Long max = 0L; - GovBizProjectBaseinfo baseMax = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) - .like(GovBizProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovBizProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(baseMax) && StringUtils.isNotBlank(baseMax.getBaseProjId())){ - max = Long.valueOf(baseMax.getBaseProjId().substring(baseMax.getBaseProjId().length() - 5)); - } - GovOperationProjectBaseinfo operationBaseMax = operationProjectBaseinfoService.getOne(Wrappers.lambdaQuery(GovOperationProjectBaseinfo.class) - .like(GovOperationProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovOperationProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(operationBaseMax) && StringUtils.isNotBlank(operationBaseMax.getBaseProjId())){ - Long operationMax = Long.valueOf(operationBaseMax.getBaseProjId().substring(operationBaseMax.getBaseProjId().length() - 5)); - max = Math.max(max,operationMax); - } - Project projectMax = projectService.getOne(Wrappers.lambdaQuery(Project.class) - .like(Project::getProjectCode, currentCode) - .orderByDesc(Project::getProjectCode) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(projectMax) && StringUtils.isNotBlank(projectMax.getProjectCode())){ - Long projectMaxCode = Long.valueOf(projectMax.getProjectCode().substring(projectMax.getProjectCode().length() - 5)); - max = Math.max(max,projectMaxCode); - } - max = max + 1; + Long max = getMaxProjectCode(currentCode); // 生成20位的项目编号 return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } @@ -91,32 +67,8 @@ public class GenerateProjectCodeUtil { // 16-20 项目序号00001 String currentCode = areaCode + year + projectType; // 16-20 项目序号00001 - //要查询 两边的项目序号 - Long max = 0L; - GovBizProjectBaseinfo baseMax = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) - .like(GovBizProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovBizProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(baseMax) && StringUtils.isNotBlank(baseMax.getBaseProjId())){ - max = Long.valueOf(baseMax.getBaseProjId().substring(baseMax.getBaseProjId().length() - 5)); - } - GovOperationProjectBaseinfo operationBaseMax = operationProjectBaseinfoService.getOne(Wrappers.lambdaQuery(GovOperationProjectBaseinfo.class) - .like(GovOperationProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovOperationProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(operationBaseMax) && StringUtils.isNotBlank(operationBaseMax.getBaseProjId())){ - Long operationMax = Long.valueOf(operationBaseMax.getBaseProjId().substring(operationBaseMax.getBaseProjId().length() - 5)); - max = Math.max(max,operationMax); - } - Project projectMax = projectService.getOne(Wrappers.lambdaQuery(Project.class) - .like(Project::getProjectCode, currentCode) - .orderByDesc(Project::getProjectCode) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(projectMax) && StringUtils.isNotBlank(projectMax.getProjectCode())){ - Long projectMaxCode = Long.valueOf(projectMax.getProjectCode().substring(projectMax.getProjectCode().length() - 5)); - max = Math.max(max,projectMaxCode); - } - max = max + 1; + //要查询 最大的项目编号 + Long max = getMaxProjectCode(currentCode); // 生成20位的项目编号 return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } @@ -138,32 +90,8 @@ public class GenerateProjectCodeUtil { BizProjectContant.ProjectCollection.IS_EFFECTIVE; String currentCode = areaCode + year + projectType; // 16-20 项目序号00001 - //要查询 两边的项目序号 - Long max = 0L; - GovBizProjectBaseinfo baseMax = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) - .like(GovBizProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovBizProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(baseMax) && StringUtils.isNotBlank(baseMax.getBaseProjId())){ - max = Long.valueOf(baseMax.getBaseProjId().substring(baseMax.getBaseProjId().length() - 5)); - } - GovOperationProjectBaseinfo operationBaseMax = operationProjectBaseinfoService.getOne(Wrappers.lambdaQuery(GovOperationProjectBaseinfo.class) - .like(GovOperationProjectBaseinfo::getBaseProjId, currentCode) - .orderByDesc(GovOperationProjectBaseinfo::getBaseProjId) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(operationBaseMax) && StringUtils.isNotBlank(operationBaseMax.getBaseProjId())){ - Long operationMax = Long.valueOf(operationBaseMax.getBaseProjId().substring(operationBaseMax.getBaseProjId().length() - 5)); - max = Math.max(max,operationMax); - } - Project projectMax = projectService.getOne(Wrappers.lambdaQuery(Project.class) - .like(Project::getProjectCode, currentCode) - .orderByDesc(Project::getProjectCode) - .last(BizConst.LIMIT_1)); - if(Objects.nonNull(projectMax) && StringUtils.isNotBlank(projectMax.getProjectCode())){ - Long projectMaxCode = Long.valueOf(projectMax.getProjectCode().substring(projectMax.getProjectCode().length() - 5)); - max = Math.max(max,projectMaxCode); - } - max = max + 1; + //要查询 最大的项目编号 + Long max = getMaxProjectCode(currentCode); // 生成20位的项目编号 return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } @@ -185,7 +113,12 @@ public class GenerateProjectCodeUtil { BizProjectContant.ProjectCollection.IS_EFFECTIVE; String currentCode = areaCode + year + projectType; // 16-20 项目序号00001 - //要查询 两边的项目序号 + //要查询 最大的项目编号 + Long max = getMaxProjectCode(currentCode); + // 生成20位的项目编号 + return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); + } + private Long getMaxProjectCode(String currentCode) { Long max = 0L; GovBizProjectBaseinfo baseMax = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) .like(GovBizProjectBaseinfo::getBaseProjId, currentCode) @@ -211,7 +144,6 @@ public class GenerateProjectCodeUtil { max = Math.max(max,projectMaxCode); } max = max + 1; - // 生成20位的项目编号 - return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); + return max; } }