Selaa lähdekoodia

状态机增加监听,根据项目状态获取对应事件

tags/24080901
CMM 1 vuosi sitten
vanhempi
commit
b5125213aa
11 muutettua tiedostoa jossa 510 lisäystä ja 65 poistoa
  1. +242
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/action/ProjectDeclareAction.java
  2. +1
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/action/ProjectDeclareChoiceAction.java
  3. +13
    -10
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/builder/ProjectDeclareStateMachineBuilder.java
  4. +88
    -36
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/event/ProjectStatusChangeEvent.java
  5. +1
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/factory/ProjectDeclareGuardFactory.java
  6. +34
    -6
      pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/util/StateMachineUtils.java
  7. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enums/ProjectStatusEnum.java
  8. +1
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java
  9. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/extension/cmd/BackToHisApprovalNodeCmd.java
  10. +100
    -7
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java
  11. +28
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java

+ 242
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/action/ProjectDeclareAction.java Näytä tiedosto

@@ -0,0 +1,242 @@
package com.ningdatech.pmapi.common.statemachine.action;

import com.ningdatech.pmapi.common.constant.StateMachineHeaderNameConstants;
import com.ningdatech.pmapi.common.statemachine.builder.ProjectDeclareStateMachineBuilder;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

/**
* 项目申报状态机action集合类
*
* @author CMM
* @since 2023/02/08 13:48
*/
@Slf4j
@WithStateMachine(id = ProjectDeclareStateMachineBuilder.MACHINEID_TO)
public class ProjectDeclareAction {

private static final String PROJECT_DECLARE = StateMachineHeaderNameConstants.PROJECT_DECLARE;

@OnTransition(source = "UNDER_INTERNAL_AUDIT",target = "PENDING_PREQUALIFICATION")
public void UNDER_INTERNAL_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode());
}
@OnTransition(source = "UNDER_INTERNAL_AUDIT",target = "UNDER_INTERNAL_AUDIT_NOT_PASS")
public void UNDER_INTERNAL_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_INTERNAL_AUDIT_NOT_PASS.getCode());
}
@OnTransition(source = "UNDER_INTERNAL_AUDIT",target = "TO_BE_DECLARED")
public void UNDER_INTERNAL_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.TO_BE_DECLARED.getCode());
}


@OnTransition(source = "PENDING_PREQUALIFICATION",target = "PENDING_PREQUALIFICATION_CHOICE")
public void PRELIMINARY_REVIEW_DECLARE(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE.getCode());
}
@OnTransition(source = "PENDING_PREQUALIFICATION",target = "UNDER_INTERNAL_AUDIT")
public void PENDING_PREQUALIFICATION_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_INTERNAL_AUDIT.getCode());
}


@OnTransition(source = "JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS",target = "PRE_APPLYING")
public void PROVINCIAL_DEPARTMENT_REVIEW_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PRE_APPLYING.getCode());
}
@OnTransition(source = "JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS",target = "THE_JOINT_REVIEW_OF_PROVINCIAL_DEPARTMENTS_FAILED")
public void PROVINCIAL_DEPARTMENT_REVIEW_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.THE_JOINT_REVIEW_OF_PROVINCIAL_DEPARTMENTS_FAILED.getCode());
}
@OnTransition(source = "JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS",target = "PENDING_PREQUALIFICATION")
public void JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode());
}


@OnTransition(source = "PRE_APPLYING",target = "DEPARTMENT_JOINT_REVIEW")
public void PRELIMINARY_REVIEW_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW.getCode());
}
@OnTransition(source = "PRE_APPLYING",target = "PREQUALIFICATION_FAILED")
public void PRELIMINARY_REVIEW_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PREQUALIFICATION_FAILED.getCode());
}
@OnTransition(source = "PRE_APPLYING",target = "PENDING_PREQUALIFICATION_CHOICE")
public void PRE_APPLYING_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE.getCode());
}


