Explorar el Código

Merge branch 'master' of http://git.ningdatech.com/liushuai/project-management into 20230913_project_declared_new

tags/24080901
PoffyZhang hace 1 año
padre
commit
0d7431cdd9
Se han modificado 2 ficheros con 186 adiciones y 17 borrados
  1. +55
    -17
      pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java
  2. +131
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollection2Test.java

+ 55
- 17
pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java Ver fichero

@@ -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,11 +119,23 @@ 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);


+ 131
- 0
pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollection2Test.java Ver fichero

@@ -0,0 +1,131 @@
package com.ningdatech.pmapi.projectCollection;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.common.constant.BizConst;
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.*;
import com.ningdatech.pmapi.gov.service.*;
import com.ningdatech.pmapi.projectdeclared.utils.GenerateProjectCodeUtil;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* @Classname ProjectCollectionTest
* @Description
* @Date 2023/9/7 15:08
* @Author PoffyZhang
*/
public class ProjectCollection2Test extends AppTests {

@Autowired
private IGovBizProjectBaseinfoService baseinfoService;

@Autowired
private IGovBizProjectApplyService applyService;

@Autowired
private IGovBizProjectApproveService approveService;

@Autowired
private IGovBizProjectCimplementService cimplementService;

@Autowired
private IGovBizProjectMimplementService mimplementService;

@Autowired
private IGovBizProjectProcureService procureService;

@Autowired
private GenerateProjectCodeUtil generateProjectCodeUtil;

@Autowired
private IProjectService projectService;

@Test
public void test(){
List<GovBizProjectBaseinfo> baseinfos = baseinfoService.list(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class)
.eq(GovBizProjectBaseinfo::getDeleted,Boolean.FALSE));

List<Project> projects = projectService.list(Wrappers.lambdaQuery(Project.class)
.eq(Project::getNewest, Boolean.TRUE));

List<String> projectCodes = projects.stream().map(Project::getProjectCode).collect(Collectors.toList());

//查出重复的 重新去生成编号
List<String> baseProjIds = baseinfos.stream().map(GovBizProjectBaseinfo::getBaseProjId)
.filter(code -> projectCodes.contains(code))
.collect(Collectors.toList());

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));
String newProjId = generateProjectCodeUtil.generateProjectCode(saveDTO);

baseinfo.setBaseProjId(newProjId);
baseinfoService.updateById(baseinfo);
apply.setBaseProjId(newProjId);
applyService.updateById(apply);

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);
}
}
}
}

Cargando…
Cancelar
Guardar