pipeline-sdlc/wwwroot/sd_test_plans/get_sd_test_plans.dspy

133 lines
3.2 KiB
Plaintext

ns = params_kw.copy()
debug(f'get_sd_test_plans.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.plan_type_text, d.status_text
from (select * from sd_test_plans 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 plan_type,
v as plan_type_text from appcodes_kv where parentid='sd_test_plan_type') c on a.plan_type = c.plan_type left join (select k as status,
v as status_text from appcodes_kv where parentid='sd_test_plan_status') d on a.status = d.status'''
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": "plan_name",
"title": "方案名称",
"type": "str",
"length": 200,
"nullable": "no"
},
{
"name": "plan_type",
"title": "方案类型",
"type": "str",
"length": 20,
"nullable": "no"
},
{
"name": "scope",
"title": "测试范围",
"type": "text"
},
{
"name": "environment",
"title": "测试环境要求(JSON)",
"type": "text"
},
{
"name": "entry_criteria",
"title": "准入条件",
"type": "text"
},
{
"name": "exit_criteria",
"title": "准出条件",
"type": "text"
},
{
"name": "status",
"title": "方案状态",
"type": "str",
"length": 20,
"nullable": "no",
"default": "'draft'"
},
{
"name": "created_by",
"title": "创建人",
"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_sdlc')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}