Commit df3489c4f238caab7afe1e959f75c6bd9b303e4d

Authored by YunaiV
1 parent 6f14c195

fix(bpm): 修复事务完成后自动审批无法推进流程

yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
@@ -60,6 +60,7 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity; @@ -60,6 +60,7 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity;
60 import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl; 60 import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
61 import org.springframework.context.annotation.Lazy; 61 import org.springframework.context.annotation.Lazy;
62 import org.springframework.stereotype.Service; 62 import org.springframework.stereotype.Service;
  63 +import org.springframework.transaction.annotation.Propagation;
63 import org.springframework.transaction.annotation.Transactional; 64 import org.springframework.transaction.annotation.Transactional;
64 import org.springframework.transaction.support.TransactionSynchronization; 65 import org.springframework.transaction.support.TransactionSynchronization;
65 import org.springframework.transaction.support.TransactionSynchronizationManager; 66 import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -569,6 +570,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -569,6 +570,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
569 570
570 // ========== Update 写入相关方法 ========== 571 // ========== Update 写入相关方法 ==========
571 572
  573 + /**
  574 + * 自动审批通过,供事务完成后的回调调用
  575 + *
  576 + * @see <a href="https://wx.zsxq.com/group/88858522214142/topic/22258281454841411">自动审批事务问题</a>
  577 + */
  578 + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
  579 + @DataPermission(enable = false)
  580 + public void approveTaskInternal(Long userId, BpmTaskApproveReqVO reqVO) {
  581 + approveTask(userId, reqVO);
  582 + }
  583 +
572 @Override 584 @Override
573 @Transactional(rollbackFor = Exception.class) 585 @Transactional(rollbackFor = Exception.class)
574 @DataPermission(enable = false) // 关闭数据权限,避免查询不到用户数据。相关案例:https://gitee.com/zhijiantianya/yudao-cloud/issues/ID1UYA 586 @DataPermission(enable = false) // 关闭数据权限,避免查询不到用户数据。相关案例:https://gitee.com/zhijiantianya/yudao-cloud/issues/ID1UYA
@@ -831,6 +843,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -831,6 +843,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
831 updateTaskStatusAndReason(task.getId(), BpmTaskStatusEnum.RUNNING.getStatus(), reqVO.getReason()); 843 updateTaskStatusAndReason(task.getId(), BpmTaskStatusEnum.RUNNING.getStatus(), reqVO.getReason());
832 } 844 }
833 845
  846 + /**
  847 + * 自动审批拒绝,供事务完成后的回调调用
  848 + *
  849 + * @see <a href="https://wx.zsxq.com/group/88858522214142/topic/22258281454841411">自动审批事务问题</a>
  850 + */
  851 + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
  852 + @DataPermission(enable = false)
  853 + public void rejectTaskInternal(Long userId, BpmTaskRejectReqVO reqVO) {
  854 + rejectTask(userId, reqVO);
  855 + }
  856 +
