Commit 2c336f9d authored by 赵杰's avatar 赵杰

Merge remote-tracking branch 'origin/manage' into manage

parents 58633b2b 0fddbcf0
......@@ -5,7 +5,10 @@
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="tamp_course_order" />
<orderEntry type="module" module-name="tamp_app_scan" />
<orderEntry type="module" module-name="recommend_project" />
<orderEntry type="module" module-name="tamp_order_py" />
<orderEntry type="module" module-name="fund_diagnose_manage" />
<orderEntry type="module" module-name="jijinhangjia-back" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
......
......@@ -2,9 +2,12 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../fund_diagnose_manage/.idea/fund_diagnose_manage.iml" filepath="$PROJECT_DIR$/../fund_diagnose_manage/.idea/fund_diagnose_manage.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/fund_report.iml" filepath="$PROJECT_DIR$/.idea/fund_report.iml" />
<module fileurl="file://$PROJECT_DIR$/../tamp_app_scan/.idea/tamp_app_scan.iml" filepath="$PROJECT_DIR$/../tamp_app_scan/.idea/tamp_app_scan.iml" />
<module fileurl="file://$PROJECT_DIR$/../jijinhangjia-back/.idea/jijinhangjia-back.iml" filepath="$PROJECT_DIR$/../jijinhangjia-back/.idea/jijinhangjia-back.iml" />
<module fileurl="file://$PROJECT_DIR$/../recommend_project/.idea/recommend_project.iml" filepath="$PROJECT_DIR$/../recommend_project/.idea/recommend_project.iml" />
<module fileurl="file://$PROJECT_DIR$/../tamp_course_order/.idea/tamp_course_order.iml" filepath="$PROJECT_DIR$/../tamp_course_order/.idea/tamp_course_order.iml" />
<module fileurl="file://$PROJECT_DIR$/../financial_management/.idea/tamp_order_py.iml" filepath="$PROJECT_DIR$/../financial_management/.idea/tamp_order_py.iml" />
</modules>
</component>
</project>
\ No newline at end of file
......@@ -2,6 +2,9 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../tamp_app_scan" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../financial_management" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../fund_diagnose_manage" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../jijinhangjia-back" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../recommend_project" vcs="Git" />
</component>
</project>
\ No newline at end of file
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : fund.py
# @Time : 2021/1/14 下午5:31
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import datetime
import time
import uuid
import oss2
from flask_restful import Resource, reqparse
from flask import request, render_template
from flask import make_response
from app.api.engine import pdf_folder, redis
class FundEvaluation(Resource):
def __init__(self):
"""."""
token = request.headers.get('Authorization', '')
token = 's:sid:' + token.split(' ')[1]
ifa_id = redis.get(token)
if not ifa_id:
return {"code": '9005', "message": "请登录", "attributes": []}
self.ifa_id = ifa_id.decode().replace('\'', '')
self.parser = reqparse.RequestParser()
def get(self):
""""""
self.parser.add_argument('fund_id', type=str, required=True, help='基金id不能为空')
args = self.parser.parse_args()
args['ifa_id'] = self.ifa_id
data = get_fund_evaluation(args)
resp = {
"statusCode": "0000",
"message": "成功",
"attributes": data
}
return resp
......@@ -7,6 +7,7 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
import datetime
import json
import time
import uuid
......@@ -16,8 +17,9 @@ from flask import request, render_template
from flask import make_response
from app.api.engine import config
from app.service.report_service import get_report_list, delete_report, get_one_report, edit_report
from app.service.template_manage_service import make_report, get_make_report_data
from app.service.report_service import get_report_list, delete_report, get_one_report, edit_report, make_report
from app.service.template_manage_service import get_make_report_data
from app.utils.format_transfer import npEncoder
from app.utils.html_to_pdf import html_to_pdf
from app.api.engine import pdf_folder, redis, env, TAMP_SQL, tamp_diagnose_app_engine
from app.utils.jinjia2html_v2 import DataIntegrate
......@@ -48,17 +50,23 @@ class ReportHandlers(Resource):
"message": "成功",
"attributes": data
}
return resp
return json.dumps(resp, cls=npEncoder, ensure_ascii=False)
def post(self):
"""保存报告."""
self.parser.add_argument('type', type=int, required=True, help='1为持仓报告2为诊断报告3周期报告')
self.parser.add_argument('name', type=str, required=False, help='报告名称或者客户姓名')
self.parser.add_argument('customer_id', type=str, required=True, help='customer_id不能为空')
self.parser.add_argument('template_data', type=str, required=True, help='template_data不能为空')
self.parser.add_argument('report_data', type=str, required=True, help='report_data不能为空')
args = self.parser.parse_args()
args['ifa_id'] = self.ifa_id
make_report(args)
resp = {
"statusCode": "0000",
"message": "成功",
"attributes": []
}
return resp
def put(self, id):
......@@ -103,10 +111,7 @@ class ReportList(Resource):
def post(self):
"""保存报告."""
self.parser.add_argument('customer_id', type=str, required=True, help='customer_id不能为空')
args = self.parser.parse_args()
make_report(args)
pass
def put(self):
"""编辑报告."""
......
......@@ -67,7 +67,6 @@ class TemplateManage(Resource):
def put(self):
"""更新模版."""
self.parser.add_argument('id', type=str, required=True, help='模版id')
# self.parser.add_argument('name', type=int, required=False, help='模版名称')
self.parser.add_argument('template_data', type=str, required=False, help='模版数据')
args = self.parser.parse_args()
args['ifa_id'] = self.ifa_id
......
......@@ -97,6 +97,10 @@ class FundReportManange(Base, BaseModel):
sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
res = tamp_user_session.execute(sql)
data['author_name'] = res.fetchone()[0]
if self.default_template:
data['sys_default'] = 1
else:
data['sys_default'] = 0
return data
......
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : fund_service.py
# @Time : 2021/1/14 下午5:31
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
def get_fund_evaluation(args):
"""返回个基点评和雷达图"""
fund_id = args.get('fund_id')
single_evaluation(self, fund_id, objective=False)
\ No newline at end of file
......@@ -7,12 +7,15 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
import datetime
import os
import uuid
from sqlalchemy import and_
# from sqlalchemy import union_all
from app.api.engine import TAMP_SQL, tamp_diagnose_app_engine
from app.model.tamp_diagnose_app import HoldReport, HoldDiagnoseReport, PeriodicReport
from app.utils.jinjia2html_v2 import DataIntegrate
def get_report_list(args):
......@@ -114,7 +117,7 @@ def get_one_report(args):
elif type == 3:
res = periodic_report
data = [r.to_dict() for r in res]
return data
return data[0]
def edit_report(args):
......@@ -153,3 +156,65 @@ def edit_report(args):
if r > 0:
return True
return False
def make_report(args):
"""制作报告."""
ifa_id = args.get('ifa_id')
customer_id = args.get('customer_id')
type = args.get('type')
name = args.get('name')
report_data = args.get('report_data')
pdf_name = str(uuid.uuid4()) + '.pdf'
args['update_time'] = datetime.datetime.now()
args['update_status'] = 1
record_id = 0
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_session = tamp_diagnose_app.session
report_record = None
if type == 1:
report_record = HoldReport(**args)
elif type == 2:
report_record = HoldDiagnoseReport(**args)
elif type == 3:
report_record = PeriodicReport(**args)
if not report_record:
return False
tamp_diagnose_session.add(report_record)
tamp_diagnose_session.flush()
record_id = report_record.id
pid = os.fork()
if pid == 0:
try:
dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, pdf_name=pdf_name, type=type)
dt.render_data(data=report_data)
hold_report = tamp_diagnose_session.query(HoldReport).filter(and_(
HoldReport.id == record_id,
HoldReport.ifa_id == ifa_id,
))
hold_diagnose_report = tamp_diagnose_session.query(HoldDiagnoseReport).filter(and_(
HoldDiagnoseReport.id == record_id,
HoldDiagnoseReport.ifa_id == ifa_id,
))
periodic_report = tamp_diagnose_session.query(PeriodicReport).filter(and_(
PeriodicReport.id == record_id,
PeriodicReport.ifa_id == ifa_id,
))
if type == 1:
res = hold_report
elif type == 2:
res = hold_diagnose_report
elif type == 3:
res = periodic_report
if not res:
return False
res.update({
'file': pdf_name,
'update_status': 2,
'update_time': datetime.datetime.now()
})
except:
pass
else:
return True
......@@ -195,9 +195,9 @@ def get_make_report_data(args):
if not template:
template = res.custom_template
template = json.loads(template)
# dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, type=type)
# data = dt.get_template_data(template)
data = template
dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, type=type)
data = dt.get_template_data(template)
# data = template
return data
......@@ -212,7 +212,8 @@ def set_default_template(args):
))
if not res:
return False
tamp_diagnose_session.query(FundReportManange).update({
type = res.type
tamp_diagnose_session.query(FundReportManange).filter(FundReportManange.type==type).update({
'default': 0
})
r = res.update({
......@@ -222,45 +223,3 @@ def set_default_template(args):
return True
return False
def make_report(args):
"""制作报告."""
ifa_id = args.get('ifa_id')
customer_id = args.get('customer_id')
type = args.get('type')
name = args.get('name')
pdf_name = str(uuid.uuid4()) + '.pdf'
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "update hold_report set update_time='{}', update_status='{}' where ifa_id='{}' and customer_id='{}'".format(
datetime.datetime.now(),
1,
ifa_id,
customer_id
)
tamp_diagnose_app_session.execute(sql)
start = time.time()
try:
dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, pdf_name=pdf_name, type=type)
dt.render_data()
except:
pass
print('耗时{}秒'.format(round(time.time() - start, 2)))
auth = oss2.Auth(config[env]['oss']['account'], config[env]['oss']['password'])
# Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'http://oss-cn-shanghai.aliyuncs.com', 'tamperdev')
# 生成下载文件的签名URL,有效时间为60s。
path = bucket.sign_url('GET', 'productionenv/Start/' + pdf_name, 60)
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "update hold_report set update_time='{}', update_status='{}', file='{}' where ifa_id='{}' and customer_id='{}'".format(
datetime.datetime.now(),
2,
pdf_name,
ifa_id,
customer_id
)
tamp_diagnose_app_session.execute(sql)
......@@ -1669,7 +1669,7 @@
</div>
<div class="dcell">
<div class="page_text">
{{{brand_name}}<br>
{{brand_name}}<br>
工作室
</div>
</div>
......
......@@ -7,6 +7,7 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
import uuid
from urllib import parse
from io import BytesIO
......@@ -18,6 +19,7 @@ from matplotlib import ticker
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
from app.api.engine import template_folder
matplotlib.use('Agg')
# 中文字体初始化
......@@ -91,11 +93,14 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2.legend(loc='upper center', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_contribution_chart(xlabels, product_list, cumulative):
......@@ -154,11 +159,15 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax2.text(a*1.1, b *1.05, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize, color='#B40A15')
ax2.legend(loc='upper left', fontsize=fontsize)
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return month_return_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
# def draw_contribution_chart(xlabels, product_list, cumulative):
# """贡献分解图"""
......@@ -294,11 +303,15 @@ def draw_old_combination_chart(xlabels, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_combination_chart(xlabels, new_combination, origin_combination, index):
......@@ -340,11 +353,15 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_index_combination_chart(compare_data):
......@@ -392,11 +409,15 @@ def draw_index_combination_chart(compare_data):
# ax3.legend()
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
if __name__ == '__main__':
# xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
......
......@@ -138,14 +138,6 @@ class DataIntegrate:
res.append(r)
for i in range(len(portfolio_evaluation)):
if portfolio_evaluation[i]['status'] == '保留':
portfolio_evaluation[i]['status'] = '<div class="self_type fl">保留</div>'
elif portfolio_evaluation[i]['status'] == '增仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl red">增仓</div>'
elif portfolio_evaluation[i]['status'] == '换仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl green">换仓</div>'
elif portfolio_evaluation[i]['status'] == '减仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl green">减仓</div>'
single_fund_data_list.append({
'fund_name': portfolio_evaluation[i]['name'],
'status': portfolio_evaluation[i]['status'],
......@@ -294,8 +286,10 @@ class DataIntegrate:
self.data = {**hold_default_template, **data}
return self.data
def render_data(self):
def render_data(self, data=None):
# 全部数据
if data:
self.data = data
# 开始渲染html模板
env = Environment(loader=PackageLoader('app', 'templates')) # 创建一个包加载器对象
# template = env.get_template('monthReport.html') # 获取一个模板文件
......@@ -314,8 +308,8 @@ class DataIntegrate:
if __name__ == '__main__':
start = time.time()
dt = DataIntegrate(ifa_id='USER_INFO15917850824287', customer_id='6716613802534121472', type=2)
dt = DataIntegrate(ifa_id='USER_INFO15917850824287', customer_id='6716613802534121472', type=1)
data = dt.get_template_data()
print(sys.getsizeof(data)*8)
print(data)
# dt.render_data()
print('耗时{}秒'.format(round(time.time()-start, 2)))
......@@ -9,6 +9,7 @@
import base64
import os
import time
import uuid
from io import BytesIO
import imgkit
......@@ -18,6 +19,8 @@ from pyecharts.charts import Radar
import cv2
import numpy as np
from app.api.engine import template_folder
def gen_radar_chart(radar_chart_data):
"""
......@@ -88,9 +91,15 @@ def gen_radar_chart(radar_chart_data):
width = len(img[0])
img = img[0:height, 160:750]
img_bin = cv2.imencode(".png", img)[1].tobytes()
img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
return img_content
# img_bin = cv2.imencode(".png", img)[1].tobytes()
# img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
# return img_content
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
cv2.imwrite(filepath, img)
return filename
if __name__ == '__main__':
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment