49 lines
1.9 KiB
Plaintext
49 lines
1.9 KiB
Plaintext
# opp_mining_start.dspy - 启动需求挖掘批次(opp_mining_popup 的按钮端点)
|
||
# GET/POST: scope=top|targeted, keyword(targeted必填), category?, days?, sources?
|
||
# 复用 opp_mining_flow.start_mining(与工具通道同一实现),返回 {status,batch_id}。
|
||
# 权限:logined;项目归属从会话当前项目解析(与列表页同一口径)。
|
||
|
||
uid = await get_user()
|
||
if not uid:
|
||
return {"status": "error", "message": "未登录"}
|
||
|
||
dbname = get_module_dbname('pipeline-opportunity')
|
||
|
||
scope = ((params_kw or {}).get("scope") or "top").strip()
|
||
keyword = ((params_kw or {}).get("keyword") or "").strip()
|
||
category = ((params_kw or {}).get("category") or "").strip()
|
||
try:
|
||
days = int((params_kw or {}).get("days") or 365)
|
||
except (TypeError, ValueError):
|
||
days = 365
|
||
sources = ((params_kw or {}).get("sources") or "").strip()
|
||
|
||
session_id = (params_kw or {}).get('session_id', '') or ''
|
||
pipeline_id = (params_kw or {}).get('pipeline_id', '') or 'opportunity_general'
|
||
|
||
_cur_pid = ''
|
||
_uorg = ''
|
||
try:
|
||
from pipeline_service.workspace import get_session_project_id
|
||
async with DBPools().sqlorContext(dbname) as sor:
|
||
_cur_pid = await get_session_project_id(sor, uid, session_id, pipeline_id) or ''
|
||
_urecs = await sor.sqlExe("SELECT orgid FROM users WHERE id=${u}$", {"u": uid})
|
||
await sor.sqlExe("COMMIT", {})
|
||
if _urecs:
|
||
_uorg = str(getattr(_urecs[0], "orgid", "") or "")
|
||
except Exception:
|
||
pass
|
||
|
||
_ctx = {"project_id": _cur_pid, "user_id": uid, "org_id": _uorg,
|
||
"pipeline_id": pipeline_id, "session_id": session_id}
|
||
|
||
async with DBPools().sqlorContext(dbname) as sor:
|
||
from pipeline_opportunity.opp_mining_flow import start_mining
|
||
bid, err = await start_mining(sor, _ctx, scope=scope, days=days, sources=sources,
|
||
keyword=keyword, category=category)
|
||
await sor.sqlExe("COMMIT", {})
|
||
|
||
if err:
|
||
return {"status": "error", "message": err}
|
||
return {"status": "ok", "batch_id": bid}
|