diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/CommonConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/CommonConst.java index 3e7e9b0..953d02c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/CommonConst.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/CommonConst.java @@ -49,6 +49,10 @@ public interface CommonConst { String ZHI = "至"; String YEAR = "年"; + Integer VERSION_ONE = 1; + Integer VERSION_SIZE = 2; + Integer VERSION_JUDGE = -1; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/ConstructionPlanReviewHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/ConstructionPlanReviewHandle.java index 196c1a2..fe2f333 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/ConstructionPlanReviewHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/ConstructionPlanReviewHandle.java @@ -6,7 +6,11 @@ import java.util.Objects; import cn.hutool.core.collection.CollUtil; import com.google.common.collect.Lists; +import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.util.NdDateUtils; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.projectlib.utils.ProjectVersionUtil; import com.ningdatech.pmapi.todocenter.utils.BuildUserUtils; import com.wflow.workflow.bean.process.ProgressNode; import com.wflow.workflow.bean.vo.ProcessDetailVO; @@ -36,32 +40,47 @@ public class ConstructionPlanReviewHandle extends AbstractProcessBusinessHandle private final IProjectInstService projectInstService; private final ProcessInstanceService processInstanceService; private final BuildUserUtils buildUserUtils; + private final ProjectVersionUtil projectVersionUtil; + private final IProjectService projectService; - public ConstructionPlanReviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils){ + public ConstructionPlanReviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils, ProjectVersionUtil projectVersionUtil, IProjectService projectService){ this.projectInstService = projectInstService; this.processInstanceService = processInstanceService; this.buildUserUtils = buildUserUtils; + this.projectVersionUtil = projectVersionUtil; + this.projectService = projectService; } @Override void businessHandle(Long projectId, List processSchedule) { ProcessDetailVO processDetailVO = new ProcessDetailVO(); + Project project = projectService.getById(projectId); // 根据项目ID查询出建设方案评审流程的流程状态 ProjectInst projectInst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) .eq(ProjectInst::getProjectId, projectId) .eq(ProjectInst::getInstType, InstTypeEnum.CONSTRUCTION_PLAN_REVIEW.getCode()) .orderByDesc(ProjectInst::getCreatOn) .last("limit 1")); - - if (Objects.isNull(projectInst)){ - processDetailVO.setStepStatus(StepStatusEnum.NOT_START); - processDetailVO.setProcessName(CommonConst.CONSTRUCTION_PLAN_REVIEW); - processSchedule.add(processDetailVO); - return; + ProcessProgressVo instanceDetail = null; + // 未找到当前版本项目的建设方案审核流程且当前项目版本号大于1(是被驳回重新申报的项目) + if (Objects.isNull(projectInst)) { + if (project.getVersion() > CommonConst.VERSION_ONE){ + // 获取上个版本的信息 + instanceDetail = projectVersionUtil.getPreVerProcessInfo(projectId); + if (Objects.isNull(instanceDetail)){ + throw new BizException("未获取到历史版本的流程详情!"); + } + }else { + // 版本号为1 + processDetailVO.setStepStatus(StepStatusEnum.NOT_START); + processDetailVO.setProcessName(CommonConst.CONSTRUCTION_PLAN_REVIEW); + processSchedule.add(processDetailVO); + return; + } + }else { + String instCode = projectInst.getInstCode(); + instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); } - - String instCode = projectInst.getInstCode(); - ProcessProgressVo instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); String status = instanceDetail.getStatus(); if (ProcessStatusEnum.UNDER_REVIEW.getDesc().equals(status)){ processDetailVO.setStepStatus(StepStatusEnum.ON_GOING); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/DeptUnitedReviewHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/DeptUnitedReviewHandle.java index 5d84a84..90057aa 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/DeptUnitedReviewHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/DeptUnitedReviewHandle.java @@ -7,6 +7,7 @@ import java.util.Objects; import cn.hutool.core.collection.CollUtil; import com.google.common.collect.Lists; import com.ningdatech.basic.util.NdDateUtils; +import com.ningdatech.pmapi.projectlib.utils.ProjectVersionUtil; import com.ningdatech.pmapi.todocenter.utils.BuildUserUtils; import com.wflow.workflow.bean.process.ProgressNode; import com.wflow.workflow.bean.vo.ProcessDetailVO; @@ -24,7 +25,7 @@ import com.wflow.workflow.enums.ProcessStatusEnum; import com.wflow.workflow.service.ProcessInstanceService; /** - * 单位内部审核处理 + * 部门联审审核处理 * * @author CMM * @since 2023/02/24 14:35 @@ -36,11 +37,13 @@ public class DeptUnitedReviewHandle extends AbstractProcessBusinessHandle { private final IProjectInstService projectInstService; private final ProcessInstanceService processInstanceService; private final BuildUserUtils buildUserUtils; + private final ProjectVersionUtil projectVersionUtil; - public DeptUnitedReviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils){ + public DeptUnitedReviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils, ProjectVersionUtil projectVersionUtil){ this.projectInstService = projectInstService; this.processInstanceService = processInstanceService; this.buildUserUtils = buildUserUtils; + this.projectVersionUtil = projectVersionUtil; } @Override diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/PreliminaryPreviewHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/PreliminaryPreviewHandle.java index fa57371..c0dd713 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/PreliminaryPreviewHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/PreliminaryPreviewHandle.java @@ -3,11 +3,15 @@ package com.ningdatech.pmapi.projectlib.handle; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.pmapi.common.constant.CommonConst; import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; +import com.ningdatech.pmapi.projectlib.model.entity.Project; import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; import com.ningdatech.pmapi.projectlib.service.IProjectInstService; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.projectlib.utils.ProjectVersionUtil; import com.ningdatech.pmapi.todocenter.utils.BuildUserUtils; import com.wflow.workflow.bean.process.ProgressNode; import com.wflow.workflow.bean.vo.ProcessDetailVO; @@ -35,30 +39,50 @@ public class PreliminaryPreviewHandle extends AbstractProcessBusinessHandle { private final IProjectInstService projectInstService; private final ProcessInstanceService processInstanceService; private final BuildUserUtils buildUserUtils; + private final ProjectVersionUtil projectVersionUtil; + private final IProjectService projectService; - public PreliminaryPreviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils) { + public PreliminaryPreviewHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils, ProjectVersionUtil projectVersionUtil, IProjectService projectService) { this.projectInstService = projectInstService; this.processInstanceService = processInstanceService; this.buildUserUtils = buildUserUtils; + this.projectVersionUtil = projectVersionUtil; + this.projectService = projectService; } @Override void businessHandle(Long projectId, List processSchedule) { ProcessDetailVO processDetailVO = new ProcessDetailVO(); + Project project = projectService.getById(projectId); + if (Objects.isNull(project)){ + throw new BizException("当前项目不存在!"); + } // 根据项目ID查询项目预审流程的流程状态 ProjectInst projectInst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) .eq(ProjectInst::getProjectId, projectId) .eq(ProjectInst::getInstType, InstTypeEnum.PRELIMINARY_PREVIEW.getCode()) .orderByDesc(ProjectInst::getCreatOn) .last("limit 1")); - if (Objects.isNull(projectInst)){ - processDetailVO.setStepStatus(StepStatusEnum.NOT_START); - processDetailVO.setProcessName(CommonConst.PRELIMINARY_PREVIEW); - processSchedule.add(processDetailVO); - return; + ProcessProgressVo instanceDetail = null; + // 未找到当前版本项目的预审审核流程且当前项目版本号大于1(是被驳回重新申报的项目) + if (Objects.isNull(projectInst)) { + if (project.getVersion() > CommonConst.VERSION_ONE){ + // 获取上个版本的信息 + instanceDetail = projectVersionUtil.getPreVerProcessInfo(projectId); + if (Objects.isNull(instanceDetail)){ + throw new BizException("未获取到历史版本的流程详情!"); + } + }else { + // 版本号为1 + processDetailVO.setStepStatus(StepStatusEnum.NOT_START); + processDetailVO.setProcessName(CommonConst.PRELIMINARY_PREVIEW); + processSchedule.add(processDetailVO); + return; + } + }else { + String instCode = projectInst.getInstCode(); + instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); } - String instCode = projectInst.getInstCode(); - ProcessProgressVo instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); String status = instanceDetail.getStatus(); if (ProcessStatusEnum.UNDER_REVIEW.getDesc().equals(status)){ processDetailVO.setStepStatus(StepStatusEnum.ON_GOING); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/UnitInnerAuditHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/UnitInnerAuditHandle.java index 2e14eb4..344d0a5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/UnitInnerAuditHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/handle/UnitInnerAuditHandle.java @@ -1,19 +1,23 @@ package com.ningdatech.pmapi.projectlib.handle; import java.time.LocalDateTime; -import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum; +import com.ningdatech.pmapi.projectlib.model.entity.Project; import com.ningdatech.pmapi.projectlib.model.entity.ProjectInst; import com.ningdatech.pmapi.projectlib.service.IProjectInstService; import com.ningdatech.pmapi.common.constant.CommonConst; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.ningdatech.pmapi.projectlib.utils.ProjectVersionUtil; import com.ningdatech.pmapi.todocenter.utils.BuildUserUtils; import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; import com.wflow.workflow.bean.process.ProgressNode; @@ -39,25 +43,43 @@ public class UnitInnerAuditHandle extends AbstractProcessBusinessHandle { private final ProcessInstanceService processInstanceService; private final BuildUserUtils buildUserUtils; + private final ProjectVersionUtil projectVersionUtil; + private final IProjectService projectService; - public UnitInnerAuditHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils){ + public UnitInnerAuditHandle(IProjectInstService projectInstService, ProcessInstanceService processInstanceService, BuildUserUtils buildUserUtils, ProjectVersionUtil projectVersionUtil, IProjectService projectService){ this.projectInstService = projectInstService; this.processInstanceService = processInstanceService; this.buildUserUtils = buildUserUtils; + this.projectVersionUtil = projectVersionUtil; + this.projectService = projectService; } @Override void businessHandle(Long projectId, List processSchedule) { ProcessDetailVO processDetailVO = new ProcessDetailVO(); + Project project = projectService.getById(projectId); // 根据项目ID查询出单位内部审核流程的流程状态 - // 注意:已经在项目库中的项目,一定是单位内部审核已经开始的项目 ProjectInst projectInst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) .eq(ProjectInst::getProjectId, projectId) .eq(ProjectInst::getInstType, InstTypeEnum.UNIT_INNER_AUDIT.getCode()) .orderByDesc(ProjectInst::getCreatOn) .last("limit 1")); - String instCode = projectInst.getInstCode(); - ProcessProgressVo instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); + ProcessProgressVo instanceDetail = null; + + // 未找到当前版本项目的单位内部审核流程且当前项目版本号大于1(是被驳回重新申报的项目) + // 注意:已经在项目库中的项目,一定是单位内部审核已经开始的项目 + if (Objects.isNull(projectInst)) { + if (project.getVersion() > CommonConst.VERSION_ONE){ + // 获取上个版本的信息 + instanceDetail = projectVersionUtil.getPreVerProcessInfo(projectId); + } + }else { + String instCode = projectInst.getInstCode(); + instanceDetail = processInstanceService.getProgressInstanceDetail(null, instCode); + } + if (Objects.isNull(instanceDetail)){ + throw new BizException("未获取到历史版本的流程详情!"); + } String status = instanceDetail.getStatus(); if (ProcessStatusEnum.UNDER_REVIEW.getDesc().equals(status)){ processDetailVO.setStepStatus(StepStatusEnum.ON_GOING); @@ -75,6 +97,7 @@ public class UnitInnerAuditHandle extends AbstractProcessBusinessHandle { if (StepStatusEnum.contains(processDetailVO.getStepStatus(), Lists.newArrayList(StepStatusEnum.REJECTED, StepStatusEnum.COMPLETED))) { + // 如果是驳回,获取流程信息时可能 ProgressNode progressNode = progressInfo.get(progressInfo.size() - 1); LocalDateTime finishTime = NdDateUtils.date2LocalDateTime(progressNode.getFinishTime()); processDetailVO.setFinishTime(finishTime); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/MergeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/MergeUtil.java deleted file mode 100644 index b7d5bc1..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/MergeUtil.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.ningdatech.pmapi.projectlib.utils; - -import java.util.List; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.util.CellRangeAddress; -import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.metadata.data.WriteCellData; -import com.alibaba.excel.write.handler.CellWriteHandler; -import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; -import com.alibaba.excel.write.metadata.holder.WriteTableHolder; -import lombok.Data; - -/** - * @description: 多表头excel导出合并单元格策略 - * @author:YJ - **/ -@Data -public class MergeUtil implements CellWriteHandler { - private int[] mergeColumnIndex; - private int mergeRowIndex; - - public MergeUtil() { - } - - public MergeUtil(int mergeRowIndex, int[] mergeColumnIndex) { - this.mergeRowIndex = mergeRowIndex; - this.mergeColumnIndex = mergeColumnIndex; - } - - - @Override - public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List> list, Cell cell, Head head, Integer integer, Boolean aBoolean) { - // 当前行 - int curRowIndex = cell.getRowIndex(); - // 当前列 - int curColIndex = cell.getColumnIndex(); - - if (curRowIndex > mergeRowIndex) { - for (int i = 0; i < mergeColumnIndex.length; i++) { - if (curColIndex == mergeColumnIndex[i]) { - mergeWithPrevRow(writeSheetHolder, cell, curRowIndex, curColIndex); - break; - } - } - } - } - - - private void mergeWithPrevRow(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex) { - // 获取当前行的当前列和上一行的当前列列数据,通过上一行数据是否相同进行合并 - Object curData = cell.getCellType() == CellType.STRING ? cell.getStringCellValue() : cell.getNumericCellValue(); - Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex); - Object preData = preCell.getCellType() == CellType.STRING ? preCell.getStringCellValue() : preCell.getNumericCellValue(); - - // 比较当前行的第一列的单元格与上一行是否相同,相同合并当前单元格与上一行 - if (curData.equals(preData)) { - Sheet sheet = writeSheetHolder.getSheet(); - List mergedRegions = sheet.getMergedRegions(); - boolean isMerged = false; - for (int i = 0; i < mergedRegions.size() && !isMerged; i++) { - CellRangeAddress cellRangeAddr = mergedRegions.get(i); - // 若上一个单元格已经被合并,则先移出原有的合并单元,再重新添加合并单元 - if (cellRangeAddr.isInRange(curRowIndex - 1, curColIndex)) { - sheet.removeMergedRegion(i); - cellRangeAddr.setLastRow(curRowIndex); - sheet.addMergedRegion(cellRangeAddr); - isMerged = true; - } - } - // 若上一个单元格未被合并,则新增合并单元 - if (!isMerged) { - CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex - 1, curRowIndex, curColIndex, curColIndex); - sheet.addMergedRegion(cellRangeAddress); - } - } - } -} - diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/ProjectVersionUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/ProjectVersionUtil.java new file mode 100644 index 0000000..92532af --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/utils/ProjectVersionUtil.java @@ -0,0 +1,69 @@ +package com.ningdatech.pmapi.projectlib.utils; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.pmapi.common.constant.CommonConst; +import com.ningdatech.pmapi.projectlib.model.entity.Project; +import com.ningdatech.pmapi.projectlib.service.IProjectService; +import com.wflow.workflow.bean.vo.ProcessProgressVo; +import com.wflow.workflow.service.ProcessInstanceService; +import liquibase.pro.packaged.I; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Objects; + +/** + * 根据项目版本获取流程详情工具类 + * + * @author CMM + * @since 2023/04/20 09:57 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class ProjectVersionUtil { + + private final IProjectService projectService; + private final ProcessInstanceService processInstanceService; + + /** + * 根据最新的项目ID获取临近项目版本的审核记录信息 + * @param projectId + * @return + */ + public ProcessProgressVo getPreVerProcessInfo(Long projectId){ + Project project = projectService.getById(projectId); + if (Objects.isNull(project)){ + throw new BizException("当前项目不存在!"); + } + String projectCode = project.getProjectCode(); + if (StringUtils.isEmpty(projectCode)){ + throw new BizException("当前项目编号为空!"); + } + // 获取相同项目编号的项目 + List projectList = projectService.list(Wrappers.lambdaQuery(Project.class) + .eq(Project::getProjectCode, projectCode) + .orderByDesc(Project::getVersion)); + if (projectList.size() < CommonConst.VERSION_SIZE){ + throw new BizException("未发现该项目的历史版本!"); + } + // 获取上个版本的项目 + int index = projectList.size() - CommonConst.VERSION_SIZE; + ProcessProgressVo instanceDetail = null; + while (index > 0){ + index = index - 1; + Project preProject = projectList.get(index); + // 获取上个版本的项目关联的流程实例ID + String preInstCode = preProject.getInstCode(); + instanceDetail = processInstanceService.getProgressInstanceDetail(null, preInstCode); + if (Objects.nonNull(instanceDetail)){ + return instanceDetail; + } + } + return null; + } +}