Browse Source

增加信创审核、终验审核成功之后的回调方法

tags/24080901
WendyYang 10 months ago
parent
commit
c702dfd2a9
9 changed files with 220 additions and 30 deletions
  1. +14
    -4
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/OperationManage.java
  2. +4
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java
  3. +6
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/model/vo/PurchaseVO.java
  4. +24
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IOperationService.java
  5. +10
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IPurchaseInstService.java
  6. +6
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java
  7. +1
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/InstTypeEnum.java
  8. +98
    -7
      hz-pm-api/src/main/java/com/hz/pm/api/todocenter/manage/HandlerManage.java
  9. +57
    -18
      hz-pm-api/src/test/java/com/hz/pm/api/todocenter/FlowableTest.java

+ 14
- 4
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/OperationManage.java View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.common.statemachine.util.StateMachineUtil;
import com.hz.pm.api.common.statemachine.util.TenderStateMachineUtil; import com.hz.pm.api.common.statemachine.util.TenderStateMachineUtil;
import com.hz.pm.api.projectdeclared.model.dto.OperationReq; import com.hz.pm.api.projectdeclared.model.dto.OperationReq;
import com.hz.pm.api.projectdeclared.model.entity.Operation; import com.hz.pm.api.projectdeclared.model.entity.Operation;
@@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;


import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;


