tmp
This commit is contained in:
parent
2766d3c222
commit
5a3f8b3dad
|
@ -0,0 +1,303 @@
|
|||
from Utils.ObjUtil import SpecObject
|
||||
from Utils.ValidateUtil import ValidateAttr, Validate
|
||||
|
||||
|
||||
class BasicBusinessInfo(SpecObject):
|
||||
"""基本工商信息"""
|
||||
|
||||
class BusinessInfo(SpecObject):
|
||||
"""基本工商信息"""
|
||||
|
||||
status = ValidateAttr(field="status", type=str, default=None)
|
||||
legal_person = ValidateAttr(field="legal_person", type=str, default=None)
|
||||
company_type = ValidateAttr(field="company_type", type=str, default=None)
|
||||
taxpayer_id = ValidateAttr(field="taxpayer_id", type=str, default=None)
|
||||
business_scope = ValidateAttr(field="business_scope", type=str, default=None)
|
||||
registered_capital = ValidateAttr(field="registered_capital", type=str, default=None)
|
||||
paid_capital = ValidateAttr(field="paid_capital", type=str, default=None)
|
||||
registered_address = ValidateAttr(field="registered_address", type=str, default=None)
|
||||
registration_authority = ValidateAttr(field="registration_authority", type=str, default=None)
|
||||
industry = ValidateAttr(field="industry", type=str, default=None)
|
||||
staff_size = ValidateAttr(field="staff_size", type=str, default=None)
|
||||
people_insured_num = ValidateAttr(field="people_insured_num", type=int, default=None)
|
||||
micro_company = ValidateAttr(field="micro_company", type=str, in_list=["是", "否"], default=None)
|
||||
|
||||
fields_map = {
|
||||
"status": "企业状态",
|
||||
"legal_person": "法定代表人",
|
||||
"company_type": "企业类型",
|
||||
"taxpayer_id": "纳税人识别号",
|
||||
"business_scope": "经营范围",
|
||||
"registered_capital": "注册资本",
|
||||
"paid_capital": "实缴资本",
|
||||
"registered_address": "注册地址",
|
||||
"registration_authority": "登记机关",
|
||||
"industry": "行业",
|
||||
"staff_size": "人员规模",
|
||||
"people_insured_num": "参保人数",
|
||||
"micro_company": "小微企业"
|
||||
}
|
||||
|
||||
class ShareHolder(SpecObject):
|
||||
"""股东信息"""
|
||||
|
||||
name = ValidateAttr(field='name', type=str)
|
||||
share_holder_type = ValidateAttr(field='share_holder_type', type=str, default=None)
|
||||
share_holding_ratio = ValidateAttr(field="share_holding_ratio", type=str, default=None)
|
||||
subscription_amount = ValidateAttr(field="subscription_amount", type=str, default=None)
|
||||
subscription_date = ValidateAttr(field="subscription_date", type=str, default=None)
|
||||
paid_amount = ValidateAttr(field="paid_amount", type=list, default=[])
|
||||
payment_method = ValidateAttr(field="payment_method", type=list, default=[])
|
||||
payment_time = ValidateAttr(field="payment_time", type=list, default=[])
|
||||
|
||||
fields_map = {
|
||||
"name": "股东",
|
||||
"share_holder_type": "股东类型",
|
||||
"share_holding_ratio": "持股比例",
|
||||
"subscription_amount": "认缴金额",
|
||||
"subscription_date": "认缴日期",
|
||||
"paid_amount": "实缴金额",
|
||||
"payment_method": "实缴方式",
|
||||
"payment_time": "实缴时间"
|
||||
}
|
||||
|
||||
class MainMember(SpecObject):
|
||||
"""主要成员"""
|
||||
|
||||
name = ValidateAttr(field="name", type=str)
|
||||
job_title = ValidateAttr(field="job_title", type=list, default=[])
|
||||
|
||||
fields_map = {
|
||||
"name": "姓名",
|
||||
"job_title": "职务"
|
||||
}
|
||||
|
||||
cid = ValidateAttr(field='cid', type=str, length=8)
|
||||
name = ValidateAttr(field='name', type=str)
|
||||
update_time = ValidateAttr(field='update_time', func=Validate.time_format)
|
||||
business_info = ValidateAttr(field="business_info", type=BusinessInfo)
|
||||
share_holder = ValidateAttr(field='share_holder', instance_list=ShareHolder)
|
||||
main_member = ValidateAttr(field='main_member', instance_list=MainMember)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"name": "企业名称",
|
||||
"update_time": "更新日期",
|
||||
"business_info": "工商信息",
|
||||
"share_holder": "股东信息",
|
||||
"main_member": "主要成员"
|
||||
}
|
||||
|
||||
|
||||
class BasicFinancialData(SpecObject):
|
||||
"""基本财务数据"""
|
||||
|
||||
class BalanceSheet(SpecObject):
|
||||
"""资产负债表"""
|
||||
|
||||
accounts_receivable = ValidateAttr(field='accounts_receivable', type=[int, float])
|
||||
stock = ValidateAttr(field='stock', type=[int, float])
|
||||
total_current_assets = ValidateAttr(field='total_current_assets', type=[int, float])
|
||||
total_assets = ValidateAttr(field='total_assets', type=[int, float])
|
||||
short_loan = ValidateAttr(field='short_loan', type=[int, float])
|
||||
one_year_liabilities = ValidateAttr(field='one_year_liabilities', type=[int, float])
|
||||
total_current_liabilities = ValidateAttr(field='total_current_liabilities', type=[int, float])
|
||||
long_term_loan = ValidateAttr(field='long_term_loan', type=[int, float])
|
||||
total_liabilities = ValidateAttr(field='total_liabilities', type=[int, float])
|
||||
total_owners_equity = ValidateAttr(field='total_owners_equity', type=[int, float])
|
||||
|
||||
fields_map = {
|
||||
'accounts_receivable': '应收账款',
|
||||
'stock': '存货',
|
||||
'total_current_assets': '流动资产合计',
|
||||
'total_assets': '资产总计',
|
||||
'short_loan': '短期借款',
|
||||
'one_year_liabilities': '一年内到期非流动负债',
|
||||
'total_current_liabilities': '流动负债合计',
|
||||
'long_term_loan': '长期借款',
|
||||
'total_liabilities': '负债合计',
|
||||
'total_owners_equity': '所有者权益合计'
|
||||
}
|
||||
|
||||
class ProfitSheet(SpecObject):
|
||||
"""利润表"""
|
||||
|
||||
operating_income = ValidateAttr(field='operating_income', type=[int, float])
|
||||
operating_cost = ValidateAttr(field='operating_cost', type=[int, float])
|
||||
total_profit = ValidateAttr(field='total_profit', type=[int, float])
|
||||
net_profit = ValidateAttr(field='net_profit', type=[int, float])
|
||||
|
||||
fields_map = {
|
||||
'operating_income': '营业收入',
|
||||
'operating_cost': '营业成本',
|
||||
'total_profit': '利润总额',
|
||||
'net_profit': '净利润'
|
||||
}
|
||||
|
||||
class AppendixDataSheet(SpecObject):
|
||||
"""补充数据表"""
|
||||
|
||||
rd_expenses = ValidateAttr(field='rd_expenses', type=[int, float])
|
||||
interest_disbursement = ValidateAttr(field='interest_disbursement', type=[int, float])
|
||||
interest_expense = ValidateAttr(field='interest_expense', type=[int, float])
|
||||
|
||||
fields_map = {
|
||||
'rd_expenses': '研发费用',
|
||||
'interest_disbursement': '计入财务费的利息支出',
|
||||
'interest_expense': '资本化利息支出'
|
||||
}
|
||||
|
||||
class FinancialIndex(SpecObject):
|
||||
"""财务指标"""
|
||||
|
||||
roe = ValidateAttr(field="roe", type=[int, float, type(None)])
|
||||
inventory_turnover = ValidateAttr(field="inventory_turnover", type=[int, float, type(None)])
|
||||
interest_multiple = ValidateAttr(field="interest_multiple", type=[int, float, type(None)])
|
||||
accounts_receivable_turnover = ValidateAttr(field="accounts_receivable_turnover", type=[int, float, type(None)])
|
||||
total_asset_turnover = ValidateAttr(field="total_asset_turnover", type=[int, float, type(None)])
|
||||
total_asset_growth_rate = ValidateAttr(field="total_asset_growth_rate", type=[int, float, type(None)])
|
||||
roa = ValidateAttr(field="roa", type=[int, float, type(None)])
|
||||
technology_investment_ratio = ValidateAttr(field="technology_investment_ratio", type=[int, float, type(None)])
|
||||
operating_growth_rate = ValidateAttr(field="operating_growth_rate", type=[int, float, type(None)])
|
||||
assets_and_liabilities = ValidateAttr(field="assets_and_liabilities", type=[int, float, type(None)])
|
||||
quick_ratio = ValidateAttr(field="quick_ratio", type=[int, float, type(None)])
|
||||
|
||||
fields_map = {
|
||||
"roe": "净资产收益率",
|
||||
"inventory_turnover": "存货周转率",
|
||||
"interest_multiple": "已获利息倍数",
|
||||
"accounts_receivable_turnover": "应收账款周转率",
|
||||
"total_asset_turnover": "总资产周转率",
|
||||
"total_asset_growth_rate": "总资产增长率",
|
||||
"roa": "总资产报酬率",
|
||||
"technology_investment_ratio": "技术投入比率",
|
||||
"operating_growth_rate": "营业增长率",
|
||||
"assets_and_liabilities": "资产负债率",
|
||||
"quick_ratio": "速动比率"
|
||||
}
|
||||
|
||||
cid = ValidateAttr(field='cid', type=str, length=8)
|
||||
name = ValidateAttr(field='name', type=str)
|
||||
report_date = ValidateAttr(field='report_date', func=Validate.date_format)
|
||||
balance_sheet = ValidateAttr(field="balance_sheet", type=BalanceSheet)
|
||||
profit_sheet = ValidateAttr(field="profit_sheet", type=ProfitSheet)
|
||||
appendix_data = ValidateAttr(field="appendix_data", type=AppendixDataSheet)
|
||||
financial_index = ValidateAttr(field="financial_index", type=FinancialIndex)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"name": "企业名称",
|
||||
"report_date": "报告期",
|
||||
"balance_sheet": "资产负债表",
|
||||
"profit_sheet": "利润表",
|
||||
"appendix_data": "补充数据表",
|
||||
"financial_index": "财务指标"
|
||||
}
|
||||
|
||||
|
||||
class FinancialElementsAnalysis(SpecObject):
|
||||
"""财务要素分析"""
|
||||
|
||||
class FinancialAnalysisDetails(SpecObject):
|
||||
"""指标详情"""
|
||||
name = ValidateAttr(field='name', type=str)
|
||||
value = ValidateAttr(field='value', type=[str, float, type(None)])
|
||||
quality = ValidateAttr(field='quality', type=str)
|
||||
|
||||
fields_map = {
|
||||
"name": "指标",
|
||||
"value": "数值",
|
||||
"quality": "水平"
|
||||
}
|
||||
|
||||
class CompareToYears(SpecObject):
|
||||
"""财务得分年度比较"""
|
||||
|
||||
class FinancialIndex(SpecObject):
|
||||
"""财务指标"""
|
||||
profit_ability = ValidateAttr(field='profit_ability', type=[int, float])
|
||||
asset_quality = ValidateAttr(field='asset_quality', type=[int, float])
|
||||
debt_risk = ValidateAttr(field='debt_risk', type=[int, float])
|
||||
business_growth = ValidateAttr(field='business_growth', type=[int, float])
|
||||
|
||||
fields_map = {
|
||||
"profit_ability": "盈利能力",
|
||||
"asset_quality": "资产质量",
|
||||
"debt_risk": "债务风险",
|
||||
"business_growth": "经营增长"
|
||||
}
|
||||
|
||||
year = ValidateAttr(field='year', type=str, func=Validate.date_format)
|
||||
index = ValidateAttr(field='index', type=FinancialIndex)
|
||||
|
||||
fields_map = {
|
||||
"year": "年度",
|
||||
"index": "指标"
|
||||
}
|
||||
|
||||
class CompareToIndustry(SpecObject):
|
||||
"""财务得分同行比较"""
|
||||
|
||||
class FinancialIndex(SpecObject):
|
||||
"""财务指标"""
|
||||
profit_ability = ValidateAttr(field='profit_ability', type=[int, float])
|
||||
asset_quality = ValidateAttr(field='asset_quality', type=[int, float])
|
||||
debt_risk = ValidateAttr(field='debt_risk', type=[int, float])
|
||||
business_growth = ValidateAttr(field='business_growth', type=[int, float])
|
||||
|
||||
fields_map = {
|
||||
"profit_ability": "盈利能力",
|
||||
"asset_quality": "资产质量",
|
||||
"debt_risk": "债务风险",
|
||||
"business_growth": "经营增长"
|
||||
}
|
||||
|
||||
company_score = ValidateAttr(field='company_score', type=FinancialIndex)
|
||||
average_score = ValidateAttr(field='average_score', type=FinancialIndex)
|
||||
|
||||
fields_map = {
|
||||
"company_score": "公司水平",
|
||||
"average_score": "平均水平"
|
||||
}
|
||||
|
||||
cid = ValidateAttr(field='cid', type=str, length=8)
|
||||
update_time = ValidateAttr(field='update_time', func=Validate.time_format)
|
||||
rid = ValidateAttr(field='rid', type=str, length=8)
|
||||
report_date = ValidateAttr(field='report_date', type=str, func=Validate.date_format)
|
||||
compare_to_years = ValidateAttr(field='compare_to_years', length=2, instance_list=CompareToYears)
|
||||
compare_to_industry = ValidateAttr(field='compare_to_industry', type=CompareToIndustry)
|
||||
delta_to_years = ValidateAttr(field='delta_to_years', type=CompareToYears.FinancialIndex)
|
||||
delta_to_industry = ValidateAttr(field='delta_to_industry', type=CompareToIndustry.FinancialIndex)
|
||||
index_details = ValidateAttr(field='index_details', instance_list=FinancialAnalysisDetails)
|
||||
|
||||
fields_map = {
|
||||
"cid": "企业ID",
|
||||
"update_time": "更新时间",
|
||||
"rid": "评价ID",
|
||||
"report_date": "财报期",
|
||||
"compare_to_years": "财务得分年度比较",
|
||||
"compare_to_industry": "财务得分同行比较",
|
||||
"delta_to_years": "财务得分较去年变化",
|
||||
"delta_to_industry": "财务得分较同行差异",
|
||||
"index_details": "指标详情"
|
||||
}
|
||||
|
||||
|
||||
class OperatingRiskAnalysis(SpecObject):
|
||||
"""经营风险分析"""
|
||||
|
||||
|
||||
class CCRatingAnalysis(SpecObject):
|
||||
"""综合信用分析"""
|
||||
|
||||
|
||||
class ESGRatingAnalysis(SpecObject):
|
||||
"""ESG评价分析"""
|
||||
|
||||
|
||||
class RatingRecords(SpecObject):
|
||||
"""评价记录"""
|
||||
|
||||
|
||||
class CompanyDataAssemble(SpecObject):
|
||||
"""企业数据_更新汇总"""
|
|
@ -5,8 +5,8 @@ class SpecObject(object):
|
|||
|
||||
fields_map = {}
|
||||
|
||||
def dict_to_show(self, **kwargs):
|
||||
"""显示对象"""
|
||||
def dict_keys_toggle(self, **kwargs):
|
||||
"""字典键值切换"""
|
||||
_dict_ = dict()
|
||||
|
||||
for key in self.__dict__.keys():
|
||||
|
@ -29,29 +29,16 @@ class SpecObject(object):
|
|||
|
||||
return _dict_
|
||||
|
||||
def dict_to_show(self, **kwargs):
|
||||
"""字典显示格式"""
|
||||
return self.dict_keys_toggle(**kwargs)
|
||||
|
||||
def dict_to_save(self, **kwargs):
|
||||
"""存储对象"""
|
||||
_dict_ = dict()
|
||||
"""字典存储格式"""
|
||||
return self.dict_keys_toggle(**kwargs)
|
||||
|
||||
for key in self.__dict__.keys():
|
||||
if type(self.__dict__[key]).__name__ in ['str', 'int', 'float', 'dict', 'bool', 'tuple']:
|
||||
_dict_[self.fields_map[key]] = self.__dict__[key]
|
||||
elif type(self.__dict__[key]).__name__ == 'list':
|
||||
if len(self.__dict__[key]) == 0:
|
||||
_dict_[self.fields_map[key]] = self.__dict__[key]
|
||||
elif type(self.__dict__[key][0]).__name__ in ['str', 'int', 'float', 'dict', 'bool', 'tuple']:
|
||||
_dict_[self.fields_map[key]] = self.__dict__[key]
|
||||
else:
|
||||
_dict_[self.fields_map[key]] = [item.dict_to_save() for item in self.__dict__[key]]
|
||||
elif self.__dict__[key] is None:
|
||||
_dict_[self.fields_map[key]] = self.__dict__[key]
|
||||
else:
|
||||
_dict_[self.fields_map[key]] = self.__dict__[key].dict_to_save()
|
||||
|
||||
if 'columns' in kwargs:
|
||||
_dict_ = {key: _dict_[key] for key in kwargs['columns']}
|
||||
|
||||
return _dict_
|
||||
def dict_to_return(self, **kwargs):
|
||||
"""字典返回格式"""
|
||||
|
||||
@staticmethod
|
||||
def dict_to_set(**kwargs):
|
||||
|
|
|
@ -4,10 +4,11 @@ from Utils.ErrorUtil import ReturnConditionCheckFailed
|
|||
|
||||
|
||||
class Validate(object):
|
||||
"""常用格式检查"""
|
||||
|
||||
@staticmethod
|
||||
def email(param):
|
||||
""""""
|
||||
"""邮箱格式"""
|
||||
regex = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
|
||||
case = (len(param) > 7) and (re.match(regex, param) is not None)
|
||||
result = True if case else False
|
||||
|
@ -15,7 +16,7 @@ class Validate(object):
|
|||
|
||||
@staticmethod
|
||||
def password(param):
|
||||
""""""
|
||||
"""密码格式"""
|
||||
regex = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)^.{8,}$"
|
||||
case = (len(param) >= 8) and (re.match(regex, param) is not None)
|
||||
return True if case else False
|
||||
|
@ -36,79 +37,75 @@ class Validate(object):
|
|||
|
||||
@staticmethod
|
||||
def image(param):
|
||||
""""""
|
||||
"""图片格式"""
|
||||
mimetype = param.mimetype
|
||||
return True if mimetype in ['image/jpeg', 'image/png'] else False
|
||||
|
||||
|
||||
class ValidateAttr(object):
|
||||
"""对象属性值检查"""
|
||||
|
||||
FIELD_ERROR_INFO = '字段【{}】异常'
|
||||
FILED_MAP_ERROR = '字段未映射完整'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
""""""
|
||||
self.kwargs = kwargs
|
||||
self.error_info = kwargs['error_info'] if 'error_info' in kwargs else ('{}异常'.format(kwargs['mark']) if 'mark' in kwargs else None)
|
||||
self.error_code = kwargs['error_code'] if 'error_code' in kwargs else 200
|
||||
# self.field = kwargs['field']
|
||||
self.info = kwargs['error_info'] if 'error_info' in kwargs else None
|
||||
self.code = kwargs['error_code'] if 'error_code' in kwargs else 200
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
if self.kwargs['field'] in instance.__dict__:
|
||||
return instance.__dict__[self.kwargs['field']]
|
||||
|
||||
def __set__(self, instance, value):
|
||||
""""""
|
||||
try:
|
||||
self.error_info = '{}异常'.format(instance.fields_map[self.kwargs['field']])
|
||||
if not self.info:
|
||||
self.info = self.FIELD_ERROR_INFO.format(instance.fields_map[self.kwargs['field']])
|
||||
except AttributeError:
|
||||
pass
|
||||
raise ReturnConditionCheckFailed(self.FILED_MAP_ERROR, 200)
|
||||
|
||||
def not_default():
|
||||
"""无默认值时属性设值检查"""
|
||||
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)
|
||||
else:
|
||||
if not isinstance(value, self.kwargs['type']):
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
|
||||
if 'type' in self.kwargs:
|
||||
"""检查实例的属性类型"""
|
||||
if type(self.kwargs['type']) is list:
|
||||
if type(value) not in self.kwargs['type']:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
else:
|
||||
if not isinstance(value, self.kwargs['type']):
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
if 'length' in self.kwargs:
|
||||
"""检查实例的属性值长度(一般是str类型)"""
|
||||
if len(value) != self.kwargs['length']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
|
||||
if 'length' in self.kwargs:
|
||||
"""检查实例的属性值长度(一般是str类型)"""
|
||||
if len(value) != self.kwargs['length']:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
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)
|
||||
else:
|
||||
for item in value:
|
||||
if item not in self.kwargs['in_list']:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
|
||||
if 'in_list' in self.kwargs:
|
||||
"""检查实例属性是否包含于列表中(属性有列表和非列表两种情况)"""
|
||||
if type(value) is not list:
|
||||
if value not in self.kwargs['in_list']:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
else:
|
||||
for item in value:
|
||||
if item not in self.kwargs['in_list']:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
if 'instance_list' in self.kwargs:
|
||||
"""检查实例列表"""
|
||||
if type(value) is not list:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
else:
|
||||
for item in value:
|
||||
if not isinstance(item, self.kwargs['instance_list']):
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
|
||||
if 'instance_list' in self.kwargs:
|
||||
"""检查实例列表"""
|
||||
if type(value) is not list:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
else:
|
||||
for item in value:
|
||||
if not isinstance(item, self.kwargs['instance_list']):
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
|
||||
if 'func' in self.kwargs:
|
||||
"""属性检查函数"""
|
||||
if not list(map(self.kwargs['func'], [value]))[0]:
|
||||
raise ReturnConditionCheckFailed(self.error_info, self.error_code)
|
||||
|
||||
instance.__dict__[self.kwargs['field']] = value
|
||||
if 'func' in self.kwargs:
|
||||
"""属性检查函数"""
|
||||
if not list(map(self.kwargs['func'], [value]))[0]:
|
||||
raise ReturnConditionCheckFailed(self.info, self.code)
|
||||
|
||||
if 'default' in self.kwargs:
|
||||
"""实例属性默认值"""
|
||||
if value is None:
|
||||
value = self.kwargs['default']
|
||||
instance.__dict__[self.kwargs['field']] = value
|
||||
else:
|
||||
not_default()
|
||||
else:
|
||||
not_default()
|
||||
|
||||
instance.__dict__[self.kwargs['field']] = value
|
|
@ -1,59 +0,0 @@
|
|||
import pymongo
|
||||
|
||||
DB_HOST = "116.63.130.34"
|
||||
DB_PASS = "UTlC9cCoglD1cI1*"
|
||||
DB_USER = "root"
|
||||
DB_PORT = "27021"
|
||||
CLIENT = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format(DB_USER, DB_PASS, DB_HOST, DB_PORT))
|
||||
|
||||
|
||||
def FIND_SINGLE_COLUMN_BY_REQ(param1, param2, param3, param4):
|
||||
"""
|
||||
查询符合条件的第一条数据的某个制定字段值
|
||||
Parameters:
|
||||
param1: str 数据库
|
||||
param2: str 数据表
|
||||
param3: dict 查询条件
|
||||
param4: str 一个指定查询字段
|
||||
Returns:
|
||||
record: 查询结果为空,返回None; 查询结果正常,返回查询结果的第一条数据;
|
||||
"""
|
||||
collection = CLIENT[param1][param2]
|
||||
column = {**{'_id': False}, **{param4: 1}}
|
||||
record = list(collection.find(param3, column))
|
||||
return None if record == [] else record[0][param4]
|
||||
|
||||
|
||||
def FIND_SINGLE_DATA_BY_REQ(param1, param2, param3, param4):
|
||||
"""
|
||||
查询符合条件的第一条数据
|
||||
Parameters:
|
||||
param1: str 数据库
|
||||
param2: str 数据表
|
||||
param3: dict 查询条件
|
||||
param4: list 查询字段
|
||||
Returns:
|
||||
record: 查询结果为空,返回False; 查询结果正常,返回查询结果的第一条数据;
|
||||
"""
|
||||
collection = CLIENT[param1][param2]
|
||||
columns = {**{'_id': False}, **dict(zip(param4, [1] * len(param4)))}
|
||||
record = list(collection.find(param3, columns))
|
||||
return False if record == [] else record[0]
|
||||
|
||||
|
||||
def FIND_SINGLE_DATA_BY_REQ_WITH_SORT(param1, param2, param3, param4, param5):
|
||||
"""
|
||||
查询符合条件的第一条数据
|
||||
Parameters:
|
||||
param1: str 数据库
|
||||
param2: str 数据表
|
||||
param3: dict 查询条件
|
||||
param4: list 查询字段
|
||||
param5: dict 排序条件 例如 {"name": 1} 表示按照name字段正序返回
|
||||
Returns:
|
||||
record: 查询结果为空,返回False; 查询结果正常,返回查询结果的第一条数据;
|
||||
"""
|
||||
collection = CLIENT[param1][param2]
|
||||
columns = {**{'_id': False}, **dict(zip(param4, [1] * len(param4)))}
|
||||
record = list(collection.find(param3, columns).sort(list(param5.keys())[0], list(param5.values())[0]).limit(1))
|
||||
return False if record == [] else record[0]
|
|
@ -1,93 +0,0 @@
|
|||
from company.company_db import FIND_SINGLE_DATA_BY_REQ_WITH_SORT, FIND_SINGLE_DATA_BY_REQ
|
||||
from company.company_utils import judge_industry
|
||||
|
||||
|
||||
def get_head_info_impl(cid):
|
||||
# company_info: 企业信息
|
||||
company_info = FIND_SINGLE_DATA_BY_REQ("应用端", "企业用户", {"企业ID": cid}, ["企业名称", "已认证"])
|
||||
|
||||
# cc_rating: 最近一期综信评价结果
|
||||
cc_rating = FIND_SINGLE_DATA_BY_REQ_WITH_SORT("综信评价数据", "评价结果", {"企业ID": cid}, ["信用评分", "信用等级", "评价时间"], {"评价年度": -1})
|
||||
# esg_rating: 最近一期ESG评价结果
|
||||
esg_rating = FIND_SINGLE_DATA_BY_REQ_WITH_SORT("ESG评价数据", "评价结果", {"企业ID": cid}, ["ESG得分", "评价等级", "评价时间"], {"评价年度": -1})
|
||||
|
||||
# head_info: 公司主要头部信息
|
||||
head_info = {
|
||||
"企业名称": company_info['企业名称'],
|
||||
"企业认证": "已认证" if company_info['已认证'] == "是" else "未认证",
|
||||
"综合信用评价": cc_rating if cc_rating else {"信用等级": "N/A", "信用评分": "N/A", "评价时间": "N/A"},
|
||||
"ESG评价": esg_rating if esg_rating else {"信用等级": "N/A", "信用评分": "N/A", "评价时间": "N/A"}
|
||||
}
|
||||
|
||||
return head_info
|
||||
|
||||
|
||||
def get_basic_info_impl(cid):
|
||||
# data: 企业基本工商信息
|
||||
data = FIND_SINGLE_DATA_BY_REQ_WITH_SORT("企业数据", "基本工商信息", {"企业ID": cid}, ["更新时间", "企业名称", "工商信息", "股东信息", "主要成员"], {"更新时间": -1})
|
||||
return data
|
||||
|
||||
|
||||
def get_cc_rating_impl(cid):
|
||||
# data: 综合信用分析数据
|
||||
data = FIND_SINGLE_DATA_BY_REQ_WITH_SORT("企业数据", "综合信用分析", {"企业ID": cid}, ["更新时间", "综合信用表现", "信用分析", "指标表格", "历史级别"], {"更新时间": -1})
|
||||
return data
|
||||
|
||||
|
||||
def get_industry_analysis_impl(cid):
|
||||
"""
|
||||
行业宏观分析数据
|
||||
Parameters:
|
||||
cid: str 企业ID
|
||||
Returns:
|
||||
Case Success:
|
||||
data: dict 行业宏观分析数据
|
||||
Case Fail:
|
||||
data: dict 空字典
|
||||
"""
|
||||
|
||||
industry = judge_industry(cid)
|
||||
|
||||
if industry is False:
|
||||
return {}
|
||||
|
||||
data = FIND_SINGLE_DATA_BY_REQ("行业数据", "行业分析", {"行业": industry}, ["行业", "行业简介", "更新时间", "正面因素", "负面因素", "增长趋势", "规模分布"])
|
||||
|
||||
if data is False:
|
||||
return {}
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_esg_rating_impl(cid):
|
||||
"""
|
||||
ESG要素分析数据
|
||||
cid: str 企业ID
|
||||
Returns:
|
||||
Case Success:
|
||||
data: dict ESG分析数据
|
||||
Case Fail:
|
||||
data: dict 空字典
|
||||
"""
|
||||
data = FIND_SINGLE_DATA_BY_REQ_WITH_SORT('企业数据', 'ESG评价分析', {"企业ID": cid}, ["更新日期", "ESG评级", "维度得分情况", "实质性议题得分情况", "实质性议题"], {"更新日期": -1})
|
||||
|
||||
if data is False:
|
||||
return {}
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_financial_elements_impl(cid):
|
||||
"""
|
||||
财务要素分析
|
||||
"""
|
||||
data = FIND_SINGLE_DATA_BY_REQ_WITH_SORT('企业数据', '财务要素分析', {"企业ID": cid}, ["更新日期", "财报期", "同行对比图", "去年对比图", "去年对比表", "同行对比表", "指标详情"], {"更新日期": -1})
|
||||
return data
|
||||
|
||||
|
||||
def get_operating_risk_impl(cid):
|
||||
"""
|
||||
经营风险分析
|
||||
"""
|
||||
data = FIND_SINGLE_DATA_BY_REQ_WITH_SORT('企业数据', '经营风险分析', {"企业ID": cid}, ["更新日期", "风险分数", "风险级别", "列入失信名单", "合规风险", "经营风险", "周边风险", "变更记录"], {"更新日期": -1})
|
||||
return data
|
|
@ -1,34 +0,0 @@
|
|||
from company.company_impl import get_head_info_impl, get_industry_analysis_impl, get_esg_rating_impl, \
|
||||
get_cc_rating_impl, get_basic_info_impl, get_financial_elements_impl, get_operating_risk_impl
|
||||
|
||||
|
||||
class CompanyIndex:
|
||||
"""
|
||||
企业主页
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.cid = None
|
||||
self.tab = None
|
||||
self.industry = None
|
||||
|
||||
def get_head_info(self):
|
||||
return get_head_info_impl(self.cid)
|
||||
|
||||
def get_basic_info(self):
|
||||
return get_basic_info_impl(self.cid)
|
||||
|
||||
def get_industry_analysis(self):
|
||||
return get_industry_analysis_impl(self.cid)
|
||||
|
||||
def get_cc_rating(self):
|
||||
return get_cc_rating_impl(self.cid)
|
||||
|
||||
def get_esg_rating(self):
|
||||
return get_esg_rating_impl(self.cid)
|
||||
|
||||
def get_financial_elements(self):
|
||||
return get_financial_elements_impl(self.cid)
|
||||
|
||||
def get_operating_risk(self):
|
||||
return get_operating_risk_impl(self.cid)
|
|
@ -1,74 +0,0 @@
|
|||
from flask import Blueprint
|
||||
|
||||
from CompanyObject.CompanyImpl import CompanyImpl
|
||||
from CompanyUser.CompanyUserAuth import verify_token
|
||||
from company.company_obj import CompanyIndex
|
||||
|
||||
company_route = Blueprint('company', __name__)
|
||||
|
||||
|
||||
@company_route.route('/head_info', methods=['GET'])
|
||||
@verify_token
|
||||
def head_info_route(**kwargs):
|
||||
company = CompanyImpl()
|
||||
company.cid = kwargs['cid']
|
||||
result = company.get_head_info()
|
||||
return {"info": "查询结果", "result": result}, 200
|
||||
|
||||
|
||||
@company_route.route('/basic_info', methods=['GET'])
|
||||
@verify_token
|
||||
def basic_info_route(**kwargs):
|
||||
company = CompanyImpl()
|
||||
company.cid = kwargs['cid']
|
||||
result = company.get_basic_info
|
||||
return {"info": "查询结果", "result": result}, 200
|
||||
|
||||
|
||||
@company_route.route('/industry_analysis', methods=['GET'])
|
||||
@verify_token
|
||||
def industry_analysis_route(**kwargs):
|
||||
"""行业分析"""
|
||||
company = CompanyImpl()
|
||||
company.cid = kwargs['cid']
|
||||
result = company.get_industry_analysis()
|
||||
return {"info": "查询结果", "result": result}, 200
|
||||
|
||||
|
||||
@company_route.route('/cc_rating', methods=['GET'])
|
||||
@verify_token
|
||||
def cc_rating_route(**kwargs):
|
||||
company_index = CompanyIndex()
|
||||
company_index.cid = kwargs['cid']
|
||||
result = company_index.get_cc_rating()
|
||||
return {"info": "查询结果", "result": result}, 200
|
||||
|
||||
|
||||
@company_route.route('/esg_rating', methods=['GET'])
|
||||
@verify_token
|
||||
def esg_rating_route(**kwargs):
|
||||
"""
|
||||
ESG评价分析
|
||||
"""
|
||||
company_index = CompanyIndex()
|
||||
company_index.cid = kwargs['cid']
|
||||
result = company_index.get_esg_rating()
|
||||
return {"info": "查询结果", "result": result}
|
||||
|
||||
|
||||
@company_route.route('/financial_elements', methods=['GET'])
|
||||
@verify_token
|
||||
def financial_elements_route(**kwargs):
|
||||
company_index = CompanyIndex()
|
||||
company_index.cid = kwargs['cid']
|
||||
result = company_index.get_financial_elements()
|
||||
return {"info": "查询结果", "result": result}
|
||||
|
||||
|
||||
@company_route.route('/operating_risk', methods=['GET'])
|
||||
@verify_token
|
||||
def operating_risk_route(**kwargs):
|
||||
company_index = CompanyIndex()
|
||||
company_index.cid = kwargs['cid']
|
||||
result = company_index.get_operating_risk()
|
||||
return {"info": "查询结果", "result": result}
|
|
@ -1,10 +0,0 @@
|
|||
from company.company_db import FIND_SINGLE_COLUMN_BY_REQ
|
||||
|
||||
|
||||
def judge_industry(cid):
|
||||
"""
|
||||
判断公司所属一级行业
|
||||
"""
|
||||
industry_L2 = FIND_SINGLE_COLUMN_BY_REQ("企业数据", "基本工商信息", {"企业ID": cid}, "工商信息")['行业']
|
||||
industry_L1 = FIND_SINGLE_COLUMN_BY_REQ("模型端", "天眼查公司行业分类", {"二级行业": industry_L2}, "远东_一级行业")
|
||||
return industry_L1
|
|
@ -14,27 +14,3 @@ def get_pdf_file_impl(file_type, fid):
|
|||
}
|
||||
filestream = FIND_FILE(ftm[file_type], fid)
|
||||
return filestream
|
||||
|
||||
|
||||
def company_esg_rating_report_by_fid(fid):
|
||||
"""
|
||||
根据fid返回文件
|
||||
Args:
|
||||
fid:
|
||||
Returns:
|
||||
filestream
|
||||
"""
|
||||
filestream = find_file('esg报告', fid)
|
||||
return filestream
|
||||
|
||||
|
||||
def company_esg_rating_certification_by_fid(fid):
|
||||
"""
|
||||
根据fid返回文件
|
||||
Args:
|
||||
fid:
|
||||
Returns:
|
||||
filestream
|
||||
"""
|
||||
filestream = find_file('ESG评价证书', fid)
|
||||
return filestream
|
||||
|
|
Loading…
Reference in New Issue