Ver código fonte

生成项目编号新规则

tags/24080901
PoffyZhang 1 ano atrás
pai
commit
d93065d143
2 arquivos alterados com 150 adições e 5 exclusões
  1. +0
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java
  2. +150
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollection2Test.java

+ 0
- 5
pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/utils/GenerateProjectCodeUtil.java Ver arquivo

@@ -140,9 +140,4 @@ public class GenerateProjectCodeUtil {
// 生成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));
}
}

+ 150
- 0
pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollection2Test.java Ver arquivo

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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.ningdatech.basic.util.StrPool;
import com.ningdatech.log.model.domain.OptLog;
import com.ningdatech.log.service.OptLogService;
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 com.ningdatech.pmapi.scheduler.task.SynProjectCollectionTask;
import com.ningdatech.pmapi.scheduler.task.SynProjectCoreBizTask;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.UnknownHostException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
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);
}
}
}
}

Carregando…
Cancelar
Salvar