package com.cpp.web.utils;


import com.cpp.web.domain.datafactory.dto.ParsingConfParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 文件字段配置提取类
 *
 * @author tl
 * @date 2022-05-11 10:08:21
 */
@Slf4j
public class ParsingFieldUtil {

    //分隔符
    private static final String SEPARATOR = "<=>";

    //单行
    public static final String SINGLE = "s";

    //多行
    public static final String MULTI = "m";


    /*
     * 解析配置格式规则：
     *   1<=>2<=>entity<=>yyyy-mm-dd
     *
     *   1：取值在1行
     *   entity=：键标记标记
     *
     *   4-20<=>3<=>?<=>yyyy-mm-dd
     *
     *   4-20：取值在4-20行
     *   3：第三列
     * */
    public static ParsingConfParam getConfig(String s) {
        ParsingConfParam fileParsingConfig = new ParsingConfParam();
        try {
            if (s != null) {
                String[] split = s.split(SEPARATOR);

                fileParsingConfig.setLineNumber(split[0]);
                fileParsingConfig.setRowNumber(split[1]);
                if (split.length > 2) {
                    fileParsingConfig.setDataSign(split[2]);
                }
                if (split.length > 3) {
                    fileParsingConfig.setFormat(split[3]);
                }
            }
        } catch (IndexOutOfBoundsException e) {
            log.error("获取配置信息出错，详情：" + e);
        } finally {
            return fileParsingConfig;
        }


    }


}
