tfse-admin-api-v0.2/Manage/Company/CompanyObj.py

105 lines
3.5 KiB
Python
Raw Normal View History

2022-04-13 17:04:07 +08:00
from Utils.ObjUtil import SpecObject
from Utils.ValidateUtil import ValidateAttr
class SearchCompanyBody(SpecObject):
""""""
class SearchBody(SpecObject):
""""""
cid = ValidateAttr(field='cid', type=str)
name = ValidateAttr(field='name', type=str)
industry = ValidateAttr(field='industry', type=str)
2022-04-14 03:12:36 +08:00
credit_level = ValidateAttr(field='credit_level', in_list=["AAA", "AA+", "AA", "AA-", "A+", "A", "A-", "BBB+", "BBB", "BBB-", "BB+", "BB", "BB-", "B+", "B", "B-", "CCC+", "CCC", "CCC-", "CC+", "CC", "CC-", "C+", "C", "C-"])
2022-04-13 17:04:07 +08:00
esg_level = ValidateAttr(field='esg_level', in_list=["A", "B", "C", "D", "E"])
fields_map = {
"cid": "企业ID",
"name": "企业名称",
"industry": "一级行业",
"credit_level": "综信评价",
"esg_level": "ESG评价"
}
def make_search_body(self):
""""""
search_keys = list(self.__dict__.keys())
body = dict()
if "cid" in search_keys:
body['企业ID'] = self.cid
if "name" in search_keys:
body['企业名称'] = {"$regex": self.name}
if "industry" in search_keys:
body['一级行业'] = {"$in": self.industry}
if "credit_level" in search_keys:
body['综信评价结果.信用等级'] = {"$in": self.credit_level}
if "esg_level" in search_keys:
body['ESG评价结果.评价等级'] = {"$in": self.esg_level}
return body
class SortBody(SpecObject):
""""""
2022-04-14 03:12:36 +08:00
field = ValidateAttr(field='field', type=str)
sort = ValidateAttr(field='sort', in_list=["asc", "desc"])
fields_map = {
"field": "排序字段",
"sort": "排序方式"
}
def make_sort_body(self):
""""""
if self.__dict__ != {}:
columns_map = {
"企业ID": "企业ID",
"企业名称": "企业名称",
"一级行业": "一级行业",
"信用等级": "综信评价结果.信用等级",
"ESG等级": "ESG评价结果.评价等级"
}
asc_or_desc = 1 if self.sort == "asc" else -1
sort_column = columns_map[self.field]
body = {sort_column: asc_or_desc}
else:
body = {"更新时间.工商信息": -1}
return body
2022-04-13 17:04:07 +08:00
search = ValidateAttr(field='search', type=SearchBody)
2022-04-14 03:12:36 +08:00
sort = ValidateAttr(field='sort', type=SortBody)
2022-04-13 17:04:07 +08:00
page_size = ValidateAttr(field='page_size', type=int)
page_no = ValidateAttr(field='page_no', type=int)
fields_map = {
"search": "搜索体",
"sort": "排序",
"page_size": "显示数量",
"page_no": "页码"
}
2022-04-14 03:12:36 +08:00
def condition_search(self):
"""条件查询"""
2022-04-13 17:04:07 +08:00
class SearchCompanyResult(SpecObject):
""""""
2022-04-14 03:12:36 +08:00
cid = ValidateAttr(field='cid', type=str)
name = ValidateAttr(field='name', type=str, default=None)
industry = ValidateAttr(field='industry', type=str, default=None)
credit_level = ValidateAttr(field='credit_level', type=str, default=None)
esg_level = ValidateAttr(field='esg_level', type=str, default=None)
2022-04-13 17:04:07 +08:00
fields_map = {
"cid": "企业ID",
"name": "企业名称",
"industry": "一级行业",
2022-04-14 03:12:36 +08:00
"credit_level": "信用等级",
"esg_level": "ESG等级"
2022-04-13 17:04:07 +08:00
}