From 3e06b2f6f2263e01d7ca38d00d5eec49e6d52d4c Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 26 Sep 2023 11:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BC=96=E5=8F=B7=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/GenerateProjectCodeUtil.java | 77 +++++++++++++++++----- 1 file changed, 60 insertions(+), 17 deletions(-) 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 9a0a2c2..ed4acb5 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 @@ -1,18 +1,14 @@ package com.ningdatech.pmapi.projectdeclared.utils; -import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.basic.function.VUtils; -import com.ningdatech.basic.util.StrPool; import com.ningdatech.pmapi.common.constant.BizConst; import com.ningdatech.pmapi.common.constant.RegionConst; import com.ningdatech.pmapi.gov.contants.BizProjectContant; import com.ningdatech.pmapi.gov.model.dto.GovBizProjectApplyDTO; import com.ningdatech.pmapi.gov.model.dto.GovBizProjectBaseinfoDTO; import com.ningdatech.pmapi.gov.model.dto.GovBizProjectSaveDTO; -import com.ningdatech.pmapi.gov.model.entity.GovBizProjectApply; import com.ningdatech.pmapi.gov.model.entity.GovBizProjectBaseinfo; -import com.ningdatech.pmapi.gov.service.IGovBizProjectApplyService; import com.ningdatech.pmapi.gov.service.IGovBizProjectBaseinfoService; import com.ningdatech.pmapi.projectdeclared.contants.ProjectCodeContant; import com.ningdatech.pmapi.projectlib.model.dto.ProjectDTO; @@ -49,13 +45,28 @@ public class GenerateProjectCodeUtil { // 14-15 项目类型 String projectType = ProjectCodeContant.PROJECT_TYPE_PREFIX + project.getProjectType(); // 16-20 项目序号00001 - Long max = projectService.count(Wrappers.lambdaQuery(Project.class) - .eq(Project::getProjectYear,project.getProjectYear()) - .eq(Project::getNewest,Boolean.TRUE)); - Long maxCurrent = max + 1; - String serialNumber = String.format(ProjectCodeContant.SHUZI_5,maxCurrent); + 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)); + } + 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; // 生成20位的项目编号 - return areaCode + year + projectType + serialNumber; + return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } public String generateProjectCode(ProjectCollection project){ @@ -67,13 +78,28 @@ public class GenerateProjectCodeUtil { // 14-15 项目类型 String projectType = ProjectCodeContant.PROJECT_TYPE_PREFIX + project.getProjectType(); // 16-20 项目序号00001 - Long max = projectService.count(Wrappers.lambdaQuery(Project.class) - .eq(Project::getProjectYear,project.getProjectYear()) - .eq(Project::getNewest,Boolean.TRUE)); - Long maxCurrent = max + 1; - String serialNumber = String.format(ProjectCodeContant.SHUZI_5,maxCurrent); + 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)); + } + 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; // 生成20位的项目编号 - return areaCode + year + projectType + serialNumber; + return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } public String generateProjectCode(GovBizProjectSaveDTO dto) { @@ -93,13 +119,30 @@ 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)); - Long max = Objects.isNull(baseMax) ? 0L : Long.valueOf(baseMax.getBaseProjId().substring(baseMax.getBaseProjId().length() - 5, baseMax.getBaseProjId().length())); + if(Objects.nonNull(baseMax) && StringUtils.isNotBlank(baseMax.getBaseProjId())){ + max = Long.valueOf(baseMax.getBaseProjId().substring(baseMax.getBaseProjId().length() - 5)); + } + 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; // 生成20位的项目编号 return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); } + + public static void main(String[] args) { + String projectCode = "33110020230100001"; + System.out.println(projectCode.substring(projectCode.length() - 5)); + } }