|
|
@@ -1673,10 +1673,14 @@ def advance_from(
|
|
|
from_node: Optional[Dict[str, Any]],
|
|
|
user_id: Optional[str],
|
|
|
initiator_select_by_node: Optional[Dict[str, List[str]]] = None,
|
|
|
-) -> None:
|
|
|
- """从某节点的下一跳开始推进;from_node 为 None 表示从 start 进入。"""
|
|
|
+) -> List[str]:
|
|
|
+ """从某节点的下一跳开始推进;from_node 为 None 表示从 start 进入。
|
|
|
+
|
|
|
+ 返回本次推进新创建的任务 id 列表(含抄送与嵌套自动通过产生的后续任务)。
|
|
|
+ """
|
|
|
root = _flow_root(_loads(ver.flow_tree_json, {}))
|
|
|
form_data = _loads(inst.form_data_json, {}) or {}
|
|
|
+ created_ids: List[str] = []
|
|
|
|
|
|
def next_node(node: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
|
|
ntype = _node_type(node)
|
|
|
@@ -1723,7 +1727,7 @@ def advance_from(
|
|
|
logger.exception(
|
|
|
"resignation kit user sync failed instance=%s", getattr(inst, "id", None)
|
|
|
)
|
|
|
- return
|
|
|
+ return created_ids
|
|
|
if ntype == "condition":
|
|
|
cur = next_node(cur)
|
|
|
continue
|
|
|
@@ -1737,6 +1741,7 @@ def advance_from(
|
|
|
initiator_select_by_node=initiator_select_by_node,
|
|
|
order_num_start=next_order,
|
|
|
)
|
|
|
+ created_ids.extend([t.id for t in tasks if getattr(t, "id", None)])
|
|
|
next_order += max(len(tasks), 1)
|
|
|
if ntype == "cc":
|
|
|
# 抄送不阻断,继续往下
|
|
|
@@ -1744,20 +1749,22 @@ def advance_from(
|
|
|
continue
|
|
|
if not tasks:
|
|
|
raise OaEngineError("审批节点未生成任务")
|
|
|
- _maybe_auto_pass_initiator(
|
|
|
+ nested = _maybe_auto_pass_initiator(
|
|
|
db,
|
|
|
inst=inst,
|
|
|
ver=ver,
|
|
|
tasks=tasks,
|
|
|
user_id=user_id,
|
|
|
)
|
|
|
- return
|
|
|
+ created_ids.extend(nested or [])
|
|
|
+ return created_ids
|
|
|
# 未知类型跳过子节点
|
|
|
cur = next_node(cur)
|
|
|
|
|
|
# 无结束也无待办:异常结束
|
|
|
if inst.status == "running":
|
|
|
raise OaEngineError("流程推进异常:未到达结束且无待办任务")
|
|
|
+ return created_ids
|
|
|
|
|
|
|
|
|
def start_instance(
|
|
|
@@ -1933,7 +1940,7 @@ def start_instance(
|
|
|
actor_user_id=initiator_user_id,
|
|
|
round_no=1,
|
|
|
)
|
|
|
- advance_from(
|
|
|
+ created = advance_from(
|
|
|
db,
|
|
|
inst=inst,
|
|
|
ver=ver,
|
|
|
@@ -1942,6 +1949,9 @@ def start_instance(
|
|
|
initiator_select_by_node=normalized_select,
|
|
|
)
|
|
|
db.commit()
|
|
|
+ from app.services.oa_wechat_notify import schedule_oa_task_notifies
|
|
|
+
|
|
|
+ schedule_oa_task_notifies(created or [])
|
|
|
db.refresh(inst)
|
|
|
return get_instance_detail(db, inst.id, tenant_no=tenant_no)
|
|
|
|
|
|
@@ -2363,10 +2373,10 @@ def _approve_task_core(
|
|
|
ver: OaAppVersion,
|
|
|
user_id: str,
|
|
|
comment: Optional[str],
|
|
|
-) -> bool:
|
|
|
+) -> List[str]:
|
|
|
"""将 pending 审批任务置为 approved 并按或签/会签决定是否推进。
|
|
|
|
|
|
- 返回 True 表示已调用 advance_from 推进;False 表示会签未齐、未推进。
|
|
|
+ 返回 advance_from 新创建的任务 id 列表;会签未齐、未推进时返回空列表。
|
|
|
调用方负责 commit(若需要)。
|
|
|
"""
|
|
|
now = datetime.now()
|
|
|
@@ -2393,7 +2403,7 @@ def _approve_task_core(
|
|
|
.count()
|
|
|
)
|
|
|
if sign_mode == "and" and pending_same > 0:
|
|
|
- return False
|
|
|
+ return []
|
|
|
|
|
|
if sign_mode != "and":
|
|
|
for s in (
|
|
|
@@ -2416,7 +2426,7 @@ def _approve_task_core(
|
|
|
node = _find_node(root, task.node_key or "")
|
|
|
if not node:
|
|
|
raise OaEngineError("找不到对应流程节点")
|
|
|
- advance_from(
|
|
|
+ return advance_from(
|
|
|
db,
|
|
|
inst=inst,
|
|
|
ver=ver,
|
|
|
@@ -2424,7 +2434,6 @@ def _approve_task_core(
|
|
|
user_id=user_id,
|
|
|
initiator_select_by_node=_load_initiator_select_by_node(inst),
|
|
|
)
|
|
|
- return True
|
|
|
|
|
|
|
|
|
def _maybe_auto_pass_initiator(
|
|
|
@@ -2434,16 +2443,16 @@ def _maybe_auto_pass_initiator(
|
|
|
ver: OaAppVersion,
|
|
|
tasks: List[OaTask],
|
|
|
user_id: Optional[str],
|
|
|
-) -> None:
|
|
|
+) -> List[str]:
|
|
|
_ = user_id
|
|
|
advanced = _advanced(ver)
|
|
|
if not advanced.get("autoPassWhenApproverIsInitiator"):
|
|
|
- return
|
|
|
+ return []
|
|
|
if inst.status != "running":
|
|
|
- return
|
|
|
+ return []
|
|
|
initiator = (inst.initiator_user_id or "").strip()
|
|
|
if not initiator:
|
|
|
- return
|
|
|
+ return []
|
|
|
self_task = None
|
|
|
for t in tasks:
|
|
|
if (
|
|
|
@@ -2454,8 +2463,8 @@ def _maybe_auto_pass_initiator(
|
|
|
self_task = t
|
|
|
break
|
|
|
if not self_task:
|
|
|
- return
|
|
|
- _approve_task_core(
|
|
|
+ return []
|
|
|
+ return _approve_task_core(
|
|
|
db,
|
|
|
task=self_task,
|
|
|
inst=inst,
|
|
|
@@ -2537,7 +2546,7 @@ def complete_task(
|
|
|
db.commit()
|
|
|
return get_instance_detail(db, inst.id, tenant_no=tenant_no)
|
|
|
|
|
|
- _approve_task_core(
|
|
|
+ created = _approve_task_core(
|
|
|
db,
|
|
|
task=task,
|
|
|
inst=inst,
|
|
|
@@ -2546,6 +2555,9 @@ def complete_task(
|
|
|
comment=comment,
|
|
|
)
|
|
|
db.commit()
|
|
|
+ from app.services.oa_wechat_notify import schedule_oa_task_notifies
|
|
|
+
|
|
|
+ schedule_oa_task_notifies(created or [])
|
|
|
return get_instance_detail(db, inst.id, tenant_no=tenant_no)
|
|
|
|
|
|
|
|
|
@@ -2609,7 +2621,7 @@ def add_sign(
|
|
|
.all()
|
|
|
}
|
|
|
now = datetime.now()
|
|
|
- created = 0
|
|
|
+ created_ids: List[str] = []
|
|
|
next_order = _next_task_order_num(db, inst.id)
|
|
|
for uid in ids:
|
|
|
if uid in existing:
|
|
|
@@ -2627,9 +2639,10 @@ def add_sign(
|
|
|
)
|
|
|
if not u:
|
|
|
raise OaEngineError(f"加签用户无效:{uid}")
|
|
|
+ new_id = generate_uuid()
|
|
|
db.add(
|
|
|
OaTask(
|
|
|
- id=generate_uuid(),
|
|
|
+ id=new_id,
|
|
|
instance_id=inst.id,
|
|
|
node_key=task.node_key,
|
|
|
node_name=task.node_name,
|
|
|
@@ -2652,8 +2665,8 @@ def add_sign(
|
|
|
)
|
|
|
)
|
|
|
next_order += 1
|
|
|
- created += 1
|
|
|
- if created == 0:
|
|
|
+ created_ids.append(new_id)
|
|
|
+ if not created_ids:
|
|
|
raise OaEngineError("所选用户已在当前节点待办中")
|
|
|
# 加签后默认按会签语义收口更稳妥:保留原 sign_mode;若原或签则一人通过仍可结束
|
|
|
if comment:
|
|
|
@@ -2662,6 +2675,9 @@ def add_sign(
|
|
|
task.update_time = now
|
|
|
db.add(task)
|
|
|
db.commit()
|
|
|
+ from app.services.oa_wechat_notify import schedule_oa_task_notifies
|
|
|
+
|
|
|
+ schedule_oa_task_notifies(created_ids)
|
|
|
return get_instance_detail(db, inst.id, tenant_no=tenant_no)
|
|
|
|
|
|
|
|
|
@@ -2735,9 +2751,10 @@ def transfer_task(
|
|
|
db.add(task)
|
|
|
|
|
|
next_order = _next_task_order_num(db, inst.id)
|
|
|
+ new_task_id = generate_uuid()
|
|
|
db.add(
|
|
|
OaTask(
|
|
|
- id=generate_uuid(),
|
|
|
+ id=new_task_id,
|
|
|
instance_id=inst.id,
|
|
|
node_key=task.node_key,
|
|
|
node_name=task.node_name,
|
|
|
@@ -2773,6 +2790,9 @@ def transfer_task(
|
|
|
)
|
|
|
|
|
|
db.commit()
|
|
|
+ from app.services.oa_wechat_notify import schedule_oa_task_notifies
|
|
|
+
|
|
|
+ schedule_oa_task_notifies([new_task_id])
|
|
|
return get_instance_detail(db, inst.id, tenant_no=tenant_no)
|
|
|
|
|
|
|