/** /**
@@ -42,6 +44,7 @@ public class OperationManage {
private final IPurchaseService purchaseService; private final IPurchaseService purchaseService;
private final IProjectService projectService; private final IProjectService projectService;
private final TenderStateMachineUtil tenderStateMachineUtil; private final TenderStateMachineUtil tenderStateMachineUtil;
private final StateMachineUtil stateMachineUtil;


/** /**
* 获取实施详情 * 获取实施详情
@@ -62,13 +65,13 @@ public class OperationManage {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String pushOperation(OperationReq req) { public String pushOperation(OperationReq req) {
UserInfoDetails user = LoginUserUtil.loginUserDetail(); UserInfoDetails user = LoginUserUtil.loginUserDetail();
Purchase purchase = purchaseService.getById(req.getBidId());
List<Purchase> purchases = purchaseService.listByProjectId(req.getProjectId());
Map<Long, Purchase> purchaseMap = CollUtils.listToMap(purchases, Purchase::getId);
Purchase purchase = purchaseMap.get(req.getBidId());
if (!TenderStatusEnum.TO_BE_SUBMIT_OPERATION_PLAN.eq(purchase.getStatus())) { if (!TenderStatusEnum.TO_BE_SUBMIT_OPERATION_PLAN.eq(purchase.getStatus())) {
throw BizException.wrap("该标段不支持填写实施计划"); throw BizException.wrap("该标段不支持填写实施计划");
} }
Operation pre = operationService.getOne(Wrappers.lambdaQuery(Operation.class)
.eq(Operation::getBidId, req.getBidId())
.last(BizConst.LIMIT_1));
Operation pre = operationService.getByBidId(req.getBidId());
Project project = projectService.getNewProject(req.getProjectId()); Project project = projectService.getNewProject(req.getProjectId());
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
Operation curr = BeanUtil.copyProperties(req, Operation.class); Operation curr = BeanUtil.copyProperties(req, Operation.class);
@@ -82,6 +85,13 @@ public class OperationManage {
curr.setUpdateOn(now); curr.setUpdateOn(now);
curr.setUpdateBy(user.getUsername()); curr.setUpdateBy(user.getUsername());
operationService.saveOrUpdate(curr); operationService.saveOrUpdate(curr);
long operationCount = operationService.countByBidIds(purchaseMap.keySet());
if (operationCount == purchaseMap.size()) {
// 修改项目状态
stateMachineUtil.pass(project);
projectService.updateById(project);
}
// 修改标段状态
tenderStateMachineUtil.pass(purchase); tenderStateMachineUtil.pass(purchase);
purchaseService.updateById(purchase); purchaseService.updateById(purchase);
return curr.getProjectCode(); return curr.getProjectCode();


+ 4
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java View File

@@ -41,6 +41,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@@ -244,6 +245,7 @@ public class PurchaseManage {
return "保存失败"; return "保存失败";
} }


@Transactional(rollbackFor = Exception.class)
public void submitPurchaseNotice(SubmitPurchaseNoticeReq req) { public void submitPurchaseNotice(SubmitPurchaseNoticeReq req) {
UserInfoDetails user = LoginUserUtil.loginUserDetail(); UserInfoDetails user = LoginUserUtil.loginUserDetail();
Long projectId = req.getProjectId(); Long projectId = req.getProjectId();
@@ -272,6 +274,8 @@ public class PurchaseManage {
return purchase; return purchase;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
purchaseService.saveOrUpdateBatch(purchases); purchaseService.saveOrUpdateBatch(purchases);
stateMachineUtil.pass(project);
projectService.updateById(project);
} }


public void submitPurchaseRecord(SubmitPurchaseRecordReq req) { public void submitPurchaseRecord(SubmitPurchaseRecordReq req) {


+ 6
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/model/vo/PurchaseVO.java View File

@@ -22,6 +22,12 @@ public class PurchaseVO {
@ApiModelProperty("id") @ApiModelProperty("id")
private Long id; private Long id;


@ApiModelProperty("标段状态")
private Integer status;

@ApiModelProperty("标段状态名称")
private String statusName;

@ApiModelProperty("标段名称") @ApiModelProperty("标段名称")
private String bidName; private String bidName;




+ 24
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IOperationService.java View File

@@ -1,7 +1,13 @@
package com.hz.pm.api.projectdeclared.service; package com.hz.pm.api.projectdeclared.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.projectdeclared.model.entity.Operation; import com.hz.pm.api.projectdeclared.model.entity.Operation;
import com.ningdatech.basic.util.CollUtils;

import java.util.Collection;
import java.util.List;


/** /**
* <p> * <p>
@@ -13,4 +19,22 @@ import com.hz.pm.api.projectdeclared.model.entity.Operation;
*/ */
public interface IOperationService extends IService<Operation> { public interface IOperationService extends IService<Operation> {


default Operation getByBidId(Long bidId) {
LambdaQueryWrapper<Operation> query = Wrappers.lambdaQuery(Operation.class)
.eq(Operation::getBidId, bidId);
return getOne(query);
}

default List<Operation> listByBidIds(Collection<Long> bidIds) {
LambdaQueryWrapper<Operation> query = Wrappers.lambdaQuery(Operation.class)
.in(Operation::getBidId, bidIds);
return list(query);
}

default long countByBidIds(Collection<Long> bidIds) {
LambdaQueryWrapper<Operation> query = Wrappers.lambdaQuery(Operation.class)
.in(Operation::getBidId, bidIds);
return count(query);
}

} }

+ 10
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/service/IPurchaseInstService.java View File

@@ -1,5 +1,7 @@
package com.hz.pm.api.projectdeclared.service; package com.hz.pm.api.projectdeclared.service;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst;


@@ -12,4 +14,12 @@ import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst;
* @since 00:12 2024/2/25 * @since 00:12 2024/2/25
*/ */
public interface IPurchaseInstService extends IService<PurchaseInst> { public interface IPurchaseInstService extends IService<PurchaseInst> {

default PurchaseInst getByProjectIdAndInstCode(Long projectId, String instCode) {
Wrapper<PurchaseInst> query = Wrappers.lambdaQuery(PurchaseInst.class)
.eq(PurchaseInst::getProjectId, projectId)
.eq(PurchaseInst::getInstCode, instCode);
return getOne(query);
}

} }

+ 6
- 1
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java View File

