常熟吴彦祖 14 hours ago
parent
commit
793db8d7e9
  1. 51
      src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java
  2. 6
      src/main/java/com/xujie/modules/workFlow/service/ErfFlowInstanceService.java
  3. 194
      src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java
  4. 375
      src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml

51
src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java

@ -29,7 +29,7 @@ public interface ErfFlowInstanceMapper extends BaseMapper<ErfFlowInstance> {
* 查询节点实例列表
*/
List<ErfFlowNodeInstanceData> searchNodeInstanceList(@Param("applyNo") String applyNo,
@Param("site") String site, @Param("orderType") String orderType);
@Param("site") String site, @Param("orderType") String orderType);
/**
* 插入流程实例
@ -45,73 +45,78 @@ public interface ErfFlowInstanceMapper extends BaseMapper<ErfFlowInstance> {
* 更新流程实例状态
*/
void updateInstanceStatus(@Param("applyNo") String applyNo, @Param("site") String site,
@Param("orderType") String orderType, @Param("status") String status,
@Param("currentNodeCode") String currentNodeCode);
@Param("orderType") String orderType, @Param("status") String status,
@Param("currentNodeCode") String currentNodeCode);
/**
* 更新流程实例完成
*/
void updateInstanceCompleted(@Param("applyNo") String applyNo, @Param("site") String site,
@Param("orderType") String orderType);
@Param("orderType") String orderType);
/**
* 更新节点实例状态
*/
void updateNodeInstanceStatus(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("taskSeq") Integer taskSeq, @Param("site") String site,
@Param("orderType") String orderType, @Param("status") String status, @Param("comment") String comment,
@Param("specialRelease") String specialRelease);
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType,
@Param("status") String status, @Param("comment") String comment, @Param("specialRelease") String specialRelease,
@Param("assigneeUsername") String assigneeUsername);
/**
* 获取节点实例详情
*/
ErfFlowNodeInstanceData getNodeInstanceDetail(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType);
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType);
/**
* 获取流程实例
*/
ErfFlowInstanceData getInstanceByApplyNo(@Param("applyNo") String applyNo, @Param("site") String site,
@Param("orderType") String orderType);
@Param("orderType") String orderType);
/**
* 获取当前节点的最大尝试次数
*/
Integer getMaxAttemptNo(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("site") String site, @Param("orderType") String orderType);
@Param("site") String site, @Param("orderType") String orderType);
/**
* 获取待审批的节点实例按当前登录用户名/展示名匹配审批人 - rqrq
* 获取待审批的节点实例
*/
ErfFlowNodeInstanceData getPendingNodeInstance(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("site") String site, @Param("orderType") String orderType,
@Param("assigneeUsername") String assigneeUsername, @Param("assigneeDisplayName") String assigneeDisplayName);
@Param("site") String site, @Param("orderType") String orderType,
@Param("assigneeUsername") String assigneeUsername, @Param("assigneeName") String assigneeName);
/**
* 统计节点当前轮次下仍为待办的任务数 - rqrq
* 指定节点下仍为 PENDING 的任务总数不区分审批人用于先判断是否有待办
*/
int countPendingNodeTasks(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType);
int countPendingForNode(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("site") String site, @Param("orderType") String orderType);
/**
* 将同节点同轮次下除指定序号外的待办任务批量更新为指定状态 - rqrq
* 当前节点当前轮次下仍为待办的任务数会签 ALL
*/
void updateOtherPendingNodeTasks(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType,
@Param("excludeTaskSeq") Integer excludeTaskSeq, @Param("newStatus") String newStatus,
@Param("comment") String comment);
int countPendingNodeInstances(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType);
/**
* 或签 ANY当前审批人已处理完毕后将其余仍为 PENDING 的同节点同轮次任务批量关闭不删行便于审计
*/
void skipRemainingPendingOnSameNodeAttempt(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode,
@Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType,
@Param("targetStatus") String targetStatus, @Param("comment") String comment);
/**
* 删除指定单据的所有节点实例 - rqrq
*/
void deleteNodeInstancesByApplyNo(@Param("applyNo") String applyNo, @Param("site") String site,
@Param("orderType") String orderType);
@Param("orderType") String orderType);
/**
* 重启流程实例 - rqrq
*/
void restartInstance(@Param("applyNo") String applyNo, @Param("site") String site,
@Param("orderType") String orderType, @Param("currentNodeCode") String currentNodeCode);
@Param("orderType") String orderType, @Param("currentNodeCode") String currentNodeCode);
ErfFlowInstance getInstanceByOrderRef1(@Param("orderRef1") String orderRef1, @Param("site") String site,@Param("orderType") String orderType);

6
src/main/java/com/xujie/modules/workFlow/service/ErfFlowInstanceService.java

@ -46,4 +46,10 @@ public interface ErfFlowInstanceService {
List<ErfFlowNodeInstanceData> getNodeInstanceList(String orderRef1, String site, String orderType);
ErfFlowNodeInstanceData getWaitApproveNode(String applyNo,String site,String orderType);
/**
* 根据审批单号获取流程实例
*/
ErfFlowInstanceData getInstanceByApplyNo(String applyNo, String site, String orderType);
}

194
src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java

@ -18,9 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
/**
* 流程实例Service实现类 - rqrq
@ -36,7 +34,6 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
@Autowired
private SrmSupplierMapper srmSupplierMapper;
@Override
public PageUtils searchInstanceList(ErfFlowInstanceData data) {
System.out.println("开始查询流程实例列表");
@ -89,6 +86,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("流程配置错误:审批节点未配置审批人");
}
validateApproverUsernamesForNode(approverList);
// 创建流程实例 - rqrq
ErfFlowInstance instance = new ErfFlowInstance();
instance.setApplyNo(applyNo);
@ -101,8 +105,23 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
instance.setCurrentNodeCode(firstApproveNode.getNodeCode());
erfFlowInstanceMapper.insertInstance(instance);
//创建节点实例会签/或签为每个审批人一行主键含 task_seq - rqrq
insertPendingNodeInstances(applyNo, site, orderType, 1, firstApproveNode);
// 创建节点实例为每个审批人创建一条记录主键含 assignee_username
for (ErfFlowNodeApproverData approver : approverList) {
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance();
nodeInstance.setApplyNo(applyNo);
nodeInstance.setNodeCode(firstApproveNode.getNodeCode());
nodeInstance.setAttemptNo(1);
nodeInstance.setSite(site);
nodeInstance.setOrderType(orderType);
nodeInstance.setAssigneeUsername(resolveApproverUsername(approver));
// 设置部门信息从节点配置获取- rqrq
nodeInstance.setDepartmentId(firstApproveNode.getDepartmentId());
nodeInstance.setDepartmentName(firstApproveNode.getDepartmentName());
nodeInstance.setAssigneeName(approver.getApproverName());
nodeInstance.setStatus("PENDING");
nodeInstance.setSpecialRelease("N");
erfFlowInstanceMapper.insertNodeInstance(nodeInstance);
}
System.out.println("创建流程实例结束");
return applyNo;
@ -118,8 +137,6 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
if (currentUser == null) {
throw new RuntimeException("获取当前用户信息失败,请重新登录");
}
String currentUserDisplay = currentUser.getUserDisplay();
// 获取流程实例
ErfFlowInstanceData instance = erfFlowInstanceMapper.getInstanceByApplyNo(
data.getApplyNo(), data.getSite(), data.getOrderType());
@ -127,47 +144,57 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
throw new RuntimeException("流程实例不存在");
}
// 获取当前登录用户对应的待审批任务会签多人时按用户名匹配 - rqrq
String operatorUsername = currentUser.getUsername() != null ? currentUser.getUsername() : "";
String operatorDisplay = currentUser.getUserDisplay() != null ? currentUser.getUserDisplay() : "";
// 先判断该节点是否还有待办不区分审批人
int pendingOnNode = erfFlowInstanceMapper.countPendingForNode(
data.getApplyNo(), data.getNodeCode(), data.getSite(), data.getOrderType());
if (pendingOnNode <= 0) {
throw new RuntimeException("未找到待审批的节点");
}
// 再匹配当前登录人自己的任务会签/或签多人时每人一行
ErfFlowNodeInstanceData nodeInstance = erfFlowInstanceMapper.getPendingNodeInstance(
data.getApplyNo(), data.getNodeCode(), data.getSite(), data.getOrderType(),
operator, currentUserDisplay);
operatorUsername, operatorDisplay);
if (nodeInstance == null) {
throw new RuntimeException("未找到待审批的节点");
throw new RuntimeException("该节点不需要您审批");
}
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("您不是该节点的审批人,无法进行审批操作");
}
String assigneeUsernameKey = nodeInstance.getAssigneeUsername() != null ? nodeInstance.getAssigneeUsername() : "";
// 更新节点实例状态含特殊放行标记- rqrq
erfFlowInstanceMapper.updateNodeInstanceStatus(
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(), nodeInstance.getTaskSeq(),
data.getSite(), data.getOrderType(), data.getAction(), data.getComment(), data.getSpecialRelease());
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(),
data.getSite(), data.getOrderType(), data.getAction(), data.getComment(), data.getSpecialRelease(),
assigneeUsernameKey);
// 处理审批结果
if ("APPROVED".equals(data.getAction())) {
String approveType = nodeInstance.getApproveType() != null ? nodeInstance.getApproveType() : "SINGLE";
nodeInstance.setSpecialRelease(data.getSpecialRelease());
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 {
// 或签 ANY一人通过即流转其余待办关闭为 SKIPPED当前行已变为 APPROVED不在 PENDING
if ("ANY".equals(nodeInstance.getApproveType())) {
erfFlowInstanceMapper.skipRemainingPendingOnSameNodeAttempt(
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(),
data.getSite(), data.getOrderType(), "SKIPPED", "或签:已由他人审批通过");
}
// 会签 ALL须本节点本 attempt 下无其它 PENDING 才流转
boolean advance = true;
if ("ALL".equals(nodeInstance.getApproveType())) {
int pendingLeft = erfFlowInstanceMapper.countPendingNodeInstances(
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(),
data.getSite(), data.getOrderType());
advance = pendingLeft <= 0;
}
if (advance) {
nodeInstance.setSpecialRelease(data.getSpecialRelease());
activateNextNode(instance, nodeInstance);
}
} else if ("REJECTED".equals(data.getAction())) {
erfFlowInstanceMapper.updateOtherPendingNodeTasks(data.getApplyNo(), data.getNodeCode(),
nodeInstance.getAttemptNo(), data.getSite(), data.getOrderType(), nodeInstance.getTaskSeq(),
"CANCELLED", "节点已驳回,任务关闭");
if ("ANY".equals(nodeInstance.getApproveType())) {
erfFlowInstanceMapper.skipRemainingPendingOnSameNodeAttempt(
data.getApplyNo(), data.getNodeCode(), nodeInstance.getAttemptNo(),
data.getSite(), data.getOrderType(), "SKIPPED", "或签:流程已驳回,待办关闭");
}
// 终止流程
erfFlowInstanceMapper.updateInstanceStatus(
data.getApplyNo(), data.getSite(), data.getOrderType(),
"TERMINATED", nodeInstance.getNodeCode());
@ -203,30 +230,20 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
erfFlowInstanceMapper.updateInstanceStatus(instance.getApplyNo(), instance.getSite(),
instance.getOrderType(), "RUNNING", nextNode.getNodeCode());
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;
// 获取审批人并创建节点实例
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(nextNode.getId());
validateApproverUsernamesForNode(approverList);
for (ErfFlowNodeApproverData approver : approverList) {
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance();
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.setApplyNo(instance.getApplyNo());
nodeInstance.setNodeCode(nextNode.getNodeCode());
nodeInstance.setAttemptNo(1);
nodeInstance.setSite(instance.getSite());
nodeInstance.setOrderType(instance.getOrderType());
nodeInstance.setAssigneeUsername(resolveApproverUsername(approver));
// 设置部门信息从节点配置获取- rqrq
nodeInstance.setDepartmentId(nextNode.getDepartmentId());
nodeInstance.setDepartmentName(nextNode.getDepartmentName());
nodeInstance.setAssigneeName(approver.getApproverName());
nodeInstance.setStatus("PENDING");
nodeInstance.setSpecialRelease("N");
@ -234,6 +251,33 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
}
}
private static String resolveApproverUsername(ErfFlowNodeApproverData approver) {
String u = approver.getApproverUsername();
if (u == null) {
return "";
}
return u.trim();
}
/**
* 多人节点须配置互不相同的 approver_username否则无法落库主键冲突
*/
private void validateApproverUsernamesForNode(List<ErfFlowNodeApproverData> approverList) {
if (approverList == null || approverList.size() <= 1) {
return;
}
Set<String> seen = new HashSet<>();
for (ErfFlowNodeApproverData approver : approverList) {
String key = resolveApproverUsername(approver);
if (key.isEmpty()) {
throw new RuntimeException("会签/多人节点须为每位审批人配置登录账号(approver_username)");
}
if (!seen.add(key)) {
throw new RuntimeException("同一审批节点内审批人登录账号不能重复:" + key);
}
}
}
@Override
public ErfFlowTemplateData getFlowPreview(String flowCode, Integer flowVersion, String site) {
System.out.println("获取流程预览,流程编码:" + flowCode + ",版本:" + flowVersion);
@ -273,7 +317,7 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
}
// 验证状态只有已完成或已终止的流程才能重新审批
if (!"COMPLETED".equals(instance.getStatus()) && !"TERMINATED".equals(instance.getStatus())) {
if (!"COMPLETED".equals(instance.getStatus()) && !"TERMINATED".equals(instance.getStatus()) && !"REJECTED".equals(instance.getStatus())) {
throw new RuntimeException("只有已完成或已终止的流程才能重新审批");
}
@ -304,13 +348,36 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
throw new RuntimeException("流程配置错误:未找到审批节点");
}
// 获取审批人
List<ErfFlowNodeApproverData> approverList = erfFlowTemplateMapper.getApproverListByNodeId(firstApproveNode.getId());
if (approverList == null || approverList.isEmpty()) {
throw new RuntimeException("流程配置错误:审批节点未配置审批人");
}
validateApproverUsernamesForNode(approverList);
// 删除原有的所有节点实例
erfFlowInstanceMapper.deleteNodeInstancesByApplyNo(applyNo, site, orderType);
// 重置流程实例状态
erfFlowInstanceMapper.restartInstance(applyNo, site, orderType, firstApproveNode.getNodeCode());
insertPendingNodeInstances(applyNo, site, orderType, 1, firstApproveNode);
// 创建第一个节点实例为每个审批人创建一条记录
for (ErfFlowNodeApproverData approver : approverList) {
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance();
nodeInstance.setApplyNo(applyNo);
nodeInstance.setNodeCode(firstApproveNode.getNodeCode());
nodeInstance.setAttemptNo(1);
nodeInstance.setSite(site);
nodeInstance.setOrderType(orderType);
nodeInstance.setAssigneeUsername(resolveApproverUsername(approver));
// 设置部门信息从节点配置获取- rqrq
nodeInstance.setDepartmentId(firstApproveNode.getDepartmentId());
nodeInstance.setDepartmentName(firstApproveNode.getDepartmentName());
nodeInstance.setAssigneeName(approver.getApproverName());
nodeInstance.setStatus("PENDING");
nodeInstance.setSpecialRelease("N");
erfFlowInstanceMapper.insertNodeInstance(nodeInstance);
}
System.out.println("重新审批流程实例结束");
}
@ -340,5 +407,10 @@ public class ErfFlowInstanceServiceImpl extends ServiceImpl<ErfFlowInstanceMappe
return null;
}
@Override
public ErfFlowInstanceData getInstanceByApplyNo(String applyNo, String site, String orderType) {
return erfFlowInstanceMapper.getInstanceByApplyNo(applyNo, site, orderType);
}
}

