@@ -269,6 +269,12 @@ | |||||
<artifactId>joda-time</artifactId> | <artifactId>joda-time</artifactId> | ||||
<version>2.10.6</version> | <version>2.10.6</version> | ||||
</dependency> | </dependency> | ||||
<!--状态机--> | |||||
<dependency> | |||||
<groupId>org.springframework.statemachine</groupId> | |||||
<artifactId>spring-statemachine-core</artifactId> | |||||
<version>2.0.1.RELEASE</version> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
<!-- 打包 --> | <!-- 打包 --> | ||||
@@ -1,4 +1,9 @@ | |||||
package com.ningdatech.pmapi.common.constant; | package com.ningdatech.pmapi.common.constant; | ||||
import io.swagger.models.auth.In; | |||||
import java.math.BigDecimal; | |||||
/** | /** | ||||
* 项目申报表单数据常量key | * 项目申报表单数据常量key | ||||
* @return | * @return | ||||
@@ -151,4 +156,16 @@ public interface ProjectDeclareConstants { | |||||
class ApplicationInformation { | class ApplicationInformation { | ||||
} | } | ||||
class Number { | |||||
public static final BigDecimal DECLARE_AMOUNT_JUDGEMENT = BigDecimal.valueOf(1000); | |||||
public static final Integer COUNTRY_BUILD_LEVEL = 1; | |||||
public static final Integer PROVINCE_BUILD_LEVEL = 2; | |||||
public static final Integer PROVINCE_SELF_BUILD_LEVEL = 3; | |||||
public static final Integer CITY_BUILD_LEVEL = 4; | |||||
public static final Integer CITY_SELF_BUILD_LEVEL = 5; | |||||
public static final Integer DISTRICTS_COUNTRIES_BUILD_LEVEL = 6; | |||||
public static final Integer VILLAGES_TOWNS_BUILD_LEVEL = 7; | |||||
} | |||||
} | } |
@@ -0,0 +1,12 @@ | |||||
package com.ningdatech.pmapi.common.constant; | |||||
/** | |||||
* @author CMM | |||||
* @since 2023/02/07 16:24 | |||||
*/ | |||||
public class StateMachineHeaderNameConstants { | |||||
public static final String PROJECT_DECLARE = "projectDeclare"; | |||||
} |
@@ -0,0 +1,38 @@ | |||||
package com.ningdatech.pmapi.common.statemachine.action; | |||||
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants; | |||||
import com.ningdatech.pmapi.common.constant.StateMachineHeaderNameConstants; | |||||
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusChangeEvent; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum; | |||||
import com.ningdatech.pmapi.projectlib.model.entity.Project; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.statemachine.StateContext; | |||||
import org.springframework.statemachine.action.Action; | |||||
/** | |||||
* 项目申报状态机选择分支action类 | |||||
* | |||||
* @author CMM | |||||
* @since 2023/02/07 22:31 | |||||
*/ | |||||
@Slf4j | |||||
public class ProjectDeclareChoiceAction implements Action<ProjectStatusEnum, ProjectStatusChangeEvent> { | |||||
private static final String PROJECT_DECLARE = StateMachineHeaderNameConstants.PROJECT_DECLARE; | |||||
@Override | |||||
public void execute(StateContext<ProjectStatusEnum, ProjectStatusChangeEvent> stateContext) { | |||||
log.info(String.valueOf(stateContext.getTarget().getId())); | |||||
ProjectStatusEnum projectStatusEnum = stateContext.getTarget().getId(); | |||||
if (projectStatusEnum.equals(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE)){ | |||||
Project project = stateContext.getMessage().getHeaders().get(PROJECT_DECLARE, Project.class); | |||||
log.info("预审申报事件之前,项目的状态为:{}"+project.getProjectStatusSecond()); | |||||
if (StateMachineUtils.isCityProject(project) && StateMachineUtils.JudgeDeclareAmount(project)){ | |||||
project.setProjectStatusSecond(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS.getCode()); | |||||
}else { | |||||
project.setProjectStatusSecond(ProjectStatusEnum.PRE_APPLYING.getCode()); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,265 @@ | |||||
package com.ningdatech.pmapi.common.statemachine.builder; | |||||
import com.ningdatech.pmapi.common.statemachine.action.ProjectDeclareChoiceAction; | |||||
import com.ningdatech.pmapi.common.statemachine.factory.ProjectDeclareGuardFactory; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusChangeEvent; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum; | |||||
import com.ningdatech.pmapi.projectlib.model.entity.Project; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.BeanFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.context.annotation.Bean; | |||||
import org.springframework.statemachine.StateMachine; | |||||
import org.springframework.statemachine.StateMachineContext; | |||||
import org.springframework.statemachine.StateMachinePersist; | |||||
import org.springframework.statemachine.config.EnableStateMachine; | |||||
import org.springframework.statemachine.config.StateMachineBuilder; | |||||
import org.springframework.statemachine.persist.DefaultStateMachinePersister; | |||||
import org.springframework.statemachine.persist.StateMachinePersister; | |||||
import org.springframework.statemachine.support.DefaultStateMachineContext; | |||||
import org.springframework.stereotype.Component; | |||||
import java.util.EnumSet; | |||||
/** | |||||
* 项目申报状态机 | |||||
* | |||||
* @author CMM | |||||
* @since 2023/02/07 15:56 | |||||
*/ | |||||
@Component | |||||
@EnableStateMachine(name= ProjectDeclareStateMachineBuilder.MACHINEID_TO) | |||||
public class ProjectDeclareStateMachineBuilder { | |||||
private static final ProjectDeclareGuardFactory projectDeclareGuardFactory = new ProjectDeclareGuardFactory(); | |||||
@Autowired | |||||
private BeanFactory beanFactory; | |||||
private Logger logger = LoggerFactory.getLogger(getClass()); | |||||
/** | |||||
* TO状态机 | |||||
*/ | |||||
public final static String MACHINEID_TO = "MACHINEID_TO"; | |||||
public StateMachine<ProjectStatusEnum, ProjectStatusChangeEvent> build() throws Exception { | |||||
StateMachine<ProjectStatusEnum, ProjectStatusChangeEvent> stateMachine = build(beanFactory); | |||||
logger.info("状态机ID:" + stateMachine.getId()); | |||||
stateMachine.start(); | |||||
return stateMachine; | |||||
} | |||||
/** | |||||
* 构建状态机 | |||||
* @param beanFactory | |||||
* @author CMM | |||||
* @since 2023/02/07 16:15 | |||||
*/ | |||||
public StateMachine<ProjectStatusEnum, ProjectStatusChangeEvent> build(BeanFactory beanFactory) throws Exception { | |||||
StateMachineBuilder.Builder<ProjectStatusEnum, ProjectStatusChangeEvent> builder = StateMachineBuilder.builder(); | |||||
builder.configureConfiguration() | |||||
.withConfiguration() | |||||
.machineId(MACHINEID_TO) | |||||
.beanFactory(beanFactory); | |||||
builder.configureStates() | |||||
.withStates() | |||||
.initial(ProjectStatusEnum.UNDER_INTERNAL_AUDIT) | |||||
.choice(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE) | |||||
.states(EnumSet.allOf(ProjectStatusEnum.class)); | |||||
builder.configureTransitions() | |||||
// 单位内部审核通过,从单位内部审核中到待预审 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.UNDER_INTERNAL_AUDIT) | |||||
.target(ProjectStatusEnum.PENDING_PREQUALIFICATION) | |||||
.event(ProjectStatusChangeEvent.UNDER_INTERNAL_PASS).and() | |||||
// 单位内部审核驳回,从单位内部审核中到单位内部审核不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.UNDER_INTERNAL_AUDIT) | |||||
.target(ProjectStatusEnum.UNDER_INTERNAL_AUDIT_NOT_PASS) | |||||
.event(ProjectStatusChangeEvent.UNDER_INTERNAL_REJECT).and() | |||||
// 单位内部审核中撤回,从单位内部审核中到待申报 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.UNDER_INTERNAL_AUDIT) | |||||
.target(ProjectStatusEnum.TO_BE_DECLARED) | |||||
.event(ProjectStatusChangeEvent.UNDER_INTERNAL_WITHDRAW).and() | |||||
// 待预审预审申报,从待预审到待预审选择 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PENDING_PREQUALIFICATION) | |||||
.target(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE) | |||||
.event(ProjectStatusChangeEvent.PRELIMINARY_REVIEW_DECLARE).and() | |||||
// 待预审申报,从待预审选择->省级部门联审中,预审中,完成其中一种状态 | |||||
.withChoice() | |||||
.source(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE) | |||||
.first(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS,projectDeclareGuardFactory.new PendingPreQualificationChoiceGuard(),new ProjectDeclareChoiceAction()) | |||||
.last(ProjectStatusEnum.PRE_APPLYING).and() | |||||
// 待预审撤回,从待预审到单位内部审核中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PENDING_PREQUALIFICATION) | |||||
.target(ProjectStatusEnum.UNDER_INTERNAL_AUDIT) | |||||
.event(ProjectStatusChangeEvent.PENDING_PREQUALIFICATION_WITHDRAW).and() | |||||
// 省级部门联审通过,从省级部门联审中到预审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS) | |||||
.target(ProjectStatusEnum.PRE_APPLYING) | |||||
.event(ProjectStatusChangeEvent.PROVINCIAL_DEPARTMENT_REVIEW_PASS).and() | |||||
// 省级部门联审不通过,从省级部门联审中到省级部门联审不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS) | |||||
.target(ProjectStatusEnum.THE_JOINT_REVIEW_OF_PROVINCIAL_DEPARTMENTS_FAILED) | |||||
.event(ProjectStatusChangeEvent.PROVINCIAL_DEPARTMENT_REVIEW_REJECT).and() | |||||
// 预审通过,从预审中到部门联审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PRE_APPLYING) | |||||
.target(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW) | |||||
.event(ProjectStatusChangeEvent.PRELIMINARY_REVIEW_PASS).and() | |||||
// 预审驳回,从预审中到预审不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PRE_APPLYING) | |||||
.target(ProjectStatusEnum.PREQUALIFICATION_FAILED) | |||||
.event(ProjectStatusChangeEvent.PRELIMINARY_REVIEW_REJECT).and() | |||||
// 预审中撤回,从预审中到待预审选择 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PRE_APPLYING) | |||||
.target(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE) | |||||
.event(ProjectStatusChangeEvent.PRE_APPLYING_WITHDRAW).and() | |||||
// 预审中撤回,从待预审选择->省级部门联审中,预审中,完成其中一种状态 | |||||
.withChoice() | |||||
.source(ProjectStatusEnum.PRE_APPLYING) | |||||
.first(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS,projectDeclareGuardFactory.new PendingPreQualificationChoiceGuard(),new ProjectDeclareChoiceAction()) | |||||
.last(ProjectStatusEnum.PRE_APPLYING).and() | |||||
// 部门联审通过,从部门联审中到年度计划中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW) | |||||
.target(ProjectStatusEnum.IN_THE_ANNUAL_PLAN) | |||||
.event(ProjectStatusChangeEvent.DEPARTMENT_UNITED_REVIEW_PASS).and() | |||||
// 部门联审驳回,从部门联审中到部门联审不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW) | |||||
.target(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW_FAILED) | |||||
.event(ProjectStatusChangeEvent.DEPARTMENT_UNITED_REVIEW_REJECT).and() | |||||
// 部门联审中撤回,从部门联审中到预审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW) | |||||
.target(ProjectStatusEnum.PRE_APPLYING) | |||||
.event(ProjectStatusChangeEvent.DEPARTMENT_JOINT_REVIEW_WITHDRAW).and() | |||||
// 年度计划中开启方案申报,从年度计划中到方案待申报 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.IN_THE_ANNUAL_PLAN) | |||||
.target(ProjectStatusEnum.PLAN_TO_BE_DECLARED) | |||||
.event(ProjectStatusChangeEvent.ANNUAL_PLAN_PROJECT_OPEN_PLAN_DECLARE).and() | |||||
// 年度计划中暂缓,从年度计划中到被暂缓 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.IN_THE_ANNUAL_PLAN) | |||||
.target(ProjectStatusEnum.BE_SUSPENDED) | |||||
.event(ProjectStatusChangeEvent.ANNUAL_PLAN_SUSPEND).and() | |||||
// 年度计划中撤回,从年度计划中到部门联审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.IN_THE_ANNUAL_PLAN) | |||||
.target(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW) | |||||
.event(ProjectStatusChangeEvent.IN_THE_ANNUAL_PLAN_WITHDRAW).and() | |||||
// 方案待申报申报方案,从方案待申报到方案评审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PLAN_TO_BE_DECLARED) | |||||
.target(ProjectStatusEnum.SCHEME_UNDER_REVIEW) | |||||
.event(ProjectStatusChangeEvent.DECLARE_PLAN).and() | |||||
// 方案待申报撤回,从方案待申报到年度计划中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.PLAN_TO_BE_DECLARED) | |||||
.target(ProjectStatusEnum.IN_THE_ANNUAL_PLAN) | |||||
.event(ProjectStatusChangeEvent.PLAN_TO_DECLARE_WITHDRAW).and() | |||||
// 方案评审通过,从方案评审中到待立项批复 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.SCHEME_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.TO_BE_APPROVED) | |||||
.event(ProjectStatusChangeEvent.PLAN_REVIEW_PASS).and() | |||||
// 方案评审驳回,从方案评审中到方案评审不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.SCHEME_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.SCHEME_REVIEW_FAILED) | |||||
.event(ProjectStatusChangeEvent.PLAN_REVIEW_REJECT).and() | |||||
// 方案评审中撤回,从方案评审中到方案待申报 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.SCHEME_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.PLAN_TO_BE_DECLARED) | |||||
.event(ProjectStatusChangeEvent.SCHEME_UNDER_REVIEW_WITHDRAW).and() | |||||
// 待立项批复批复,从待立项批复到待采购 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_APPROVED) | |||||
.target(ProjectStatusEnum.TO_BE_PURCHASED) | |||||
.event(ProjectStatusChangeEvent.PROJECT_APPROVAL).and() | |||||
// 待立项批复撤回,从待立项批复到方案评审中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_APPROVED) | |||||
.target(ProjectStatusEnum.SCHEME_UNDER_REVIEW) | |||||
.event(ProjectStatusChangeEvent.TO_BE_APPROVED_WITHDRAW).and() | |||||
// 待采购采购备案,从待采购到建设中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_PURCHASED) | |||||
.target(ProjectStatusEnum.UNDER_CONSTRUCTION) | |||||
.event(ProjectStatusChangeEvent.PURCHASE_PUT_ON_RECORD).and() | |||||
// 待采购撤回,从待采购到待立项批复 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_PURCHASED) | |||||
.target(ProjectStatusEnum.TO_BE_APPROVED) | |||||
.event(ProjectStatusChangeEvent.TO_BE_PURCHASED_WITHDRAW).and() | |||||
// 建设中初验备案,从建设中到待终验 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.UNDER_CONSTRUCTION) | |||||
.target(ProjectStatusEnum.TO_BE_FINALLY_INSPECTED) | |||||
.event(ProjectStatusChangeEvent.PRELIMINARY_ACCEPTANCE_PUT_ON_RECORD).and() | |||||
// 建设中撤回,从建设中到待采购 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.UNDER_CONSTRUCTION) | |||||
.target(ProjectStatusEnum.TO_BE_PURCHASED) | |||||
.event(ProjectStatusChangeEvent.UNDER_CONSTRUCTION_WITHDRAW).and() | |||||
// 待终验终验申请,从待终验到终验审核中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_FINALLY_INSPECTED) | |||||
.target(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW) | |||||
.event(ProjectStatusChangeEvent.FINAL_ACCEPTANCE_APPLICATION).and() | |||||
// 待终验撤回,从待终验到建设中 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.TO_BE_FINALLY_INSPECTED) | |||||
.target(ProjectStatusEnum.UNDER_CONSTRUCTION) | |||||
.event(ProjectStatusChangeEvent.TO_BE_FINALLY_INSPECTED_WITHDRAW).and() | |||||
// 终审审核通过,从终审审核中到已归档 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.ARCHIVED) | |||||
.event(ProjectStatusChangeEvent.FINAL_ACCEPTANCE_PASS).and() | |||||
// 终审审核不通过,从终审审核中到终审审核不通过 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.FINAL_ACCEPTANCE_REVIEW_FAILED) | |||||
.event(ProjectStatusChangeEvent.FINAL_ACCEPTANCE_REJECT).and() | |||||
// 终审审核中撤回,从终审审核中到待终验 | |||||
.withExternal() | |||||
.source(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW) | |||||
.target(ProjectStatusEnum.TO_BE_FINALLY_INSPECTED) | |||||
.event(ProjectStatusChangeEvent.FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW).and(); | |||||
return builder.build(); | |||||
} | |||||
/** | |||||
* 持久化配置 | |||||
* @author CMM | |||||
* @since 2023/02/07 16:22 | |||||
*/ | |||||
@Bean(name = "projectDeclareStateMachinePersister") | |||||
public StateMachinePersister<ProjectStatusEnum, ProjectStatusChangeEvent, Project> getProjectPersister() { | |||||
return new DefaultStateMachinePersister<>(new StateMachinePersist<ProjectStatusEnum, ProjectStatusChangeEvent, Project>() { | |||||
@Override | |||||
public void write(StateMachineContext<ProjectStatusEnum, ProjectStatusChangeEvent> context, Project contextObj) { | |||||
} | |||||
@Override | |||||
public StateMachineContext<ProjectStatusEnum, ProjectStatusChangeEvent> read(Project contextObj) { | |||||
StateMachineContext<ProjectStatusEnum, ProjectStatusChangeEvent> result = new DefaultStateMachineContext(ProjectStatusEnum.getValueByCode(contextObj.getProjectStatusSecond()), | |||||
null, null, null, null, MACHINEID_TO); | |||||
return result; | |||||
} | |||||
}); | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
package com.ningdatech.pmapi.common.statemachine.factory; | |||||
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants; | |||||
import com.ningdatech.pmapi.common.constant.StateMachineHeaderNameConstants; | |||||
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusChangeEvent; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum; | |||||
import com.ningdatech.pmapi.projectlib.model.entity.Project; | |||||
import org.springframework.statemachine.StateContext; | |||||
import org.springframework.statemachine.guard.Guard; | |||||
/** | |||||
* 项目申报状态机guard集合类 | |||||
* | |||||
* @author CMM | |||||
* @since 2023/02/07 16:18 | |||||
*/ | |||||
public class ProjectDeclareGuardFactory { | |||||
private static final String PROJECT_DECLARE = StateMachineHeaderNameConstants.PROJECT_DECLARE; | |||||
public class PendingPreQualificationChoiceGuard implements Guard<ProjectStatusEnum, ProjectStatusChangeEvent> { | |||||
@Override | |||||
public boolean evaluate(StateContext<ProjectStatusEnum, ProjectStatusChangeEvent> context) { | |||||
Project project = context.getMessage().getHeaders().get(PROJECT_DECLARE, Project.class); | |||||
// 判断申报项目是否是市级项目,且申报金额是否大于等于1000万元 | |||||
if (StateMachineUtils.isCityProject(project) && StateMachineUtils.JudgeDeclareAmount(project)){ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,75 @@ | |||||
package com.ningdatech.pmapi.common.statemachine.util; | |||||
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants; | |||||
import com.ningdatech.pmapi.common.constant.StateMachineHeaderNameConstants; | |||||
import com.ningdatech.pmapi.common.statemachine.builder.ProjectDeclareStateMachineBuilder; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusChangeEvent; | |||||
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum; | |||||
import com.ningdatech.pmapi.projectlib.model.entity.Project; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.messaging.Message; | |||||
import org.springframework.messaging.support.MessageBuilder; | |||||
import org.springframework.statemachine.StateMachine; | |||||
import org.springframework.statemachine.persist.StateMachinePersister; | |||||
import javax.annotation.Resource; | |||||
/** | |||||
* 状态机工具类 | |||||
* | |||||
* @author CMM | |||||
* @since 2023/02/07 22:49 | |||||
*/ | |||||
@Slf4j | |||||
public class StateMachineUtils { | |||||
private static final String PROJECT_DECLARE = StateMachineHeaderNameConstants.PROJECT_DECLARE; | |||||
@Autowired | |||||
private ProjectDeclareStateMachineBuilder projectDeclareStateMachineBuilder; | |||||
@Resource(name = "projectDeclareStateMachinePersister") | |||||
private StateMachinePersister projectDeclareStateMachinePersister; | |||||
public void execute(Project project, ProjectStatusChangeEvent event) throws Exception{ | |||||
log.debug("调用状态机前的项目状态为>>>>>>>>>>{}"+project.getProjectStatusSecond()); | |||||
//获取TO状态机 | |||||
StateMachine<ProjectStatusEnum, ProjectStatusChangeEvent> stateMachine = projectDeclareStateMachineBuilder.build(); | |||||
Message message = MessageBuilder.withPayload(event).setHeader(PROJECT_DECLARE, project).build(); | |||||
//初始化状态机 | |||||
projectDeclareStateMachinePersister.restore(stateMachine,project); | |||||
stateMachine.sendEvent(message); | |||||
log.debug("调用状态机后的项目状态为>>>>>>>>>>{}"+project.getProjectStatusSecond()); | |||||
} | |||||
/** | |||||
* 判断 | |||||
* @param project | |||||
* @return boolean | |||||
* @author CMM | |||||
* @since 2023/02/07 17:13 | |||||
*/ | |||||
public static boolean JudgeDeclareAmount(Project project) { | |||||
int flag = project.getDeclareAmount().compareTo(ProjectDeclareConstants.Number.DECLARE_AMOUNT_JUDGEMENT); | |||||
if (flag > 0 || flag == 0){ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 判断项目建设层级是否为市级项目 | |||||
* @param project | |||||
* @return boolean | |||||
* @author CMM | |||||
* @since 2023/02/07 17:05 | |||||
*/ | |||||
public static boolean isCityProject(Project project) { | |||||
if (ProjectDeclareConstants.Number.CITY_BUILD_LEVEL.equals(project.getBuildLevel()) || | |||||
ProjectDeclareConstants.Number.CITY_SELF_BUILD_LEVEL.equals(project.getBuildLevel())){ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} |
@@ -0,0 +1,153 @@ | |||||
package com.ningdatech.pmapi.projectlib.enums; | |||||
/** | |||||
* 项目状态改变事件 | |||||
* @return | |||||
* @author CMM | |||||
* @since 2023/02/07 9:22 | |||||
*/ | |||||
public enum ProjectStatusChangeEvent { | |||||
/** | |||||
* 项目申报暂存(项目状态进入:待申报) | |||||
*/ | |||||
PROJECT_APPLICATION_HOLD, | |||||
/** | |||||
* 项目申报提交(项目状态进入:单位内部审核中) | |||||
*/ | |||||
PROJECT_APPLICATION_SUBMIT, | |||||
/** | |||||
* 单位内部审核驳回(项目状态进入:单位内部审核不通过) | |||||
*/ | |||||
UNDER_INTERNAL_REJECT, | |||||
/** | |||||
* 单位内部审核通过(项目状态进入:待预审) | |||||
*/ | |||||
UNDER_INTERNAL_PASS, | |||||
/** | |||||
* 预审申报(项目状态进入:待预审选择,有判断条件:市级项目且申报金额大于1000万项目状态变为:省级部门联审中;否则项目状态变为:预审中) | |||||
*/ | |||||
PRELIMINARY_REVIEW_DECLARE, | |||||
/** | |||||
* 省级部门联审不通过(项目状态变为:省级部门联审不通过) | |||||
*/ | |||||
PROVINCIAL_DEPARTMENT_REVIEW_REJECT, | |||||
/** | |||||
* 省级部门联审通过(项目状态变为:预审中) | |||||
*/ | |||||
PROVINCIAL_DEPARTMENT_REVIEW_PASS, | |||||
/** | |||||
* 预审驳回(项目状态变为:预审不通过) | |||||
*/ | |||||
PRELIMINARY_REVIEW_REJECT, | |||||
/** | |||||
* 预审通过(项目状态变为:部门联审中) | |||||
*/ | |||||
PRELIMINARY_REVIEW_PASS, | |||||
/** | |||||
* 部门联审驳回(项目状态变为:部门联审不通过) | |||||
*/ | |||||
DEPARTMENT_UNITED_REVIEW_REJECT, | |||||
/** | |||||
* 部门联审通过(项目状态变为:年度计划中) | |||||
*/ | |||||
DEPARTMENT_UNITED_REVIEW_PASS, | |||||
/** | |||||
* 年度计划暂缓(项目状态变为:被暂缓) | |||||
*/ | |||||
ANNUAL_PLAN_SUSPEND, | |||||
/** | |||||
* 年度计划项目开启方案申报(项目状态变为:方案待申报) | |||||
*/ | |||||
ANNUAL_PLAN_PROJECT_OPEN_PLAN_DECLARE, | |||||
/** | |||||
* 申报方案(项目状态变为:方案评审中) | |||||
*/ | |||||
DECLARE_PLAN, | |||||
/** | |||||
* 方案评审驳回(项目状态变为:方案评审不通过) | |||||
*/ | |||||
PLAN_REVIEW_REJECT, | |||||
/** | |||||
* 方案评审通过(项目状态变为:待立项批复) | |||||
*/ | |||||
PLAN_REVIEW_PASS, | |||||
/** | |||||
* 立项批复(项目状态变为:已立项-待采购) | |||||
*/ | |||||
PROJECT_APPROVAL, | |||||
/** | |||||
* 采购备案(项目状态变为:建设中) | |||||
*/ | |||||
PURCHASE_PUT_ON_RECORD, | |||||
/** | |||||
* 初验备案(项目状态变为:待终验) | |||||
*/ | |||||
PRELIMINARY_ACCEPTANCE_PUT_ON_RECORD, | |||||
/** | |||||
* 终验申请(项目状态变为:终验审核中) | |||||
*/ | |||||
FINAL_ACCEPTANCE_APPLICATION, | |||||
/** | |||||
* 终验审核不通过(项目状态变为:终验审核不通过) | |||||
*/ | |||||
FINAL_ACCEPTANCE_REJECT, | |||||
/** | |||||
* 终验审核通过(项目状态变为:已归档) | |||||
*/ | |||||
FINAL_ACCEPTANCE_PASS, | |||||
// 下个节点还未提交审核意见时,流程发起人和前一个审核人可以点击撤回 | |||||
/** | |||||
* 单位内部审核中时被撤回(项目状态进入:待申报) | |||||
*/ | |||||
UNDER_INTERNAL_WITHDRAW, | |||||
/** | |||||
* 待预审时被撤回(项目状态进入:单位内部审核中) | |||||
*/ | |||||
PENDING_PREQUALIFICATION_WITHDRAW, | |||||
/** | |||||
* 省级部门联审中时被撤回(项目状态进入:待预审) | |||||
*/ | |||||
JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS_WITHDRAW, | |||||
/** | |||||
* 预审中时被撤回(项目状态进入:待预审选择,,有判断条件:市级项目且申报金额大于1000万项目状态变为:省级部门联审中;否则项目状态变为:预审中) | |||||
*/ | |||||
PRE_APPLYING_WITHDRAW, | |||||
/** | |||||
* 部门联审中时被撤回(项目状态进入:预审中) | |||||
*/ | |||||
DEPARTMENT_JOINT_REVIEW_WITHDRAW, | |||||
/** | |||||
* 年度计划中时被撤回(项目状态进入:部门联审中) | |||||
*/ | |||||
IN_THE_ANNUAL_PLAN_WITHDRAW, | |||||
/** | |||||
* 方案待申报时被撤回(项目状态进入:年度计划中) | |||||
*/ | |||||
PLAN_TO_DECLARE_WITHDRAW, | |||||
/** | |||||
* 方案评审中时被撤回(项目状态进入:方案待申报) | |||||
*/ | |||||
SCHEME_UNDER_REVIEW_WITHDRAW, | |||||
/** | |||||
* 待立项批复时被撤回(项目状态进入:方案评审中) | |||||
*/ | |||||
TO_BE_APPROVED_WITHDRAW, | |||||
/** | |||||
* 待采购时被撤回(项目状态进入:待立项批复) | |||||
*/ | |||||
TO_BE_PURCHASED_WITHDRAW, | |||||
/** | |||||
* 建设中时被撤回(项目状态进入:待采购) | |||||
*/ | |||||
UNDER_CONSTRUCTION_WITHDRAW, | |||||
/** | |||||
* 待终验时被撤回(项目状态进入:建设中) | |||||
*/ | |||||
TO_BE_FINALLY_INSPECTED_WITHDRAW, | |||||
/** | |||||
* 终验审核中时被撤回(项目状态进入:待终验) | |||||
*/ | |||||
FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW, | |||||
} |
@@ -3,6 +3,7 @@ package com.ningdatech.pmapi.projectlib.enums; | |||||
import lombok.AllArgsConstructor; | import lombok.AllArgsConstructor; | ||||
import lombok.Getter; | import lombok.Getter; | ||||
import lombok.NoArgsConstructor; | import lombok.NoArgsConstructor; | ||||
import org.apache.commons.lang3.EnumUtils; | |||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
@@ -29,6 +30,9 @@ public enum ProjectStatusEnum { | |||||
SCHEME_UNDER_REVIEW (10012,"方案评审中"), | SCHEME_UNDER_REVIEW (10012,"方案评审中"), | ||||
SCHEME_REVIEW_FAILED (10013,"方案评审不通过"), | SCHEME_REVIEW_FAILED (10013,"方案评审不通过"), | ||||
TO_BE_APPROVED (10014,"待立项批复"), | TO_BE_APPROVED (10014,"待立项批复"), | ||||
TO_BE_DECLARED (10015,"待申报"), | |||||
PLAN_TO_BE_DECLARED (10016,"方案待申报"), | |||||
PENDING_PREQUALIFICATION_CHOICE (10016,"待预审选择态"), | |||||
PROJECT_APPROVED (20000,"已立项"), | PROJECT_APPROVED (20000,"已立项"), | ||||
TO_BE_PURCHASED (20001,"待采购"), | TO_BE_PURCHASED (20001,"待采购"), | ||||
UNDER_CONSTRUCTION (20002,"建设中"), | UNDER_CONSTRUCTION (20002,"建设中"), | ||||
@@ -51,4 +55,17 @@ public enum ProjectStatusEnum { | |||||
} | } | ||||
return StringUtils.EMPTY; | return StringUtils.EMPTY; | ||||
} | } | ||||
public static ProjectStatusEnum getValueByCode(Integer code) { | |||||
if(Objects.isNull(code)){ | |||||
return null; | |||||
} | |||||
for (ProjectStatusEnum t : ProjectStatusEnum.values()) { | |||||
if (code.equals(t.getCode())) { | |||||
return t; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
} | } |