update 修改数据库信息
This commit is contained in:
parent
a79537e02c
commit
293a5c316d
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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['工商信息']['纳税人识别号']
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
75
Report/db.py
75
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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue