__init__.py 3.3 KB
# coding=utf-8
#author:        4N
#createtime:    2020/12/8
#email:         nheweijun@sina.com
from flasgger import swag_from
from flask import Blueprint
from app.util import BlueprintApi

from flask import send_from_directory
import os
from . import data_download_task
from . import get_meta
from . import data_entry_by_meta
from . import get_data_list
from . import data_entry_simple
import configure
from  app.decorators.auth_decorator import  auth_decorator

class DataManager(BlueprintApi):

    bp:Blueprint = Blueprint("DataTool", __name__, url_prefix="/API/IO")


    @staticmethod
    @bp.route('/Download/<file>', methods=['GET'])
    @auth_decorator(configure.DataPermission)
    def table_download_file(file):
        parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        dirpath = os.path.join(parent,"file_tmp")

        # @staticmethod
        # @after_this_request
        # def delete(response):
        #     try:
        #         os.remove(os.path.join(dirpath,file))
        #         # shutil.rmtree(dirpath)
        #         print("删除文件成功!")
        #     except Exception as e:
        #         print(e)
        #         print("删除文件失败!")
        #     return response

        return send_from_directory(dirpath, filename=file, as_attachment=True)

    @staticmethod
    @bp.route('/DeleteFile/<file>', methods=['GET'])
    @auth_decorator(configure.DataPermission)
    def d_file(file):
        parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        dirpath = os.path.join(parent, "file_tmp")

        result={}
        try:
            os.remove(os.path.join(dirpath, file))
            # shutil.rmtree(dirpath)
            result["message"]="删除文件成功!"
        except Exception as e:
            print(e)
            result["message"] ="删除文件失败!"
        return result


    @staticmethod
    @bp.route('/DataDownloadTask', methods=['POST'])
    @swag_from(data_download_task.Api.api_doc)
    @auth_decorator(configure.DataPermission)
    def api_data_download_task():
        """
        下载数据任务
        """
        return data_download_task.Api().result


    @staticmethod
    @bp.route('/GetMeta', methods=['POST'])
    @swag_from(get_meta.Api.api_doc)
    @auth_decorator(configure.DataPermission)
    def get_meta():
        """
        数据Meta
        """
        return get_meta.Api().result

    @staticmethod
    @bp.route('/GetDataList', methods=['POST'])
    @swag_from(get_data_list.Api.api_doc)
    @auth_decorator(configure.DataPermission)
    def get_data_list():
        """
        本地数据list
        """
        return get_data_list.Api().result

    @staticmethod
    @bp.route('/DataEntryByMeta', methods=['POST'])
    @swag_from(data_entry_by_meta.Api.api_doc)
    @auth_decorator(configure.DataPermission)
    def data_entry_by_meta():
        """
        数据入库ByMeta
        """
        return data_entry_by_meta.Api().result

    @staticmethod
    @bp.route('/DataEntrySimple', methods=['POST'])
    @swag_from(data_entry_simple.Api.api_doc)
    @auth_decorator(configure.DataPermission)
    def data_entry_simple():
        """
        数据入库Simple
        """
        return data_entry_simple.Api().result