31 lines
1.3 KiB
Plaintext
31 lines
1.3 KiB
Plaintext
id = params_kw.get('id', '')
|
|
if not id:
|
|
return {"widgettype":"Error","options":{"title":"更新失败","message":"id required","cwidth":16,"cheight":9,"timeout":3}}
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('reallife_asset')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
recs = await sor.R("rl_vendor_config", {"id": id})
|
|
if not recs:
|
|
return {"widgettype":"Error","options":{"title":"更新失败","message":"Not found","cwidth":16,"cheight":9,"timeout":3}}
|
|
|
|
upd = {}
|
|
for k in ['status', 'callback_url', 'vendor', 'vendor_title', 'upappid']:
|
|
if params_kw.get(k) is not None:
|
|
upd[k] = params_kw.get(k)
|
|
|
|
api_mapping = params_kw.get('api_mapping', None)
|
|
if api_mapping is not None:
|
|
try:
|
|
api_mapping_dict = json.loads(api_mapping) if api_mapping else {}
|
|
upd['api_mapping'] = json.dumps(api_mapping_dict, ensure_ascii=False)
|
|
except json.JSONDecodeError:
|
|
return {"widgettype":"Error","options":{"title":"更新失败","message":"API映射必须是有效的JSON","cwidth":16,"cheight":9,"timeout":3}}
|
|
|
|
upd['update_time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
async with db.sqlorContext(dbname) as sor:
|
|
await sor.U("rl_vendor_config", {**upd, "id": id})
|
|
|
|
return {"widgettype":"Message","options":{"title":"更新成功","message":"ok","cwidth":16,"cheight":9,"timeout":3}}
|