package com.cf.imes.module.executor.util;

import com.cf.imes.framework.excel.core.util.ExcelUtils;
import org.apache.poi.ss.usermodel.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class OrderExcelUtil extends ExcelUtils {
    public static <T> List<T> read(MultipartFile file, Class<T> head , int upload) throws IOException {
        if (file.isEmpty()) {
            throw new IOException("文件为空");
        } else if (!file.getOriginalFilename().endsWith(".xlsx")) {
            throw new IOException("文件格式不正确");
        } else if (file.getSize() > 1024 * 1024 * 10) {
            throw new IOException("文件大小超过 10M");
        } else if (file.getSize() == 0) {
            throw new IOException("文件大小为 0");
        } else {
            //读取文件内容


            try {
                // 将 MultipartFile 转换为 InputStream
                InputStream inputStream = file.getInputStream();
                // 使用 WorkbookFactory 创建 Workbook 对象
                Workbook workbook = WorkbookFactory.create(inputStream);
                Sheet sheet = workbook.getSheetAt(0);
                extractOrderInformation(sheet, file);

                workbook.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return null;
    }

    private static void extractOrderInformation(Sheet sheet, MultipartFile file) throws IOException {
        int rowNum=sheet.getLastRowNum();
        for (Row row : sheet) {
            Cell firstCell = row.getCell(0);
            if (firstCell != null && firstCell.getCellType() == CellType.STRING) {
                String cellValue = firstCell.getStringCellValue().trim();
                if (cellValue.equals("&&&")) {


                }
            }
        }
    }

}
