131 lines
2.7 KiB
Plaintext

ns = params_kw.copy()
debug(f'get_opp_reports.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["created_at desc"]
sql = '''select * from opp_reports where 1=1 [[filterstr]]'''
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
},
{
"name": "software",
"title": "软件/主题",
"type": "str",
"length": 128,
"nullable": "no"
},
{
"name": "title",
"title": "报告标题",
"type": "str",
"length": 255,
"nullable": "no"
},
{
"name": "content",
"title": "报告正文",
"type": "text"
},
{
"name": "status",
"title": "报告状态",
"type": "str",
"length": 24,
"nullable": "no",
"default": "draft"
},
{
"name": "confirm_task_id",
"title": "确认任务ID",
"type": "str",
"length": 32
},
{
"name": "ppt_path",
"title": "PPT文件路径",
"type": "str",
"length": 500
},
{
"name": "confirmed_by",
"title": "确认人",
"type": "str",
"length": 64
},
{
"name": "created_by",
"title": "创建人",
"type": "str",
"length": 64
},
{
"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_opportunity')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}