Merge branch 'ps' into 'main'
update 完善CompanyObject See merge request root/guarantee-admin-api-v0.2!1
This commit is contained in:
commit
c48a636019
|
@ -0,0 +1,40 @@
|
|||
from werkzeug.security import generate_password_hash
|
||||
|
||||
from DBHelper.MongoHelperInstance import DB_GUA
|
||||
from Modules.AdminUser.UserObject1 import User
|
||||
from Modules.AdminUser.UserUtils1 import UserUtils
|
||||
from Modules.Common.CommonUtils import CommonUtils
|
||||
|
||||
|
||||
class UserImpl(object):
|
||||
|
||||
@staticmethod
|
||||
def create(email, name, pwd, role):
|
||||
"""创建"""
|
||||
|
||||
UserUtils.check_mail_fmt(email)
|
||||
UserUtils.check_email_registered(email)
|
||||
|
||||
user = User()
|
||||
user.uid = UserUtils.generate_new_uid()
|
||||
user.email = email
|
||||
user.name = name
|
||||
user.pwd = generate_password_hash(pwd)
|
||||
user.status = "normal"
|
||||
user.role = role
|
||||
user.create_time = CommonUtils.get_current_time()
|
||||
|
||||
DB_GUA.insert_single_data(
|
||||
"管理端",
|
||||
"用户",
|
||||
user.dict_keys_toggle()
|
||||
)
|
||||
|
||||
def login(self):
|
||||
"""登录"""
|
||||
|
||||
def disable(self):
|
||||
"""禁用"""
|
||||
|
||||
def active(self):
|
||||
"""激活"""
|
|
@ -65,7 +65,7 @@ class User:
|
|||
def check_role(self):
|
||||
"""用户角色校验"""
|
||||
|
||||
if self.role not in ['admin', 'analysts', 'developer', 'operator', 'guest']:
|
||||
if self.role not in ['admin', 'analysts', 'guest']:
|
||||
raise ReturnConditionCheckFailed("用户角色格式错误", 200)
|
||||
|
||||
def check_obj(self, **kwargs):
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from Modules.AdminUser.UserUtils1 import UserUtils
|
||||
|
||||
from Utils.ObjUtil import SpecObject
|
||||
from Utils.ValidateUtil import ValidateAttr, Validate
|
||||
|
||||
|
||||
class User(SpecObject):
|
||||
"""管理端用户"""
|
||||
|
||||
uid = ValidateAttr(field="uid", type=str)
|
||||
email = ValidateAttr(field="email", func=Validate.email)
|
||||
name = ValidateAttr(field="name", type=str)
|
||||
pwd = ValidateAttr(field="pwd", func=Validate.password)
|
||||
status = ValidateAttr(field="status", in_list=UserUtils.user_enum("User", "status"))
|
||||
role = ValidateAttr(field="role", in_list=UserUtils.user_enum("User", "role"))
|
||||
create_time = ValidateAttr(field="create_time", func=Validate.time_format)
|
||||
|
||||
fields_map = {
|
||||
"uid": "用户ID",
|
||||
"email": "邮箱",
|
||||
"name": "用户名",
|
||||
"pwd": "密码",
|
||||
"status": "用户状态",
|
||||
"role": "角色",
|
||||
"create_time": "创建时间"
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
from flask import Blueprint, request
|
||||
|
||||
from Utils.ErrorUtil import ReturnConditionCheckFailed
|
||||
from Modules.AdminUser.UserImpl import UserManageImpl, ListUserImpl, UserLoginImpl, SendLoginVcodeEmailImpl
|
||||
from Modules.AdminUser.UserImpl1 import UserImpl
|
||||
from Modules.AdminUser.UserUtils1 import UserUtils
|
||||
from Utils.ErrorUtil import ReturnConditionCheckFailed, AttrCheckError
|
||||
from Modules.AdminUser.UserImpl import UserLoginImpl, SendLoginVcodeEmailImpl
|
||||
from Modules.AdminUser.UserAuthUtils import verify_token, authority_scope
|
||||
|
||||
user_route = Blueprint('user', __name__)
|
||||
|
@ -17,43 +19,27 @@ def online_check_route(**kwargs):
|
|||
|
||||
|
||||
@user_route.route('/create', methods=['POST'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
def create_user_route(**kwargs):
|
||||
"""新建用户"""
|
||||
try:
|
||||
req = request.json
|
||||
user_manage = UserManageImpl()
|
||||
user_manage.email, user_manage.name, user_manage.pwd, user_manage.role = req['email'], req['name'], req['pwd'], req['role']
|
||||
user_manage.check_obj(columns=["email", "name", "pwd", "role"])
|
||||
user_manage.create()
|
||||
return {"info": "用户创建成功"}
|
||||
except ReturnConditionCheckFailed as e:
|
||||
e.log_error()
|
||||
return {"info": e.__str__()}, e.status_code
|
||||
|
||||
impl = UserImpl()
|
||||
|
||||
@user_route.route('/list', methods=['POST'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
def list_user_route(**kwargs):
|
||||
"""
|
||||
用户信息列表接口
|
||||
"""
|
||||
try:
|
||||
req = request.json
|
||||
list_user = ListUserImpl(
|
||||
req['search'],
|
||||
req['sort'],
|
||||
req['page_size'],
|
||||
req['page_no']
|
||||
impl.create(
|
||||
req['email'],
|
||||
req['name'],
|
||||
UserUtils.decrypt_data(encrypt_msg=req['pwd']),
|
||||
req['role']
|
||||
)
|
||||
list_user.check_obj()
|
||||
result = list_user.list()
|
||||
return {"info": '查询结果', "result": result}, 200
|
||||
except ReturnConditionCheckFailed as e:
|
||||
e.log_error()
|
||||
return {"info": e.__str__()}, e.status_code
|
||||
|
||||
return {"info": "用户创建成功"}, 200
|
||||
except AssertionError as e:
|
||||
return {"info": e.__str__()}, 202
|
||||
except AttrCheckError as e:
|
||||
return {"info": e.__str__()}, 202
|
||||
|
||||
|
||||
@user_route.route('/login', methods=['POST'])
|
||||
|
@ -87,51 +73,74 @@ def send_vcode_to_user_route():
|
|||
return {"info": e.__str__()}, e.status_code
|
||||
|
||||
|
||||
@user_route.route('/disable', methods=['GET'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
def disable_user_route(**kwargs):
|
||||
"""停用用户接口"""
|
||||
try:
|
||||
user = UserManageImpl()
|
||||
user.uid = request.args['UID']
|
||||
user.status = "disable"
|
||||
user.check_obj(columns=["uid", "status"])
|
||||
user.disable()
|
||||
return {"info": "已停用该用户"}, 200
|
||||
except ReturnConditionCheckFailed as e:
|
||||
e.log_error()
|
||||
return {"info": e.__str__()}, e.status_code
|
||||
# @user_route.route('/list', methods=['POST'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
# def list_user_route(**kwargs):
|
||||
# """
|
||||
# 用户信息列表接口
|
||||
# """
|
||||
# try:
|
||||
# req = request.json
|
||||
# list_user = ListUserImpl(
|
||||
# req['search'],
|
||||
# req['sort'],
|
||||
# req['page_size'],
|
||||
# req['page_no']
|
||||
# )
|
||||
# list_user.check_obj()
|
||||
# result = list_user.list()
|
||||
# return {"info": '查询结果', "result": result}, 200
|
||||
# except ReturnConditionCheckFailed as e:
|
||||
# e.log_error()
|
||||
# return {"info": e.__str__()}, e.status_code
|
||||
|
||||
|
||||
@user_route.route('/active', methods=['GET'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
def active_user_route(**kwargs):
|
||||
"""激活用户接口"""
|
||||
try:
|
||||
user = UserManageImpl()
|
||||
user.uid = request.args['UID']
|
||||
user.status = "normal"
|
||||
user.check_obj(columns=["uid", "status"])
|
||||
user.active()
|
||||
return {"info": "已激活该用户"}, 200
|
||||
except ReturnConditionCheckFailed as e:
|
||||
e.log_error()
|
||||
return {"info": e.__str__()}, e.status_code
|
||||
|
||||
|
||||
@user_route.route('/delete', methods=['GET'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
def delete_user_route(**kwargs):
|
||||
"""删除用户接口"""
|
||||
return {"info": "调整中"}, 200
|
||||
|
||||
|
||||
@user_route.route('/manage_role', methods=['POST'])
|
||||
@verify_token
|
||||
@authority_scope(['admin'])
|
||||
def manage_role_of_user_route(**kwargs):
|
||||
"""管理用户角色接口"""
|
||||
return {"info": "调整中"}, 200
|
||||
# @user_route.route('/disable', methods=['GET'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
# def disable_user_route(**kwargs):
|
||||
# """停用用户接口"""
|
||||
# try:
|
||||
# user = UserManageImpl()
|
||||
# user.uid = request.args['UID']
|
||||
# user.status = "disable"
|
||||
# user.check_obj(columns=["uid", "status"])
|
||||
# user.disable()
|
||||
# return {"info": "已停用该用户"}, 200
|
||||
# except ReturnConditionCheckFailed as e:
|
||||
# e.log_error()
|
||||
# return {"info": e.__str__()}, e.status_code
|
||||
#
|
||||
#
|
||||
# @user_route.route('/active', methods=['GET'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
# def active_user_route(**kwargs):
|
||||
# """激活用户接口"""
|
||||
# try:
|
||||
# user = UserManageImpl()
|
||||
# user.uid = request.args['UID']
|
||||
# user.status = "normal"
|
||||
# user.check_obj(columns=["uid", "status"])
|
||||
# user.active()
|
||||
# return {"info": "已激活该用户"}, 200
|
||||
# except ReturnConditionCheckFailed as e:
|
||||
# e.log_error()
|
||||
# return {"info": e.__str__()}, e.status_code
|
||||
#
|
||||
#
|
||||
# @user_route.route('/delete', methods=['GET'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
# def delete_user_route(**kwargs):
|
||||
# """删除用户接口"""
|
||||
# return {"info": "调整中"}, 200
|
||||
#
|
||||
#
|
||||
# @user_route.route('/manage_role', methods=['POST'])
|
||||
# @verify_token
|
||||
# @authority_scope(['admin'])
|
||||
# def manage_role_of_user_route(**kwargs):
|
||||
# """管理用户角色接口"""
|
||||
# return {"info": "调整中"}, 200
|
||||
|
|
|
@ -78,3 +78,7 @@ def check_pwd_fmt(pwd):
|
|||
case = (len(password) >= 8) and (re.match(regex, password) is not None)
|
||||
result = True if case else False
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(encrypt_data(msg="Fecr1988."))
|
|
@ -0,0 +1,131 @@
|
|||
import json
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import base64
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto.Cipher import PKCS1_v1_5 as PKCS1_cipher
|
||||
|
||||
from DBHelper.MongoHelperInstance import DB_GUA
|
||||
|
||||
|
||||
class UserUtils(object):
|
||||
|
||||
@staticmethod
|
||||
def encrypt_data(**kwargs):
|
||||
"""
|
||||
用公钥加密
|
||||
Parameters: msg str 待加密信息
|
||||
Returns: 加密后结果
|
||||
"""
|
||||
msg = kwargs['msg'] # 待加密信息
|
||||
|
||||
with open(os.path.abspath(os.path.dirname(__file__)+'/static/rsa_public_key.pem')) as f:
|
||||
data = f.read()
|
||||
public_key = RSA.importKey(data)
|
||||
|
||||
cipher = PKCS1_cipher.new(public_key)
|
||||
encrypt_text = base64.b64encode(cipher.encrypt(bytes(msg.encode("utf8"))))
|
||||
return encrypt_text.decode('utf-8')
|
||||
|
||||
@staticmethod
|
||||
def decrypt_data(**kwargs):
|
||||
"""
|
||||
用私钥解密
|
||||
Parameters: encrypt_msg str 加密信息
|
||||
Returns: 执行正确 解密后结果 执行错误 False
|
||||
"""
|
||||
try:
|
||||
encrypt_msg = kwargs['encrypt_msg'] # 加密信息
|
||||
|
||||
with open(os.path.abspath(os.path.dirname(__file__)+'/static/rsa_private_key.pem')) as f:
|
||||
data = f.read()
|
||||
private_key = RSA.importKey(data)
|
||||
|
||||
cipher = PKCS1_cipher.new(private_key)
|
||||
back_text = cipher.decrypt(base64.b64decode(encrypt_msg), 0)
|
||||
return back_text.decode('utf-8')
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def user_enum(obj, field):
|
||||
"""获取枚举属性范围"""
|
||||
|
||||
with open(os.path.abspath(os.path.dirname(__file__)+'/static/EnumDataSetting.json')) as f:
|
||||
return json.loads(f.read())[obj][field]
|
||||
|
||||
@staticmethod
|
||||
def check_mail_fmt(email):
|
||||
"""
|
||||
邮箱地址格式校验,仅允许@fecr.com.cn
|
||||
Parameters: email: 邮箱
|
||||
Returns: result: 邮箱校验结果,正确返回True,不正确返回False
|
||||
"""
|
||||
regex = "^.+\\@fecr.com.cn"
|
||||
case = (len(email) > 7) and (re.match(regex, email) is not None)
|
||||
result = True if case else False
|
||||
assert result, "未满足@fecr.com.cn邮箱格式"
|
||||
|
||||
@staticmethod
|
||||
def check_pwd_fmt(pwd):
|
||||
"""
|
||||
密码强度校验
|
||||
Parameters: pwd: 密码(已加密)
|
||||
Returns: result: 密码强度校验结果,正确返回True,不正确返回False
|
||||
"""
|
||||
password = UserUtils.decrypt_data(encrypt_msg=pwd)
|
||||
assert not password, "密码强度校验失败"
|
||||
|
||||
regex = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)^.{8,}$"
|
||||
case = (len(password) >= 8) and (re.match(regex, password) is not None)
|
||||
assert not case, "密码强度不够"
|
||||
|
||||
@staticmethod
|
||||
def check_email_registered(email):
|
||||
"""检查邮箱是否已注册"""
|
||||
|
||||
email_is_existed = DB_GUA.find_single_column(
|
||||
"管理端",
|
||||
"用户",
|
||||
{"邮箱": email},
|
||||
"邮箱"
|
||||
)
|
||||
|
||||
assert not email_is_existed, "邮箱已被注册"
|
||||
|
||||
@staticmethod
|
||||
def generate_new_uid():
|
||||
"""生成新的用户ID"""
|
||||
|
||||
def uid_maker(num):
|
||||
"""
|
||||
用户ID生成器
|
||||
num: ID长度 int
|
||||
"""
|
||||
|
||||
choices = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
salt = ''
|
||||
for i in range(num):
|
||||
salt += random.choice(choices)
|
||||
return salt
|
||||
|
||||
def uid_checker(__uid):
|
||||
"""
|
||||
用户ID重复检查
|
||||
__uid: 用户ID str
|
||||
return: True 用户ID可用 False 用户ID不可用
|
||||
"""
|
||||
is_uid_existed = DB_GUA.find_single_column(
|
||||
"管理端",
|
||||
"用户",
|
||||
{"UID": __uid},
|
||||
"UID"
|
||||
)
|
||||
return True if is_uid_existed is None else False
|
||||
|
||||
uid = uid_maker(8)
|
||||
while not uid_checker(uid):
|
||||
uid = uid_maker(8)
|
||||
return uid
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"User":{
|
||||
"status": ["normal", "disable"],
|
||||
"role": ["admin", "analysts", "guest"]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import time
|
||||
|
||||
|
||||
class CommonUtils(object):
|
||||
|
||||
@staticmethod
|
||||
def get_current_time():
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
@ -1,6 +1,89 @@
|
|||
import xlrd
|
||||
|
||||
from Modules.Company.CompanyObject import BasicBusinessInfo
|
||||
from Modules.Company.CompanyUtils import CommonUtils, ExcelSheetParser
|
||||
|
||||
|
||||
class BasicBusinessInfoImpl(object):
|
||||
class BasicBusinessInfoImpl(BasicBusinessInfo):
|
||||
|
||||
def parse_excel(self):
|
||||
""""""
|
||||
def create_company_and_parse_excel(self, file):
|
||||
""""""
|
||||
|
||||
work_book = xlrd.open_workbook(file_contents=file.read())
|
||||
|
||||
for sheet in work_book.sheets():
|
||||
|
||||
if sheet.name == '企业信息':
|
||||
data = ExcelSheetParser(sheet=sheet).parse_sheet1()
|
||||
|
||||
data
|
||||
|
||||
# elif sheet.name == '高管股东信息':
|
||||
# data1, data2 = parse_gua_sheet2(sheet)
|
||||
# for i in data1:
|
||||
# i['企业名称'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_2.update_one({"高管姓名": i['姓名'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
|
||||
# for i in data2:
|
||||
# i['企业名称'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_3.update_one({"股东名称": i['股东名称'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '经营情况':
|
||||
# data = parse_gua_sheet3(sheet)
|
||||
# for i in data:
|
||||
# i['企业名称'] = company
|
||||
# i['所在省份'] = province
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_4.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '客户信息':
|
||||
# data = parse_gua_sheet4(sheet)
|
||||
# for i in data:
|
||||
# i['担保企业'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_5.update_one({"年度": i['年度'], "客户名称": i['客户名称'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '区域分布':
|
||||
# data = parse_gua_sheet5(sheet)
|
||||
# for i in data:
|
||||
# i['担保企业'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_6.update_one({"年度": i['年度'], "地区": i['地区'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '行业分布':
|
||||
# data = parse_gua_sheet5(sheet)
|
||||
# for i in data:
|
||||
# i['担保企业'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_7.update_one({"年度": i['年度'], "所属行业": i['所属行业'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '担保金额分布':
|
||||
# data = parse_gua_sheet6(sheet)
|
||||
# for i in data:
|
||||
# i['担保企业'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_8.update_one({"年度": i['年度'], "担保企业": i['担保企业']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '资产负债表':
|
||||
# data = parse_gua_sheet7(sheet)
|
||||
# for i in data:
|
||||
# i['企业名称'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_9.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
|
||||
#
|
||||
# elif sheet.name == '利润表':
|
||||
# data = parse_gua_sheet8(sheet)
|
||||
# for i in data:
|
||||
# i['企业名称'] = company
|
||||
# if cid:
|
||||
# i['cid'] = cid
|
||||
# col_10.update_one({"年度": i['年度'], "企业名称": i['企业名称']}, {"$set": i}, upsert=True)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from Utils.ObjUtil import SpecObject
|
||||
from Utils.ValidateUtil import ValidateAttr
|
||||
from Utils.ValidateUtil import ValidateAttr, Validate
|
||||
|
||||
|
||||
class BasicBusinessInfo(SpecObject):
|
||||
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
enterprise_abbreviation = ValidateAttr(field="enterprise_abbreviation", type=str)
|
||||
|
@ -53,3 +52,415 @@ class BasicBusinessInfo(SpecObject):
|
|||
"shareholder_information": "股东信息",
|
||||
"executive_information": "高管信息"
|
||||
}
|
||||
|
||||
|
||||
class CompanyOverviewInfo(SpecObject):
|
||||
"""公司概览信息"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
credit_rating = ValidateAttr(field="credit_rating", type=str)
|
||||
rating_date = ValidateAttr(field="rating_date", func=Validate.date_format)
|
||||
province_city = ValidateAttr(field="province_city", type=str)
|
||||
label = ValidateAttr(field="label", type=str)
|
||||
update_time = ValidateAttr(field="update_time", func=Validate.date_format)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"credit_rating": "信用评级",
|
||||
"rating_date": "评级日期",
|
||||
"province_city": "所属省市",
|
||||
"label": "公司标签",
|
||||
"update_time": "更新时间"
|
||||
}
|
||||
|
||||
|
||||
class FinancialData(SpecObject):
|
||||
class BalanceSheet(SpecObject):
|
||||
"""资产负债表"""
|
||||
money_funds = ValidateAttr(field="", type=[str, float, int])
|
||||
entrusted_loans = ValidateAttr(field="", type=[str, float, int])
|
||||
other_receivables = ValidateAttr(field="", type=[str, float, int])
|
||||
reimbursement_receivable = ValidateAttr(field="", type=[str, float, int])
|
||||
total_current_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
available_sale_financial_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
long_term_equity_investment = ValidateAttr(field="", type=[str, float, int])
|
||||
fixed_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
foreclosed_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
other_non_current_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
total_non_current_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
total_assets = ValidateAttr(field="", type=[str, float, int])
|
||||
short_term_borrowing = ValidateAttr(field="", type=[str, float, int])
|
||||
other_payables = ValidateAttr(field="", type=[str, float, int])
|
||||
total_current_liabilities = ValidateAttr(field="", type=[str, float, int])
|
||||
long_term_borrowing = ValidateAttr(field="", type=[str, float, int])
|
||||
interest_bearing_liabilities = ValidateAttr(field="", type=[str, float, int])
|
||||
total_non_current_liabilities = ValidateAttr(field="", type=[str, float, int])
|
||||
total_liabilities = ValidateAttr(field="", type=[str, float, int])
|
||||
paid_capital = ValidateAttr(field="", type=[str, float, int])
|
||||
capital_reserve = ValidateAttr(field="", type=[str, float, int])
|
||||
undistributed_profit = ValidateAttr(field="", type=[str, float, int])
|
||||
total_Owner_equity = ValidateAttr(field="", type=[str, float, int])
|
||||
net_worth = ValidateAttr(field="", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
money_funds: "货币资金",
|
||||
entrusted_loans: "委托贷款",
|
||||
other_receivables: "其他应收款",
|
||||
reimbursement_receivable: "应收代偿款",
|
||||
total_current_assets: "流动资产合计",
|
||||
available_sale_financial_assets: "可供出售金融资产",
|
||||
long_term_equity_investment: "长期股权投资",
|
||||
fixed_assets: "固定资产",
|
||||
foreclosed_assets: "抵债资产",
|
||||
other_non_current_assets: "其他非流动资产",
|
||||
total_non_current_assets: "非流动资产合计",
|
||||
total_assets: "资产总额",
|
||||
short_term_borrowing: "短期借款",
|
||||
other_payables: "其他应付款",
|
||||
total_current_liabilities: "流动负债合计",
|
||||
long_term_borrowing: "长期借款",
|
||||
interest_bearing_liabilities: "有息负债",
|
||||
total_non_current_liabilities: "非流动负债合计",
|
||||
total_liabilities: "负债合计",
|
||||
paid_capital: "实收资本",
|
||||
capital_reserve: "资本公积",
|
||||
undistributed_profit: "未分配利润",
|
||||
total_Owner_equity: "所有者权益合计",
|
||||
net_worth: "净资产"
|
||||
}
|
||||
|
||||
class IncomeSheet(SpecObject):
|
||||
"""利润表"""
|
||||
operating_income = ValidateAttr(field="operating_income", type=[str, float, int])
|
||||
guarantee_fee_income = ValidateAttr(field="guarantee_fee_income", type=[str, float, int])
|
||||
loan_interest_income = ValidateAttr(field="loan_interest_income", type=[str, float, int])
|
||||
investment_business_income = ValidateAttr(field="investment_business_income", type=[str, float, int])
|
||||
other_business_income = ValidateAttr(field="other_business_income", type=[str, float, int])
|
||||
main_business_cost = ValidateAttr(field="main_business_cost", type=[str, float, int])
|
||||
taxes_surcharges = ValidateAttr(field="taxes_surcharges", type=[str, float, int])
|
||||
operating_administrative_expenses = ValidateAttr(field="operating_administrative_expenses",
|
||||
type=[str, float, int])
|
||||
interest_income = ValidateAttr(field="interest_income", type=[str, float, int])
|
||||
interest_expense = ValidateAttr(field="interest_expense", type=[str, float, int])
|
||||
asset_impairment_loss = ValidateAttr(field="asset_impairment_loss", type=[str, float, int])
|
||||
investment_income = ValidateAttr(field="investment_income", type=[str, float, int])
|
||||
operating_profit = ValidateAttr(field="operating_profit", type=[str, float, int])
|
||||
other_income = ValidateAttr(field="other_income", type=[str, float, int])
|
||||
net_profit = ValidateAttr(field="net_profit", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"operating_income": "营业收入",
|
||||
"guarantee_fee_income": "担保费收入",
|
||||
"loan_interest_income": "委贷利息收入",
|
||||
"investment_business_income": "投资业务收入",
|
||||
"other_business_income": "其他业务收入",
|
||||
"main_business_cost": "主营业务成本",
|
||||
"taxes_surcharges": "税金及附加",
|
||||
"operating_administrative_expenses": "业务及管理费用",
|
||||
"interest_income": "利息收入",
|
||||
"interest_expense": "利息支出",
|
||||
"asset_impairment_loss": "资产减值损失",
|
||||
"investment_income": "投资收益",
|
||||
"operating_profit": "营业利润",
|
||||
"other_income": "其他收益",
|
||||
"net_profit": "净利润"
|
||||
}
|
||||
|
||||
class AppendixSheet(SpecObject):
|
||||
"""补充数据表"""
|
||||
current_compensation_amount = ValidateAttr(field="current_compensation_amount", type=[str, float, int])
|
||||
current_compensation_recycle_amount = ValidateAttr(field="current_compensation_recycle_amount",
|
||||
type=[str, float, int])
|
||||
guarantee_liability = ValidateAttr(field="guarantee_liability", type=[str, float, int])
|
||||
accumulated_compensation_amount = ValidateAttr(field="accumulated_compensation_amount", type=[str, float, int])
|
||||
cumulative_compensation_recovery_amount = ValidateAttr(field="cumulative_compensation_recovery_amount",
|
||||
type=[str, float, int])
|
||||
cumulative_amount = ValidateAttr(field="cumulative_amount", type=[str, float, int])
|
||||
largest_financing = ValidateAttr(field="largest_financing", type=[str, float, int])
|
||||
financing_guarantee_liabilities = ValidateAttr(field="financing_guarantee_liabilities", type=[str, float, int])
|
||||
financial_guarantee_responsibility_balance = ValidateAttr(field="financial_guarantee_responsibility_balance",
|
||||
type=[str, float, int])
|
||||
risk_weighted_assets = ValidateAttr(field="risk_weighted_assets", type=[str, float, int])
|
||||
guaranteed_risk_reserve_balance = ValidateAttr(field="guaranteed_risk_reserve_balance", type=[str, float, int])
|
||||
top_five_financing_guarantee_liabilities = ValidateAttr(field="top_five_financing_guarantee_liabilities",
|
||||
type=[str, float, int])
|
||||
maximum_enterprise_financing_guarantee = ValidateAttr(field="maximum_enterprise_financing_guarantee",
|
||||
type=[str, float, int])
|
||||
guarantee_compensation_reserve = ValidateAttr(field="guarantee_compensation_reserve", type=[str, float, int])
|
||||
unexpired_liability_reserve = ValidateAttr(field="unexpired_liability_reserve", type=[str, float, int])
|
||||
counter_guarantee_amount = ValidateAttr(field="counter_guarantee_amount", type=[str, float, int])
|
||||
bank_credit_limit = ValidateAttr(field="bank_credit_limit", type=[str, float, int])
|
||||
unused_credit_limit = ValidateAttr(field="unused_credit_limit", type=[str, float, int])
|
||||
number_cooperative_banks = ValidateAttr(field="number_cooperative_banks", type=[str, float, int])
|
||||
deposit_margin = ValidateAttr(field="deposit_margin", type=[str, float, int])
|
||||
save_margin = ValidateAttr(field="save_margin", type=[str, float, int])
|
||||
guaranteed_balance = ValidateAttr(field="guaranteed_balance", type=[str, float, int])
|
||||
current_guarantee_business_income = ValidateAttr(field="current_guarantee_business_income",
|
||||
type=[str, float, int])
|
||||
last_period_guarantee_business_income = ValidateAttr(field="last_period_guarantee_business_income",
|
||||
type=[str, float, int])
|
||||
one_assets = ValidateAttr(field="one_assets", type=[str, float, int])
|
||||
two_assets = ValidateAttr(field="two_assets", type=[str, float, int])
|
||||
three_assets = ValidateAttr(field="three_assets", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"current_compensation_amount": "当期代偿金额",
|
||||
"current_compensation_recycle_amount": "当期代偿回收金额",
|
||||
"guarantee_liability": "当期解除担保责任余额",
|
||||
"accumulated_compensation_amount": "近三年累计代偿金额",
|
||||
"cumulative_compensation_recovery_amount": "近三年累计代偿回收金额",
|
||||
"cumulative_amount": "近三年累计解除担保责任金额",
|
||||
"largest_financing": "最大单一行业融资担保责任余额",
|
||||
"financing_guarantee_liabilities": "当期新增融资担保责任余额",
|
||||
"financial_guarantee_responsibility_balance": "融资担保责任余额",
|
||||
"risk_weighted_assets": "风险加权资产",
|
||||
"guaranteed_risk_reserve_balance": "担保风险准备金余额",
|
||||
"top_five_financing_guarantee_liabilities": "前五大被担保企业融资担保责任余额",
|
||||
"maximum_enterprise_financing_guarantee": "最大被担保企业融资担保责任余额",
|
||||
"guarantee_compensation_reserve": "担保赔偿准备金",
|
||||
"unexpired_liability_reserve": "未到期责任准备金",
|
||||
"counter_guarantee_amount": "反担保金额",
|
||||
"bank_credit_limit": "银行授信额度",
|
||||
"unused_credit_limit": "授信未使用额度",
|
||||
"number_cooperative_banks": "合作银行数量",
|
||||
"deposit_margin": "存入保证金",
|
||||
"save_margin": "存出保证金",
|
||||
"guaranteed_balance": "担保在保余额",
|
||||
"current_guarantee_business_income": "当期担保业务收入",
|
||||
"last_period_guarantee_business_income": "上期担保业务收入",
|
||||
"one_assets": "I类资产",
|
||||
"two_assets": "II类资产",
|
||||
"three_assets": "III类资产"
|
||||
}
|
||||
|
||||
class FinancialIndicator(SpecObject):
|
||||
"""财务指标"""
|
||||
guaranteed_insured_balance_growth_rate = ValidateAttr(field="guaranteed_insured_balance_growth_rate",
|
||||
type=[str, float, int])
|
||||
guaranteed_revenue_growth_rate = ValidateAttr(field="guaranteed_revenue_growth_rate", type=[str, float, int])
|
||||
growth_rate_of_total_assets = ValidateAttr(field="growth_rate_of_total_assets", type=[str, float, int])
|
||||
cash_assets_ratio = ValidateAttr(field="cash_assets_ratio", type=[str, float, int])
|
||||
current_ratio = ValidateAttr(field="current_ratio", type=[str, float, int])
|
||||
compensation_reserve_ratio = ValidateAttr(field="compensation_reserve_ratio", type=[str, float, int])
|
||||
compensation_rate = ValidateAttr(field="compensation_rate", type=[str, float, int])
|
||||
risk_reserve_adequacy_ratio = ValidateAttr(field="risk_reserve_adequacy_ratio", type=[str, float, int])
|
||||
single_customer_concentration = ValidateAttr(field="single_customer_concentration", type=[str, float, int])
|
||||
current_guarantee_compensation_rate = ValidateAttr(field="current_guarantee_compensation_rate",
|
||||
type=[str, float, int])
|
||||
current_compensation_recovery_rate = ValidateAttr(field="current_compensation_recovery_rate",
|
||||
type=[str, float, int])
|
||||
financing_guarantee_magnification = ValidateAttr(field="financing_guarantee_magnification",
|
||||
type=[str, float, int])
|
||||
industry_concentration = ValidateAttr(field="industry_concentration", type=[str, float, int])
|
||||
return_total_assets = ValidateAttr(field="return_total_assets", type=[str, float, int])
|
||||
operating_margin = ValidateAttr(field="operating_margin", type=[str, float, int])
|
||||
roe = ValidateAttr(field="roe", type=[str, float, int])
|
||||
actual_asset_liability_ratio = ValidateAttr(field="actual_asset_liability_ratio", type=[str, float, int])
|
||||
capital_adequacy_ratio = ValidateAttr(field="capital_adequacy_ratio", type=[str, float, int])
|
||||
paid_capital = ValidateAttr(field="paid_capital", type=[str, float, int])
|
||||
guarantee_business_income = ValidateAttr(field="guarantee_business_income", type=[str, float, int])
|
||||
cumulative_guarantee_compensation_rate = ValidateAttr(field="cumulative_guarantee_compensation_rate",
|
||||
type=[str, float, int])
|
||||
cumulative_compensation_recovery_rate = ValidateAttr(field="cumulative_compensation_recovery_rate",
|
||||
type=[str, float, int])
|
||||
risk_coverage_ratio = ValidateAttr(field="risk_coverage_ratio", type=[str, float, int])
|
||||
cash_asset_compensation_rate = ValidateAttr(field="cash_asset_compensation_rate", type=[str, float, int])
|
||||
margin_ratio = ValidateAttr(field="margin_ratio", type=[str, float, int])
|
||||
proportion_investment_business_income = ValidateAttr(field="proportion_investment_business_income",
|
||||
type=[str, float, int])
|
||||
investment_income_growth_rate = ValidateAttr(field="investment_income_growth_rate", type=[str, float, int])
|
||||
one_proportion_class_assets = ValidateAttr(field="one_proportion_class_assets", type=[str, float, int])
|
||||
customer_concentration = ValidateAttr(field="customer_concentration", type=[str, float, int])
|
||||
proportion_income_guarantee_business = ValidateAttr(field="proportion_income_guarantee_business",
|
||||
type=[str, float, int])
|
||||
two_proportion_class_assets = ValidateAttr(field="two_proportion_class_assets", type=[str, float, int])
|
||||
three_proportion_class_assets = ValidateAttr(field="three_proportion_class_assets", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
guaranteed_insured_balance_growth_rate: "担保在保余额增长率(%)",
|
||||
guaranteed_revenue_growth_rate: "担保收入增长率(%)",
|
||||
growth_rate_of_total_assets: "资产总额增长率(%)",
|
||||
cash_assets_ratio: "现金类资产比率(%)",
|
||||
current_ratio: "流动比率(%)",
|
||||
compensation_reserve_ratio: "代偿准备金比率(%)",
|
||||
compensation_rate: "代偿保障率(%)",
|
||||
risk_reserve_adequacy_ratio: "风险准备金充足率(%)",
|
||||
single_customer_concentration: "单一客户集中度(%)",
|
||||
current_guarantee_compensation_rate: "当期担保代偿率(%)",
|
||||
current_compensation_recovery_rate: "当期代偿回收率(%)",
|
||||
financing_guarantee_magnification: "融资担保放大倍数(倍)",
|
||||
industry_concentration: "行业集中度(%)",
|
||||
return_total_assets: "总资产收益率(%)",
|
||||
operating_margin: "营业利润率(%)",
|
||||
roe: "净资产收益率(%)",
|
||||
actual_asset_liability_ratio: "实际资产负债率(%)",
|
||||
capital_adequacy_ratio: "资本充足率(%)",
|
||||
paid_capital: "实收资本(亿元)",
|
||||
guarantee_business_income: "担保业务收入(万元)",
|
||||
cumulative_guarantee_compensation_rate: "近三年累计担保代偿率(%)",
|
||||
cumulative_compensation_recovery_rate: "近三年累计代偿回收率(%)",
|
||||
risk_coverage_ratio: "风险覆盖率(%)",
|
||||
cash_asset_compensation_rate: "现金类资产代偿保障率(%)",
|
||||
margin_ratio: "保证金比率(%)",
|
||||
proportion_investment_business_income: "投资业务收入占比(%)",
|
||||
investment_income_growth_rate: "投资收益增长率(%)",
|
||||
one_proportion_class_assets: "I类资产占比(%)",
|
||||
customer_concentration: "客户集中度(%)",
|
||||
proportion_income_guarantee_business: "担保业务收入占比(%)",
|
||||
two_proportion_class_assets: "II类资产占比(%)",
|
||||
three_proportion_class_assets: "III类资产占比(%)"
|
||||
}
|
||||
|
||||
"""财务数据"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
report_period = ValidateAttr(field="report_period", type=str)
|
||||
balance_sheet = ValidateAttr(field="balance_sheet", type=BalanceSheet)
|
||||
income_sheet = ValidateAttr(field="income_sheet", type=IncomeSheet)
|
||||
appendix_sheet = ValidateAttr(field="appendix_sheet", type=AppendixSheet)
|
||||
financial_indicator = ValidateAttr(field="financial_indicator", type=FinancialIndicator)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"report_period": "报告期",
|
||||
"balance_sheet": "资产负债表",
|
||||
"income_sheet": "利润表",
|
||||
"appendix_sheet": "补充数据表",
|
||||
"financial_indicator": "财务指标"
|
||||
}
|
||||
|
||||
|
||||
class CustomerInfo(SpecObject):
|
||||
"""客户信息"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
report_period = ValidateAttr(field="report_period", type=str)
|
||||
client_name = ValidateAttr(field="client_name", type=str)
|
||||
guarantee_type = ValidateAttr(field="guarantee_type", type=str)
|
||||
balance_under_insurance = ValidateAttr(field="balance_under_insurance", type=[str, float, int])
|
||||
financing_guarantee_balance = ValidateAttr(field="financing_guarantee_balance", type=[str, float, int])
|
||||
guarantee_start_date = ValidateAttr(field="guarantee_start_date", type=[str, float, int])
|
||||
guarantee_end_date = ValidateAttr(field="guarantee_end_date", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"report_period": "报告期",
|
||||
"client_name": "客户名称",
|
||||
"guarantee_type": "担保类型",
|
||||
"balance_under_insurance": "在保余额",
|
||||
"financing_guarantee_balance": "融资担保责任余额",
|
||||
"guarantee_start_date": "担保起始日",
|
||||
"guarantee_end_date": "担保截止日"
|
||||
}
|
||||
|
||||
|
||||
class RegionalDistribution(SpecObject):
|
||||
"""区域分布"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
report_period = ValidateAttr(field="report_period", type=str)
|
||||
region = ValidateAttr(field="region", type=str)
|
||||
year_end_insured_balance = ValidateAttr(field="year_end_insured_balance", type=[str, float, int])
|
||||
year_end_insured_liability_balance = ValidateAttr(field="year_end_insured_balance", type=[str, float, int])
|
||||
insured_balance_newly_added = ValidateAttr(field="insured_balance_newly_added", type=[str, float, int])
|
||||
insured_liability_newly_added = ValidateAttr(field="insured_liability_newly_added", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"report_period": "报告期",
|
||||
"region": "地区",
|
||||
"year_end_insured_balance": "年末在保余额",
|
||||
"year_end_insured_liability_balance": "年末在保责任余额",
|
||||
"insured_balance_newly_added": "当年新增在保余额",
|
||||
"insured_liability_newly_added": "当年新增在保责任余额"
|
||||
}
|
||||
|
||||
|
||||
class IndustryDistribution(SpecObject):
|
||||
"""行业分布"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
report_period = ValidateAttr(field="report_period", type=str)
|
||||
industry = ValidateAttr(field="industry", type=str)
|
||||
year_end_insured_balance = ValidateAttr(field="year_end_insured_balance", type=[str, float, int])
|
||||
year_end_insured_liability_balance = ValidateAttr(field="year_end_insured_balance", type=[str, float, int])
|
||||
insured_balance_newly_added = ValidateAttr(field="insured_balance_newly_added", type=[str, float, int])
|
||||
insured_liability_newly_added = ValidateAttr(field="insured_liability_newly_added", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"report_period": "报告期",
|
||||
"industry": "所属行业",
|
||||
"year_end_insured_balance": "年末在保余额",
|
||||
"year_end_insured_liability_balance": "年末在保责任余额",
|
||||
"insured_balance_newly_added": "当年新增在保余额",
|
||||
"insured_liability_newly_added": "当年新增在保责任余额"
|
||||
}
|
||||
|
||||
|
||||
class GuaranteedBalanceDistribution(SpecObject):
|
||||
"""担保余额分布"""
|
||||
|
||||
class GuaranteeBalance(SpecObject):
|
||||
"""担保金额相关"""
|
||||
one_million = ValidateAttr(field="one_million", type=[str, float, int])
|
||||
five_million = ValidateAttr(field="five_million", type=[str, float, int])
|
||||
ten_million = ValidateAttr(field="ten_million", type=[str, float, int])
|
||||
thirty_million = ValidateAttr(field="thirty_million", type=[str, float, int])
|
||||
fifty_million = ValidateAttr(field="fifty_million", type=[str, float, int])
|
||||
eighty_million = ValidateAttr(field="eighty_million", type=[str, float, int])
|
||||
one_hundred_million = ValidateAttr(field="one_hundred_million", type=[str, float, int])
|
||||
more_than_one_hundred_million = ValidateAttr(field="more_than_one_hundred_million", type=[str, float, int])
|
||||
total = ValidateAttr(field="total", type=[str, float, int])
|
||||
|
||||
fields_map = {
|
||||
"one_million": "金额<=100w",
|
||||
"five_million": "100w<金额<=500w",
|
||||
"ten_million": "500w<金额<=1000w",
|
||||
"thirty_million": "1000w<金额<=3000w",
|
||||
"fifty_million": "3000w<金额<=5000w",
|
||||
"eighty_million": "5000w<金额<=8000w",
|
||||
"one_hundred_million": "8000w<金额<=10000w",
|
||||
"more_than_one_hundred_million": "金额>10000w",
|
||||
"total": "合计"
|
||||
}
|
||||
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
report_period = ValidateAttr(field="report_period", type=str)
|
||||
guarantee_account = ValidateAttr(field="guaranteed_account", type=GuaranteeBalance)
|
||||
guarantee_number = ValidateAttr(field="guaranteed_number", type=GuaranteeBalance)
|
||||
guarantee_liability_balance = ValidateAttr(field="guarantee_liability_balance", type=GuaranteeBalance)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"report_period": "报告期",
|
||||
"guaranteed_account": "担保户数",
|
||||
"guaranteed_number": "担保笔数",
|
||||
"guarantee_liability_balance": "担保责任余额"
|
||||
}
|
||||
|
||||
|
||||
class RatingRecord(SpecObject):
|
||||
"""评级记录"""
|
||||
cid = ValidateAttr(field="cid", type=str)
|
||||
company_name = ValidateAttr(field="company_name", type=str)
|
||||
rid = ValidateAttr(field="rid", type=str)
|
||||
level = ValidateAttr(field="level", type=str)
|
||||
rating_date = ValidateAttr(field="rating_date", func=Validate.date_format)
|
||||
rating_report = ValidateAttr(field="rating_report", type=str)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"company_name": "企业名称",
|
||||
"rid": "评级ID",
|
||||
"level": "信用等级",
|
||||
"rating_date": "评级日期",
|
||||
"rating_report": "评级报告"
|
||||
}
|
|
@ -13,4 +13,4 @@ def create_route(**kwargs):
|
|||
company_name = request.form['company_name']
|
||||
file = request.files['file']
|
||||
|
||||
BasicBusinessInfoImpl
|
||||
BasicBusinessInfoImpl.parse_excel(file)
|
|
@ -6,6 +6,33 @@ from datetime import datetime, timedelta
|
|||
from DBHelper.MongoHelperInstance import DB_GUA
|
||||
|
||||
|
||||
class CommonUtils(object):
|
||||
|
||||
# 生成新的企业ID,如果该ID存在,则重新生成
|
||||
@staticmethod
|
||||
def make_new_cid():
|
||||
|
||||
def random_cid(num):
|
||||
"""随机企业ID"""
|
||||
choices = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
salt = ''
|
||||
for i in range(num):
|
||||
salt += random.choice(choices)
|
||||
return salt
|
||||
|
||||
new_cid = random_cid(8)
|
||||
|
||||
case = DB_GUA.find_single_column(
|
||||
"应用端",
|
||||
"企业用户",
|
||||
{"企业ID": new_cid},
|
||||
"企业ID"
|
||||
) is not None
|
||||
while case:
|
||||
new_cid = random_cid(8)
|
||||
return new_cid
|
||||
|
||||
|
||||
class ExcelParserUtil(object):
|
||||
|
||||
# 转换excel日期
|
||||
|
@ -33,30 +60,6 @@ class ExcelParserUtil(object):
|
|||
def list_decimal(_list):
|
||||
return list(map(lambda _v: round(_v, 2) if isinstance(_v, float) else _v, _list))
|
||||
|
||||
# 生成新的企业ID,如果该ID存在,则重新生成
|
||||
@staticmethod
|
||||
def make_new_cid():
|
||||
|
||||
def random_cid(num):
|
||||
"""随机企业ID"""
|
||||
choices = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
salt = ''
|
||||
for i in range(num):
|
||||
salt += random.choice(choices)
|
||||
return salt
|
||||
|
||||
new_cid = random_cid(8)
|
||||
|
||||
case = DB_GUA.find_single_column(
|
||||
"应用端",
|
||||
"企业用户",
|
||||
{"企业ID": new_cid},
|
||||
"企业ID"
|
||||
) is not None
|
||||
while case:
|
||||
new_cid = random_cid(8)
|
||||
return new_cid
|
||||
|
||||
|
||||
class ExcelSheetParser(object):
|
||||
|
||||
|
|
|
@ -43,6 +43,16 @@ class APIReturnError(RuntimeError):
|
|||
return self.error_info
|
||||
|
||||
|
||||
class AttrCheckError(RuntimeError):
|
||||
"""属性检查异常"""
|
||||
|
||||
def __init__(self, error_info):
|
||||
self.error_info = error_info
|
||||
|
||||
def __str__(self):
|
||||
return self.error_info
|
||||
|
||||
|
||||
class CheckFailed(RuntimeError):
|
||||
"""检查异常"""
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
class SpecObject(object):
|
||||
"""自定义类"""
|
||||
"""自定义父类"""
|
||||
|
||||
fields_map = {}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from Utils.ErrorUtil import ReturnConditionCheckFailed
|
||||
from Utils.ErrorUtil import AttrCheckError
|
||||
|
||||
|
||||
class Validate(object):
|
||||
|
@ -59,71 +59,62 @@ class Validate(object):
|
|||
class ValidateAttr(object):
|
||||
"""对象属性值检查"""
|
||||
|
||||
FIELD_ERROR_INFO = '字段【{}】异常'
|
||||
FILED_MAP_ERROR = '字段未映射完整'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.kwargs = kwargs
|
||||
|
||||
self.code = kwargs['error_code'] if 'error_code' in kwargs else 202
|
||||
|
||||
if 'error_info' in kwargs:
|
||||
self.info = kwargs['error_info']
|
||||
elif 'mark' in kwargs:
|
||||
self.info = self.FIELD_ERROR_INFO.format(kwargs['mark'])
|
||||
else:
|
||||
self.info = None
|
||||
self.error_info = kwargs['error_info'] if 'error_info' in kwargs else None
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
if self.kwargs['field'] in instance.__dict__:
|
||||
return instance.__dict__[self.kwargs['field']]
|
||||
|
||||
def __set__(self, instance, value):
|
||||
try:
|
||||
if not self.info:
|
||||
if instance.fields_map.__contains__(self.kwargs['field']):
|
||||
self.info = self.FIELD_ERROR_INFO.format(instance.fields_map[self.kwargs['field']])
|
||||
except AttributeError:
|
||||
raise ReturnConditionCheckFailed(self.FILED_MAP_ERROR, self.code)
|
||||
|
||||
if not self.error_info:
|
||||
if instance.fields_map.__contains__(self.kwargs['field']):
|
||||
info_template = '赋值异常: {}; 请检查: {};'
|
||||
self.error_info = info_template.format(
|
||||
self.kwargs['field'],
|
||||
instance.fields_map[self.kwargs['field']]
|
||||
)
|
||||
|
||||
if 'type' in self.kwargs:
|
||||
"""检查实例的属性类型"""
|
||||
if type(self.kwargs['type']) is list:
|
||||
if type(value) not in self.kwargs['type']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
else:
|
||||
if not isinstance(value, self.kwargs['type']):
|
||||
if value is not None and 'default' not in self.kwargs:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
|
||||
if 'length' in self.kwargs:
|
||||
"""检查实例的属性值长度(一般是str类型)"""
|
||||
if len(value) != self.kwargs['length']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
|
||||
if 'in_list' in self.kwargs:
|
||||
"""检查实例属性是否包含于列表中(属性有列表和非列表两种情况)"""
|
||||
if type(value) is not list:
|
||||
if value not in self.kwargs['in_list']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
else:
|
||||
for item in value:
|
||||
if item not in self.kwargs['in_list']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
|
||||
if 'instance_list' in self.kwargs:
|
||||
"""检查实例列表"""
|
||||
if type(value) is not list:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
else:
|
||||
for item in value:
|
||||
if not isinstance(item, self.kwargs['instance_list']):
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
|
||||
if 'func' in self.kwargs:
|
||||
"""属性检查函数"""
|
||||
if not list(map(self.kwargs['func'], [value]))[0]:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
raise AttrCheckError(self.error_info)
|
||||
|
||||
if 'default' in self.kwargs:
|
||||
"""实例属性默认值"""
|
||||
|
|
|
@ -7,4 +7,5 @@ gevent
|
|||
pymongo~=3.11.0
|
||||
requests~=2.25.1
|
||||
pandas~=1.3.5
|
||||
pycryptodome
|
||||
pycryptodome
|
||||
xlrd~=1.2.0
|
Loading…
Reference in New Issue