kboss/b/product/requirement_add.dspy
2025-08-04 13:49:41 +08:00

72 lines
2.8 KiB
Plaintext

async def requirement_add(ns={}):
if ns.get('userid'):
userid = ns.get('userid')
else:
userid = await get_user()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 区分运营和普通客户
user_list = await sor.R('users', {'id': userid})
if not user_list:
return {
'status': False,
'msg': '没有找到匹配的用户'
}
orgid = user_list[0]['orgid']
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
product_category = ns.get('product_category')
company_type = ns.get('company_type')
ns_dic = {
"id": uuid(),
"orgid": orgid,
"domain_name": domain_name,
"requirement_name": ns.get("requirement_name"),
"product_category": product_category,
"company_name": ns.get("company_name"),
"company_type": json.dumps(company_type) if isinstance(company_type, list) else company_type,
"contact_person": ns.get("contact_person"),
"job_title": ns.get("job_title"),
"phone_number": ns.get("phone_number"),
"email": ns.get("email"),
"cpu": ns.get("cpu"),
"memory": ns.get("memory"),
"gpu": ns.get("gpu"),
"sys_disk": ns.get("sys_disk"),
"data_disk": ns.get("data_disk"),
"net_card": ns.get("net_card"),
"price": ns.get("price"),
"priority": ns.get("priority") if ns.get("priority") else 1,
"status": ns.get("status") if ns.get("status") else '0',
"title": ns.get("title"),
"label": ns.get("label"),
"first_page": ns.get("first_page") if ns.get("first_page") else '0',
"requirement_summary": ns.get("requirement_summary"),
"related_parameters": ns.get("related_parameters"),
"application_scenario": ns.get("application_scenario"),
"audit_status": ns.get('audit_status', 'pending'),
}
user_role = await get_user_role({'userid': userid, 'sor': sor})
# 非客户角色不需要审批
if user_role != '客户':
ns['status'] = '1'
ns_dic['audit_status'] = 'approved'
ns_dic['first_page'] = '1'
try:
await sor.C('user_publish_requirement', ns_dic)
return {
'status': True,
'msg': 'Requirement created successfully'
}
except Exception as e:
return {
'status': False,
'msg': 'Failed to create requirement, %s' % str(e)
}
ret = await requirement_add(params_kw)
return ret