package com.post.excel.create;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.postCheck.domain.excel.problem.ProblemExportBean;
import com.ruoyi.postCheck.util.excel.create.PostProblemCreateExcel;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.*;

public class ProblemTest {
    public static void main(String[] args) throws Exception {
        List<ProblemExportBean> list = new ArrayList<>();
        ProblemExportBean data = new ProblemExportBean();
        data.setNo(1);
        data.setProblemNo("GJ-YXYB-2024-00001");
        data.setCheckWorkgroupName("工作组一");
        data.setCheckGroupName("检查小组一");

        data.setCheckUserName("张三丰");
        data.setCheckTime(new Date());
        data.setCheckedDeptName("运行一");
        data.setCheckedPostName("高级工程师");
        data.setProblemLevel(1);
        data.setDutyType(1);
        data.setProblemAttribute(2);
        data.setProblemCategory(1);
        data.setDescription("这是测试导出的问题11");

        list.add(data);

        data = new ProblemExportBean();
        data.setNo(3);
        data.setProblemNo("GJ-YXYB-2024-00002");
        data.setCheckWorkgroupName("工作组二");
        data.setCheckGroupName("检查小组二");

        data.setCheckUserName("张翠山");
        data.setCheckTime(new Date());
        data.setCheckedDeptName("运行二");
        data.setCheckedPostName("中级工程师");
        data.setProblemLevel(2);
        data.setDutyType(2);
        data.setProblemAttribute(2);
        data.setProblemCategory(2);
        data.setDescription("这是测试导出的问题222");
        list.add(data);

        data = new ProblemExportBean();
        data.setNo(3);
        data.setProblemNo("GJ-YXYB-2024-00003");
        data.setCheckWorkgroupName("工作组三");
        data.setCheckGroupName("检查小组三");

        data.setCheckUserName("张无忌");
        data.setCheckTime(new Date());
        data.setCheckedDeptName("运行三");
        data.setCheckedPostName("除级工程师");
        data.setProblemLevel(1);
        data.setDutyType(3);
        data.setProblemAttribute(3);
        data.setProblemCategory(3);
        data.setDescription("这是测试导出的问题333");
        list.add(data);

        PostProblemCreateExcel<ProblemExportBean> excelBeanExcelUtil = new PostProblemCreateExcel<>(ProblemExportBean.class);
        //生成Excel
//        AjaxResult ajaxResult = excelBeanExcelUtil.exportExcel(list, "岗位责任制检查问题整改表", "岗位责任制检查问题整改表",null);
//        System.out.println(ajaxResult);
        //读取Excel

        String sourceFile = "c://test//岗位责任制检查问题整改表_20240331005532-638594.xlsx";
        FileInputStream inputStream = new FileInputStream(sourceFile);
        List<ProblemExportBean> beanList = excelBeanExcelUtil.importExcel(inputStream, 1);
        for (int i = 0; i < beanList.size(); i++) {
            System.out.println((i + 1) + "\t" + JSON.toJSONString(beanList.get(i)));
        }
    }

}
