ns = params_kw.copy() debug(f'get_sd_bugs.dspy:{ns=}') if not ns.get('page'): ns['page'] = 1 if not ns.get('sort'): ns['sort'] = ["created_at desc"] sql = '''select a.*, b.iteration_id_text, c.severity_text, d.priority_text, e.status_text, f.reporter_type_text from (select * from sd_bugs where 1=1 [[filterstr]]) a left join (select id as iteration_id, iteration_name as iteration_id_text from sd_iterations where 1 = 1) b on a.iteration_id = b.iteration_id left join (select k as severity, v as severity_text from appcodes_kv where parentid='sd_bug_severity') c on a.severity = c.severity left join (select k as priority, v as priority_text from appcodes_kv where parentid='sd_priority') d on a.priority = d.priority left join (select k as status, v as status_text from appcodes_kv where parentid='sd_bug_status') e on a.status = e.status left join (select k as reporter_type, v as reporter_type_text from appcodes_kv where parentid='sd_reporter_type') f on a.reporter_type = f.reporter_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": "iteration_id", "title": "迭代ID", "type": "str", "length": 32, "nullable": "no" }, { "name": "case_id", "title": "关联用例ID", "type": "str", "length": 32 }, { "name": "step_name", "title": "发现步骤名", "type": "str", "length": 100 }, { "name": "title", "title": "Bug标题", "type": "str", "length": 300, "nullable": "no" }, { "name": "description", "title": "详细描述", "type": "text" }, { "name": "severity", "title": "严重程度", "type": "str", "length": 10, "nullable": "no", "default": "'major'" }, { "name": "priority", "title": "优先级", "type": "str", "length": 10, "nullable": "no", "default": "'P1'" }, { "name": "status", "title": "Bug状态", "type": "str", "length": 20, "nullable": "no", "default": "'open'" }, { "name": "reporter_type", "title": "提交人类型", "type": "str", "length": 10, "nullable": "no" }, { "name": "reporter_id", "title": "提交人ID", "type": "str", "length": 32, "nullable": "no" }, { "name": "assignee_id", "title": "处理人ID", "type": "str", "length": 32 }, { "name": "fix_description", "title": "修复说明", "type": "text" }, { "name": "fix_commit", "title": "修复Commit", "type": "str", "length": 100 }, { "name": "verified_by", "title": "验证人", "type": "str", "length": 32 }, { "name": "created_at", "title": "创建时间", "type": "timestamp", "nullable": "no" }, { "name": "updated_at", "title": "更新时间", "type": "timestamp" }, { "name": "closed_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_sdlc') async with db.sqlorContext(dbname) as sor: r = await sor.sqlPaging(sql, ns) return r return { "total":0, "rows":[] }