package com.zcxk.core.utils.export;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Andy
 * @description: csv构造类, 用于定义每列的数据类型
 * @date 2021/7/16
 * @version V1.0
 **/
public class CsvConverter {

    private final List<CsvEntry> entries = new ArrayList<CsvEntry>();

    public void addEntry(String fieldName, String cellName) {
        CsvEntry entry = new CsvEntry(fieldName, cellName, CsvEnum.COMMON);
        entries.add(entry);
    }

    public void addEntry(String fieldName, String cellName, CsvEnum excelEnum) {
        CsvEntry entry = new CsvEntry(fieldName, cellName, excelEnum);
        entries.add(entry);
    }

    public List<CsvEntry> getEntries() {
        return entries;
    }

    public static enum CsvEnum {
        /**
         * 普通格式.
         */
        COMMON,
        /**
         * 格式化字符串类时间 如:20130820 ,20130820121212
         */
        FORMATTER,
    }

    @Data
    public static class CsvEntry {

        /**
         * 类的字段名
         */
        private String fieldName;
        /**
         * csv里面对应的列名
         */
        private String cellName;
        /**
         * 转换的类型
         */
        private CsvEnum type;

        public CsvEntry() {
            super();
        }

        public CsvEntry(String fieldName, String cellName, CsvEnum type) {
            super();
            this.fieldName = fieldName;
            this.cellName = cellName;
            this.type = type;
        }
    }
}
