diff --git a/src/main/java/com/xujie/modules/workFlow/entity/ErfFlowNodeInstance.java b/src/main/java/com/xujie/modules/workFlow/entity/ErfFlowNodeInstance.java index 151424a..9b661cf 100644 --- a/src/main/java/com/xujie/modules/workFlow/entity/ErfFlowNodeInstance.java +++ b/src/main/java/com/xujie/modules/workFlow/entity/ErfFlowNodeInstance.java @@ -12,7 +12,7 @@ import java.util.Date; /** * 节点实例实体类(审批记录) - rqrq - * 复合主键:apply_no + node_code + attempt_no + site + order_type + * 复合主键:apply_no + node_code + attempt_no + task_seq + site + order_type */ @Data @Alias("ErfFlowNodeInstance") @@ -34,6 +34,11 @@ public class ErfFlowNodeInstance extends QueryPage { */ private Integer attemptNo; + /** + * 同一节点同一轮次下的任务序号(会签/或签多审批人时每行递增,主键之一) - rqrq + */ + private Integer taskSeq; + /** * 工厂编码(主键之一) */ @@ -59,6 +64,11 @@ public class ErfFlowNodeInstance extends QueryPage { */ private Long assigneeUserId; + /** + * 审批人登录名(与 erf_flow_node_approver.approver_username 一致,用于待办匹配) - rqrq + */ + private String assigneeUsername; + /** * 审批人姓名 */ diff --git a/src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java b/src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java index f8d803e..6fbbf7c 100644 --- a/src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java +++ b/src/main/java/com/xujie/modules/workFlow/mapper/ErfFlowInstanceMapper.java @@ -58,8 +58,9 @@ public interface ErfFlowInstanceMapper extends BaseMapper { * 更新节点实例状态 */ void updateNodeInstanceStatus(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode, - @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("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); /** * 获取节点实例详情 @@ -80,10 +81,25 @@ public interface ErfFlowInstanceMapper extends BaseMapper { @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("site") String site, @Param("orderType") String orderType, + @Param("assigneeUsername") String assigneeUsername, @Param("assigneeDisplayName") String assigneeDisplayName); + + /** + * 统计节点当前轮次下仍为待办的任务数 - rqrq + */ + int countPendingNodeTasks(@Param("applyNo") String applyNo, @Param("nodeCode") String nodeCode, + @Param("attemptNo") Integer attemptNo, @Param("site") String site, @Param("orderType") String orderType); + + /** + * 将同节点同轮次下除指定序号外的待办任务批量更新为指定状态 - rqrq + */ + 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); /** * 删除指定单据的所有节点实例 - rqrq diff --git a/src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java b/src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java index a98e13c..ac1167d 100644 --- a/src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java +++ b/src/main/java/com/xujie/modules/workFlow/service/impl/ErfFlowInstanceServiceImpl.java @@ -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 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 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 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 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("重新审批流程实例结束"); } diff --git a/src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml b/src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml index 0565307..8aaeb63 100644 --- a/src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml +++ b/src/main/resources/mapper/workFlow/ErfFlowInstanceMapper.xml @@ -44,16 +44,18 @@ - 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, @@ -61,7 +63,6 @@ ni.receive_time, ni.complete_time, ni.duration_seconds, - ni.special_release, n.node_name, n.node_order, n.approve_type @@ -72,7 +73,7 @@ WHERE ni.apply_no = #{applyNo} AND ni.site = #{site} AND ni.order_type = #{orderType} - ORDER BY n.node_order, ni.attempt_no + ORDER BY n.node_order, ni.attempt_no, ni.task_seq @@ -87,13 +88,14 @@ + INSERT INTO erf_flow_node_instance ( - apply_no, node_code, attempt_no, site, order_type, - department_id, department_name, assignee_user_id, assignee_name, status, receive_time + 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 ) VALUES ( - #{applyNo}, #{nodeCode}, #{attemptNo}, #{site}, #{orderType}, - #{departmentId}, #{departmentName}, #{assigneeUserId}, #{assigneeName}, #{status}, GETDATE() + #{applyNo}, #{nodeCode}, #{attemptNo}, #{taskSeq}, #{site}, #{orderType}, + #{departmentId}, #{departmentName}, #{assigneeUserId}, #{assigneeUsername}, #{assigneeName}, #{status}, GETDATE() ) @@ -127,6 +129,7 @@ WHERE apply_no = #{applyNo} AND node_code = #{nodeCode} AND attempt_no = #{attemptNo} + AND task_seq = #{taskSeq} AND site = #{site} AND order_type = #{orderType} @@ -137,9 +140,11 @@ 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, @@ -194,14 +199,17 @@ + + + + + + + UPDATE erf_flow_node_instance + SET status = #{newStatus}, + 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 <> #{excludeTaskSeq} + + @@ -247,9 +286,11 @@ 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,