import-controller.js 773 Bytes
const Context = require('../framework/context');
const Api = require('../common/api');
const XlsxService = require('../service/xlsx-service');

class FileController extends Context {
    constructor() {
        super();
        this.api = this.instance(Api);
        this.xlsxService = this.instance(XlsxService);
    }
    import(req, res, next) {
        let file = req.files && req.files.file;

        if (!file) {
            return res.json({
                code: 400,
                message: '请上传文件'
            });
        }
        let cols = JSON.parse(req.body.cols);

        this.xlsxService.resolveExcel(file.path, cols).then(excelData => {
            return res.json(excelData);
        }).catch(next);
    }
}

module.exports = FileController;