pipeline-bidding/wwwroot/bid_qc_reviews/get_bid_qc_reviews.dspy

168 lines
4.1 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.

ns = params_kw.copy()
# 会话当前项目强制过滤(2026-09-11 用户要求):会话级解析(session→全局兜底+产线隔离+悬空自愈),
# 无项目报错提示;强制覆盖前端 project_id 传值(含搜索框),列表只显示当前项目数据。
_uid = await get_user()
if not _uid:
_uid = 'user-01'
_sid = (params_kw or {}).get('session_id', '') or ''
_pl = (params_kw or {}).get('pipeline_id', '') or 'bidding_general'
_cur_pid = ''
try:
from pipeline_service.workspace import get_session_project_id
async with DBPools().sqlorContext(get_module_dbname('pipeline_bidding')) as _sor:
_cur_pid = await get_session_project_id(_sor, _uid, _sid, _pl) or ''
except Exception:
_cur_pid = ''
if not _cur_pid:
return {"widgettype":"Error","options":{"title":"错误","timeout":3,"cwidth":22,"cheight":9,"message":"当前会话没有项目,请先选择或新建项目"}}
ns['_cur_pid'] = _cur_pid
ns['project_id'] = _cur_pid
debug(f'get_bid_qc_reviews.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["qc_type","round desc"]
sql = '''select a.*, b.qc_type_text
from (select * from bid_qc_reviews where project_id = ${_cur_pid}$ [[filterstr]]) a left join (select k as qc_type,
v as qc_type_text from appcodes_kv where parentid='bid_qc_type') b on a.qc_type = b.qc_type'''
filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str):
try:
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{
"name": "id",
"title": "主键ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "project_id",
"title": "项目ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "qc_type",
"title": "审核对象",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "round",
"title": "审核轮次",
"type": "int",
"nullable": "no",
"default": "1"
},
{
"name": "reviewer",
"title": "审核方",
"type": "str",
"length": 64
},
{
"name": "review_type",
"title": "审核类型",
"type": "str",
"length": 16,
"default": "agent"
},
{
"name": "fit_score",
"title": "契合度得分(10分制)",
"type": "float",
"length": 4,
"dec": 2
},
{
"name": "pass_score",
"title": "通过分",
"type": "float",
"length": 4,
"dec": 2
},
{
"name": "passed",
"title": "是否通过",
"type": "str",
"length": 1,
"nullable": "no",
"default": "0"
},
{
"name": "improvement",
"title": "改进意见",
"type": "text"
},
{
"name": "comments",
"title": "审核说明",
"type": "text"
},
{
"name": "task_id",
"title": "关联任务ID",
"type": "str",
"length": 32
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp",
"nullable": "no"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pipeline_bidding')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}