@@ -58,6 +58,7 @@ import com.hz.pm.api.projectlib.model.entity.*;
import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum; import com.hz.pm.api.projectlib.model.enumeration.InstTypeEnum;
import com.hz.pm.api.projectlib.model.enumeration.ProjectRenewalApprovalStatusEnum; import com.hz.pm.api.projectlib.model.enumeration.ProjectRenewalApprovalStatusEnum;
import com.hz.pm.api.projectlib.model.enumeration.ProjectStatusEnum; import com.hz.pm.api.projectlib.model.enumeration.ProjectStatusEnum;
import com.hz.pm.api.projectlib.model.enumeration.TenderStatusEnum;
import com.hz.pm.api.projectlib.model.po.ProjectPO; import com.hz.pm.api.projectlib.model.po.ProjectPO;
import com.hz.pm.api.projectlib.model.req.ProjectApplicationListReq; import com.hz.pm.api.projectlib.model.req.ProjectApplicationListReq;
import com.hz.pm.api.projectlib.model.req.ProjectListReq; import com.hz.pm.api.projectlib.model.req.ProjectListReq;
@@ -689,7 +690,11 @@ public class ProjectLibManage {


//查询采购备案 //查询采购备案
List<Purchase> purchases = purchaseService.listByProjectIds(allVersionProjectId); List<Purchase> purchases = purchaseService.listByProjectIds(allVersionProjectId);
vo.setPurchases(BeanUtil.copyToList(purchases, PurchaseVO.class));
vo.setPurchases(CollUtils.fieldList(purchases,w -> {
PurchaseVO purchase = BeanUtil.copyProperties(w, PurchaseVO.class);
purchase.setStatusName(TenderStatusEnum.getDescByStatus(w.getStatus()));
return purchase;
}));


//查询合同备案 //查询合同备案
List<ContractVO> contracts = constructionManage.detailContractByProjectId(projectInfo.getId()); List<ContractVO> contracts = constructionManage.detailContractByProjectId(projectInfo.getId());


+ 1
- 0
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/enumeration/InstTypeEnum.java View File

@@ -28,6 +28,7 @@ public enum InstTypeEnum {


APPLY_DELAY(6, "申请延期审批流程"), APPLY_DELAY(6, "申请延期审批流程"),
DECLARED_RECORD(8, "立项备案审批流程"), DECLARED_RECORD(8, "立项备案审批流程"),
XCFHX_APPLY(9, "信创审查审批流程"),


APPLY_BORROW(7, "申请借阅审批流程"); APPLY_BORROW(7, "申请借阅审批流程");




+ 98
- 7
hz-pm-api/src/main/java/com/hz/pm/api/todocenter/manage/HandlerManage.java View File

@@ -7,17 +7,25 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.hz.pm.api.common.enumeration.ProjectProcessStageEnum;
import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.common.statemachine.util.StateMachineUtil; import com.hz.pm.api.common.statemachine.util.StateMachineUtil;
import com.hz.pm.api.common.statemachine.util.TenderStateMachineUtil;
import com.hz.pm.api.common.util.BizUtils;
import com.hz.pm.api.filemanage.model.entity.ProjectApplyBorrow; import com.hz.pm.api.filemanage.model.entity.ProjectApplyBorrow;
import com.hz.pm.api.filemanage.service.INdProjectApplyBorrowService; import com.hz.pm.api.filemanage.service.INdProjectApplyBorrowService;
import com.hz.pm.api.projectdeclared.manage.DeclaredProjectManage; import com.hz.pm.api.projectdeclared.manage.DeclaredProjectManage;
import com.hz.pm.api.projectdeclared.model.dto.ProjectDraftSaveDTO; import com.hz.pm.api.projectdeclared.model.dto.ProjectDraftSaveDTO;
import com.hz.pm.api.projectdeclared.model.entity.ProjectConstructionSuggestions; import com.hz.pm.api.projectdeclared.model.entity.ProjectConstructionSuggestions;
import com.hz.pm.api.projectdeclared.model.entity.Purchase;
import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst;
import com.hz.pm.api.projectdeclared.model.enumerization.ProjectDraftTypeEnum; import com.hz.pm.api.projectdeclared.model.enumerization.ProjectDraftTypeEnum;
import com.hz.pm.api.projectdeclared.service.IConstructionSuggestionsService; import com.hz.pm.api.projectdeclared.service.IConstructionSuggestionsService;
import com.hz.pm.api.projectdeclared.service.IPurchaseInstService;
import com.hz.pm.api.projectdeclared.service.IPurchaseService;
import com.hz.pm.api.projectlib.model.dto.ProjectApplicationDTO; import com.hz.pm.api.projectlib.model.dto.ProjectApplicationDTO;
import com.hz.pm.api.projectlib.model.dto.ProjectDTO; import com.hz.pm.api.projectlib.model.dto.ProjectDTO;
import com.hz.pm.api.projectlib.model.entity.Project; import com.hz.pm.api.projectlib.model.entity.Project;
@@ -36,6 +44,7 @@ import com.hz.pm.api.sys.manage.NoticeManage;
import com.hz.pm.api.todocenter.constant.TodoCenterConst; import com.hz.pm.api.todocenter.constant.TodoCenterConst;
import com.hz.pm.api.user.util.LoginUserUtil; import com.hz.pm.api.user.util.LoginUserUtil;
import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.basic.util.NdDateUtils; import com.ningdatech.basic.util.NdDateUtils;
import com.wflow.contants.HisProInsEndActId; import com.wflow.contants.HisProInsEndActId;
import com.wflow.workflow.bean.process.ProgressNode; import com.wflow.workflow.bean.process.ProgressNode;
@@ -49,6 +58,7 @@ import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.HistoryService; import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService; import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.task.Comment; import org.flowable.engine.task.Comment;
import org.flowable.variable.api.history.HistoricVariableInstance; import org.flowable.variable.api.history.HistoricVariableInstance;
@@ -88,6 +98,9 @@ public class HandlerManage {
private final INdProjectDelayApplyService projectDelayApplyService; private final INdProjectDelayApplyService projectDelayApplyService;
private final INdProjectApplyBorrowService projectApplyBorrowService; private final INdProjectApplyBorrowService projectApplyBorrowService;
private final IConstructionSuggestionsService constructionSuggestionsService; private final IConstructionSuggestionsService constructionSuggestionsService;
private final IPurchaseService purchaseService;
private final IPurchaseInstService purchaseInstService;
private final TenderStateMachineUtil tenderStateMachineUtil;


@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
private String active; private String active;
@@ -177,6 +190,12 @@ public class HandlerManage {
// 判断是否 保存建设建议信息 // 判断是否 保存建设建议信息
saveConstructionSuggestInfo(instance.getId(), project); saveConstructionSuggestInfo(instance.getId(), project);
break; break;
case ON_FIRST_INSPECTED:
purchasePassedCallback(project, instanceId, ProjectProcessStageEnum.XC_APPROVAL_PROCESS);
break;
case ON_FINALLY_INSPECTED:
purchasePassedCallback(project, instanceId, ProjectProcessStageEnum.ACCEPTANCE_DECLARATION_APPROVAL_PROCESS);
break;
default: default:
throw new BizException("传入项目状态错误: " + project.getStatus()); throw new BizException("传入项目状态错误: " + project.getStatus());
} }
@@ -200,6 +219,67 @@ public class HandlerManage {
} }
} }


private void purchasePassedCallback(Project project, String instanceId, ProjectProcessStageEnum processStage) {
// 查询所有的标段
List<Purchase> purchases = purchaseService.listByProjectId(project.getId());
Map<Long, Purchase> purchaseMap = CollUtils.listToMap(purchases, Purchase::getId);
// 查询所有标段对应的最新的信创审批流程编码
List<PurchaseInst> instList = purchaseInstService.list(Wrappers.lambdaQuery(PurchaseInst.class)
.in(PurchaseInst::getBidId, purchaseMap.keySet())
.eq(PurchaseInst::getInstType, processStage.getCode()));

Purchase currPurchase = instList.stream()
.filter(w -> w.getInstCode().equals(instanceId))
.findFirst()
.flatMap(w -> Optional.ofNullable(purchaseMap.get(w.getBidId())))
.orElseThrow(() -> BizException.wrap("当前审批的标段不存在"));

tenderStateMachineUtil.pass(currPurchase);
purchaseService.updateById(currPurchase);

Collection<PurchaseInst> lastInstList = BizUtils.groupFirst(instList, PurchaseInst::getBidId, Comparator.comparing(PurchaseInst::getCreatOn).reversed());
Set<String> instCodes = CollUtils.fieldSet(lastInstList, PurchaseInst::getInstCode);
if (instCodes.size() != purchases.size()) {
return;
}
long finishedCount = historyService.createHistoricProcessInstanceQuery()
.processInstanceIds(instCodes)
.finished()
.count();
if (finishedCount != instCodes.size()) {
return;
}
for (String instCode : instCodes) {
HistoricActivityInstance task = historyService.createHistoricActivityInstanceQuery()
.activityType("userTask")
.processInstanceId(instCode)
.orderByHistoricActivityInstanceEndTime()
.desc()
.singleResult();
if (task == null) {
return;
}
HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instCode)
.variableName("approve_" + task.getTaskId())
.singleResult();
if (variableInstance == null || !"PASS".equals(variableInstance.getValue())) {
return;
}
}
stateMachineUtil.pass(project);
projectService.updateById(project);
}