375
src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml

@ -2,27 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- rqrq - 流程实例Mapper XML -->
<mapper namespace="com.xujie.modules.workFlow.mapper.ErfFlowInstanceMapper">
<!-- 查询流程实例列表(分页) - rqrq -->
<select id="searchInstanceList" resultType="ErfFlowInstanceData">
SELECT
i.apply_no,
i.order_ref1,
i.site,
i.order_type,
i.flow_code,
i.flow_version,
i.status,
i.current_node_code,
i.start_time,
i.end_time,
i.remark,
t.flow_name,
n.node_name AS currentNodeName
i.apply_no,
i.order_ref1,
i.site,
i.order_type,
i.flow_code,
i.flow_version,
i.status,
i.current_node_code,
i.start_time,
i.end_time,
i.remark,
t.flow_name,
n.node_name AS currentNodeName
FROM erf_flow_instance i
LEFT JOIN erf_flow_template t ON t.flow_code = i.flow_code AND t.flow_version = i.flow_version AND t.site = i.site
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = i.current_node_code
AND n.site = i.site AND n.node_code = i.current_node_code
<where>
<if test="query.site != null and query.site != ''">
AND i.site = #{query.site}
@ -44,58 +43,56 @@
</select>
<!-- 查询节点实例列表 -->
<select id="searchNodeInstanceList" resultType="ErfFlowNodeInstanceData">
<select id="searchNodeInstanceList" resultType="ErfFlowNodeInstanceData">
SELECT
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.task_seq,
ni.site,
ni.order_type,
ni.department_id,
ni.department_name,
ni.assignee_user_id,
ni.assignee_username,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
ni.duration_seconds,
n.node_name,
n.node_order,
n.approve_type
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.site,
ni.order_type,
ni.assignee_username,
ni.department_id,
ni.department_name,
ni.assignee_user_id,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
ni.duration_seconds,
n.node_name,
n.node_order,
n.approve_type
FROM erf_flow_node_instance ni
LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = ni.node_code
AND n.site = i.site AND n.node_code = ni.node_code
WHERE ni.apply_no = #{applyNo}
AND ni.site = #{site}
AND ni.order_type = #{orderType}
ORDER BY n.node_order, ni.attempt_no, ni.task_seq
AND ni.site = #{site}
AND ni.order_type = #{orderType}
ORDER BY n.node_order, ni.attempt_no
</select>
<!-- 插入流程实例 - rqrq -->
<insert id="insertInstance">
INSERT INTO erf_flow_instance (
apply_no, order_ref1, site, order_type, flow_code, flow_version,
status, current_node_code, start_time
apply_no, order_ref1, site, order_type, flow_code, flow_version,
status, current_node_code, start_time
) VALUES (
#{applyNo}, #{orderRef1}, #{site}, #{orderType}, #{flowCode}, #{flowVersion},
#{status}, #{currentNodeCode}, GETDATE()
#{applyNo}, #{orderRef1}, #{site}, #{orderType}, #{flowCode}, #{flowVersion},
#{status}, #{currentNodeCode}, GETDATE()
)
</insert>
<!-- 插入节点实例 -->
<!-- rqrq -插入节点实例(含 task_seq、assignee_username,支持会签/或签多行) -->
<insert id="insertNodeInstance">
INSERT INTO erf_flow_node_instance (
apply_no, node_code, attempt_no, task_seq, site, order_type,
department_id, department_name, assignee_user_id, assignee_username, assignee_name, status, receive_time
apply_no, node_code, attempt_no, site, order_type, assignee_username,
department_id, department_name, assignee_user_id, assignee_name, status, receive_time, special_release
) VALUES (
#{applyNo}, #{nodeCode}, #{attemptNo}, #{taskSeq}, #{site}, #{orderType},
#{departmentId}, #{departmentName}, #{assigneeUserId}, #{assigneeUsername}, #{assigneeName}, #{status}, GETDATE()
#{applyNo}, #{nodeCode}, #{attemptNo}, #{site}, #{orderType}, #{assigneeUsername},
#{departmentId}, #{departmentName}, #{assigneeUserId}, #{assigneeName}, #{status}, GETDATE(), #{specialRelease}
)
</insert>
@ -103,89 +100,87 @@
<update id="updateInstanceStatus">
UPDATE erf_flow_instance
SET status = #{status},
current_node_code = #{currentNodeCode}
current_node_code = #{currentNodeCode}
WHERE apply_no = #{applyNo}
AND site = #{site}
AND order_type = #{orderType}
AND site = #{site}
AND order_type = #{orderType}
</update>
<!-- 更新流程实例完成 -->
<update id="updateInstanceCompleted">
UPDATE erf_flow_instance
SET status = 'COMPLETED',
end_time = GETDATE()
end_time = GETDATE()
WHERE apply_no = #{applyNo}
AND site = #{site}
AND order_type = #{orderType}
AND site = #{site}
AND order_type = #{orderType}
</update>
<!-- 更新节点实例状态 -->
<update id="updateNodeInstanceStatus">
UPDATE erf_flow_node_instance
SET status = #{status},
comment = #{comment},
special_release = #{specialRelease},
complete_time = GETDATE()
comment = #{comment},
special_release = #{specialRelease},
complete_time = GETDATE()
WHERE apply_no = #{applyNo}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND task_seq = #{taskSeq}
AND site = #{site}
AND order_type = #{orderType}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND site = #{site}
AND order_type = #{orderType}
AND assignee_username = #{assigneeUsername}
</update>
<!-- 获取节点实例详情 -->
<select id="getNodeInstanceDetail" resultType="ErfFlowNodeInstanceData">
SELECT
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.task_seq,
ni.site,
ni.order_type,
ni.assignee_user_id,
ni.assignee_username,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
n.node_name,
n.node_order,
n.approve_type,
i.flow_code,
i.flow_version
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.site,
ni.order_type,
ni.assignee_user_id,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
n.node_name,
n.node_order,
n.approve_type,
i.flow_code,
i.flow_version
FROM erf_flow_node_instance ni
LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = ni.node_code
AND n.site = i.site AND n.node_code = ni.node_code
WHERE ni.apply_no = #{applyNo}
AND ni.node_code = #{nodeCode}
AND ni.attempt_no = #{attemptNo}
AND ni.site = #{site}
AND ni.order_type = #{orderType}
AND ni.node_code = #{nodeCode}
AND ni.attempt_no = #{attemptNo}
AND ni.site = #{site}
AND ni.order_type = #{orderType}
</select>
<!-- 获取流程实例 - rqrq -->
<select id="getInstanceByApplyNo" resultType="ErfFlowInstanceData">
SELECT
i.apply_no,
i.order_ref1,
i.site,
i.order_type,
i.flow_code,
i.flow_version,
i.status,
i.current_node_code,
i.start_time,
i.end_time,
t.flow_name
i.apply_no,
i.order_ref1,
i.site,
i.order_type,
i.flow_code,
i.flow_version,
i.status,
i.current_node_code,
i.start_time,
i.end_time,
t.flow_name
FROM erf_flow_instance i
LEFT JOIN erf_flow_template t ON t.flow_code = i.flow_code AND t.flow_version = i.flow_version AND t.site = i.site
WHERE i.apply_no = #{applyNo}
AND i.site = #{site}
AND i.order_type = #{orderType}
AND i.site = #{site}
AND i.order_type = #{orderType}
</select>
<!-- 获取当前节点的最大尝试次数 -->
@ -193,120 +188,123 @@
SELECT ISNULL(MAX(attempt_no), 0)
FROM erf_flow_node_instance
WHERE apply_no = #{applyNo}
AND node_code = #{nodeCode}
AND site = #{site}
AND order_type = #{orderType}
AND node_code = #{nodeCode}
AND site = #{site}
AND order_type = #{orderType}
</select>
<!-- 获取待审批的节点实例 -->
<!-- rqrq - 待办按审批人精确匹配,避免会签多人时取错行 -->
<!-- 获取待审批的节点实例(当前登录人对应的一条;assignee_username 与 approver_username 一致) -->
<select id="getPendingNodeInstance" resultType="ErfFlowNodeInstanceData">
SELECT TOP 1
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.task_seq,
ni.site,
ni.order_type,
ni.assignee_user_id,
ni.assignee_username,
ni.assignee_name,
ni.status,
ni.special_release,
n.node_name,
n.node_order,
n.approve_type,
n.node_type
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.site,
ni.order_type,
ni.assignee_username,
ni.assignee_user_id,
ni.assignee_name,
ni.status,
ni.special_release,
n.node_name,
n.node_order,
n.approve_type,
n.node_type
FROM erf_flow_node_instance ni
LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = ni.node_code
AND n.site = i.site AND n.node_code = ni.node_code
WHERE ni.apply_no = #{applyNo}
AND ni.node_code = #{nodeCode}
AND ni.site = #{site}
AND ni.order_type = #{orderType}
AND ni.status = 'PENDING'
AND (
(ni.assignee_username IS NOT NULL AND ni.assignee_username = #{assigneeUsername})
OR (ni.assignee_username IS NULL AND ni.assignee_name = #{assigneeDisplayName})
)
ORDER BY ni.attempt_no DESC, ni.task_seq ASC
AND ni.node_code = #{nodeCode}
AND ni.site = #{site}
AND ni.order_type = #{orderType}
AND ni.status = 'PENDING'
AND (
ni.assignee_username = #{assigneeUsername}
OR (ISNULL(ni.assignee_username, N'') = N'' AND ni.assignee_name = #{assigneeName})
)
ORDER BY ni.attempt_no DESC
</select>
<!-- rqrq - 当前节点轮次待办数量 -->
<select id="countPendingNodeTasks" resultType="int">
<select id="countPendingForNode" resultType="int">
SELECT COUNT(1)
FROM erf_flow_node_instance
WHERE apply_no = #{applyNo}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND site = #{site}
AND order_type = #{orderType}
AND status = 'PENDING'
AND node_code = #{nodeCode}
AND site = #{site}
AND order_type = #{orderType}
AND status = 'PENDING'
</select>
<!-- rqrq - 批量关闭同节点其他待办(或签跳过 / 驳回关闭) -->
<update id="updateOtherPendingNodeTasks">
<select id="countPendingNodeInstances" resultType="int">
SELECT COUNT(1)
FROM erf_flow_node_instance
WHERE apply_no = #{applyNo}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND site = #{site}
AND order_type = #{orderType}
AND status = 'PENDING'
</select>
<update id="skipRemainingPendingOnSameNodeAttempt">
UPDATE erf_flow_node_instance
SET status = #{newStatus},
comment = #{comment},
complete_time = GETDATE()
SET status = #{targetStatus},
comment = #{comment},
complete_time = GETDATE()
WHERE apply_no = #{applyNo}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND site = #{site}
AND order_type = #{orderType}
AND status = 'PENDING'
AND task_seq &lt;&gt; #{excludeTaskSeq}
AND node_code = #{nodeCode}
AND attempt_no = #{attemptNo}
AND site = #{site}
AND order_type = #{orderType}
AND status = 'PENDING'
</update>
<!-- 删除指定单据的所有节点实例 - rqrq -->
<delete id="deleteNodeInstancesByApplyNo">
DELETE FROM erf_flow_node_instance
WHERE apply_no = #{applyNo}
AND site = #{site}
AND order_type = #{orderType}
AND site = #{site}
AND order_type = #{orderType}
</delete>
<!-- 重启流程实例 - rqrq -->
<update id="restartInstance">
UPDATE erf_flow_instance
SET status = 'RUNNING',
current_node_code = #{currentNodeCode},
start_time = GETDATE(),
end_time = NULL
current_node_code = #{currentNodeCode},
start_time = GETDATE(),
end_time = NULL
WHERE apply_no = #{applyNo}
AND site = #{site}
AND order_type = #{orderType}
AND site = #{site}
AND order_type = #{orderType}
</update>
<select id="nodeInstanceList" resultType="com.xujie.modules.workFlow.data.ErfFlowNodeInstanceData">
SELECT
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.task_seq,
ni.site,
ni.order_type,
ni.assignee_user_id,
ni.assignee_username,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
ni.department_name,
n.node_name,
n.node_order,
n.approve_type,
i.flow_code,
i.flow_version
ni.apply_no,
ni.node_code,
ni.attempt_no,
ni.site,
ni.order_type,
ni.assignee_username,
ni.assignee_user_id,
ni.assignee_name,
ni.status,
ni.comment,
ni.special_release,
ni.receive_time,
ni.complete_time,
ni.department_name,
n.node_name,
n.node_order,
n.approve_type,
i.flow_code,
i.flow_version
FROM erf_flow_node_instance ni
LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = ni.node_code
LEFT JOIN erf_flow_instance i ON i.apply_no = ni.apply_no AND i.site = ni.site AND i.order_type = ni.order_type
LEFT JOIN erf_flow_node n ON n.flow_code = i.flow_code AND n.flow_version = i.flow_version
AND n.site = i.site AND n.node_code = ni.node_code
WHERE ni.site = #{site}
<if test="applyNo != null and applyNo != '' "> and ni.apply_no = #{applyNo}</if>
<if test="status != null and status != '' "> and ni.status = #{status}</if>
@ -314,10 +312,10 @@
</select>
<select id="searchNodeApproverList" resultType="com.xujie.modules.workFlow.data.ErfFlowNodeApproverData">
SELECT
na.node_id,
na.approver_username,
na.approver_name,
na.approver_order
na.node_id,
na.approver_username,
na.approver_name,
na.approver_order
from erf_flow_node_approver na
left join erf_flow_node n on n.id = na.node_id
left join erf_flow_node_instance ni on ni.node_code = n.node_code
@ -329,18 +327,19 @@
<select id="getInstanceByOrderRef1" resultType="com.xujie.modules.workFlow.entity.ErfFlowInstance">
SELECT apply_no, order_ref1, site, order_type, flow_code, flow_version,
status, current_node_code
status, current_node_code
FROM erf_flow_instance
WHERE order_ref1 = #{orderRef1}
AND site = #{site}
AND order_type = #{orderType}
AND site = #{site}
AND order_type = #{orderType}
</select>
<select id="getFlowNodeData" resultType="com.xujie.modules.workFlow.data.ErfFlowNodeData">
SELECT
id,node_code,node_name,node_order,node_type,approve_type,site,flow_code,flow_version,department_id,department_name
id,node_code,node_name,node_order,node_type,approve_type,site,flow_code,flow_version,department_id,department_name
FROM erf_flow_node
WHERE node_code = #{nodeCode}
AND site = #{site}
AND site = #{site}
</select>
</mapper>
Loading…
Cancel
Save