package com.wms_main.controller.wms;

import com.wms_main.excel.easypoi.service.IImportExcelEasyPoi;
import com.wms_main.model.dto.query.DbsQuery;
import com.wms_main.model.dto.request.wms.InitKateWorkRequest;
import com.wms_main.model.vo.others.FileVo;
import com.wms_main.model.dto.response.wms.BaseWmsApiResponse;
import com.wms_main.model.vo.wms.ImageVo;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.repository.utils.UUIDUtils;
import com.wms_main.service.controller.ITestControllerService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 测试专用
 */
@RestController
@ResponseBody
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/test")
public class TestController {

    private final IImportExcelEasyPoi importExcelEasyPoi;
    private final ITestControllerService testService;

    @GetMapping(value = "/test")
    public String testApi() {
        return UUIDUtils.getNewUUID();
    }
//
//
//    @PostMapping(value = "/test2")
//    public WmsApiResponse<Object> testApiPost(@RequestBody String msg) {
//
//        return WmsApiResponse.success("收到", "收到" + msg);
//    }
//
//    @GetMapping(value = "/testQuartz")
//    public String testQuartz() {
//        JobUtils.createJob(scheduler, new JobBean(JobTest.class.getName(), JobTest.class, "0/2 * * * * ? *"));
//        return "创建定时任务成功。";
//    }
//
//    @PostMapping("/testFilter")
//    public WmsApiResponse<WaveRequest> testFilter(@RequestBody WaveRequest originRequest) {
//        originRequest.setWavesId("new");
//        return WmsApiResponse.success("收到", originRequest);
//    }

    @PostMapping("/testImportImage")
    public BaseWmsApiResponse testFilter(@RequestPart("file") MultipartFile file, @RequestPart("fileVo") FileVo fileVo) throws Exception {
        return importExcelEasyPoi.doImportDbs(file, fileVo);
    }

    /**
     * 测试前台向后台请求图片
     * @param request 请求
     * @return 结果
     */
    @PostMapping("/testRequestImage")
    public WmsApiResponse<List<ImageVo>> testRequestImage(@RequestBody InitKateWorkRequest request) {
        return testService.testRequestImage(request);
    }

    /**
     * 测试导出
     * @param dbsQuery 请求
     */
    @PostMapping("/testExport")
    public void testExport(@RequestBody DbsQuery dbsQuery, HttpServletResponse response) {
        try {
            testService.testExport(dbsQuery, response);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
