@@ -56,4 +56,8 @@ public interface AbstractStateChangeEvent { | |||
throw BizException.wrap("该状态下没有对应的撤回操作!"); | |||
} | |||
default boolean eq(String name){ | |||
return name().equals(name); | |||
} | |||
} |
@@ -1,8 +1,12 @@ | |||
package com.hz.pm.api.projectlib.handle; | |||
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; | |||
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; | |||
import com.wflow.workflow.bean.vo.ProcessDetailVO; | |||
import com.wflow.workflow.bean.vo.ProcessInfoVO; | |||
import com.wflow.workflow.bean.vo.ProcessInstanceVo; | |||
import com.wflow.workflow.bean.vo.ProcessProgressVo; | |||
import com.wflow.workflow.enums.ProcessStatusEnum; | |||
import com.wflow.workflow.enums.StepStatusEnum; | |||
import lombok.AllArgsConstructor; | |||
@@ -95,4 +99,17 @@ public abstract class AbstractProcessHandle implements Ordered, ProcessHandle { | |||
} | |||
} | |||
public void buildStepStatus(ProcessDetailVO detail, ProcessProgressVo progress, ProjectStatusChange event) { | |||
detail.setProcessProgressVo(progress); | |||
if (ProcessStatusEnum.BE_REJECTED.getDesc().equals(progress.getStatus())) { | |||
detail.setStepStatus(StepStatusEnum.REJECTED); | |||
detail.setFinishTime(event.getCreateOn()); | |||
} else if (ProcessStatusEnum.APPROVED.getDesc().equals(progress.getStatus())) { | |||
detail.setStepStatus(StepStatusEnum.COMPLETED); | |||
detail.setFinishTime(event.getCreateOn()); | |||
} else { | |||
detail.setStepStatus(StepStatusEnum.ON_GOING); | |||
} | |||
} | |||
} |
@@ -1,14 +1,18 @@ | |||
package com.hz.pm.api.projectlib.handle; | |||
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.model.entity.Purchase; | |||
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; | |||
import com.hz.pm.api.projectlib.model.entity.Project; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectInst; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; | |||
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; | |||
import com.wflow.workflow.bean.vo.ProcessDetailVO; | |||
import com.wflow.workflow.enums.StepStatusEnum; | |||
import lombok.Data; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
@@ -29,8 +33,14 @@ public final class HandleParamContext { | |||
private List<PurchaseInst> purchaseInstList; | |||
private List<ProjectStatusChange> projectStatusChanges; | |||
private Map<ProjectStateChangeEvent, ProjectStatusChange> projectStatusChanges; | |||
private Map<InstTypeEnum, ProjectInst> projectInstMap; | |||
private StepStatusEnum preStepStatus; | |||
public ProjectStatusChange getProjectStateChange(ProjectStateChangeEvent event) { | |||
return projectStatusChanges.get(event); | |||
} | |||
} |
@@ -1,18 +1,11 @@ | |||
package com.hz.pm.api.projectlib.handle.stage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.hz.pm.api.common.model.constant.BizConst; | |||
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; | |||
import com.hz.pm.api.projectlib.handle.AbstractProcessHandle; | |||
import com.hz.pm.api.projectlib.handle.HandleParamContext; | |||
import com.hz.pm.api.projectlib.model.entity.Project; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectInst; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; | |||
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; | |||
import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; | |||
import com.hz.pm.api.projectlib.service.IProjectInstService; | |||
import com.hz.pm.api.projectlib.service.IProjectService; | |||
import com.hz.pm.api.projectlib.service.IProjectStatusChangeService; | |||
import com.wflow.workflow.bean.vo.ProcessDetailVO; | |||
import com.wflow.workflow.bean.vo.ProcessProgressVo; | |||
import com.wflow.workflow.enums.ProcessStatusEnum; | |||
@@ -21,9 +14,11 @@ import com.wflow.workflow.service.ProcessInstanceService; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.stereotype.Component; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Objects; | |||
import java.util.Comparator; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import static com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent.*; | |||
/** | |||
* 立项批复处理 | |||
@@ -35,9 +30,6 @@ import java.util.Objects; | |||
@RequiredArgsConstructor | |||
public class ProjectApprovalHandle extends AbstractProcessHandle { | |||
private final IProjectStatusChangeService projectStatusChangeService; | |||
private final IProjectService projectService; | |||
private final IProjectInstService projectInstService; | |||
private final ProcessInstanceService processInstanceService; | |||
@Override | |||
@@ -50,46 +42,30 @@ public class ProjectApprovalHandle extends AbstractProcessHandle { | |||
ProcessDetailVO detail = new ProcessDetailVO(); | |||
detail.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(detail); | |||
Project project = ctx.getProject(); | |||
Integer status = project.getStatus(); | |||
if (!StepStatusEnum.COMPLETED.equals(ctx.getPreStepStatus())) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
return; | |||
} | |||
// 项目状态为待立项批复之前的状态 | |||
if (status == null || (status < ProjectStatus.DECLARED_APPROVED_TO_BE_RECORD.getCode())) { | |||
Map<ProjectStateChangeEvent, ProjectStatusChange> eventMap = ctx.getProjectStatusChanges(); | |||
if (!eventMap.containsKey(DECLARED_RECORD_SUBMIT)) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
List<Long> projectIds = projectService.allVersionProjectIds(project.getProjectCode()); | |||
// 当前项目状态为待立项批复 | |||
if (ProjectStatus.DECLARED_APPROVED_TO_BE_RECORD.eq(status) | |||
|| ProjectStatus.DECLARED_APPROVED_RECORD_AUDITING.eq(status)) { | |||
// 根据建设方案评审通过的时间获取 | |||
final List<ProjectStateChangeEvent> events = Arrays.asList( | |||
ProjectStateChangeEvent.DECLARED_RECORD_SUBMIT, | |||
ProjectStateChangeEvent.DECLARED_RECORD_RESUBMIT); | |||
ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectIds, events); | |||
if (projectStatusChange != null) { | |||
detail.setFinishTime(projectStatusChange.getCreateOn()); | |||
} | |||
detail.setStepStatus(StepStatusEnum.ON_GOING); | |||
ProjectInst inst = ctx.getProjectInstMap().get(InstTypeEnum.DECLARED_RECORD); | |||
if (inst == null) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
// 取 状态机 改变状态时间 | |||
final List<ProjectStateChangeEvent> events = Arrays.asList( | |||
ProjectStateChangeEvent.DECLARED_RECORD_FAILED, | |||
ProjectStateChangeEvent.DECLARED_RECORD_PASS); | |||
ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectIds, events); | |||
if (Objects.nonNull(projectStatusChange)) { | |||
detail.setFinishTime(projectStatusChange.getCreateOn()); | |||
detail.setStepStatus(StepStatusEnum.COMPLETED); | |||
ProjectInst inst = projectInstService.getOne(Wrappers.lambdaQuery(ProjectInst.class) | |||
.in(ProjectInst::getProjectId, projectIds) | |||
.eq(ProjectInst::getInstType, InstTypeEnum.DECLARED_RECORD.getCode()) | |||
.orderByDesc(ProjectInst::getCreateOn) | |||
.last(BizConst.LIMIT_1)); | |||
if (inst != null) { | |||
ProcessProgressVo instDetail = processInstanceService.getProgressInstanceDetail(null, inst.getInstCode()); | |||
detail.setProcessProgressVo(instDetail); | |||
if (ProcessStatusEnum.BE_REJECTED.getDesc().equals(instDetail.getStatus())) { | |||
detail.setStepStatus(StepStatusEnum.REJECTED); | |||
} | |||
} | |||
Optional<ProjectStatusChange> event = eventMap.values().stream() | |||
.filter(w -> DECLARED_RECORD_SUBMIT.eq(w.getEvent()) | |||
|| DECLARED_RECORD_PASS.eq(w.getEvent()) | |||
|| DECLARED_RECORD_RESUBMIT.eq(w.getEvent()) | |||
|| DECLARED_RECORD_FAILED.eq(w.getEvent()) | |||
).max(Comparator.comparing(ProjectStatusChange::getCreateOn)); | |||
if (event.isPresent()) { | |||
ProcessProgressVo progress = processInstanceService.getProgressInstanceDetail(null, inst.getInstCode()); | |||
buildStepStatus(detail, progress, event.get()); | |||
} else { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} | |||
} | |||
} | |||
@@ -1,14 +1,29 @@ | |||
package com.hz.pm.api.projectlib.handle.stage; | |||
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; | |||
import com.hz.pm.api.common.util.BizUtils; | |||
import com.hz.pm.api.projectdeclared.utils.ProjectIdCodeCacheUtil; | |||
import com.hz.pm.api.projectlib.handle.AbstractProcessHandle; | |||
import com.hz.pm.api.projectlib.handle.HandleParamContext; | |||
import com.hz.pm.api.projectlib.model.entity.Project; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectInst; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; | |||
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; | |||
import com.hz.pm.api.projectlib.service.IProjectInstService; | |||
import com.hz.pm.api.projectlib.service.IProjectStatusChangeService; | |||
import com.wflow.workflow.bean.vo.ProcessDetailVO; | |||
import com.wflow.workflow.bean.vo.ProcessProgressVo; | |||
import com.wflow.workflow.enums.StepStatusEnum; | |||
import com.wflow.workflow.service.ProcessInstanceService; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.stereotype.Component; | |||
import java.time.LocalDateTime; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import static com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent.*; | |||
/** | |||
* 项目申报处理 | |||
@@ -20,6 +35,10 @@ import java.time.LocalDateTime; | |||
@RequiredArgsConstructor | |||
public class ProjectDeclareHandle extends AbstractProcessHandle { | |||
private final IProjectStatusChangeService projectStatusChangeService; | |||
private final IProjectInstService projectInstService; | |||
private final ProcessInstanceService processInstanceService; | |||
@Override | |||
public ProcessNode getProcessNode() { | |||
return ProcessNode.PROJECT_DECLARED; | |||
@@ -27,15 +46,41 @@ public class ProjectDeclareHandle extends AbstractProcessHandle { | |||
@Override | |||
public void handle(HandleParamContext ctx) { | |||
// 因为此时在项目库中的项目,都是已经申报过的项目,所以直接设置环节状态为已完成 | |||
ProcessDetailVO processDetailVO = new ProcessDetailVO(); | |||
processDetailVO.setStepStatus(StepStatusEnum.COMPLETED); | |||
// 项目库中查出申报完成时间 | |||
ProcessDetailVO detail = new ProcessDetailVO(); | |||
detail.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(detail); | |||
Project project = ctx.getProject(); | |||
LocalDateTime createOn = project.getCreateOn(); | |||
processDetailVO.setFinishTime(createOn); | |||
processDetailVO.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(processDetailVO); | |||
// 项目状态为待立项批复之前的状态 | |||
Map<ProjectStateChangeEvent, ProjectStatusChange> eventMap = projectStatusChangeService.listLastEventMap(project.getProjectCode()); | |||
ctx.setProjectStatusChanges(eventMap); | |||
if (!eventMap.containsKey(PROJECT_APPLICATION_SUBMIT)) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
List<Long> projectIds = ProjectIdCodeCacheUtil.get(project.getProjectCode()); | |||
List<ProjectInst> projectInstList = projectInstService.listByProjectIds(projectIds); | |||
Map<InstTypeEnum, ProjectInst> instMap = BizUtils.groupFirstMap(projectInstList, | |||
w -> InstTypeEnum.getNoNull(w.getInstType()), | |||
Comparator.comparing(ProjectInst::getCreateOn).reversed()); | |||
ctx.setProjectInstMap(instMap); | |||
ProjectInst inst = instMap.get(InstTypeEnum.COMPLIANCE_REVIEW); | |||
if (inst == null) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
Optional<ProjectStatusChange> event = eventMap.values().stream() | |||
.filter(w -> PROJECT_APPLICATION_SUBMIT.eq(w.getEvent()) | |||
|| COMPLIANCE_REVIEW_FAILED.eq(w.getEvent()) | |||
|| COMPLIANCE_REVIEW_RESUBMIT.eq(w.getEvent()) | |||
|| COMPLIANCE_REVIEW_PASS.eq(w.getEvent()) | |||
).max(Comparator.comparing(ProjectStatusChange::getCreateOn)); | |||
if (event.isPresent()) { | |||
ProcessProgressVo progress = processInstanceService.getProgressInstanceDetail(null, inst.getInstCode()); | |||
buildStepStatus(detail, progress, event.get()); | |||
} else { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} | |||
} | |||
} | |||
ctx.setPreStepStatus(detail.getStepStatus()); | |||
} | |||
@Override | |||
@@ -1,7 +1,5 @@ | |||
package com.hz.pm.api.projectlib.handle.stage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.hz.pm.api.common.model.constant.BizConst; | |||
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; | |||
import com.hz.pm.api.projectdeclared.model.entity.Purchase; | |||
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; | |||
@@ -19,6 +17,7 @@ import org.springframework.stereotype.Component; | |||
import java.util.List; | |||
import static com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent.SUBMIT_OPERATION_PLAN; | |||
import static com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus.ON_PURCHASING; | |||
import static com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus.TO_BE_PURCHASED; | |||
@@ -51,8 +50,10 @@ public class ProjectPurchaseHandle extends AbstractProcessHandle { | |||
ProcessDetailVO detail = new ProcessDetailVO(); | |||
detail.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(detail); | |||
// 根据项目是否通过立项批复(立项批复时间)来判断招标采购是否开始 | |||
// 进行了立项批复且项目状态是待采购 | |||
if (!StepStatusEnum.COMPLETED.equals(ctx.getPreStepStatus())) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
return; | |||
} | |||
Project project = ctx.getProject(); | |||
if (TO_BE_PURCHASED.eq(project.getStatus())) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
@@ -60,11 +61,7 @@ public class ProjectPurchaseHandle extends AbstractProcessHandle { | |||
detail.setStepStatus(StepStatusEnum.ON_GOING); | |||
} else { | |||
// 根据采购备案的时间获取 | |||
ProjectStatusChange change = projectStatusChangeService.getOne(Wrappers.lambdaQuery(ProjectStatusChange.class) | |||
.eq(ProjectStatusChange::getProjectCode, project.getProjectCode()) | |||
.eq(ProjectStatusChange::getEvent, ProjectStateChangeEvent.SUBMIT_OPERATION_PLAN) | |||
.orderByDesc(ProjectStatusChange::getCreateOn) | |||
.last(BizConst.LIMIT_1)); | |||
ProjectStatusChange change = ctx.getProjectStateChange(SUBMIT_OPERATION_PLAN); | |||
if (change == null) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
@@ -77,7 +74,6 @@ public class ProjectPurchaseHandle extends AbstractProcessHandle { | |||
} | |||
} | |||
ctx.setPreStepStatus(detail.getStepStatus()); | |||
detail.setProcessName(getProcessNode().getName()); | |||
} | |||
} |
@@ -1,12 +1,23 @@ | |||
package com.hz.pm.api.projectlib.handle.stage; | |||
import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; | |||
import com.hz.pm.api.projectlib.handle.AbstractProcessHandle; | |||
import com.hz.pm.api.projectlib.handle.HandleParamContext; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectInst; | |||
import com.hz.pm.api.projectlib.model.entity.ProjectStatusChange; | |||
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; | |||
import com.wflow.workflow.bean.vo.ProcessDetailVO; | |||
import com.wflow.workflow.bean.vo.ProcessProgressVo; | |||
import com.wflow.workflow.enums.StepStatusEnum; | |||
import com.wflow.workflow.service.ProcessInstanceService; | |||
import lombok.RequiredArgsConstructor; | |||
import org.springframework.stereotype.Component; | |||
import java.time.LocalDateTime; | |||
import java.util.Comparator; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import static com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent.*; | |||
/** | |||
* 项目申报处理 | |||
@@ -14,10 +25,12 @@ import java.time.LocalDateTime; | |||
* @author CMM | |||
* @since 2023/02/24 14:35 | |||
*/ | |||
@Component | |||
@RequiredArgsConstructor | |||
public class ProjectReviewHandle extends AbstractProcessHandle { | |||
private final ProcessInstanceService processInstanceService; | |||
@Override | |||
public ProcessNode getProcessNode() { | |||
return ProcessNode.PROJECT_REVIEW; | |||
@@ -30,14 +43,37 @@ public class ProjectReviewHandle extends AbstractProcessHandle { | |||
@Override | |||
public void handle(HandleParamContext ctx) { | |||
// 因为此时在项目库中的项目,都是已经申报过的项目,所以直接设置环节状态为已完成 | |||
ProcessDetailVO processDetailVO = new ProcessDetailVO(); | |||
processDetailVO.setStepStatus(StepStatusEnum.COMPLETED); | |||
// 项目库中查出申报完成时间 | |||
LocalDateTime createOn = ctx.getProject().getCreateOn(); | |||
processDetailVO.setFinishTime(createOn); | |||
processDetailVO.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(processDetailVO); | |||
ProcessDetailVO detail = new ProcessDetailVO(); | |||
detail.setProcessName(getProcessNode().getName()); | |||
ctx.getProcessDetails().add(detail); | |||
if (!StepStatusEnum.COMPLETED.equals(ctx.getPreStepStatus())) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
return; | |||
} | |||
// 项目状态为待立项批复之前的状态 | |||
Map<ProjectStateChangeEvent, ProjectStatusChange> eventMap = ctx.getProjectStatusChanges(); | |||
if (!eventMap.containsKey(PROJECT_REVIEW_SUBMIT)) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
ProjectInst inst = ctx.getProjectInstMap().get(InstTypeEnum.PROJECT_REVIEW); | |||
if (inst == null) { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} else { | |||
Optional<ProjectStatusChange> event = eventMap.values().stream() | |||
.filter(w -> PROJECT_REVIEW_PASS.eq(w.getEvent()) | |||
|| PROJECT_REVIEW_RESUBMIT.eq(w.getEvent()) | |||
|| PROJECT_REVIEW_FAILED.eq(w.getEvent()) | |||
|| PROJECT_REVIEW_SUBMIT.eq(w.getEvent()) | |||
).max(Comparator.comparing(ProjectStatusChange::getCreateOn)); | |||
if (event.isPresent()) { | |||
ProcessProgressVo progress = processInstanceService.getProgressInstanceDetail(null, inst.getInstCode()); | |||
buildStepStatus(detail, progress, event.get()); | |||
} else { | |||
detail.setStepStatus(StepStatusEnum.NOT_START); | |||
} | |||
} | |||
} | |||
ctx.setPreStepStatus(detail.getStepStatus()); | |||
} | |||
} |
@@ -28,7 +28,7 @@ public interface IProjectInstService extends IService<ProjectInst> { | |||
default List<ProjectInst> listByProjectIds(Collection<Long> projectIds) { | |||
LambdaQueryWrapper<ProjectInst> query = Wrappers.lambdaQuery(ProjectInst.class) | |||
.in(ProjectInst::getProjectId, projectIds) | |||
.orderByDesc(ProjectInst::getProjectId); | |||
.orderByDesc(ProjectInst::getCreateOn); | |||
return list(query); | |||
} | |||
@@ -62,8 +62,7 @@ public interface IProjectStatusChangeService extends IService<ProjectStatusChang | |||
default Map<ProjectStateChangeEvent, ProjectStatusChange> listLastEventMap(String projectCode) { | |||
Wrapper<ProjectStatusChange> query = Wrappers.lambdaQuery(ProjectStatusChange.class) | |||
.eq(ProjectStatusChange::getProjectCode, projectCode) | |||
.orderByDesc(ProjectStatusChange::getCreateOn) | |||
.last(BizConst.LIMIT_1); | |||
.orderByDesc(ProjectStatusChange::getCreateOn); | |||
return BizUtils.groupFirstMap(list(query), | |||
w -> ProjectStateChangeEvent.valueOf(w.getEvent()), | |||
Comparator.comparing(ProjectStatusChange::getCreateOn).reversed()); | |||