@@ -1,7 +1,9 @@ | |||
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; | |||
@@ -9,7 +11,9 @@ 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; | |||
import com.ningdatech.pmapi.projectlib.model.entity.Project; | |||
@@ -34,7 +38,7 @@ public class GenerateProjectCodeUtil { | |||
private IProjectService projectService; | |||
@Autowired | |||
private IGovBizProjectApplyService applyService; | |||
private IGovBizProjectBaseinfoService baseinfoService; | |||
public String generateProjectCode(ProjectDTO project){ | |||
// 获取所属行政区划代码(9位) | |||
@@ -72,7 +76,7 @@ public class GenerateProjectCodeUtil { | |||
return areaCode + year + projectType + serialNumber; | |||
} | |||
public String generateProjectCode(GovBizProjectSaveDTO dto){ | |||
public String generateProjectCode(GovBizProjectSaveDTO dto) { | |||
// 获取所属行政区划代码(9位) | |||
GovBizProjectBaseinfoDTO baseinfo = dto.getBaseinfo(); | |||
GovBizProjectApplyDTO apply = dto.getApply(); | |||
@@ -80,19 +84,22 @@ public class GenerateProjectCodeUtil { | |||
VUtils.isTrue(Objects.isNull(baseinfo)).throwMessage("没有项目基本信息 无法生成项目编号!"); | |||
VUtils.isTrue(Objects.isNull(apply)).throwMessage("没有项目申报信息 无法生成项目编号!"); | |||
String areaCode = (StringUtils.isNotBlank(baseinfo.getBaseAreaCode())?baseinfo.getBaseAreaCode(): RegionConst.RC_LS + BizConst.NINE_AREA_CODE_LAST); | |||
String areaCode = (StringUtils.isNotBlank(baseinfo.getBaseAreaCode()) ? baseinfo.getBaseAreaCode() : RegionConst.RC_LS + BizConst.NINE_AREA_CODE_LAST); | |||
// 获取建设年度 (10-13) | |||
String year = Objects.nonNull(apply.getBaseProjSetYear()) ? apply.getBaseProjSetYear() | |||
: String.valueOf(LocalDateTime.now().getYear()); | |||
// 14-15 项目类型 | |||
String projectType = StringUtils.isNotBlank(baseinfo.getBaseProjType()) ? baseinfo.getBaseProjType() : | |||
BizProjectContant.ProjectCollection.IS_EFFECTIVE; | |||
String currentCode = areaCode + year + projectType; | |||
// 16-20 项目序号00001 | |||
Long max = applyService.count(Wrappers.lambdaQuery(GovBizProjectApply.class) | |||
.eq(GovBizProjectApply::getBaseProjSetYear,apply.getBaseProjSetYear())); | |||
Long maxCurrent = max + 1; | |||
String serialNumber = String.format(ProjectCodeContant.SHUZI_5,maxCurrent); | |||
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())); | |||
max = max + 1; | |||
// 生成20位的项目编号 | |||
return areaCode + year + projectType + serialNumber; | |||
return currentCode + String.format(ProjectCodeContant.SHUZI_5, max); | |||
} | |||
} |
@@ -75,15 +75,20 @@ public class ProjectCollectionTest extends AppTests { | |||
@Test | |||
public void test(){ | |||
List<String> baseProjIds = Lists.newArrayList("33110000020230100061"); | |||
List<String> baseProjIds = Lists.newArrayList("33110000020230200001"); | |||
for(String baseProjId : baseProjIds){ | |||
GovBizProjectBaseinfo baseinfo = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) | |||
.eq(GovBizProjectBaseinfo::getBaseProjId, baseProjId) | |||
.orderByDesc(GovBizProjectBaseinfo::getTongTime) | |||
.last(BizConst.LIMIT_1)); | |||
GovBizProjectApply apply = applyService.getOne(Wrappers.lambdaQuery(GovBizProjectApply.class) | |||
.eq(GovBizProjectApply::getBaseProjId, baseProjId) | |||
.orderByDesc(GovBizProjectApply::getTongTime) | |||
.last(BizConst.LIMIT_1)); | |||
if(Objects.isNull(baseinfo)){ | |||
System.out.println("项目不存在 直接下一个"); | |||
continue; | |||
} | |||
GovBizProjectSaveDTO saveDTO = new GovBizProjectSaveDTO(); | |||
saveDTO.setApply(BeanUtil.copyProperties(apply, GovBizProjectApplyDTO.class)); | |||
saveDTO.setBaseinfo(BeanUtil.copyProperties(baseinfo, GovBizProjectBaseinfoDTO.class)); | |||
@@ -93,18 +98,45 @@ public class ProjectCollectionTest extends AppTests { | |||
baseinfoService.updateById(baseinfo); | |||
apply.setBaseProjId(newProjId); | |||
applyService.updateById(apply); | |||
approveService.update(Wrappers.lambdaUpdate(GovBizProjectApprove.class) | |||
.eq(GovBizProjectApprove::getBaseProjId,baseProjId) | |||
.set(GovBizProjectApprove::getBaseProjId,newProjId)); | |||
cimplementService.update(Wrappers.lambdaUpdate(GovBizProjectCimplement.class) | |||
.eq(GovBizProjectCimplement::getBaseProjId,baseProjId) | |||
.set(GovBizProjectCimplement::getBaseProjId,newProjId)); | |||
mimplementService.update(Wrappers.lambdaUpdate(GovBizProjectMimplement.class) | |||
.eq(GovBizProjectMimplement::getBaseProjId,baseProjId) | |||
.set(GovBizProjectMimplement::getBaseProjId,newProjId)); | |||
procureService.update(Wrappers.lambdaUpdate(GovBizProjectProcure.class) | |||
.eq(GovBizProjectProcure::getBaseProjId,baseProjId) | |||
.set(GovBizProjectProcure::getBaseProjId,newProjId)); | |||
GovBizProjectApprove approve = approveService.getOne(Wrappers.lambdaUpdate(GovBizProjectApprove.class) | |||
.eq(GovBizProjectApprove::getBaseProjId, baseProjId) | |||
.orderByDesc(GovBizProjectApprove::getTongTime) | |||
.last(BizConst.LIMIT_1)); | |||
if(Objects.nonNull(approve)){ | |||
approve.setBaseProjId(newProjId); | |||
approveService.updateById(approve); | |||
} | |||
GovBizProjectCimplement cimplement = cimplementService.getOne(Wrappers.lambdaQuery(GovBizProjectCimplement.class) | |||
.eq(GovBizProjectCimplement::getBaseProjId, baseProjId) | |||
.orderByDesc(GovBizProjectCimplement::getTongTime) | |||
.last(BizConst.LIMIT_1)); | |||
if(Objects.nonNull(cimplement)){ | |||
cimplement.setBaseProjId(newProjId); | |||
cimplement.setBaseBidCode(newProjId); | |||
cimplementService.updateById(cimplement); | |||
} | |||
GovBizProjectMimplement mimplement = mimplementService.getOne(Wrappers.lambdaQuery(GovBizProjectMimplement.class) | |||
.eq(GovBizProjectMimplement::getBaseProjId, baseProjId) | |||
.orderByDesc(GovBizProjectMimplement::getTongTime) | |||
.last(BizConst.LIMIT_1)); | |||
if(Objects.nonNull(mimplement)){ | |||
mimplement.setBaseProjId(newProjId); | |||
mimplement.setBaseBidCode(newProjId); | |||
mimplementService.updateById(mimplement); | |||
} | |||
List<GovBizProjectProcure> procures = procureService.list(Wrappers.lambdaUpdate(GovBizProjectProcure.class) | |||
.eq(GovBizProjectProcure::getBaseProjId, baseProjId)); | |||
for(GovBizProjectProcure procure : procures){ | |||
procure.setBaseProjId(newProjId); | |||
procure.setBaseBidCode(newProjId + "-" + procure.getBaseBidCode().split("-")[1]); | |||
procureService.updateById(procure); | |||
} | |||
} | |||
} | |||