pipeline-opportunity/wwwroot/api/opp_confirm_report.dspy

43 lines
1.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# opp_confirm_report.dspy - 研发报告人工确认(门禁)
# 入参:human_task_id=<确认任务id>, decision=approve|reject, comment=意见(可选)
import json as _json
uid = await get_user()
if not uid:
return _json.dumps({"success": False, "error": "未登录"}, ensure_ascii=False)
human_task_id = ((params_kw or {}).get('human_task_id') or '').strip()
decision = ((params_kw or {}).get('decision') or '').strip()
comment = ((params_kw or {}).get('comment') or '').strip()
if not human_task_id:
return _json.dumps({"success": False, "error": "缺少 human_task_id"}, ensure_ascii=False)
if decision not in ('approve', 'reject'):
return _json.dumps({"success": False, "error": "decision 必须是 approve/reject"}, ensure_ascii=False)
dbname = get_module_dbname('pipeline-opportunity')
async with DBPools().sqlorContext(dbname) as sor:
from pipeline_opportunity.opp_report_capability import confirm_report
# 确认任务 → 报告(opp_reports.confirm_task_id)
recs = await sor.sqlExe(
"SELECT id, title, status FROM opp_reports WHERE confirm_task_id=${t}$",
{"t": human_task_id})
await sor.sqlExe("COMMIT", {})
if not recs:
return _json.dumps({"success": False, "error": "未找到该确认任务对应的报告"}, ensure_ascii=False)
report_id = getattr(recs[0], 'id', '')
ok, msg = await confirm_report(report_id, decision == 'approve', operator=uid)
if not ok:
return _json.dumps({"success": False, "error": msg}, ensure_ascii=False)
if comment:
try:
await sor.sqlExe(
"UPDATE pipeline_human_tasks SET result_data=${r}$ WHERE id=${i}$",
{"r": _json.dumps({"comment": comment}, ensure_ascii=False), "i": human_task_id})
await sor.sqlExe("COMMIT", {})
except Exception:
pass
return _json.dumps({"success": True,
"message": ("报告已确认,可发起研发审批" if decision == 'approve' else "报告已退回草稿待修改")},
ensure_ascii=False)