- Added rules to discount field: required, number, min:0, max:1 - Frontend: Form validates on submit, shows error below field - Backend: auto-generated dspy validates before DB write
135 lines
3.3 KiB
Plaintext
135 lines
3.3 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['ownerid'] = userorgid
|
|
ns['userorgid'] = userorgid
|
|
|
|
debug(f'get_pricing_program.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = 'name'
|
|
|
|
|
|
|
|
sql = '''select a.*, b.ownerid_text, c.providerid_text, d.pricing_belong_text
|
|
from (select * from pricing_program where 1=1 [[filterstr]]) a left join (select id as ownerid,
|
|
orgname as ownerid_text from organization where 1 = 1) b on a.ownerid = b.ownerid left join (select id as providerid,
|
|
orgname as providerid_text from organization where 1 = 1) c on a.providerid = c.providerid left join (select k as pricing_belong,
|
|
v as pricing_belong_text from appcodes_kv where parentid='pricing_belong') d on a.pricing_belong = d.pricing_belong'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if filterjson and isinstance(filterjson, str):
|
|
try:
|
|
filterjson = json.loads(filterjson)
|
|
except (json.JSONDecodeError, TypeError):
|
|
filterjson = None
|
|
# data_filter可能是CRUD字段定义({"fields":[...]}),不是过滤条件,忽略
|
|
if filterjson and isinstance(filterjson, dict) and 'fields' in filterjson:
|
|
filterjson = None
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "name",
|
|
"title": "项目名称",
|
|
"type": "str",
|
|
"length": 256
|
|
},
|
|
{
|
|
"name": "ownerid",
|
|
"title": "所属机构",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "providerid",
|
|
"title": "供应商",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "pricing_belong",
|
|
"title": "定价属于",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "discount",
|
|
"title": "供应商折扣",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 2
|
|
},
|
|
{
|
|
"name": "description",
|
|
"title": "描述",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "pricing_spec",
|
|
"title": "规格明细",
|
|
"type": "text"
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
|
|
# 确保 logined 过滤条件始终生效
|
|
if filterjson:
|
|
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
|
filterjson = {'AND': [filterjson] if filterjson else []}
|
|
|
|
filterjson['AND'].append({'field': 'ownerid', 'op': '=', 'var': '__logined_orgid__'})
|
|
ns['__logined_orgid__'] = userorgid
|
|
|
|
|
|
|
|
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)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |