package com.bonus.system.download;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.bonus.common.core.constant.BusinessConstants;
import com.bonus.common.core.utils.ExcelStyleUtil;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.UploadCheckUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.Log;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.BusinessType;
import com.bonus.common.log.enums.OperaType;
import com.bonus.system.basic.service.SysOrgService;
import com.bonus.system.dept.entity.SubOrgBean;
import com.bonus.system.dept.service.SubOrgService;
import com.bonus.system.holiday.entity.HolidayBean;
import com.bonus.system.holiday.service.HolidayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


/**
 * @author：fly
 * @date：2024-10-14-10:30
 * @version：1.0
 * @description：导入文件-web层
 */
@RestController
@RequestMapping("/import")
@Slf4j
public class ImportFileController {


    /**
     * 轮休、请假、临时外出导出
     */
    @Resource(name = "HolidayService")
    private HolidayService holidayService;

    /**
     * 组织导入
     */
    @Resource(name = "sysOrgService")
    private SysOrgService sysOrgService;


    @PostMapping("excelUpload")
//    @RequiresPermissions("basic:person:excelUpload")
    @Log(title = "流程管理->假期管理->导入Excel", businessType = BusinessType.IMPORT)
    public AjaxResult excelUpload(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        String result = UploadCheckUtils.uploadExcelVerify(file);
        if (StringUtils.isNotBlank(result)) {
            return AjaxResult.error(result);
        }
        return holidayService.excelUpload(file, request, response);
    }

    @PostMapping("orgUpload")
//    @RequiresPermissions("basic:person:excelUpload")
    @Log(title = "组织管理->组织管理->导入Excel", businessType = BusinessType.IMPORT)
    public AjaxResult orgUpload(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        String result = UploadCheckUtils.uploadExcelVerify(file);
        if (StringUtils.isNotBlank(result)) {
            return AjaxResult.error(result);
        }
        return sysOrgService.orgUpload(file, request, response);
    }

}
