package com.gyee.wisdom.report.controller;


import com.gyee.wisdom.report.service.SeleniumService;
import com.gyee.wisdom.report.service.ReportService;
import com.gyee.wisdom.report.utils.ResponseWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

import java.util.List;
import java.util.Map;


/**
 * @author ：xugp
 * @date ：Created in 2022/10/27 15:50
 * @description：报表接口
 * @modified By：
 * @version: $
 */
@Slf4j
@RestController
@RequestMapping("/report")
@Tag(name = "报表接口")
public class ReportController {



    @Autowired
    private ReportService reportService;


    @Autowired
    private SeleniumService seleniumService;



    @Operation(description = "生产日报报表导入")
    @PostMapping(value = "/importPro")
    @ResponseBody
    public ResponseWrapper ImportPro(@RequestParam(value = "file", required = false) MultipartFile file,
                                           HttpServletRequest request, String departId) throws Exception {

        log.info("开始导入");
        ResponseWrapper<T> wrapper = new ResponseWrapper<T>();
        if (!file.isEmpty()) {
            //得到三个sheet页数据
            Map<Integer, List<String[]>> map = reportService.commonReport(file);
            seleniumService.loginAndWrite(map,departId);
            wrapper.setMsg("填报成功");
        }
        return wrapper;
    }

}
