# -*- 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
from app.service.fund_service import single_evaluation
from app.utils.auth import login_require


class FundEvaluation(Resource):
    def __init__(self):
        """."""
        self.parser = reqparse.RequestParser()

    @login_require
    def get(self):
        """"""
        self.parser.add_argument('fund_id', type=str, required=True, help='基金id不能为空')
        self.parser.add_argument('type', type=int, required=True, help='基金类型不能为空')
        args = self.parser.parse_args()
        try:
            data = single_evaluation(fund_id=args.get('fund_id'), invest_type=args.get('type'))
            resp = {
                "statusCode": "0000",
                "message": "成功",
                "attributes": data
            }
        except:
            resp = {
                "statusCode": "9999",
                "message": "该基金最近一年无净值更新，暂不提供该基金评价。",
                "attributes": ""
            }
        return resp
