diff --git a/Certificate/db.py b/Certificate/db.py index 3d069dd..547f43a 100644 --- a/Certificate/db.py +++ b/Certificate/db.py @@ -8,58 +8,35 @@ from gridfs import GridFS from Certificate.scripts.path_tool import get_gen_report_path -DB_HOST = '116.63.130.34' -DB_USER = 'root' -DB_PASS = 'sromitdTW569kC#M' -DB_PORT = 27018 - +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 upload_pdf(name): +def upload_certificate_pdf(param1, param2, param3): """ 根据名称保存该企业证书 + Parameters: + param1: str 数据库 + param2: str 数据集 + param3: str 文件名称 + Returns: + pdf_id: type describe """ try: - path = get_gen_report_path(name=name) - database = '评价' - collection = '评价证书' + path = get_gen_report_path(name=param3) + database = param1 + collection = param2 fs = GridFS(client[database], collection) content = open(path, 'rb').read() - pdf_id = fs.put(content, content_type='application/pdf', filename=name) + pdf_id = fs.put(content, content_type='application/pdf', filename=param3) return str(pdf_id) except Exception: return False -def upload_esg_pdf(name): - """ - 根据名称保存该企业证书 - """ - try: - path = get_gen_report_path(name=name) - database = '评价' - collection = 'ESG评价证书' - fs = GridFS(client[database], collection) - content = open(path, 'rb').read() - pdf_id = fs.put(content, content_type='application/pdf', filename=name) - return str(pdf_id) - except Exception: - return False - - -def download_pdf(pdf_id): - """ - 根据pdf_id查询pdf文件 - """ - database = '评价' - collection = '综合信用报告' - fs = GridFS(client[database], collection) - data = fs.get(ObjectId(pdf_id)).read() - - return data - - def find_tfse_db(**kwargs): """ 查询数据库记录 @@ -73,21 +50,3 @@ def find_tfse_db(**kwargs): data = list(result) return data - -def update_data(param1, param2, param3, param4): - """ - 根据查询条件更新数据 - Parameters: - param1: str 数据库 - param2: str 数据表 - param3: dict 查询条件 - param4: dict 更新数据 - Returns: - res: bool 保存结果 - """ - try: - collection = client[param1][param2] - collection.update_one(param3, {"$set": param4}, upsert=True) - return True - except Exception: - return False diff --git a/Certificate/routes.py b/Certificate/routes.py index 8783d60..31fa8b0 100644 --- a/Certificate/routes.py +++ b/Certificate/routes.py @@ -7,7 +7,7 @@ from flask import Blueprint, request from Certificate.PdfCertificate import CertificateGenerator from Certificate.scripts.common import get_certificate_data from Certificate.scripts.path_tool import get_gen_report_path -from Certificate.db import upload_pdf, upload_esg_pdf +from Certificate.db import upload_certificate_pdf from common.scripts import verify_token certificate_route = Blueprint('certificate', __name__) @@ -55,9 +55,9 @@ def gen_certificate(): """ # 保存PDF报告文件,删除临时存储的报告 if len(text_data) > 5: - file_id = upload_esg_pdf(param) + file_id = upload_certificate_pdf('文件', 'ESG证书', param) else: - file_id = upload_pdf(param) + file_id = upload_certificate_pdf('文件', '综信证书', param) certificate_path = get_gen_report_path(name=param) os.remove(certificate_path) diff --git a/Certificate/scripts/common.py b/Certificate/scripts/common.py index c8d0ff3..3b06508 100644 --- a/Certificate/scripts/common.py +++ b/Certificate/scripts/common.py @@ -23,9 +23,9 @@ def get_certificate_data(param): result: dict 证书所需数据 """ # 企业基本信息 - data_01 = find_tfse_db(db="企业", col="公司基本信息", query={'企业ID': param['cid']})[0] + data_01 = find_tfse_db(db="企业数据", col="基本工商信息", query={'企业ID': param['cid']})[0] # 评价结果 - data_02 = find_tfse_db(db="评价", col="评价结果", query={"评价ID": param['rid']})[0] + data_02 = find_tfse_db(db="综信评价数据", col="评价结果", query={"评价ID": param['rid']})[0] info = dict() info['企业名称'] = param['company'] info['统一社会信用代码'] = data_01['工商信息']['纳税人识别号'] @@ -43,9 +43,9 @@ def get_certificate_data(param): result: dict 证书所需数据 """ # 企业基本信息 - data_01 = find_tfse_db(db="企业", col="公司基本信息", query={'企业ID': param['cid']})[0] + data_01 = find_tfse_db(db="企业数据", col="基本工商信息", query={'企业ID': param['cid']})[0] # 评价结果 - data_02 = find_tfse_db(db="评价", col="ESG评价结果", query={"评价ID": param['rid']})[0] + data_02 = find_tfse_db(db="ESG评价数据", col="评价结果", query={"评价ID": param['rid']})[0] info = dict() info['企业名称'] = param['company'] info['统一社会信用代码'] = data_01['工商信息']['纳税人识别号'] diff --git a/Rating/RatingModel.py b/Rating/RatingModel.py index 69444c8..1b62490 100644 --- a/Rating/RatingModel.py +++ b/Rating/RatingModel.py @@ -218,7 +218,7 @@ class RatingModel: 保存评价结果 """ rating_result = self.rating_result - update_data('评价', '评价结果', {"企业ID": self.cid}, rating_result) + update_data('综信评价数据', '评价结果', {"企业ID": self.cid}, rating_result) def save_indicators(self): """ @@ -227,4 +227,4 @@ class RatingModel: for item in self.financial_indicators: item['企业ID'] = self.cid item['企业名称'] = self.company - update_data('企业', '指标明细', {"企业ID": self.cid, "年报期": item['年报期']}, item) + update_data('综信评价数据', '财指结果', {"企业ID": self.cid, "年报期": item['年报期']}, item) diff --git a/Rating/db.py b/Rating/db.py index e227689..4e55f9c 100644 --- a/Rating/db.py +++ b/Rating/db.py @@ -4,7 +4,11 @@ Mongo_tfse import pymongo -client = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format('root', 'sromitdTW569kC#M', '116.63.130.34', 27018)) +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_threshold(param): @@ -15,7 +19,7 @@ def find_threshold(param): Returns: data 查询结果 """ - collection = client['模型']['财务指标阈值'] + collection = client['模型端']['综信评价财指阈值'] data = collection.find({"二级行业": param}, {'_id': False}) return list(data) diff --git a/Report/db.py b/Report/db.py index 00ec3be..9644dfe 100644 --- a/Report/db.py +++ b/Report/db.py @@ -8,70 +8,33 @@ from gridfs import GridFS from Report.scripts.path_tool import get_gen_report_path -DB_HOST = '116.63.130.34' -DB_USER = 'root' -DB_PASS = 'sromitdTW569kC#M' -DB_PORT = 27018 - +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 upload_pdf(name): +def upload_report_pdf(param1, param2, param3): """ 根据名称保存该企业报告 - """ - try: - path = get_gen_report_path(name=name) - database = '评价' - collection = '综合信用报告' - fs = GridFS(client[database], collection) - content = open(path, 'rb').read() - pdf_id = fs.put(content, content_type='application/pdf', filename=name) - return str(pdf_id) - except Exception: - return False - - -def upload_esg_pdf(name): - """ - 根据名称保存该企业esg报告 - """ - try: - path = get_gen_report_path(name=name) - database = '评价' - collection = 'esg报告' - fs = GridFS(client[database], collection) - content = open(path, 'rb').read() - pdf_id = fs.put(content, content_type='application/pdf', filename=name) - return str(pdf_id) - except Exception: - return False - - -def download_pdf(pdf_id): - """ - 根据pdf_id查询pdf文件 - """ - database = '评价' - collection = '综合信用报告' - fs = GridFS(client[database], collection) - data = fs.get(ObjectId(pdf_id)).read() - - return data - - -def find_tfse_db(**kwargs): - """ - 查询数据库记录 Parameters: - kwargs: 查询条件 + param1: str 数据库 + param2: str 数据集 + param3: str 文件名称 Returns: - data: tfse数据 + pdf_id: type describe """ - collection = client[kwargs['db']][kwargs['col']] - result = collection.find(kwargs['query'], {'_id': False}) - data = list(result) - return data + try: + path = get_gen_report_path(name=param3) + database = param1 + collection = param2 + fs = GridFS(client[database], collection) + content = open(path, 'rb').read() + pdf_id = fs.put(content, content_type='application/pdf', filename=param3) + return str(pdf_id) + except Exception: + return False def update_data(param1, param2, param3, param4): diff --git a/Report/routes.py b/Report/routes.py index 2eb848a..6a1981c 100644 --- a/Report/routes.py +++ b/Report/routes.py @@ -7,7 +7,7 @@ from flask import Blueprint, request from Report.PdfReport import ReportGenerator from Report.ReportModel import ReportModel -from Report.db import upload_pdf, update_data, upload_esg_pdf +from Report.db import update_data, upload_report_pdf from Report.scripts.esg_contents import handle_esg_report_data from Report.scripts.path_tool import get_gen_report_path from common.scripts import verify_token, read_json_file @@ -53,7 +53,7 @@ def report_pdf(): res: 处理成功返回报告FileID;处理失败返回False """ # 保存报告数据 - report_data_result = update_data('评价', '报告数据', param1, param2) + report_data_result = update_data('综信评价数据', '报告数据', param1, param2) # 保存报告数据失败,返回False if not report_data_result: return False @@ -64,7 +64,7 @@ def report_pdf(): pdf_report.gen_report() # 保存PDF报告文件,删除临时存储的报告 - file_id = upload_pdf(report_file_name) + file_id = upload_report_pdf('文件', '综信报告', report_file_name) report_path = get_gen_report_path(name=report_file_name) os.remove(report_path) @@ -129,7 +129,7 @@ def esg_report_pdf(): res: 处理成功返回报告FileID;处理失败返回False """ # 保存报告数据 - report_data_result = update_data('评价', 'ESG报告数据', param1, param2) + report_data_result = update_data('ESG评价数据', '报告数据', param1, param2) # 保存报告数据失败,返回False if not report_data_result: return False @@ -140,7 +140,7 @@ def esg_report_pdf(): pdf_report.gen_report() # 保存PDF报告文件,删除临时存储的报告 - file_id = upload_esg_pdf(report_file_name) + file_id = upload_report_pdf('文件', 'ESG报告', report_file_name) report_path = get_gen_report_path(name=report_file_name) os.remove(report_path) @@ -185,7 +185,7 @@ def gen_pdf(): pdf_report.gen_report() # 保存PDF报告文件,删除临时存储的报告 - file_id = upload_pdf(report_file_name) + file_id = upload_report_pdf('文件', '综信报告', report_file_name) report_path = get_gen_report_path(name=report_file_name) os.remove(report_path)