@OnTransition(source = "DEPARTMENT_JOINT_REVIEW",target = "IN_THE_ANNUAL_PLAN")
public void DEPARTMENT_UNITED_REVIEW_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.IN_THE_ANNUAL_PLAN.getCode());
}
@OnTransition(source = "DEPARTMENT_JOINT_REVIEW",target = "DEPARTMENT_JOINT_REVIEW_FAILED")
public void DEPARTMENT_UNITED_REVIEW_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW_FAILED.getCode());
}
@OnTransition(source = "DEPARTMENT_JOINT_REVIEW",target = "PRE_APPLYING")
public void DEPARTMENT_JOINT_REVIEW_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PRE_APPLYING.getCode());
}


@OnTransition(source = "IN_THE_ANNUAL_PLAN",target = "PLAN_TO_BE_DECLARED")
public void ANNUAL_PLAN_PROJECT_OPEN_PLAN_DECLARE(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PLAN_TO_BE_DECLARED.getCode());
}
@OnTransition(source = "IN_THE_ANNUAL_PLAN",target = "BE_SUSPENDED")
public void ANNUAL_PLAN_SUSPEND(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.BE_SUSPENDED.getCode());
}
@OnTransition(source = "IN_THE_ANNUAL_PLAN",target = "DEPARTMENT_JOINT_REVIEW")
public void IN_THE_ANNUAL_PLAN_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW.getCode());
}


@OnTransition(source = "PLAN_TO_BE_DECLARED",target = "SCHEME_UNDER_REVIEW")
public void DECLARE_PLAN(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.SCHEME_UNDER_REVIEW.getCode());
}
@OnTransition(source = "PLAN_TO_BE_DECLARED",target = "IN_THE_ANNUAL_PLAN")
public void PLAN_TO_DECLARE_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.IN_THE_ANNUAL_PLAN.getCode());
}


@OnTransition(source = "SCHEME_UNDER_REVIEW",target = "TO_BE_APPROVED")
public void PLAN_REVIEW_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.TO_BE_APPROVED.getCode());
}
@OnTransition(source = "SCHEME_UNDER_REVIEW",target = "SCHEME_REVIEW_FAILED")
public void PLAN_REVIEW_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.SCHEME_REVIEW_FAILED.getCode());
}
@OnTransition(source = "SCHEME_UNDER_REVIEW",target = "PLAN_TO_BE_DECLARED")
public void SCHEME_UNDER_REVIEW_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.PLAN_TO_BE_DECLARED.getCode());
}


@OnTransition(source = "TO_BE_APPROVED",target = "TO_BE_PURCHASED")
public void PROJECT_APPROVAL(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
// 待立项批复批复后,项目一级状态变更为已立项
project.setProjectStatusFirst(ProjectStatusEnum.PROJECT_APPROVED.getCode());
project.setProjectStatusSecond(ProjectStatusEnum.TO_BE_PURCHASED.getCode());
}
@OnTransition(source = "TO_BE_APPROVED",target = "SCHEME_UNDER_REVIEW")
public void TO_BE_APPROVED_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.SCHEME_UNDER_REVIEW.getCode());
}


@OnTransition(source = "TO_BE_PURCHASED",target = "UNDER_CONSTRUCTION")
public void PURCHASE_PUT_ON_RECORD(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_CONSTRUCTION.getCode());
}
@OnTransition(source = "TO_BE_PURCHASED",target = "TO_BE_APPROVED")
public void TO_BE_PURCHASED_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
// 待采购状态撤回后,项目一级状态回退到未立项
project.setProjectStatusFirst(ProjectStatusEnum.NOT_APPROVED.getCode());
project.setProjectStatusSecond(ProjectStatusEnum.TO_BE_APPROVED.getCode());
}


@OnTransition(source = "UNDER_CONSTRUCTION",target = "TO_BE_FINALLY_INSPECTED")
public void PRELIMINARY_ACCEPTANCE_PUT_ON_RECORD(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_CONSTRUCTION.getCode());
}
@OnTransition(source = "UNDER_CONSTRUCTION",target = "TO_BE_PURCHASED")
public void UNDER_CONSTRUCTION_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.TO_BE_PURCHASED.getCode());
}


@OnTransition(source = "TO_BE_FINALLY_INSPECTED",target = "FINAL_ACCEPTANCE_IS_UNDER_REVIEW")
public void FINAL_ACCEPTANCE_APPLICATION(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW.getCode());
}
@OnTransition(source = "TO_BE_FINALLY_INSPECTED",target = "UNDER_CONSTRUCTION")
public void TO_BE_FINALLY_INSPECTED_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_CONSTRUCTION.getCode());
}


