package com.jeeplus.modules.sg.managementcenter.project.util;

import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.sg.managementcenter.project.entity.*;
import com.jeeplus.modules.sg.managementcenter.project.mapper.ProjectMapper;
import org.apache.poi.ss.usermodel.Row;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CapitalImportUtil {
    public static Map<String, List<ImportErp>> getProjectGroup(ImportExcel ei, int lastDataRowNum) {
        List<ImportErp> importErpList = new ArrayList<>();
        ImportErp importErp = null;
        Map<String, List<ImportErp>> map = new HashMap<>();
        for (int i = 1; i < lastDataRowNum; i++) {
            Row row = ei.getRow(i);
            importErp = new ImportErp();
            String projectId = (String) ei.getCellValue(row, 10);
            if (null!=projectId && !"".equals(projectId)) {
                importErp.setCompanyCode((String)ei.getCellValue(row, 0));
                importErp.setProfitCenter((String)ei.getCellValue(row, 1));
                importErp.setPostingDate((String)ei.getCellValue(row, 2));
                importErp.setVoucherCode((String)ei.getCellValue(row, 3));
                importErp.setArchiveType((String)ei.getCellValue(row, 4));
                importErp.setArchiveCode((String)ei.getCellValue(row, 5));
                importErp.setHeaderText((String)ei.getCellValue(row, 6));
                importErp.setHangUpCode((String)ei.getCellValue(row, 7));
                importErp.setCode((String)ei.getCellValue(row, 8));
                importErp.setDescription((String)ei.getCellValue(row, 9));
                importErp.setProjectId(projectId);
                importErp.setProjectDescription((String)ei.getCellValue(row, 11));
                importErp.setAccountCode((String)ei.getCellValue(row, 12));
                importErp.setAccountName((String)ei.getCellValue(row, 13));
                importErp.setLendingDirection((String)ei.getCellValue(row, 14));
                importErp.setLineAmount((String)ei.getCellValue(row, 15));
                importErp.setNumber((String)ei.getCellValue(row, 16));
                importErp.setBatch((String)ei.getCellValue(row, 17));
                importErp.setItemCode((String)ei.getCellValue(row, 18));
                importErp.setItemDescription((String)ei.getCellValue(row, 19));
                importErp.setCompany((String)ei.getCellValue(row, 20));
                importErp.setAmountOfTaxes((String)ei.getCellValue(row, 21));
                importErp.setInputTax((String)ei.getCellValue(row, 22));
                importErp.setVoucherNo((String)ei.getCellValue(row, 23));
                importErp.setPostingDateOut((String)ei.getCellValue(row, 24));
                importErp.setSupplier((String)ei.getCellValue(row, 25));
                importErp.setSupplierName((String)ei.getCellValue(row, 26));
                importErpList.add(importErp);
            }
        }
        for (ImportErp erp : importErpList) {
            if (map.containsKey(erp.getProjectId())) {
                map.get(erp.getProjectId()).add(erp);
            } else {
                List<ImportErp> mapList = new ArrayList<>();
                mapList.add(erp);
                map.put(erp.getProjectId(), mapList);
            }
        }
        return map;
    }
}
