Commit e04a86bf authored by pengxiong's avatar pengxiong

app端月报生成接口

parent ce855a22
......@@ -96,11 +96,11 @@ tamp_diagnose_app_engine = create_engine(
)
# redis = redis.StrictRedis(
# host=config[env]['redis']['host'],
# port=config[env]['redis']['port'],
# db=config[env]['redis']['db']
# )
redis = redis.StrictRedis(
host=config[env]['redis']['host'],
port=config[env]['redis']['port'],
db=config[env]['redis']['db']
)
logging.basicConfig(level=logging.INFO,
filename=work_dir + config[env]['log']['filename'],
......
......@@ -11,6 +11,9 @@ dev:
host: localhost
port: 6379
db: 0
oss:
account: LTAI4FzkGhAMecinBCKwuoUW
password: KJpPWg9U0kYO71yB41gqYbrFNJ4hso
log:
filename: /logs/fund_report.log
filemode: a
......@@ -44,14 +47,18 @@ prod:
tamp_order_db: tamp_order
tamp_user_db: tamp_user
tamp_fund_db: tamp_fund
tamp_diagnose_app_db: tamp_diagnose_app
host: tamper.mysql.polardb.rds.aliyuncs.com
port: 3306
user: tamp_admin
password: '@imeng123'
user: tamp_fund
password: '@imeng408'
redis:
host: localhost
port: 6379
db: 0
oss:
account: LTAI4FzkGhAMecinBCKwuoUW
password: KJpPWg9U0kYO71yB41gqYbrFNJ4hso
log:
filename: /logs/fund_report.log
filemode: a
......
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : order.py
# @Time : 2020/11/18 下午3:19
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import uuid
from flask_restful import Resource, reqparse
from flask import request, render_template
from flask import make_response
from app.utils.html_to_pdf import html_to_pdf
from app.api.engine import pdf_folder
class OrderHandlers(Resource):
"""."""
def __init__(self):
"""."""
self.parser = reqparse.RequestParser()
def get(self):
"""."""
# self.parser.add_argument('product_id',type=str,required=True,help='商品ID不能为空')
# args = self.parser.parse_args()
STUDENT_LIST = [
{'name': 'pj', 'age': 38, 'gender': '中'},
{'name': 'lc', 'age': 73, 'gender': '男'},
{'name': 'fy', 'age': 84, 'gender': '女'}
]
params = {'a': 'hello', 'b': 'world'}
template = render_template('student.html', student=STUDENT_LIST, params=params)
html_to_pdf(template, pdf_folder + str(uuid.uuid4()) + '.pdf')
resp = make_response(template)
resp.headers['Content-Type'] = 'text/html'
return resp
def post(self):
"""."""
pass
def put(self, id):
"""."""
pass
def delete(self, id):
"""."""
pass
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : report.py
# @Time : 2020/11/18 下午3:19
# @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 config
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
class ReportHandlers(Resource):
"""."""
def __init__(self):
"""."""
self.parser = reqparse.RequestParser()
def get(self):
"""."""
# self.parser.add_argument('ifa_id', type=str, required=True, help='ifa_id不能为空')
self.parser.add_argument('customer_id', type=str, required=True, help='customer_id不能为空')
args = self.parser.parse_args()
token = request.headers.get('Authorization', '')
token = 's:sid:' + token.split(' ')[1]
ifa_id = redis.get(token).decode()
if not ifa_id:
return {"code":40005,"data":None,"lang":"zh_CN","msg":"请登陆"}
ifa_id = ifa_id.replace('\'', '')
customer_id = args['customer_id']
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)
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)
resp = {
"code": 0,
"data": {
"path": path
},
"lang": "zh_CN",
"msg": "成功"
}
return resp
def post(self):
"""."""
pass
def put(self, id):
"""."""
pass
def delete(self, id):
"""."""
pass
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : order.py
# @File Name : report.py
# @Time : 2020/11/18 下午3:11
# @Author : X. Peng
# @Email : acepengxiong@163.com
......
......@@ -7,8 +7,8 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
from app.controller.order import *
from app.controller.report import *
def add_route(api):
"""注册路由"""
api.add_resource(OrderHandlers, '/tamp_course_order/order')
api.add_resource(ReportHandlers, '/fund_report/report')
This diff is collapsed.
......@@ -12,11 +12,14 @@ from urllib import parse
from io import BytesIO
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import ticker
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
matplotlib.use('Agg')
# 中文字体初始化
plt.rcParams['font.sans-serif']=['Heiti TC']
......
......@@ -22,7 +22,8 @@ class DataIntegrate:
self.user_customer = UserCustomerResultAdaptor(ifa_id, customer_id)
self.customer_name = self.user_customer.customer_real_name
self.ifa_name = self.user_customer.ifa_real_name
self.pdf_name = self.ifa_name + "_" + self.customer_name + "_" + '.pdf'
# self.pdf_name = self.ifa_name + "_" + self.customer_name + "_" + '.pdf'
self.pdf_name = pdf_name
# 全部数据
self.df = self.user_customer.calculate_total_data()
# 组合结果数据
......@@ -313,9 +314,9 @@ class DataIntegrate:
template = env.get_template('/v2/monthReportV2.1.html') # 获取一个模板文件
monthReport_html = template.render(data) # 渲染
# 保存 monthReport_html
save_file = "app/html/monthReport.html"
with open(save_file, 'w', encoding="utf-8") as f:
f.write(monthReport_html)
# save_file = "app/html/monthReport.html"
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
# save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f:
......
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