@OnTransition(source = "FINAL_ACCEPTANCE_IS_UNDER_REVIEW",target = "ARCHIVED")
public void FINAL_ACCEPTANCE_PASS(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
// 终验审核通过后,项目一级状态变更为已归档
project.setProjectStatusFirst(ProjectStatusEnum.ARCHIVED.getCode());
project.setProjectStatusSecond(ProjectStatusEnum.ARCHIVED.getCode());
}
@OnTransition(source = "FINAL_ACCEPTANCE_IS_UNDER_REVIEW",target = "FINAL_ACCEPTANCE_REVIEW_FAILED")
public void FINAL_ACCEPTANCE_REJECT(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.FINAL_ACCEPTANCE_REVIEW_FAILED.getCode());
}
@OnTransition(source = "FINAL_ACCEPTANCE_IS_UNDER_REVIEW",target = "FINAL_ACCEPTANCE_IS_UNDER_REVIEW")
public void FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW(Message<ProjectStatusChangeEvent> message){
Project project = (Project) message.getHeaders().get(PROJECT_DECLARE);
project.setProjectStatusSecond(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW.getCode());
}


public class ProjectDeclareChoiceAction implements Action<ProjectStatusEnum, ProjectStatusChangeEvent> {

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

+ 1
- 2
pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/action/ProjectDeclareChoiceAction.java Näytä tiedosto

@@ -1,9 +1,8 @@
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.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import lombok.extern.slf4j.Slf4j;


+ 13
- 10
pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/builder/ProjectDeclareStateMachineBuilder.java Näytä tiedosto

@@ -1,14 +1,15 @@
package com.ningdatech.pmapi.common.statemachine.builder;

import com.ningdatech.pmapi.common.statemachine.action.ProjectDeclareChoiceAction;
import com.ningdatech.pmapi.common.statemachine.action.ProjectDeclareAction;
import com.ningdatech.pmapi.common.statemachine.factory.ProjectDeclareGuardFactory;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import lombok.RequiredArgsConstructor;
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;
@@ -30,11 +31,11 @@ import java.util.EnumSet;
*/
@Component
@EnableStateMachine(name= ProjectDeclareStateMachineBuilder.MACHINEID_TO)
@RequiredArgsConstructor
public class ProjectDeclareStateMachineBuilder {
private static final ProjectDeclareGuardFactory projectDeclareGuardFactory = new ProjectDeclareGuardFactory();

@Autowired
private BeanFactory beanFactory;
private static final ProjectDeclareAction projectDeclareAction = new ProjectDeclareAction();
private final BeanFactory beanFactory;
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* TO状态机
@@ -89,7 +90,7 @@ public class ProjectDeclareStateMachineBuilder {
// 待预审申报,从待预审选择->省级部门联审中,预审中,完成其中一种状态
.withChoice()
.source(ProjectStatusEnum.PENDING_PREQUALIFICATION_CHOICE)
.first(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS,projectDeclareGuardFactory.new PendingPreQualificationChoiceGuard(),new ProjectDeclareChoiceAction())
.first(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS,projectDeclareGuardFactory.new PendingPreQualificationChoiceGuard(),projectDeclareAction.new ProjectDeclareChoiceAction())
.last(ProjectStatusEnum.PRE_APPLYING).and()
// 待预审撤回,从待预审到单位内部审核中
.withExternal()
@@ -106,6 +107,11 @@ public class ProjectDeclareStateMachineBuilder {
.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.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS)
.target(ProjectStatusEnum.PENDING_PREQUALIFICATION)
.event(ProjectStatusChangeEvent.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS_WITHDRAW).and()
// 预审通过,从预审中到部门联审中
.withExternal()
.source(ProjectStatusEnum.PRE_APPLYING)
@@ -234,11 +240,8 @@ public class ProjectDeclareStateMachineBuilder {
// 终审审核中撤回,从终审审核中到待终验
.withExternal()
.source(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW)
.target(ProjectStatusEnum.TO_BE_FINALLY_INSPECTED)
.target(ProjectStatusEnum.FINAL_ACCEPTANCE_IS_UNDER_REVIEW)
.event(ProjectStatusChangeEvent.FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW).and();



return builder.build();
}



pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enums/ProjectStatusChangeEvent.java → pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/event/ProjectStatusChangeEvent.java Näytä tiedosto

@@ -1,153 +1,205 @@
package com.ningdatech.pmapi.projectlib.enums;
package com.ningdatech.pmapi.common.statemachine.event;

import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
* 项目状态改变事件
* @return
* @author CMM
* @since 2023/02/07 9:22
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum ProjectStatusChangeEvent {

/**
* 项目申报暂存(项目状态进入:待申报)
*/
PROJECT_APPLICATION_HOLD,
PROJECT_APPLICATION_HOLD(null,null,null),
/**
* 项目申报提交(项目状态进入:单位内部审核中)
*/
PROJECT_APPLICATION_SUBMIT,
PROJECT_APPLICATION_SUBMIT(1015,null,null),
/**
* 单位内部审核驳回(项目状态进入:单位内部审核不通过)
*/
UNDER_INTERNAL_REJECT,
UNDER_INTERNAL_REJECT(null,1001,null),
/**
* 单位内部审核通过(项目状态进入:待预审)
*/
UNDER_INTERNAL_PASS,
UNDER_INTERNAL_PASS(1001,null,null),
/**
* 预审申报(项目状态进入:待预审选择,有判断条件:市级项目且申报金额大于1000万项目状态变为:省级部门联审中;否则项目状态变为:预审中)
*/
PRELIMINARY_REVIEW_DECLARE,
PRELIMINARY_REVIEW_DECLARE(1003,null,null),
/**
* 省级部门联审不通过(项目状态变为:省级部门联审不通过)
*/
PROVINCIAL_DEPARTMENT_REVIEW_REJECT,
PROVINCIAL_DEPARTMENT_REVIEW_REJECT(null,1004,null),
/**
* 省级部门联审通过(项目状态变为:预审中)
*/
PROVINCIAL_DEPARTMENT_REVIEW_PASS,
PROVINCIAL_DEPARTMENT_REVIEW_PASS(1004,null,null),
/**
* 预审驳回(项目状态变为:预审不通过)
*/
PRELIMINARY_REVIEW_REJECT,
PRELIMINARY_REVIEW_REJECT(null,1006,null),
/**
* 预审通过(项目状态变为:部门联审中)
*/
PRELIMINARY_REVIEW_PASS,
PRELIMINARY_REVIEW_PASS(1006,null,null),
/**
* 部门联审驳回(项目状态变为:部门联审不通过)
*/
DEPARTMENT_UNITED_REVIEW_REJECT,
DEPARTMENT_UNITED_REVIEW_REJECT(null,1008,null),
/**
* 部门联审通过(项目状态变为:年度计划中)
*/
DEPARTMENT_UNITED_REVIEW_PASS,
DEPARTMENT_UNITED_REVIEW_PASS(1008,null,null),
/**
* 年度计划暂缓(项目状态变为:被暂缓)
*/
ANNUAL_PLAN_SUSPEND,
ANNUAL_PLAN_SUSPEND(null,10010,null),
/**
* 年度计划项目开启方案申报(项目状态变为:方案待申报)
*/
ANNUAL_PLAN_PROJECT_OPEN_PLAN_DECLARE,
ANNUAL_PLAN_PROJECT_OPEN_PLAN_DECLARE(10010,null,null),
/**
* 申报方案(项目状态变为:方案评审中)
*/
DECLARE_PLAN,
DECLARE_PLAN(10016,null,null),
/**
* 方案评审驳回(项目状态变为:方案评审不通过)
*/
PLAN_REVIEW_REJECT,
PLAN_REVIEW_REJECT(null,10012,null),
/**
* 方案评审通过(项目状态变为:待立项批复)
*/
PLAN_REVIEW_PASS,
PLAN_REVIEW_PASS(10012,null,null),
/**
* 立项批复(项目状态变为:已立项-待采购)
*/
PROJECT_APPROVAL,
PROJECT_APPROVAL(10014,null,null),
/**
* 采购备案(项目状态变为:建设中)
*/
PURCHASE_PUT_ON_RECORD,
PURCHASE_PUT_ON_RECORD(20001,null,null),
/**
* 初验备案(项目状态变为:待终验)
*/
PRELIMINARY_ACCEPTANCE_PUT_ON_RECORD,
PRELIMINARY_ACCEPTANCE_PUT_ON_RECORD(20002,null,null),
/**
* 终验申请(项目状态变为:终验审核中)
*/
FINAL_ACCEPTANCE_APPLICATION,
FINAL_ACCEPTANCE_APPLICATION(20003,null,null),
/**
* 终验审核不通过(项目状态变为:终验审核不通过)
*/
FINAL_ACCEPTANCE_REJECT,
FINAL_ACCEPTANCE_REJECT(null,20004,null),
/**
* 终验审核通过(项目状态变为:已归档)
*/
FINAL_ACCEPTANCE_PASS,
FINAL_ACCEPTANCE_PASS(null,null,null),

// 下个节点还未提交审核意见时,流程发起人和前一个审核人可以点击撤回

/**
* 单位内部审核中时被撤回(项目状态进入:待申报)
*/
UNDER_INTERNAL_WITHDRAW,
UNDER_INTERNAL_WITHDRAW(null,null,10001),
/**
* 待预审时被撤回(项目状态进入:单位内部审核中)
*/
PENDING_PREQUALIFICATION_WITHDRAW,
PENDING_PREQUALIFICATION_WITHDRAW(null,null,10003),
/**
* 省级部门联审中时被撤回(项目状态进入:待预审)
*/
JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS_WITHDRAW,
JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS_WITHDRAW(null,null,10004),
/**
* 预审中时被撤回(项目状态进入:待预审选择,,有判断条件:市级项目且申报金额大于1000万项目状态变为:省级部门联审中;否则项目状态变为:预审中)
*/
PRE_APPLYING_WITHDRAW,
PRE_APPLYING_WITHDRAW(null,null,10006),
/**
* 部门联审中时被撤回(项目状态进入:预审中)
*/
DEPARTMENT_JOINT_REVIEW_WITHDRAW,
DEPARTMENT_JOINT_REVIEW_WITHDRAW(null,null,10008),
/**
* 年度计划中时被撤回(项目状态进入:部门联审中)
*/
IN_THE_ANNUAL_PLAN_WITHDRAW,
IN_THE_ANNUAL_PLAN_WITHDRAW(null,null,10010),
/**
* 方案待申报时被撤回(项目状态进入:年度计划中)
*/
PLAN_TO_DECLARE_WITHDRAW,
PLAN_TO_DECLARE_WITHDRAW(null,null,10016),
/**
* 方案评审中时被撤回(项目状态进入:方案待申报)
*/
SCHEME_UNDER_REVIEW_WITHDRAW,
SCHEME_UNDER_REVIEW_WITHDRAW(null,null,10012),
/**
* 待立项批复时被撤回(项目状态进入:方案评审中)
*/
TO_BE_APPROVED_WITHDRAW,
TO_BE_APPROVED_WITHDRAW(null,null,10014),
/**
* 待采购时被撤回(项目状态进入:待立项批复)
*/
TO_BE_PURCHASED_WITHDRAW,
TO_BE_PURCHASED_WITHDRAW(null,null,20001),
/**
* 建设中时被撤回(项目状态进入:待采购)
*/
UNDER_CONSTRUCTION_WITHDRAW,
UNDER_CONSTRUCTION_WITHDRAW(null,null,20002),
/**
* 待终验时被撤回(项目状态进入:建设中)
*/
TO_BE_FINALLY_INSPECTED_WITHDRAW,
TO_BE_FINALLY_INSPECTED_WITHDRAW(null,null,20003),
/**
* 终验审核中时被撤回(项目状态进入:待终验)
*/
FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW,
FINAL_ACCEPTANCE_IS_UNDER_REVIEW_WITHDRAW(null,null,20004);

private Integer passProjectStatusCode;
private Integer rejectProjectStatusCode;
private Integer withdrawProjectStatusCode;

public static ProjectStatusChangeEvent getPassValueByCode(Integer code) {
if(Objects.isNull(code)){
return null;
}
for (ProjectStatusChangeEvent t : ProjectStatusChangeEvent.values()) {
if (code.equals(t.getPassProjectStatusCode())) {
return t;
}
}
return null;
}

public static ProjectStatusChangeEvent getRejectValueByCode(Integer code) {
if(Objects.isNull(code)){
return null;
}
for (ProjectStatusChangeEvent t : ProjectStatusChangeEvent.values()) {
if (code.equals(t.getRejectProjectStatusCode())) {
return t;
}
}
return null;
}

public static ProjectStatusChangeEvent getWithdrawValueByCode(Integer code) {
if(Objects.isNull(code)){
return null;
}
for (ProjectStatusChangeEvent t : ProjectStatusChangeEvent.values()) {
if (code.equals(t.getWithdrawProjectStatusCode())) {
return t;
}
}
return null;
}
}

+ 1
- 2
pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/factory/ProjectDeclareGuardFactory.java Näytä tiedosto

@@ -1,9 +1,8 @@
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.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import org.springframework.statemachine.StateContext;


+ 34
- 6
pmapi/src/main/java/com/ningdatech/pmapi/common/statemachine/util/StateMachineUtils.java Näytä tiedosto

@@ -1,19 +1,22 @@
package com.ningdatech.pmapi.common.statemachine.util;

import com.ningdatech.basic.exception.BizException;
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.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import lombok.RequiredArgsConstructor;
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 org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
* 状态机工具类
@@ -22,25 +25,26 @@ import javax.annotation.Resource;
* @since 2023/02/07 22:49
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class StateMachineUtils {

private static final String PROJECT_DECLARE = StateMachineHeaderNameConstants.PROJECT_DECLARE;

@Autowired
private ProjectDeclareStateMachineBuilder projectDeclareStateMachineBuilder;
private final ProjectDeclareStateMachineBuilder projectDeclareStateMachineBuilder;

@Resource(name = "projectDeclareStateMachinePersister")
private StateMachinePersister projectDeclareStateMachinePersister;

public void execute(Project project, ProjectStatusChangeEvent event) throws Exception{
log.debug("调用状态机前的项目状态为>>>>>>>>>>{}"+project.getProjectStatusSecond());
log.info("调用状态机前的项目状态为>>>>>>>>>>{}"+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());
log.info("调用状态机后的项目状态为>>>>>>>>>>{}"+project.getProjectStatusSecond());
}

/**
@@ -72,4 +76,28 @@ public class StateMachineUtils {
}
return false;
}

public ProjectStatusChangeEvent getProjectStatusPassEvent(Integer projectStatusSecond) {
ProjectStatusChangeEvent event = ProjectStatusChangeEvent.getPassValueByCode(projectStatusSecond);
if (Objects.isNull(event)){
throw new BizException("该状态下没有对应的通过操作!");
}
return event;
}

public ProjectStatusChangeEvent getProjectStatusRejectEvent(Integer projectStatusSecond) {
ProjectStatusChangeEvent event = ProjectStatusChangeEvent.getRejectValueByCode(projectStatusSecond);
if (Objects.isNull(event)){
throw new BizException("该状态下没有对应的驳回操作!");
}
return event;
}

public ProjectStatusChangeEvent getProjectStatusWithdrawEvent(Integer projectStatusSecond) {
ProjectStatusChangeEvent event = ProjectStatusChangeEvent.getWithdrawValueByCode(projectStatusSecond);
if (Objects.isNull(event)){
throw new BizException("该状态下没有对应的撤回操作!");
}
return event;
}
}

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/projectlib/enums/ProjectStatusEnum.java Näytä tiedosto

@@ -32,7 +32,7 @@ public enum ProjectStatusEnum {
TO_BE_APPROVED (10014,"待立项批复"),
TO_BE_DECLARED (10015,"待申报"),
PLAN_TO_BE_DECLARED (10016,"方案待申报"),
PENDING_PREQUALIFICATION_CHOICE (10016,"待预审选择态"),
PENDING_PREQUALIFICATION_CHOICE (10017,"待预审选择态"),
PROJECT_APPROVED (20000,"已立项"),
TO_BE_PURCHASED (20001,"待采购"),
UNDER_CONSTRUCTION (20002,"建设中"),


+ 1
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java Näytä tiedosto

@@ -68,6 +68,7 @@ public class TodoCenterController {
@GetMapping("/progress/{instanceId}/{nodeId}")
public ApiResponse<ProcessProgressDetailVo> getProcessDetail(@PathVariable String instanceId,
@PathVariable(required = false) String nodeId) {

return ApiResponse.ofSuccess(todoCenterManage.getProcessDetail(nodeId, instanceId));
}



+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/extension/cmd/BackToHisApprovalNodeCmd.java Näytä tiedosto

@@ -146,7 +146,7 @@ public class BackToHisApprovalNodeCmd implements Command<String>, Serializable {
if (targetRealSpecialGateway != null) {
createTargetInSpecialGatewayEndExecutions(commandContext, realExecutions, process, targetInSpecialGatewayList, targetRealSpecialGateway);
}
// TODO 调用原生的excute方法 在流程实例表中END_ACT_ID添加对应的字段标识
// TODO 调用原生的execute方法 在流程实例表中END_ACT_ID添加对应的字段标识
Map<String, Object> var = new HashMap<>(16);
var.put("approve_" + task.getId(), ProcessHandlerEnum.BACK);
taskService.complete(task.getId(), var);


+ 100
- 7
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java Näytä tiedosto

@@ -20,8 +20,10 @@ import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.NdDateUtils;
import com.ningdatech.pmapi.common.constant.DingConstant;
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.common.util.ExcelExportStyle;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import com.ningdatech.pmapi.todocenter.bean.entity.ProcessComment;
@@ -120,8 +122,8 @@ public class TodoCenterManage {
private final WflowCcTasksMapper ccTasksMapper;
private final ProcessModelService processModelService;
private final IUserInfoService userInfoService;

private final IProjectService projectService;
private final StateMachineUtils stateMachineUtils;
@Resource(name = "executableClient")
private ExecutableClient client;
/**
@@ -294,8 +296,40 @@ public class TodoCenterManage {
FlowNode rootNode = (FlowNode) process.getFlowElement("root", true);
// TODO 中止流程并使项目进入对应状态,给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被驳回,请及时处理。
sendWorkNoticeToStartUser(task,projectName,rootNode);

// 更新项目状态
updateRejectProjectStatus(task);
taskService.complete(param.getTaskId(), var);
}

/**
* 当为驳回操作时,更新项目表中的项目状态
* @param task 当前任务
* @return void
* @author CMM
* @since 2023/02/08 20:44
*/
private void updateRejectProjectStatus(Task task) {
// 获取当前登录用户
Long userId = LoginUserUtil.getUserId();
// 获取当前申报项目
Project declaredProject = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getInstCode, task.getProcessInstanceId()));
// 获取当前流程项目状态
Integer projectStatusSecond = declaredProject.getProjectStatusSecond();
// 根据当前状态获取对应的通过事件
ProjectStatusChangeEvent event = stateMachineUtils.getProjectStatusRejectEvent(projectStatusSecond);
try {
stateMachineUtils.execute(declaredProject,event);
declaredProject.setUpdateOn(LocalDateTime.now());
declaredProject.setUpdateBy(userId);
} catch (Exception e) {
throw new BizException("状态机执行失败!");
}
// 更新项目状态到下一个状态
projectService.updateById(declaredProject);
}

/**
* 获取最新版本的流程配置
* @param task 当前任务
@@ -325,6 +359,8 @@ public class TodoCenterManage {

// TODO 市级单位:为大数据局;区县单位:为大数据中心(根据附件区分?)

// 更新项目状态到下一个状态
updatePassProjectStatus(task);
taskService.complete(param.getTaskId(), var);
}

@@ -357,8 +393,39 @@ public class TodoCenterManage {
FlowNode rootNode = (FlowNode) process.getFlowElement("root", true);
sendWorkNoticeToStartUser(task, projectName, rootNode);
}

updatePassProjectStatus(task);
taskService.complete(param.getTaskId(), var);
}

/**
* 当为通过操作时,更新项目表中项目状态
* @param task 当前任务
* @return void
* @author CMM
* @since 2023/02/08 20:38
*/
private void updatePassProjectStatus(Task task) {
// 获取当前登录用户
Long userId = LoginUserUtil.getUserId();
// 获取当前申报项目
Project declaredProject = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getInstCode, task.getProcessInstanceId()));
// 获取当前流程项目状态
Integer projectStatusSecond = declaredProject.getProjectStatusSecond();
// 根据当前状态获取对应的通过事件
ProjectStatusChangeEvent event = stateMachineUtils.getProjectStatusPassEvent(projectStatusSecond);
try {
stateMachineUtils.execute(declaredProject,event);
declaredProject.setUpdateOn(LocalDateTime.now());
declaredProject.setUpdateBy(userId);
} catch (Exception e) {
throw new BizException("状态机执行失败!");
}
// 更新项目状态到下一个状态
projectService.updateById(declaredProject);
}

/**
* 给流程发起人发送工作通知
* @param task 当前任务
@@ -509,11 +576,7 @@ public class TodoCenterManage {
Long userId = LoginUserUtil.getUserId();
if (rootUserId.equals(String.valueOf(userId))){
// TODO 若是流程发起人点击撤回,项目回到上一个状态,并删除当前审核人对应的待办记录
// 获取当前流程项目状态
Project declaredProject = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getInstCode, task.getProcessInstanceId()));
Integer projectStatusSecond = declaredProject.getProjectStatusSecond();

updateWithdrawProjectStatus(task, userId);
List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceId(task.getProcessInstanceId())
.onlyChildExecutions().list();
@@ -533,6 +596,8 @@ public class TodoCenterManage {
// 待我处理中移除当前审核人的待办记录、
// 待我处理中增加自己的待办记录、
// 我已处理中去掉自己之前处理的记录
// 更新项目状态
updateWithdrawProjectStatus(task, userId);
HistoricTaskInstance beforeTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(beforeUserTask.getId()).singleResult();
List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceId(beforeTaskInstance.getProcessInstanceId())
@@ -551,6 +616,33 @@ public class TodoCenterManage {
}

/**
* 当为撤回操作时,更新项目表中的项目状态为前一个状态
* @param task
* @param userId
* @return void
* @author CMM
* @since 2023/02/08 20:41
*/
private void updateWithdrawProjectStatus(Task task, Long userId) {
// 获取当前申报项目
Project declaredProject = projectService.getOne(Wrappers.lambdaQuery(Project.class)
.eq(Project::getInstCode, task.getProcessInstanceId()));
// 获取当前流程项目状态
Integer projectStatusSecond = declaredProject.getProjectStatusSecond();
// 根据当前状态获取对应的撤回事件
ProjectStatusChangeEvent event = stateMachineUtils.getProjectStatusWithdrawEvent(projectStatusSecond);
try {
stateMachineUtils.execute(declaredProject,event);
declaredProject.setUpdateOn(LocalDateTime.now());
declaredProject.setUpdateBy(userId);
} catch (Exception e) {
throw new BizException("状态机执行失败!");
}
// 更新项目状态
projectService.updateById(declaredProject);
}

/**
* 退回流程处理
*
* @param task
@@ -575,8 +667,9 @@ public class TodoCenterManage {

/**
* 查询流程表单数据及审批的进度步骤
*
* @param nodeId 当前获取流程人员关联的流程节点ID
* @param instanceId 流程实例ID
* @param nodeId 当前获取流程人员关联的流程节点ID
* @return 流程进度及表单详情
*/
public ProcessProgressDetailVo getProcessDetail(String nodeId, String instanceId) {


+ 28
- 0
pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java Näytä tiedosto

@@ -0,0 +1,28 @@
package com.ningdatech.pmapi.statemachine;

import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enums.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
* 状态机测试
*
* @author CMM
* @since 2023/02/08 11:46
*/

public class StateMachineTest extends AppTests {
@Autowired
private StateMachineUtils stateMachineUtils;

@Test
public void stateMachineTest() throws Exception {
Project project = new Project();
project.setProjectStatusSecond(ProjectStatusEnum.UNDER_INTERNAL_AUDIT.getCode());
stateMachineUtils.execute(project, ProjectStatusChangeEvent.UNDER_INTERNAL_PASS);
}
}

Loading…
Peruuta
Tallenna