__init__.py 2.7 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,current_app,send_file
import os
import shutil
from . import data_download
from . import get_meta
from . import data_entry_by_meta
from . import get_data_list
from flask import after_this_request
import time

class DataManager(BlueprintApi):

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


    @staticmethod
    @bp.route('/Download/<file>', methods=['GET'])
    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'])
    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('/DataDownload', methods=['POST'])
    @swag_from(data_download.Api.api_doc)
    def table_download():
        """
        下载数据
        """
        return data_download.Api().result


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

    @staticmethod
    @bp.route('/GetDataList', methods=['POST'])
    @swag_from(get_data_list.Api.api_doc)
    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)
    def data_entry_by_meta():
        """
        数据入库ByMeta
        """
        return data_entry_by_meta.Api().result