125 lines
5.4 KiB
Plaintext
125 lines
5.4 KiB
Plaintext
async def GetUserBill(ns={}):
|
|
"""
|
|
-> 获取bill -> 同步到jncs_bill table
|
|
-> 通过(loginId(即orgid)=customerid,providerrid, productname)找到resourceid
|
|
-> 同步到resource_using table -> 更新customer_goods table
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
orgname = '济南超算'
|
|
base_url = 'https://hpc.kaiyuancloud.cn/rms/api'
|
|
|
|
url_sign = base_url + "/sign"
|
|
cipher = "WIfHaMnen2WaRw4Agwenoe6TwDD3LxBbLEgMjVKDHADPE7xDJicjSG3yAfK4iNes1vUmVcoTxV2/+gMfla8ZDg=="
|
|
response = requests.post(url=url_sign, data={"cipher": cipher})
|
|
cookie = response.headers.get("Set-Cookie")
|
|
|
|
url = base_url + '/biz/user/cTimeInfoList'
|
|
# data = {
|
|
# 'loginId': '86ee065f-2a3a-416c-b0df-5c759988ebbb',
|
|
# 'loginName': 'bakerwm'
|
|
# }
|
|
res = requests.get(url=url, headers={"Cookie": cookie})
|
|
if res.status_code != 200:
|
|
res_return = {
|
|
'status': False,
|
|
'msg': '济南超算 url get status code is not 200, %s' % url
|
|
}
|
|
print(res_return)
|
|
return res_return
|
|
res_dict_li = json.loads(res.text)
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
for res_dict in res_dict_li.get('data'):
|
|
current_date = await get_business_date(sor)
|
|
# current_date = '2023-12-28'
|
|
ns_jncs_bill = {
|
|
'loginid': res_dict.get('loginId') or '',
|
|
'loginname': res_dict.get('loginName') or '',
|
|
'clustercode': res_dict.get('clusterCode') or '',
|
|
'clustername': res_dict.get('clusterName') or '',
|
|
'queuecode': res_dict.get('queueCode') or '',
|
|
'queuename': res_dict.get('queueName') or '',
|
|
'totalctime': res_dict.get('totalCtime'),
|
|
'usedctime': res_dict.get('usedCtime'),
|
|
'remainctime': res_dict.get('remainCtime'),
|
|
'expiredctime': res_dict.get('expiredCtime')
|
|
}
|
|
# jncs_li = await sor.R('organization', {'orgname': orgname, 'del_flg': '0'})
|
|
# if jncs_li:
|
|
# jscs_id = jncs_li[0].get('id')
|
|
# else:
|
|
# res = {
|
|
# 'status': False,
|
|
# 'msg': 'can not find jncs id in organization: %s' % orgname
|
|
# }
|
|
# print(res)
|
|
# return res
|
|
# ns_goods = {
|
|
# 'providerrid': jscs_id,
|
|
# 'customerid': ns_jncs_bill.get('loginid'),
|
|
# # 'productname': ns_jncs_bill.get('queuename'), # TODO 如果只有一个产品 这个可以不填
|
|
# 'del_flg': '0'
|
|
# }
|
|
# goods_li = await sor.R('customer_goods', ns_goods)
|
|
# if goods_li:
|
|
# resourceid = goods_li[0].get('id')
|
|
# else:
|
|
# # res = {
|
|
# # 'status': False,
|
|
# # 'msg': '无法从持有表中获取数据, providerrid:%s, loginid:%s, queuename: %s' %
|
|
# # (jscs_id, ns_jncs_bill.get('loginid'), ns_jncs_bill.get('queuename'))
|
|
# # }
|
|
# continue
|
|
# ns_resouce_using = {
|
|
# 'resourceid': resourceid,
|
|
# 'total_quantity': ns_jncs_bill.get('totalctime'),
|
|
# 'used_quantity': ns_jncs_bill.get('usedctime'),
|
|
# 'rest_quantity': ns_jncs_bill.get('remainctime'),
|
|
# }
|
|
# ns_customer_goods = {
|
|
# 'id': resourceid,
|
|
# 'total_quantity': ns_jncs_bill.get('totalctime'),
|
|
# 'used_quantity': ns_jncs_bill.get('usedctime'),
|
|
# 'rest_quantity': ns_jncs_bill.get('remainctime'),
|
|
# }
|
|
|
|
# 查找机构表中是否存在
|
|
exist_id = await sor.R('organization', {'id': ns_jncs_bill['loginid']})
|
|
if not exist_id:
|
|
exist_ids = {
|
|
'status': False,
|
|
'msg': 'can not find loginid in organizaiton'
|
|
}
|
|
continue
|
|
|
|
# judge jncs bill exist
|
|
ns_jncs_bill_exist = await sor.R('jncs_bill', ns_jncs_bill)
|
|
if not ns_jncs_bill_exist:
|
|
ns_jncs_bill['id'] = uuid()
|
|
ns_jncs_bill['bill_date'] = current_date
|
|
ns_jncs_bill['bill_timestamp'] = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
await sor.C('jncs_bill', ns_jncs_bill)
|
|
|
|
# judge jncs resource using exist
|
|
# ns_resouce_using_exist = await sor.R('resource_using', ns_resouce_using)
|
|
# if not ns_resouce_using_exist:
|
|
# ns_resouce_using['id'] = uuid()
|
|
# ns_resouce_using['use_date'] = current_date
|
|
# await sor.C('resource_using', ns_resouce_using)
|
|
#
|
|
# await sor.U('customer_goods', ns_customer_goods)
|
|
return {
|
|
'status': True,
|
|
'msg': 'sync jncs bill success'
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
'status': False,
|
|
'msg': 'jncs get bill failed'
|
|
}
|
|
|
|
ret = await GetUserBill(params_kw)
|
|
return ret |