private void purchaseRejectedCallback(Project project, String instanceId) {
PurchaseInst purchaseInst = purchaseInstService.getByProjectIdAndInstCode(project.getId(), instanceId);
Assert.notNull(purchaseInst, "该标段对应的流程不存在");
Purchase purchase = purchaseService.getById(purchaseInst.getBidId());
Assert.notNull(purchase, "标段信息不存在");
tenderStateMachineUtil.reject(purchase);
purchaseService.updateById(purchase);
}

/** /**
* 去保存 建设建议信息 * 去保存 建设建议信息
* *
@@ -264,22 +344,33 @@ public class HandlerManage {
/** /**
* 驳回后 所处理的逻辑 * 驳回后 所处理的逻辑
* *
* @param project \
* @param instance \
* @param project \
* @param hiInst \
*/ */
public void afterRejectTodo(Project project, HistoricProcessInstance instance) {
public void afterRejectTodo(Project project, HistoricProcessInstance hiInst) {
Long userId = LoginUserUtil.getUserId(); Long userId = LoginUserUtil.getUserId();
// 获取当前流程实例类型 // 获取当前流程实例类型
String instanceId = project.getInstCode(); String instanceId = project.getInstCode();
ProjectInst projectInst = projectInstService.getByInstCode(instanceId); ProjectInst projectInst = projectInstService.getByInstCode(instanceId);
Integer instType = projectInst.getInstType(); Integer instType = projectInst.getInstType();
// 审批流程不是申请延期和申请借阅,需调用状态机 // 审批流程不是申请延期和申请借阅,需调用状态机
if (!InstTypeEnum.APPLY_DELAY.eq(instType) && !InstTypeEnum.APPLY_BORROW.eq(instType)) {
// 更新项目状态和流程状态
updateRejectProjectStatus(userId, project, instType);
InstTypeEnum instTypeEnum = InstTypeEnum.getByCode(instType);
Assert.notNull(instTypeEnum, "不支持的流程类型");
switch (instTypeEnum) {
case APPLY_BORROW:
case APPLY_DELAY:
break;
case XCFHX_APPLY:
case PROJECT_FINAL_INSPECTION:
purchaseRejectedCallback(project, instanceId);
break;
default:
updateRejectProjectStatus(userId, project, instType);
break;

} }
//发送消息 //发送消息
noticeManage.sendNotice(userId, project, instance.getProcessDefinitionName(),
noticeManage.sendNotice(userId, project, hiInst.getProcessDefinitionName(),
REJECT_MSG_TEMPLATE, MsgTypeEnum.PROJECT_REVIEW_REJECT); REJECT_MSG_TEMPLATE, MsgTypeEnum.PROJECT_REVIEW_REJECT);
} }




