From 188a2d3bc709d2dc73de691a0efb98b7d3bfc376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Thu, 19 May 2022 17:11:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201.=20Changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CCRating/R1_RiskDataCountDataJob.py | 310 ++++++++++++++++++ .../Im2_RatingData/CCRating/__init__.py | 0 .../Im2_RatingData/ESGRating/__init__.py | 0 .../CCRatingInput.py} | 0 .../Rating/CCRating/CCRatingRiskDataCount.py | 79 +++++ Objects/Common/Rating/CCRating/__init__.py | 0 Objects/Common/Rating/ESGRating/__init__.py | 0 .../R0_CCRating/R1_RiskDataRoutes.py | 37 +++ app.py | 3 + 9 files changed, 429 insertions(+) create mode 100644 Implements/Im2_RatingData/CCRating/R1_RiskDataCountDataJob.py create mode 100644 Implements/Im2_RatingData/CCRating/__init__.py create mode 100644 Implements/Im2_RatingData/ESGRating/__init__.py rename Objects/Common/Rating/{WideRatingInput.py => CCRating/CCRatingInput.py} (100%) create mode 100644 Objects/Common/Rating/CCRating/CCRatingRiskDataCount.py create mode 100644 Objects/Common/Rating/CCRating/__init__.py create mode 100644 Objects/Common/Rating/ESGRating/__init__.py diff --git a/Implements/Im2_RatingData/CCRating/R1_RiskDataCountDataJob.py b/Implements/Im2_RatingData/CCRating/R1_RiskDataCountDataJob.py new file mode 100644 index 0000000..6592214 --- /dev/null +++ b/Implements/Im2_RatingData/CCRating/R1_RiskDataCountDataJob.py @@ -0,0 +1,310 @@ +import time +import datetime + +from DBHelper.MongoHelperInstance import DB_TYC +from Objects.Common.Rating.CCRating.CCRatingRiskDataCount import CCRatingRiskDataCount +from Objects.InProject.ETL.WideETL import DataJob, DataProcess +from Utils.ErrorUtil import JustThrowError + + +class PrepareTarget(DataProcess): + + def extract(self): + pass + + def transform(self): + + self.target.operating_risk_data_count = CCRatingRiskDataCount.OperatingRiskDataCount() + self.target.compliance_risk_data_count = CCRatingRiskDataCount.ComplianceRiskDataCount() + self.target.association_risk_data_count = CCRatingRiskDataCount.AssociationRiskDataCount() + + def load(self): + pass + + +class ProcessDishonestPerson(DataProcess): + """失信人""" + + def extract(self): + + data = DB_TYC.find_single_column( + "司法风险", + "失信人", + {"企业名称": self.target.name}, + "失信人" + ) + + self.source["失信人"] = data if data else [] + + def transform(self): + + source = self.source["失信人"] + target = self.target.compliance_risk_data_count + + def dishonest_person(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['失信人']) + if quantity: + for num in range(quantity): + try: + date = int(data['失信人'][num]['publishdate'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + target.untrustworthy = dishonest_person(source) + + def load(self): + pass + + +class ProcessSeriousIllegal(DataProcess): + """严重违法""" + + def extract(self): + + data = DB_TYC.find_single_column( + "经营风险", + "严重违法", + {"企业名称": self.target.name}, + "严重违法" + ) + + self.source["严重违法"] = data if data else [] + + def transform(self): + + source = self.source["严重违法"] + target = self.target.compliance_risk_data_count + + def serious_illegal(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['严重违法']['result']) + if quantity: + for num in range(quantity): + try: + timestamp = data['严重违法']['result'][num]['putDate'] / 1000 + put_date = time.localtime(timestamp) + date = int(time.strftime("%Y", put_date)) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + target.serious_violation = serious_illegal(source) + + def load(self): + pass + + +class ProcessAbnormalOperation(DataProcess): + """经营异常""" + + def extract(self): + pass + + def transform(self): + + def abnormal_operation(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['经营异常']['result']) + if quantity: + for num in range(quantity): + try: + date = int(data['经营异常']['result'][num]['putDate'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + def load(self): + pass + + +class ProcessOwingTaxes(DataProcess): + """欠税公告""" + + def extract(self): + pass + + def transform(self): + + def owing_taxes(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['欠税公告']['result']) + if quantity: + for num in range(quantity): + try: + date = int(data['经营异常']['result'][num]['publishDate'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + def load(self): + pass + + +class ProcessTaxViolation(DataProcess): + """税收违法""" + + def extract(self): + pass + + def transform(self): + + def tax_violation(param): + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['税收违法']['result']) + if quantity: + for num in range(quantity): + try: + date = int(data['税收违法']['result'][num]['publish_time'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + def load(self): + pass + + +class ProcessAdministrativePunish(DataProcess): + """行政处罚""" + + def extract(self): + pass + + def transform(self): + + def administrative_punish(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['行政处罚']['result']) + if quantity: + for num in range(quantity): + try: + date = int(data['行政处罚']['result'][num]['decisionDate'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + def load(self): + pass + + +class ProcessEnvironmentalPunish(DataProcess): + """环保处罚""" + + def extract(self): + pass + + def transform(self): + + def environmental_punish(param): + + total = 0 + if len(param): + data = param[0] + try: + quantity = len(data['环保处罚']['result']) + if quantity: + for num in range(quantity): + try: + date = int(data['环保处罚']['result'][num]['publish_time'][:4]) + current_year = datetime.date.today().year + if current_year - date <= 3: + total += 1 + except Exception: + total += 1 + return total + except KeyError: + return total + else: + return total + + def load(self): + pass + + +class RiskDataCountDataJob(CCRatingRiskDataCount): + + def create(self): + + data_job = DataJob( + instance=self, + title="综信评价风险数据统计", + job_type="初始数据", + status="正常", + detail="评价ID->{}; 企业ID->{}; 企业名称->{}; ".format(self.rid, self.cid, self.name) + ) + + data_job.processes = [ + # 准备 + PrepareTarget, + + # 合规风险 + ProcessDishonestPerson + ] + + data_job.start() diff --git a/Implements/Im2_RatingData/CCRating/__init__.py b/Implements/Im2_RatingData/CCRating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Implements/Im2_RatingData/ESGRating/__init__.py b/Implements/Im2_RatingData/ESGRating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Objects/Common/Rating/WideRatingInput.py b/Objects/Common/Rating/CCRating/CCRatingInput.py similarity index 100% rename from Objects/Common/Rating/WideRatingInput.py rename to Objects/Common/Rating/CCRating/CCRatingInput.py diff --git a/Objects/Common/Rating/CCRating/CCRatingRiskDataCount.py b/Objects/Common/Rating/CCRating/CCRatingRiskDataCount.py new file mode 100644 index 0000000..8253472 --- /dev/null +++ b/Objects/Common/Rating/CCRating/CCRatingRiskDataCount.py @@ -0,0 +1,79 @@ +from Utils.ObjUtil import SpecObject +from Utils.ValidateUtil import ValidateAttr + + +class CCRatingRiskDataCount(SpecObject): + """风险数据""" + + class OperatingRiskDataCount(SpecObject): + """经营风险""" + + case_filing_information = ValidateAttr(field='case_filing_information', type=int, default=0) + court_announcement = ValidateAttr(field='court_announcement', type=int, default=0) + person_to_be_executed = ValidateAttr(field='person_to_be_executed', type=int, default=0) + court_notice = ValidateAttr(field='court_notice', type=int, default=0) + litigation = ValidateAttr(field='litigation', type=int, default=0) + service_announcement = ValidateAttr(field='service_announcement', type=int, default=0) + equity_pledge = ValidateAttr(field='equity_pledge', type=int, default=0) + change_of_legal_entity = ValidateAttr(field='change_of_legal_entity', type=int, default=0) + change_of_key_members = ValidateAttr(field='change_of_key_members', type=int, default=0) + + fields_map = { + "case_filing_information": "立案信息", + "court_announcement": "开庭公告", + "person_to_be_executed": "被执行人", + "court_notice": "法院公告", + "litigation": "诉讼", + "service_announcement": "送达公告", + "equity_pledge": "股权出质", + "change_of_legal_entity": "法人变更", + "change_of_key_members": "主要成员变更" + } + + class ComplianceRiskDataCount(SpecObject): + """合规风险""" + + untrustworthy = ValidateAttr(field="untrustworthy", type=int, default=0) + serious_violation = ValidateAttr(field="serious_violation", type=int, default=0) + abnormal_operation = ValidateAttr(field="abnormal_operation", type=int, default=0) + tax_arrears_announcement = ValidateAttr(field="tax_arrears_announcement", type=int, default=0) + tax_violation = ValidateAttr(field="tax_violation", type=int, default=0) + administrative_penalties = ValidateAttr(field="administrative_penalties", type=int, default=0) + environmental_penalties = ValidateAttr(field="environmental_penalties", type=int, default=0) + + fields_map = { + "untrustworthy": "失信人", + "serious_violation": "严重违法", + "abnormal_operation": "经营异常", + "tax_arrears_announcement": "欠税公告", + "tax_violation": "税收违法", + "administrative_penalties": "行政处罚", + "environmental_penalties": "环保处罚" + } + + class AssociationRiskDataCount(SpecObject): + """关联风险""" + + high_risk_around = ValidateAttr(field="high_risk_around", type=int, default=0) + peripheral_warning_risk = ValidateAttr(field="peripheral_warning_risk", type=int, default=0) + + fields_map = { + "high_risk_around": "周边高风险", + "peripheral_warning_risk": "周边警示风险" + } + + rid = ValidateAttr(field="rid", type=str, length=8) + cid = ValidateAttr(field="cid", type=str, length=8) + name = ValidateAttr(field="name", type=str) + operating_risk_data_count = ValidateAttr(field="operating_risk_data_count", type=OperatingRiskDataCount) + compliance_risk_data_count = ValidateAttr(field="compliance_risk_data_count", type=ComplianceRiskDataCount) + association_risk_data_count = ValidateAttr(field="association_risk_data_count", type=AssociationRiskDataCount) + + fields_map = { + "rid": "评价ID", + "cid": "企业ID", + "name": "企业名称", + "operating_risk_data_count": "经营风险", + "compliance_risk_data_count": "合规风险", + "association_risk_data_count": "关联风险" + } diff --git a/Objects/Common/Rating/CCRating/__init__.py b/Objects/Common/Rating/CCRating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Objects/Common/Rating/ESGRating/__init__.py b/Objects/Common/Rating/ESGRating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Routes/R2_RatingData/R0_CCRating/R1_RiskDataRoutes.py b/Routes/R2_RatingData/R0_CCRating/R1_RiskDataRoutes.py index e69de29..030557a 100644 --- a/Routes/R2_RatingData/R0_CCRating/R1_RiskDataRoutes.py +++ b/Routes/R2_RatingData/R0_CCRating/R1_RiskDataRoutes.py @@ -0,0 +1,37 @@ +""" +评价数据-综合信用评价-风险数据 +""" + +from flask import Blueprint, request + +from Implements.Im2_RatingData.CCRating.R1_RiskDataCountDataJob import RiskDataCountDataJob +from Utils.CommonUtil import verify_token +from Utils.RouteUtil import RouteUtil +from Utils.ErrorUtil import APIReturnError, ReturnConditionCheckFailed + +cc_rating_risk_data_route = Blueprint('risk_data', __name__) + + +@cc_rating_risk_data_route.route('/create', methods=['GET']) +@verify_token +def create_route(): + """新建风险数据""" + + try: + + args = request.args + RouteUtil.require_params_check(args, ['rid', 'cid', 'company_name']) + + data_job = RiskDataCountDataJob() + data_job.rid = args['rid'] + data_job.cid = args['cid'] + data_job.name = args['company_name'] + + data_job.create() + + return {"info": "没有评价记录"}, 200 + + except APIReturnError as e: + return {"info": e.error_info}, e.status_code + except ReturnConditionCheckFailed as e: + return {"info": e.failed_info}, e.status_code diff --git a/app.py b/app.py index 485a139..bdc7a40 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from Routes.R1_CompanyData.C0_RatingRecordsRoutes import rating_records_route from Routes.R1_CompanyData.C1_LatestDataRoutes import latest_data_route from Routes.R1_CompanyData.C2_AssembleDataRoutes import assemble_view_route from Routes.R1_CompanyData.C3_BasicBusinessInfoRoutes import business_info_route +from Routes.R2_RatingData.R0_CCRating.R1_RiskDataRoutes import cc_rating_risk_data_route app = Flask(__name__) CORS(app, supports_credentials=True) @@ -16,6 +17,8 @@ app.register_blueprint(latest_data_route, url_prefix='/etl_tfse/company/latest_d app.register_blueprint(assemble_view_route, url_prefix='/etl_tfse/company/assemble_view') app.register_blueprint(business_info_route, url_prefix='/etl_tfse/company/business_info') +app.register_blueprint(cc_rating_risk_data_route, url_prefix='/etl_tfse/rating/cc/risk_data') + if __name__ == '__main__': app.run()