119 lines
2.7 KiB
Plaintext
119 lines
2.7 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
debug(f'get_pricing_item.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = 'name'
|
|
|
|
|
|
|
|
sql = '''select a.*, b.pptid_text, c.psid_text, d.subppid_text
|
|
from (select * from pricing_item where 1=1 [[filterstr]]) a left join (select id as pptid,
|
|
id as pptid_text from pricing_program_timing where 1 = 1) b on a.pptid = b.pptid left join (select id as psid,
|
|
name as psid_text from pricing_spec where 1 = 1) c on a.psid = c.psid left join (select id as subppid,
|
|
name as subppid_text from pricing_program where 1 = 1) d on a.subppid = d.subppid'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in [
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "name",
|
|
"title": "定价项名",
|
|
"type": "str",
|
|
"length": 256
|
|
},
|
|
{
|
|
"name": "description",
|
|
"title": "描述",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "pptid",
|
|
"title": "项目id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "psid",
|
|
"title": "定价规格id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "subppid",
|
|
"title": "子项目id",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "yes"
|
|
},
|
|
{
|
|
"name": "spec_value",
|
|
"title": "规格值",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "pricing_unit",
|
|
"title": "定价单位",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 5
|
|
},
|
|
{
|
|
"name": "pricing_amount",
|
|
"title": "定价金额",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 5
|
|
},
|
|
{
|
|
"name": "cost_amount",
|
|
"title": "成本金额",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 5
|
|
}
|
|
] ]
|
|
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('pricing')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
for d in r['rows']:
|
|
if d.spec_value:
|
|
ad = json.loads(d.spec_value)
|
|
d.update(ad)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
}
|