|
|
|
@ -21,7 +21,6 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 流程实例Service实现类 - rqrq |
|
|
|
@ -90,12 +89,6 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe |
|
|
|
throw new RuntimeException("流程配置错误:未找到审批节点"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取审批人 |
|
|
|
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(firstApproveNode.getId()); |
|
|
|
if (approverList == null || approverList.isEmpty()) { |
|
|
|
throw new RuntimeException("流程配置错误:审批节点未配置审批人"); |
|
|
|
} |
|
|
|
|
|
|
|
// 创建流程实例 - rqrq |
|
|
|
ErfFlowInstance instance = new ErfFlowInstance(); |
|
|
|
instance.setApplyNo(applyNo); |
|
|
|
@ -108,23 +101,8 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe |
|
|
|
instance.setCurrentNodeCode(firstApproveNode.getNodeCode()); |
|
|
|
erfFlowInstanceMapper.insertInstance(instance); |
|
|
|
|
|
|
|
// 创建节点实例(为每个审批人创建一条记录) |
|
|
|
for (ErfFlowNodeApproverData approver : approverList) { |
|
|
|
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance(); |
|
|
|
nodeInstance.setApplyNo(applyNo); |
|
|
|
nodeInstance.setNodeCode(firstApproveNode.getNodeCode()); |
|
|
|
nodeInstance.setAttemptNo(1); |
|
|
|
nodeInstance.setSite(site); |
|
|
|
nodeInstance.setOrderType(orderType); |
|
|
|
// 设置部门信息(从节点配置获取)- rqrq |
|
|
|
nodeInstance.setDepartmentId(firstApproveNode.getDepartmentId()); |
|
|
|
nodeInstance.setDepartmentName(firstApproveNode.getDepartmentName()); |
|
|
|
// 需要通过username查找用户ID |
|
|
|
nodeInstance.setAssigneeName(approver.getApproverName()); |
|
|
|
nodeInstance.setStatus("PENDING"); |
|
|
|
nodeInstance.setSpecialRelease("N"); |
|
|
|
erfFlowInstanceMapper.insertNodeInstance(nodeInstance); |
|
|
|
} |
|
|
|
//创建节点实例(会签/或签为每个审批人一行,主键含 task_seq) - rqrq |
|
|
|
insertPendingNodeInstances(applyNo, site, orderType, 1, firstApproveNode); |
|
|
|
|
|
|
|
System.out.println("创建流程实例结束"); |
|
|
|
return applyNo; |
|
|
|
@ -149,30 +127,47 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe |
|
|
|
throw new RuntimeException("流程实例不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取待审批的节点实例 |
|
|
|
// 获取当前登录用户对应的待审批任务(会签多人时按用户名匹配) - rqrq |
|
|
|
ErfFlowNodeInstanceData nodeInstance = erfFlowInstanceMapper.getPendingNodeInstance( |
|
|
|
data.getApplyNo(), data.getNodeCode(), data.getSite(), data.getOrderType()); |
|
|
|
data.getApplyNo(), data.getNodeCode(), data.getSite(), data.getOrderType(), |
|
|
|
operator, currentUserDisplay); |
|
|
|
if (nodeInstance == null) { |
|
|
|
throw new RuntimeException("未找到待审批的节点"); |
|
|
|
} |
|
|
|
|
|
|
|
// 校验当前用户是否是审批人 - rqrq |
|
|
|
if (nodeInstance.getAssigneeName() != null && !nodeInstance.getAssigneeName().equals(currentUserDisplay)) { |
|
|
|
if (nodeInstance.getAssigneeUsername() != null && !nodeInstance.getAssigneeUsername().equals(operator)) { |
|
|
|
throw new RuntimeException("您不是该节点的审批人,无法进行审批操作"); |
|
|
|
} |
|
|
|
if (nodeInstance.getAssigneeUsername() == null && nodeInstance.getAssigneeName() != null |
|
|
|
&& !nodeInstance.getAssigneeName().equals(currentUserDisplay)) { |
|
|
|
throw new RuntimeException("您不是该节点的审批人,无法进行审批操作"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新节点实例状态(含特殊放行标记)- rqrq |
|
|
|
erfFlowInstanceMapper.updateNodeInstanceStatus( |
|
|
|
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(), |
|
|
|
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(), nodeInstance.getTaskSeq(), |
|
|
|
data.getSite(), data.getOrderType(), data.getAction(), data.getComment(), data.getSpecialRelease()); |
|
|
|
|
|
|
|
// 处理审批结果 |
|
|
|
if ("APPROVED".equals(data.getAction())) { |
|
|
|
// 激活下一个节点 |
|
|
|
String approveType = nodeInstance.getApproveType() != null ? nodeInstance.getApproveType() : "SINGLE"; |
|
|
|
nodeInstance.setSpecialRelease(data.getSpecialRelease()); |
|
|
|
activateNextNode(instance, nodeInstance); |
|
|
|
if ("ALL".equals(approveType)) { |
|
|
|
int pendingLeft = erfFlowInstanceMapper.countPendingNodeTasks(data.getApplyNo(), data.getNodeCode(), |
|
|
|
nodeInstance.getAttemptNo(), data.getSite(), data.getOrderType()); |
|
|
|
if (pendingLeft == 0) { |
|
|
|
activateNextNode(instance, nodeInstance); |
|
|
|
} |
|
|
|
} else if ("ANY".equals(approveType)) { |
|
|
|
erfFlowInstanceMapper.updateOtherPendingNodeTasks(data.getApplyNo(), data.getNodeCode(), |
|
|
|
nodeInstance.getAttemptNo(), data.getSite(), data.getOrderType(), nodeInstance.getTaskSeq(), |
|
|
|
"SKIPPED", "或签:已有他人审批通过"); |
|
|
|
activateNextNode(instance, nodeInstance); |
|
|
|
} else { |
|
|
|
activateNextNode(instance, nodeInstance); |
|
|
|
} |
|
|
|
} else if ("REJECTED".equals(data.getAction())) { |
|
|
|
// 终止流程 |
|
|
|
erfFlowInstanceMapper.updateOtherPendingNodeTasks(data.getApplyNo(), data.getNodeCode(), |
|
|
|
nodeInstance.getAttemptNo(), data.getSite(), data.getOrderType(), nodeInstance.getTaskSeq(), |
|
|
|
"CANCELLED", "节点已驳回,任务关闭"); |
|
|
|
erfFlowInstanceMapper.updateInstanceStatus( |
|
|
|
data.getApplyNo(), data.getSite(), data.getOrderType(), |
|
|
|
"TERMINATED", nodeInstance.getNodeCode()); |
|
|
|
@ -208,20 +203,33 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe |
|
|
|
erfFlowInstanceMapper.updateInstanceStatus(instance.getApplyNo(), instance.getSite(), |
|
|
|
instance.getOrderType(), "RUNNING", nextNode.getNodeCode()); |
|
|
|
|
|
|
|
// 获取审批人并创建节点实例 |
|
|
|
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(nextNode.getId()); |
|
|
|
insertPendingNodeInstances(instance.getApplyNo(), instance.getSite(), instance.getOrderType(), 1, nextNode); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 按节点定义生成待办任务行(每人一行) - rqrq |
|
|
|
*/ |
|
|
|
private void insertPendingNodeInstances(String applyNo, String site, String orderType, int attemptNo, |
|
|
|
ErfFlowNodeData node) { |
|
|
|
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(node.getId()); |
|
|
|
if (approverList == null || approverList.isEmpty()) { |
|
|
|
throw new RuntimeException("流程配置错误:审批节点未配置审批人"); |
|
|
|
} |
|
|
|
int taskSeq = 1; |
|
|
|
for (ErfFlowNodeApproverData approver : approverList) { |
|
|
|
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance(); |
|
|
|
nodeInstance.setApplyNo(instance.getApplyNo()); |
|
|
|
nodeInstance.setNodeCode(nextNode.getNodeCode()); |
|
|
|
nodeInstance.setAttemptNo(1); |
|
|
|
nodeInstance.setSite(instance.getSite()); |
|
|
|
nodeInstance.setOrderType(instance.getOrderType()); |
|
|
|
// 设置部门信息(从节点配置获取)- rqrq |
|
|
|
nodeInstance.setDepartmentId(nextNode.getDepartmentId()); |
|
|
|
nodeInstance.setDepartmentName(nextNode.getDepartmentName()); |
|
|
|
nodeInstance.setApplyNo(applyNo); |
|
|
|
nodeInstance.setNodeCode(node.getNodeCode()); |
|
|
|
nodeInstance.setAttemptNo(attemptNo); |
|
|
|
nodeInstance.setTaskSeq(taskSeq++); |
|
|
|
nodeInstance.setSite(site); |
|
|
|
nodeInstance.setOrderType(orderType); |
|
|
|
nodeInstance.setDepartmentId(node.getDepartmentId()); |
|
|
|
nodeInstance.setDepartmentName(node.getDepartmentName()); |
|
|
|
nodeInstance.setAssigneeUsername(approver.getApproverUsername()); |
|
|
|
nodeInstance.setAssigneeName(approver.getApproverName()); |
|
|
|
nodeInstance.setStatus("PENDING"); |
|
|
|
nodeInstance.setSpecialRelease("N"); |
|
|
|
erfFlowInstanceMapper.insertNodeInstance(nodeInstance); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -296,33 +304,13 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe |
|
|
|
throw new RuntimeException("流程配置错误:未找到审批节点"); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取审批人 |
|
|
|
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(firstApproveNode.getId()); |
|
|
|
if (approverList == null || approverList.isEmpty()) { |
|
|
|
throw new RuntimeException("流程配置错误:审批节点未配置审批人"); |
|
|
|
} |
|
|
|
|
|
|
|
// 删除原有的所有节点实例 |
|
|
|
erfFlowInstanceMapper.deleteNodeInstancesByApplyNo(applyNo, site, orderType); |
|
|
|
|
|
|
|
// 重置流程实例状态 |
|
|
|
erfFlowInstanceMapper.restartInstance(applyNo, site, orderType, firstApproveNode.getNodeCode()); |
|
|
|
|
|
|
|
// 创建第一个节点实例(为每个审批人创建一条记录) |
|
|
|
for (ErfFlowNodeApproverData approver : approverList) { |
|
|
|
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance(); |
|
|
|
nodeInstance.setApplyNo(applyNo); |
|
|
|
nodeInstance.setNodeCode(firstApproveNode.getNodeCode()); |
|
|
|
nodeInstance.setAttemptNo(1); |
|
|
|
nodeInstance.setSite(site); |
|
|
|
nodeInstance.setOrderType(orderType); |
|
|
|
// 设置部门信息(从节点配置获取)- rqrq |
|
|
|
nodeInstance.setDepartmentId(firstApproveNode.getDepartmentId()); |
|
|
|
nodeInstance.setDepartmentName(firstApproveNode.getDepartmentName()); |
|
|
|
nodeInstance.setAssigneeName(approver.getApproverName()); |
|
|
|
nodeInstance.setStatus("PENDING"); |
|
|
|
erfFlowInstanceMapper.insertNodeInstance(nodeInstance); |
|
|
|
} |
|
|
|
insertPendingNodeInstances(applyNo, site, orderType, 1, firstApproveNode); |
|
|
|
|
|
|
|
System.out.println("重新审批流程实例结束"); |
|
|
|
} |
|
|
|
|