|
|
|
@ -107,102 +107,61 @@ public class ErfFlowEngineServiceImpl implements ErfFlowEngineService { |
|
|
|
log.info("审批人信息 - 技术经理: {}, 生产经理: {}, 质量经理: {}", |
|
|
|
techManagerId, prodManagerIds, qualityManagerIds); |
|
|
|
|
|
|
|
// 创建流程实例,保存审批人信息到remark字段 |
|
|
|
ErfFlowInstance flowInstance = new ErfFlowInstance(); |
|
|
|
flowInstance.setApplyNo(applyNo); |
|
|
|
flowInstance.setFlowCode("EXP_APPLY_" + buCode); |
|
|
|
flowInstance.setFlowVersion(1); |
|
|
|
flowInstance.setStatus("运行中"); |
|
|
|
flowInstance.setStartTime(new Date()); |
|
|
|
flowInstance.setCurrentNodeCode("技术经理审批"); |
|
|
|
// 1. 删除该申请单已有的所有节点实例,确保每次下达都是全新的节点 |
|
|
|
deleteFlowNodes(applyNo); |
|
|
|
|
|
|
|
// 将审批人信息序列化保存到remark字段(方便后续节点读取) |
|
|
|
// 2. 将审批人信息序列化保存到remark字段(方便后续节点读取) |
|
|
|
String approverJson = String.format( |
|
|
|
"{\"techManagerId\":%d,\"prodManagerIds\":[%s],\"qualityManagerIds\":[%s]}", |
|
|
|
techManagerId, |
|
|
|
prodManagerIds.stream().map(String::valueOf).collect(Collectors.joining(",")), |
|
|
|
qualityManagerIds.stream().map(String::valueOf).collect(Collectors.joining(",")) |
|
|
|
); |
|
|
|
flowInstance.setRemark(approverJson); |
|
|
|
erfFlowInstanceMapper.insert(flowInstance); |
|
|
|
|
|
|
|
// 创建第一个审批节点实例(技术经理审批) |
|
|
|
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance(); |
|
|
|
nodeInstance.setApplyNo(applyNo); |
|
|
|
nodeInstance.setNodeCode("技术经理审批"); |
|
|
|
nodeInstance.setAttemptNo(1); |
|
|
|
nodeInstance.setStatus("待审核"); |
|
|
|
nodeInstance.setReceiveTime(new Date()); |
|
|
|
nodeInstance.setAssigneeUserId(techManagerId); // 使用传入的技术经理ID |
|
|
|
// 根据审批人id查询审批人名称并设置到节点实例(冗余存储,方便查询和展示) |
|
|
|
nodeInstance.setAssigneeName(sysUserDao.getUserDisplayById(techManagerId)); |
|
|
|
erfFlowNodeInstanceMapper.insert(nodeInstance); |
|
|
|
|
|
|
|
log.info("流程启动成功,当前节点:技术经理审批,审批人ID:{}", techManagerId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void restartFlowWithApprovers(String applyNo, Map<String, Object> approverInfo) { |
|
|
|
log.info("=== 重新启动流程(驳回后重新下达)=== 申请单号: {}", applyNo); |
|
|
|
|
|
|
|
Long techManagerId = (Long) approverInfo.get("techManagerId"); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Long> prodManagerIds = (List<Long>) approverInfo.get("prodManagerIds"); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Long> qualityManagerIds = (List<Long>) approverInfo.get("qualityManagerIds"); |
|
|
|
|
|
|
|
log.info("审批人信息 - 技术经理: {}, 生产经理: {}, 质量经理: {}", |
|
|
|
techManagerId, prodManagerIds, qualityManagerIds); |
|
|
|
|
|
|
|
// 1. 查询已有的流程实例 |
|
|
|
// 3. 创建或更新流程实例 |
|
|
|
QueryWrapper<ErfFlowInstance> flowQuery = new QueryWrapper<>(); |
|
|
|
flowQuery.eq("apply_no", applyNo); |
|
|
|
ErfFlowInstance flowInstance = erfFlowInstanceMapper.selectOne(flowQuery); |
|
|
|
|
|
|
|
boolean isNewInstance = (flowInstance == null); |
|
|
|
if (flowInstance == null) { |
|
|
|
throw new XJException("流程实例不存在,无法重新下达"); |
|
|
|
flowInstance = new ErfFlowInstance(); |
|
|
|
flowInstance.setApplyNo(applyNo); |
|
|
|
flowInstance.setFlowCode("EXP_APPLY_" + buCode); |
|
|
|
flowInstance.setFlowVersion(1); |
|
|
|
flowInstance.setStartTime(new Date()); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 更新流程实例的审批人信息和状态 |
|
|
|
flowInstance.setStatus("运行中"); |
|
|
|
flowInstance.setCurrentNodeCode("技术经理审批"); |
|
|
|
|
|
|
|
// 更新审批人信息到remark字段 |
|
|
|
String approverJson = String.format( |
|
|
|
"{\"techManagerId\":%d,\"prodManagerIds\":[%s],\"qualityManagerIds\":[%s]}", |
|
|
|
techManagerId, |
|
|
|
prodManagerIds.stream().map(String::valueOf).collect(Collectors.joining(",")), |
|
|
|
qualityManagerIds.stream().map(String::valueOf).collect(Collectors.joining(",")) |
|
|
|
); |
|
|
|
flowInstance.setRemark(approverJson); |
|
|
|
erfFlowInstanceMapper.updateById(flowInstance); |
|
|
|
|
|
|
|
log.info("更新流程实例,当前节点:技术经理审批"); |
|
|
|
|
|
|
|
// 3. 查询技术经理审批节点的最大attempt_no |
|
|
|
QueryWrapper<ErfFlowNodeInstance> nodeQuery = new QueryWrapper<>(); |
|
|
|
nodeQuery.eq("apply_no", applyNo) |
|
|
|
.eq("node_code", "技术经理审批") |
|
|
|
.orderByDesc("attempt_no") |
|
|
|
.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"); |
|
|
|
ErfFlowNodeInstance lastInstance = erfFlowNodeInstanceMapper.selectOne(nodeQuery); |
|
|
|
|
|
|
|
int nextAttemptNo = (lastInstance != null) ? lastInstance.getAttemptNo() + 1 : 1; |
|
|
|
if (isNewInstance) { |
|
|
|
erfFlowInstanceMapper.insert(flowInstance); |
|
|
|
log.info("新建流程实例"); |
|
|
|
} else { |
|
|
|
erfFlowInstanceMapper.updateById(flowInstance); |
|
|
|
log.info("更新已有流程实例"); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 创建新的技术经理审批节点实例(attempt_no递增) |
|
|
|
// 4. 创建第一个审批节点实例(技术经理审批) |
|
|
|
ErfFlowNodeInstance nodeInstance = new ErfFlowNodeInstance(); |
|
|
|
nodeInstance.setApplyNo(applyNo); |
|
|
|
nodeInstance.setNodeCode("技术经理审批"); |
|
|
|
nodeInstance.setAttemptNo(nextAttemptNo); |
|
|
|
nodeInstance.setAttemptNo(1); |
|
|
|
nodeInstance.setStatus("待审核"); |
|
|
|
nodeInstance.setReceiveTime(new Date()); |
|
|
|
nodeInstance.setAssigneeUserId(techManagerId); // 使用新的技术经理ID |
|
|
|
// 根据审批人id查询审批人名称并设置到节点实例(冗余存储,方便查询和展示) |
|
|
|
nodeInstance.setAssigneeUserId(techManagerId); |
|
|
|
nodeInstance.setAssigneeName(sysUserDao.getUserDisplayById(techManagerId)); |
|
|
|
erfFlowNodeInstanceMapper.insert(nodeInstance); |
|
|
|
|
|
|
|
log.info("流程重新启动成功,当前节点:技术经理审批,尝试次数:{},审批人ID:{}", |
|
|
|
nextAttemptNo, techManagerId); |
|
|
|
log.info("流程启动成功,当前节点:技术经理审批,审批人ID:{}", techManagerId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteFlowNodes(String applyNo) { |
|
|
|
int deletedCount = erfFlowNodeInstanceMapper.delete( |
|
|
|
new QueryWrapper<ErfFlowNodeInstance>().eq("apply_no", applyNo) |
|
|
|
); |
|
|
|
log.info("删除申请单 {} 的流程节点实例,共 {} 条", applyNo, deletedCount); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|