package com.boman.file.controller;

import com.boman.domain.dto.AjaxResult;
import com.boman.domain.dto.ExportExcelDto;
import com.boman.file.service.ISysFileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author shiqian
 * @date 2021年06月07日 16:24
 **/
@RestController
@RequestMapping("/common/file")
public class ExcelController {

    @Resource
    private ISysFileService fileService;

    /**
     * 功能描述: 通用的导入接口
     *
     * @param multipartFile MultipartFile
     * @param tableName     tableName
     * @return void
     */
    @PostMapping("/import")
    public AjaxResult importExcelCommon(MultipartFile multipartFile, String tableName) {
        try {
            return fileService.importExcelCommon(multipartFile, tableName);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return AjaxResult.error("失败");
    }


    /**
     * 功能描述: 通用的导出接口
     *
     * @param response response
     * @param dto      tableName
     *                 empty(true=>只带表头的excel，不含数据, false=>带数据的excel)
     *                 condition 查询条件
     * @return com.boman.domain.dto.AjaxResult
     */
    @PostMapping("/export")
    public AjaxResult exportExcelCommon(HttpServletResponse response, @RequestBody ExportExcelDto dto) {
        try {
            return fileService.exportExcelCommon(response, dto);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return AjaxResult.error("失败");
    }



}
