This commit is contained in:
王思川 2022-04-11 17:15:07 +08:00
parent f9a657141f
commit 2a77b58e50
6 changed files with 129 additions and 11 deletions

View File

@ -0,0 +1,46 @@
from CompanyObject.CompanyObj import Company, HeadInfo
from DBHelper.MongoHelper import MongoHelper
class CompanyImpl(Company):
"""企业实现类"""
db = MongoHelper("tfse_v0.21")
def get_head_info(self):
""""""
verify_status = self.db.find_single_column(
"应用端",
"企业用户",
{"企业ID": self.cid},
"已认证"
)
company_data = self.db.find_single_data(
"企业数据",
"企业数据_更新汇总",
{"企业ID": self.cid},
["企业名称", "综信评价结果", "ESG评价结果"]
)
head_info = HeadInfo()
head_info.name = company_data['企业名称']
head_info.verify_status = "已认证" if verify_status == "" else "未认证"
latest_cc_rating = HeadInfo.LatestCCRating()
latest_esg_rating = HeadInfo.LatestESGRating()
cc_rating = company_data['综信评价结果']
latest_cc_rating.level = cc_rating['信用等级']
latest_cc_rating.score = str(cc_rating['信用评分'])
latest_cc_rating.rating_time = cc_rating['评价时间']
esg_rating = company_data['ESG评价结果']
latest_esg_rating.level = esg_rating['评价等级']
latest_esg_rating.score = esg_rating['ESG得分']
latest_esg_rating.rating_time = esg_rating['评价时间']
return head_info.dict_to_show()
def get_basic_info(self):
""""""

View File

@ -156,6 +156,46 @@ class FinancialIndex(SpecObject):
}
class HeadInfo(SpecObject):
""""""
class LatestCCRating(SpecObject):
""""""
level = ValidateAttr(field='level', type=str, default='N/A')
score = ValidateAttr(field='level', type=str, default='N/A')
rating_time = ValidateAttr(field='level', type=str, default='N/A')
fields_map = {
"level": "信用等级",
"score": "信用评分",
"rating_time": "评价时间"
}
class LatestESGRating(SpecObject):
""""""
level = ValidateAttr(field='level', type=str, default='N/A')
score = ValidateAttr(field='level', type=str, default='N/A')
rating_time = ValidateAttr(field='level', type=str, default='N/A')
fields_map = {
"level": "ESG等级",
"score": "ESG评分",
"rating_time": "评价时间"
}
name = ValidateAttr(field='name', type=str)
verify_status = ValidateAttr(field='verify_status', in_list=["已认证", "未认证"])
latest_cc_rating = ValidateAttr(field='latest_cc_rating', type=LatestCCRating)
latest_esg_rating = ValidateAttr(field='latest_esg_rating', type=LatestESGRating)
fields_map = {
"name": "企业名称",
"verify_status": "企业认证",
"latest_cc_rating": "综合信用评价",
"latest_esg_rating": "ESG评价"
}
class Company(object):
"""企业"""
@ -193,4 +233,9 @@ class Company(object):
"update_time": "更新时间"
}
def get_head_info(self):
"""头部信息"""
def get_basic_info(self):
"""获取基本工商信息"""

View File

@ -0,0 +1,15 @@
from flask import Blueprint
from CompanyObject.CompanyImpl import CompanyImpl
from CompanyUser.CompanyUserAuth import verify_token
company_route_v021 = Blueprint('company', __name__)
@company_route_v021.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

View File

@ -6,6 +6,27 @@ class SpecObject(object):
def dict_to_show(self, **kwargs):
"""显示对象"""
_dict_ = dict()
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_show()
if 'columns' in kwargs:
_dict_ = {key: _dict_[key] for key in kwargs['columns']}
return _dict_
def dict_to_save(self, **kwargs):
"""存储对象"""

4
app.py
View File

@ -1,8 +1,8 @@
from flask import Flask
from flask_cors import *
from CompanyObject.CompanyRoutes import company_route_v021
from CompanyUser.CompanyUserRoute import company_user_route
from company.company_routes import company_route
from file.file_routes import file_route
from cc_rating.CCRatingRoute import cc_route
from esg.esg_routes import esg_route
@ -15,7 +15,7 @@ app.config['JSON_SORT_KEYS'] = False
app.register_blueprint(file_route, url_prefix='/app/file')
app.register_blueprint(company_user_route, url_prefix='/app/user')
app.register_blueprint(cc_route, url_prefix='/app/input')
app.register_blueprint(company_route, url_prefix='/app/company')
app.register_blueprint(company_route_v021, url_prefix='/app/company')
app.register_blueprint(esg_route, url_prefix='/app/esg')

View File

@ -6,15 +6,6 @@ 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 = CompanyIndex()
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):