from Utils.ObjUtil import SpecObject from Utils.ValidateUtil import ValidateAttr, Validate class IndustryReport(SpecObject): """行业报告""" industry = ValidateAttr(field="industry", type=str, default=None) title = ValidateAttr(field="title", type=str) upload_time = ValidateAttr(field="upload_time", func=Validate.time_format) report_fid = ValidateAttr(field="report_fid", type=str) fields_map = { "industry": "一级行业", "title": "报告标题", "upload_time": "上传日期", "report_fid": "报告fid" } class SearchMacroAPi(SpecObject): """宏观查询体""" class SearchBody(SpecObject): """查询体""" industry_01 = ValidateAttr(field="industry_01", type=str) industry_02 = ValidateAttr(field="industry_02", type=str) name = ValidateAttr(field="name", type=str) year = ValidateAttr(field="year", type=str) cycle = ValidateAttr(field="cycle", type=str, in_list=['年度', '季度', '月度']) fields_map = { "industry_01": "一级行业", "industry_02": "二级行业", "name": "统计字段名称", "year": "统计时间", "cycle": "统计周期" } def make_search_body(self): """""" search_keys = list(self.__dict__.keys()) body = dict() if "industry_01" in search_keys: body['一级行业'] = {"$regex": self.industry_01} if "industry_02" in search_keys: body['二级行业'] = {"$regex": self.industry_02} if "name" in search_keys: body['企业名称'] = {"$regex": self.name} if "year" in search_keys: body['统计时间'] = {"$regex": self.year} if "cycle" in search_keys: body['统计周期'] = {"$regex": self.cycle} return body class SortBody(SpecObject): """排序体""" 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 = { "一级行业": "一级行业", "二级行业": "二级行业", "统计字段名称": "统计字段名称", "统计时间": "统计时间", "统计周期": "统计周期", "数据": "数据" } 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 search = ValidateAttr(field='search', type=SearchBody) sort = ValidateAttr(field='sort', type=SortBody) page_size = ValidateAttr(field='page_size', type=int) page_no = ValidateAttr(field='page_no', type=int) fields_map = { "search": "搜索体", "sort": "排序", "page_size": "显示数量", "page_no": "页码" } def condition_search(self): """条件查询""" class SearchMacroDataResult(SpecObject): """二级行业统计数据查询结果""" industry_01 = ValidateAttr(field="industry_01", type=str) industry_02 = ValidateAttr(field="industry_02", type=str) name = ValidateAttr(field="name", type=str) year = ValidateAttr(field="year", type=str) data = ValidateAttr(field="data", type=[float, int, str]) unit = ValidateAttr(field="unit", type=str) cycle = ValidateAttr(field="cycle", type=str, in_list=['年度', '季度', '月度']) fields_map = { "industry_01": "一级行业", "industry_02": "二级行业", "name": "统计字段名称", "year": "统计时间", "data": "数据", "unit": "数据单位", "cycle": "统计周期" }