package com.wms_main.controller.wms;

import com.wms_main.excel.easypoi.service.IExportExcelEasyPoi;
import com.wms_main.excel.easypoi.service.IImportExcelEasyPoi;
import com.wms_main.model.dto.query.DbsQuery;
import com.wms_main.model.dto.query.KittingBomQuery;
import com.wms_main.model.dto.query.KittingBomRelationQuery;
import com.wms_main.model.dto.response.wms.BaseWmsApiResponse;
import com.wms_main.model.vo.others.FileVo;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * excel控制类
 */
@ResponseBody
@RestController
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/wms/excel")
public class ExcelController {
    /**
     * excel导入服务
     */
    private final IImportExcelEasyPoi importExcelEasyPoi;
    /**
     * excel导出服务
     */
    private final IExportExcelEasyPoi exportExcelEasyPoi;

    /**
     * 导入基础物料数据
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importBaseGoods")
    public BaseWmsApiResponse importBaseGoods(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportBaseGoods(file, fileVo);
    }

    /**
     * 导入看板数据
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importKanban")
    public BaseWmsApiResponse importKanban(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportKanban(file, fileVo);
    }

    /**
     * 导入DBS计划数据
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importDbs")
    public BaseWmsApiResponse importDbs(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportDbs(file, fileVo);
    }

    /**
     * 导入配料单及图纸
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importProduct")
    public BaseWmsApiResponse importProduct(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportProduct(file, fileVo);
    }

    /**
     * 导入单片配料单及图纸
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importSingleProduct")
    public BaseWmsApiResponse importSingleProduct(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportSingleProduct(file, fileVo);
    }

    /**
     * 导入总成-单片对应关系
     * @param file 文件
     * @param fileVo 文件信息
     * @return 导入结果
     * @throws Exception 异常
     */
    @PostMapping("/importProductExtend")
    public BaseWmsApiResponse importProductExtend(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportProductExtend(file, fileVo);
    }

    /**
     * 导出DBS
     * @param dbsQuery 请求
     */
    @PostMapping("/exportDbsWithExcel")
    public void exportDbsWithExcel(@RequestBody DbsQuery dbsQuery, HttpServletResponse response) throws IOException {
        exportExcelEasyPoi.doExportDbs(dbsQuery, response);
    }

    /**
     * 导出配料单
     * @param kittingBomQuery 请求
     */
    @PostMapping("/exportKittingBomWithExcel")
    public void exportKittingBomWithExcel(@RequestBody KittingBomQuery kittingBomQuery, HttpServletResponse response) throws IOException {
        exportExcelEasyPoi.doExportKittingBom(kittingBomQuery, response);
    }

    /**
     * 导出配对关系
     * @param kittingBomRelationQuery 请求
     */
    @PostMapping("/exportKittingBomRelationWithExcel")
    public void exportKittingBomRelationWithExcel(@RequestBody KittingBomRelationQuery kittingBomRelationQuery, HttpServletResponse response) throws IOException {
        exportExcelEasyPoi.doExportKittingBomRelations(kittingBomRelationQuery, response);
    }
}