+ 57
- 18
hz-pm-api/src/test/java/com/hz/pm/api/todocenter/FlowableTest.java View File

@@ -1,5 +1,6 @@
package com.hz.pm.api.todocenter; package com.hz.pm.api.todocenter;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.exception.BizException;
import com.hz.pm.api.AppTests; import com.hz.pm.api.AppTests;
@@ -17,10 +18,13 @@ import org.flowable.bpmn.model.FlowElement;
import org.flowable.common.engine.impl.cmd.CustomSqlExecution; import org.flowable.common.engine.impl.cmd.CustomSqlExecution;
import org.flowable.engine.*; import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.impl.cmd.AbstractCustomSqlExecution; import org.flowable.engine.impl.cmd.AbstractCustomSqlExecution;
import org.flowable.engine.runtime.Execution; import org.flowable.engine.runtime.Execution;
import org.flowable.task.api.Task; import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;


@@ -58,14 +62,14 @@ public class FlowableTest extends AppTests {
private WflowCcTasksMapper ccTasksMapper; private WflowCcTasksMapper ccTasksMapper;


@Test @Test
public void withdrawTest(){
public void withdrawTest() {
String taskId = "cc3d7536-f1f3-11ed-b9e0-02426daa406d"; String taskId = "cc3d7536-f1f3-11ed-b9e0-02426daa406d";


// 不是流程发起人撤回 // 不是流程发起人撤回
HistoricTaskInstance handledTaskInstance = historyService.createHistoricTaskInstanceQuery() HistoricTaskInstance handledTaskInstance = historyService.createHistoricTaskInstanceQuery()
.taskId(taskId) .taskId(taskId)
.singleResult(); .singleResult();
if (Objects.isNull(handledTaskInstance)){
if (Objects.isNull(handledTaskInstance)) {
throw new BizException("获取任务实例失败!"); throw new BizException("获取任务实例失败!");
} }


@@ -96,7 +100,7 @@ public class FlowableTest extends AppTests {
// 传节点定义key 获取撤回操作人在流程配置中所在的节点 // 传节点定义key 获取撤回操作人在流程配置中所在的节点
FlowElement beforeFlowElement = bpmnModel.getFlowElement(handledNodeId); FlowElement beforeFlowElement = bpmnModel.getFlowElement(handledNodeId);
// 获取执行撤回操作的节点所在子流程所有节点ID // 获取执行撤回操作的节点所在子流程所有节点ID
List<String> actIdList = Lists.newArrayList(handledNodeId,currentNodeId);
List<String> actIdList = Lists.newArrayList(handledNodeId, currentNodeId);


List<HistoricActivityInstance> historicActivityInstanceList = historyService List<HistoricActivityInstance> historicActivityInstanceList = historyService
.createHistoricActivityInstanceQuery() .createHistoricActivityInstanceQuery()
@@ -121,11 +125,11 @@ public class FlowableTest extends AppTests {
// 强制流程指向前一个审核人节点 // 强制流程指向前一个审核人节点
runtimeService.createChangeActivityStateBuilder() runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId) .processInstanceId(processInstanceId)
.moveActivityIdsToSingleActivityId(actIds,handledNodeId)
.moveActivityIdsToSingleActivityId(actIds, handledNodeId)
.changeState(); .changeState();


// 如果是从会签节点撤回,执行会签节点的节点ID和当前待处理节点ID相同,只需要标记当前会签节点为被撤回 // 如果是从会签节点撤回,执行会签节点的节点ID和当前待处理节点ID相同,只需要标记当前会签节点为被撤回
if (handledNodeId.equals(currentNodeId)){
if (handledNodeId.equals(currentNodeId)) {
activityInstances = activityInstances.stream().filter(a -> currentNodeId.equals(a.getActivityId())).collect(Collectors.toList()); activityInstances = activityInstances.stream().filter(a -> currentNodeId.equals(a.getActivityId())).collect(Collectors.toList());
} }
for (HistoricActivityInstance activityInstance : activityInstances) { for (HistoricActivityInstance activityInstance : activityInstances) {
@@ -145,7 +149,7 @@ public class FlowableTest extends AppTests {
} }


@Test @Test
public void testWithDraw(){
public void testWithDraw() {
ReqProcessHandlerDTO param = new ReqProcessHandlerDTO(); ReqProcessHandlerDTO param = new ReqProcessHandlerDTO();
param.setProjectId(633L); param.setProjectId(633L);
param.setTaskId("8e3e9329-f544-11ed-91fd-02426daa406d"); param.setTaskId("8e3e9329-f544-11ed-91fd-02426daa406d");
@@ -156,7 +160,7 @@ public class FlowableTest extends AppTests {
HistoricTaskInstance handledTaskInstance = historyService.createHistoricTaskInstanceQuery() HistoricTaskInstance handledTaskInstance = historyService.createHistoricTaskInstanceQuery()
.taskId(param.getTaskId()) .taskId(param.getTaskId())
.singleResult(); .singleResult();
if (Objects.isNull(handledTaskInstance)){
if (Objects.isNull(handledTaskInstance)) {
throw new BizException("获取任务实例失败!"); throw new BizException("获取任务实例失败!");
} }


@@ -189,7 +193,7 @@ public class FlowableTest extends AppTests {
// 传节点定义key 获取撤回操作人在流程配置中所在的节点 // 传节点定义key 获取撤回操作人在流程配置中所在的节点
FlowElement beforeFlowElement = bpmnModel.getFlowElement(handledNodeId); FlowElement beforeFlowElement = bpmnModel.getFlowElement(handledNodeId);
// 获取执行撤回操作的节点所在子流程所有节点ID // 获取执行撤回操作的节点所在子流程所有节点ID
List<String> actIdList = Lists.newArrayList(handledNodeId,currentNodeId);
List<String> actIdList = Lists.newArrayList(handledNodeId, currentNodeId);


List<HistoricActivityInstance> historicActivityInstanceList = historyService List<HistoricActivityInstance> historicActivityInstanceList = historyService
.createHistoricActivityInstanceQuery() .createHistoricActivityInstanceQuery()
@@ -199,11 +203,11 @@ public class FlowableTest extends AppTests {
// 标记执行撤回操作节点及当前待处理节点(userTask类型)为被撤回(使用DELETE_REASON_标志) // 标记执行撤回操作节点及当前待处理节点(userTask类型)为被撤回(使用DELETE_REASON_标志)
List<HistoricActivityInstance> activityInstances = historicActivityInstanceList.stream() List<HistoricActivityInstance> activityInstances = historicActivityInstanceList.stream()
.filter(a -> { .filter(a -> {
if(actIdList.contains(a.getActivityId())){
if(a.getActivityId().equals(handledNodeId)){
return (CodeUtil.computationTime(a.getStartTime(),handleCreateTime) == 0L);
}else if(a.getActivityId().equals(currentNodeId)){
return (CodeUtil.computationTime(a.getStartTime(),currentCreateTime) == 0L);
if (actIdList.contains(a.getActivityId())) {
if (a.getActivityId().equals(handledNodeId)) {
return (CodeUtil.computationTime(a.getStartTime(), handleCreateTime) == 0L);
} else if (a.getActivityId().equals(currentNodeId)) {
return (CodeUtil.computationTime(a.getStartTime(), currentCreateTime) == 0L);
} }
} }
return Boolean.FALSE; return Boolean.FALSE;
@@ -224,11 +228,11 @@ public class FlowableTest extends AppTests {
runtimeService.createChangeActivityStateBuilder() runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId) .processInstanceId(processInstanceId)
// .moveActivityIdTo(currentNodeId,handledNodeId) // .moveActivityIdTo(currentNodeId,handledNodeId)
.moveActivityIdsToSingleActivityId(actIds,handledNodeId)
.moveActivityIdsToSingleActivityId(actIds, handledNodeId)
.changeState(); .changeState();


// 如果是从会签节点撤回,执行会签节点的节点ID和当前待处理节点ID相同,只需要标记当前会签节点为被撤回 // 如果是从会签节点撤回,执行会签节点的节点ID和当前待处理节点ID相同,只需要标记当前会签节点为被撤回
if (handledNodeId.equals(currentNodeId)){
if (handledNodeId.equals(currentNodeId)) {
activityInstances = activityInstances.stream().filter(a -> currentNodeId.equals(a.getActivityId())).collect(Collectors.toList()); activityInstances = activityInstances.stream().filter(a -> currentNodeId.equals(a.getActivityId())).collect(Collectors.toList());
} }
for (HistoricActivityInstance activityInstance : activityInstances) { for (HistoricActivityInstance activityInstance : activityInstances) {
@@ -247,11 +251,11 @@ public class FlowableTest extends AppTests {
} }
// 如果当前执行撤回操作的节点后有抄送节点,撤回后,需将抄送任务节点删除 // 如果当前执行撤回操作的节点后有抄送节点,撤回后,需将抄送任务节点删除
String ccNodeId = param.getCcNodeId(); String ccNodeId = param.getCcNodeId();
ccTasksMapper.delete(Wrappers.lambdaQuery(WflowCcTasks.class).eq(WflowCcTasks::getNodeId,ccNodeId));
ccTasksMapper.delete(Wrappers.lambdaQuery(WflowCcTasks.class).eq(WflowCcTasks::getNodeId, ccNodeId));
} }


@Test @Test
public void reject(){
public void reject() {
String instCode = "0e63faec-08ff-11ee-9663-00163e000353"; String instCode = "0e63faec-08ff-11ee-9663-00163e000353";
String nodeId1 = "node_6486ddcbe4b0ab4a27ccfdbd"; String nodeId1 = "node_6486ddcbe4b0ab4a27ccfdbd";
String nodeId2 = "node_6486ddcbe4b0ab4a27ccfdc1"; String nodeId2 = "node_6486ddcbe4b0ab4a27ccfdc1";
@@ -263,11 +267,46 @@ public class FlowableTest extends AppTests {
//强制流程指向驳回 //强制流程指向驳回
runtimeService.createChangeActivityStateBuilder() runtimeService.createChangeActivityStateBuilder()
.processInstanceId(instCode) .processInstanceId(instCode)
.moveActivityIdsToSingleActivityId(Lists.newArrayList(nodeId1,nodeId2,nodeId3), "refuse-end")
.moveActivityIdsToSingleActivityId(Lists.newArrayList(nodeId1, nodeId2, nodeId3), "refuse-end")
.moveExecutionsToSingleActivityId(executions.stream().map(Execution::getId) .moveExecutionsToSingleActivityId(executions.stream().map(Execution::getId)
.collect(Collectors.toList()), "refuse-end") .collect(Collectors.toList()), "refuse-end")
.changeState(); .changeState();


log.info("操作成功!"); log.info("操作成功!");
} }

@Test
public void ifInstFinishedAndPassed() {
String processInstanceId = "3c44c787-d387-11ee-9016-02426daa406d";

HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId)
.finished()
.singleResult();

if (historicProcessInstance != null && historicProcessInstance.getEndTime() != null) {
HistoricActivityInstance lastTaskInstance = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricActivityInstanceEndTime()
.desc()
.list()
.stream()
.filter(instance -> instance.getActivityType().equals("userTask"))
.findFirst()
.orElse(null);

if (lastTaskInstance != null) {
String lastTaskId = lastTaskInstance.getActivityId();
System.out.println(JSONUtil.toJsonStr(lastTaskInstance));

HistoricVariableInstance approvalStatusVariable = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(processInstanceId)
.variableName("approve_" + lastTaskInstance.getTaskId())
.singleResult();
System.out.println(approvalStatusVariable.getValue());
}
}

}

} }

Loading…
Cancel
Save