834 @Override 857 @Override
835 @Transactional(rollbackFor = Exception.class) 858 @Transactional(rollbackFor = Exception.class)
836 @DataPermission(enable = false) // 关闭数据权限,避免查询不到用户数据。相关案例:https://gitee.com/zhijiantianya/yudao-cloud/issues/ID1UYA 859 @DataPermission(enable = false) // 关闭数据权限,避免查询不到用户数据。相关案例:https://gitee.com/zhijiantianya/yudao-cloud/issues/ID1UYA
@@ -1433,19 +1456,19 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1433,19 +1456,19 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1433 return; 1456 return;
1434 } 1457 }
1435 if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.APPROVE.getType())) { 1458 if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.APPROVE.getType())) {
1436 - getSelf().approveTask(null, new BpmTaskApproveReqVO() 1459 + getSelf().approveTaskInternal(null, new BpmTaskApproveReqVO()
1437 .setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_APPROVE.getReason())); 1460 .setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_APPROVE.getReason()));
1438 } else if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.REJECT.getType())) { 1461 } else if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.REJECT.getType())) {
1439 - getSelf().rejectTask(null, new BpmTaskRejectReqVO() 1462 + getSelf().rejectTaskInternal(null, new BpmTaskRejectReqVO()
1440 .setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_REJECT.getReason())); 1463 .setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_REJECT.getReason()));
1441 } 1464 }
1442 // 特殊情况二:【自动审核】审批类型为自动通过、不通过 1465 // 特殊情况二:【自动审核】审批类型为自动通过、不通过
1443 } else { 1466 } else {
1444 if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_APPROVE.getType())) { 1467 if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_APPROVE.getType())) {
1445 - getSelf().approveTask(null, new BpmTaskApproveReqVO() 1468 + getSelf().approveTaskInternal(null, new BpmTaskApproveReqVO()
1446 .setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_APPROVE.getReason())); 1469 .setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_APPROVE.getReason()));
1447 } else if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_REJECT.getType())) { 1470 } else if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_REJECT.getType())) {
1448 - getSelf().rejectTask(null, new BpmTaskRejectReqVO() 1471 + getSelf().rejectTaskInternal(null, new BpmTaskRejectReqVO()
1449 .setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_REJECT.getReason())); 1472 .setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_REJECT.getReason()));
1450 } 1473 }
1451 } 1474 }
@@ -1526,7 +1549,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1526,7 +1549,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1526 .finished(); 1549 .finished();
1527 if (BpmAutoApproveTypeEnum.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType()) 1550 if (BpmAutoApproveTypeEnum.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
1528 && approvedTaskQuery.taskAssignee(task.getAssignee()).count() > 0) { 1551 && approvedTaskQuery.taskAssignee(task.getAssignee()).count() > 0) {
1529 - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1552 + getSelf().approveTaskInternal(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
1530 .setReason(BpmAutoApproveTypeEnum.APPROVE_ALL.getName())); 1553 .setReason(BpmAutoApproveTypeEnum.APPROVE_ALL.getName()));
1531 return; 1554 return;
1532 } 1555 }
@@ -1543,7 +1566,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1543,7 +1566,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1543 approvedTaskQuery.taskDefinitionKeys(sourceTaskIds).orderByTaskCreateTime().desc(); // 设置 taskIds, 并按创建时间倒序排序 1566 approvedTaskQuery.taskDefinitionKeys(sourceTaskIds).orderByTaskCreateTime().desc(); // 设置 taskIds, 并按创建时间倒序排序
1544 HistoricTaskInstance firstHisTask = CollUtil.getFirst(approvedTaskQuery.list()); 1567 HistoricTaskInstance firstHisTask = CollUtil.getFirst(approvedTaskQuery.list());
1545 if (firstHisTask != null && StrUtil.equals(firstHisTask.getAssignee(), task.getAssignee())) { 1568 if (firstHisTask != null && StrUtil.equals(firstHisTask.getAssignee(), task.getAssignee())) {
1546 - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1569 + getSelf().approveTaskInternal(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
1547 .setReason(BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getName())); 1570 .setReason(BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getName()));
1548 return; 1571 return;
1549 } 1572 }
@@ -1566,7 +1589,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1566,7 +1589,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1566 && (skipStartUserNodeFlag == null // 目的:一般是“主流程”,发起人节点,自动通过审核 1589 && (skipStartUserNodeFlag == null // 目的:一般是“主流程”,发起人节点,自动通过审核
1567 || BooleanUtil.isTrue(skipStartUserNodeFlag)) // 目的:一般是“子流程”,发起人节点,按配置自动通过审核 1590 || BooleanUtil.isTrue(skipStartUserNodeFlag)) // 目的:一般是“子流程”,发起人节点,按配置自动通过审核
1568 && ObjUtil.notEqual(returnTaskFlag, Boolean.TRUE)) { 1591 && ObjUtil.notEqual(returnTaskFlag, Boolean.TRUE)) {
1569 - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1592 + getSelf().approveTaskInternal(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
1570 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_SKIP_START_USER_NODE.getReason())); 1593 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_SKIP_START_USER_NODE.getReason()));
1571 return; 1594 return;
1572 } 1595 }
@@ -1579,7 +1602,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1579,7 +1602,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1579 // 情况一:自动跳过 1602 // 情况一:自动跳过
1580 if (ObjectUtils.equalsAny(assignStartUserHandlerType, 1603 if (ObjectUtils.equalsAny(assignStartUserHandlerType,
1581 BpmUserTaskAssignStartUserHandlerTypeEnum.SKIP.getType())) { 1604 BpmUserTaskAssignStartUserHandlerTypeEnum.SKIP.getType())) {
1582 - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1605 + getSelf().approveTaskInternal(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
1583 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_SKIP.getReason())); 1606 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_SKIP.getReason()));
1584 return; 1607 return;
1585 } 1608 }
@@ -1593,7 +1616,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -1593,7 +1616,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
1593 // 找不到部门负责人的情况下,自动审批通过 1616 // 找不到部门负责人的情况下,自动审批通过
1594 // noinspection DataFlowIssue 1617 // noinspection DataFlowIssue
1595 if (dept.getLeaderUserId() == null) { 1618 if (dept.getLeaderUserId() == null) {
1596 - getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) 1619 + getSelf().approveTaskInternal(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
1597 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_DEPT_LEADER_NOT_FOUND.getReason())); 1620 .setReason(BpmReasonEnum.ASSIGN_START_USER_APPROVE_WHEN_DEPT_LEADER_NOT_FOUND.getReason()));
1598 return; 1621 return;
1599 } 1622 }