package net.northking.cctp.testbug.util;

import net.northking.cctp.common.util.excelUtil.ExcelToolUtil;
import net.northking.cctp.common.util.excelUtil.excelEntity.ExcelHead;
import net.northking.cctp.common.util.excelUtil.excelEntity.SheetHead;
import net.northking.cctp.testbug.dto.cases.MtProjectTemplateDetailDto;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * @author: puchao.ma
 * @date: 2021/10/20 10:54
 */
public class ExcelUtil {

    /**
     * 处理自定义字段
     * @param heads
     * @param head1s
     * @param expands
     */
    public static void handleExpands(List<SheetHead> heads, List<ExcelHead> head1s, List<MtProjectTemplateDetailDto> expands) {
        if (CollectionUtils.isNotEmpty(expands)) {
            //  自定义属性
            List<MtProjectTemplateDetailDto> collect = expands.stream()
                    .sorted(Comparator.comparing(MtProjectTemplateDetailDto::getTemplatePropSort))
                    .collect(Collectors.toList());

            AtomicInteger size = new AtomicInteger(heads.size());

            collect.forEach(c->{
                SheetHead head = new SheetHead();
                head.setStartRow(1);
                head.setEndRow(1);
                head.setStartCol(ExcelToolUtil.getExcelColumnLabel(size.get()) );
                head.setEndCol(ExcelToolUtil.getExcelColumnLabel(size.get()) );
                head.setName(c.getTemplatePropDisplay());
                heads.add(head);

                ExcelHead head1 = new ExcelHead();
                head1.setIsMerge("0");
                head1.setTemplatePropDisplay(c.getTemplatePropDisplay());
                head1.setTemplatePropName(c.getTemplatePropName());
                head1s.add(head1);

                size.getAndIncrement();
            });
        }
    }
}
