
package com.lideeyunji.core.framework.utils;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.lideeyunji.core.framework.entity.*;
import com.lideeyunji.core.framework.mapper.LideeYunJiMapper;
import com.lideeyunji.core.framework.params.CopyEnhanceParam;
import com.lideeyunji.core.framework.params.vo.ReportFieldVo;
import com.lideeyunji.tool.framework.exception.lideeYunJiException;
import com.lideeyunji.tool.framework.yunji.adapter.IlideeYunjiAdapter;
import com.lideeyunji.tool.framework.yunji.constant.lideeYunjiCodeConstant;
import com.lideeyunji.tool.framework.yunji.enums.*;
import com.lideeyunji.tool.framework.yunji.model.lideeYunjiDept;
import com.lideeyunji.tool.framework.yunji.model.global.BaseTenantEntity;
import com.lideeyunji.tool.framework.yunji.params.lideeYunJiDeptParam;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
import com.lideeyunji.tool.framework.yunji.utils.lideeYunJiUtils;
import com.lideeyunji.tool.framework.yunji.component.properties.lideeYunjiProperties;
import com.lideeyunji.core.framework.params.model.WebFormatConfigModel;
import com.lideeyunji.core.framework.params.vo.DbFormFieldIdVo;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.lideeyunji.tool.framework.sql.SqlHelper;
import com.lideeyunji.tool.framework.sql.build.buildmodel.wrapper.SqlInfoQueryWrapper;
import com.lideeyunji.tool.framework.sql.core.model.OrderByModel;
import com.lideeyunji.tool.framework.sql.core.model.SqlFormatModel;
import com.lideeyunji.tool.framework.sql.core.model.WhereModel;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import oracle.sql.TIMESTAMP;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import java.io.*;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.sql.Blob;
import java.sql.Clob;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 工具类
 */
public class Func extends FuncBase {


    //校验数据类型
    public static Object fomatDbValue(String fieldType, Object value) {
        if (FuncBase.isEmpty(value)) {
            return null;
        }
        if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.STRING.getFieldType())
                || FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.TEXT.getFieldType())
                || FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.LONGTEXT.getFieldType())) {//字符串
            return FuncBase.toStr(value);
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.INTEGER.getFieldType())) {
            return FuncBase.toInt(value);
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.BIGINT.getFieldType())) {
            return FuncBase.toLong(value);
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.BIGDECIMAL.getFieldType())) {
            return new BigDecimal(FuncBase.toStr(value));
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.DATE.getFieldType())) {
            //yyyy-MM-dd
            String str = FuncBase.toStr(value);
            return DateUtil.parseDate(str.substring(0, 10));
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.DATETIME.getFieldType())) {
            //yyyy-MM-dd HH:mm:ss
            String str = FuncBase.toStr(value);
            return DateUtil.parseDateTime(str.substring(0, 19));
        } else if (FuncBase.equals(fieldType, LideeYunJiFieldTypeEnum.TIME.getFieldType())) {
            //HH:mm:ss
            String str = FuncBase.toStr(value);
            return DateUtil.parseTime(str.substring(0, 8));
        }
        return FuncBase.toStr(value);
    }

    /**
     * 校验表名称是否可用
     *
     * @param tableName
     * @return true=可用 false=不可用
     */
    public static Boolean checkTableName(String tableName) {
        List<String> excludeTableNamesList = lideeYunjiProperties.getExcludeTableNames();
        if (FuncBase.isEmpty(excludeTableNamesList)) {
            return true;
        }

        boolean flag = excludeTableNamesList.stream()
                .anyMatch(fieldName -> tableName.startsWith(fieldName));
        return !flag;

    }


    /**
     * 将list转为map  key=id  value=id
     *
     * @param dataList
     * @return
     */
    public static Set<String> list2SetId(List<Map<String, Object>> dataList) {
        Set<String> idSet = dataList.stream()
                .filter(subParamMap -> !Func.isEmpty(Func.getMap2Str(subParamMap, "id")))
                .map(subParamMap -> Func.getMap2Str(subParamMap, "id"))
                .collect(Collectors.toSet());

        return idSet;
    }

    /**
     * 判断新字段和旧字段是否一致
     *
     * @return false=不一致  true=一致
     */
    public static boolean dbFormFieldEquals(List<FormFieldEntity> oldFieldList, List<FormFieldEntity> newFieldList) {
        if (FuncBase.isEmpty(oldFieldList) && FuncBase.isNotEmpty(newFieldList)) {
            return false;
        }
        Map<String, FormFieldEntity> oldMap = new HashMap<>();
        for (FormFieldEntity dbFormFieldEntity : oldFieldList) {
            String fieldCode = dbFormFieldEntity.getFieldCode();
            oldMap.put(fieldCode, dbFormFieldEntity);
        }

        for (FormFieldEntity newField : newFieldList) {
            String fieldCode = newField.getFieldCode();
            String isDb = newField.getIsDb();
            if (Func.equals(isDb, YNEnum.N.getCode())) {//不用同步到数据库
                continue;
            }

            FormFieldEntity oldfield = oldMap.get(fieldCode);
            if (FuncBase.isEmpty(oldfield)) {//新-存在，旧不存在
                return false;
            }
            //不一样
            if (!FuncBase.equals(oldfield.getFieldCode(), newField.getFieldCode())
                    || !FuncBase.equals(oldfield.getFieldName(), newField.getFieldName())
                    || !FuncBase.equals(oldfield.getFieldLen(), newField.getFieldLen())
                    || !FuncBase.equals(oldfield.getFieldPointLen(), newField.getFieldPointLen())
                    || !FuncBase.equals(oldfield.getFieldDefaultVal(), newField.getFieldDefaultVal())
                    || !FuncBase.equals(oldfield.getFieldType(), newField.getFieldType())
                    || !FuncBase.equals(oldfield.getIsPrimaryKey(), newField.getIsPrimaryKey())
                    || !FuncBase.equals(oldfield.getIsNull(), newField.getIsNull())
                    || !FuncBase.equals(oldfield.getIsDb(), newField.getIsDb())) {
                return false;
            }

        }
        //判断旧的存在，新的不存在情况
        Map<String, FormFieldEntity> newMap = new HashMap<>();
        for (FormFieldEntity dbFormFieldEntity : newFieldList) {
            String fieldCode = dbFormFieldEntity.getFieldCode();
            newMap.put(fieldCode, dbFormFieldEntity);
        }
        for (FormFieldEntity oldField : oldFieldList) {
            String fieldCode = oldField.getFieldCode();
            String isDb = oldField.getIsDb();
            if (Func.equals(isDb, YNEnum.N.getCode())) {//不用同步到数据库
                continue;
            }
            FormFieldEntity newfield = newMap.get(fieldCode);
            if (FuncBase.isEmpty(newfield)) {//旧的存在新的不存在
                return false;
            }

        }
        return true;

    }


    public static List<String> getSummaryFieldList(String fieldCode, String summarySql) {
        List<String> selfFieldList = new ArrayList<>();
        if (Func.equals(summarySql, "sum")) {
            selfFieldList.add(String.format("sum(%s) as \"%s\"", fieldCode, fieldCode));
        } else if (Func.equals(summarySql, "avg")) {
            selfFieldList.add(String.format("avg(%s) as \"%s\"", fieldCode, fieldCode));
        } else if (Func.equals(summarySql, "max")) {
            selfFieldList.add(String.format("max(%s) as \"%s\"", fieldCode, fieldCode));
        } else if (Func.equals(summarySql, "min")) {
            selfFieldList.add(String.format("min(%s) as \"%s\"", fieldCode, fieldCode));
        } else {
            selfFieldList.add(String.format("(" + summarySql + ")" + " as \"%s\"", fieldCode));
        }
        return selfFieldList;
    }

    public static String getFormatExecuteSql(WebFormatConfigModel.SqlModel sqlModel) {
        String valueType = sqlModel.getValueType();
        String sql = "";
        if (Func.equals(valueType, "group")) {
            sql = sqlModel.getGroup();
        } else if (Func.equals(valueType, "custom")) {
            sql = sqlModel.getCustom();
        }
        return sql;
    }

    /**
     * 执行某一个类下的方法，
     *
     * @param classPath  类路径
     * @param methodName 方法名称
     * @param dataMap    参数
     * @return
     */
    public static Object runByClass(String classPath, String methodName, Map<String, Object> dataMap) {
        try {
            // 1. 获取Class对象
            Class<?> clazz = Class.forName(classPath);

            // 2. 创建DemoClass的一个实例
            Object demoClassInstance = clazz.getDeclaredConstructor().newInstance();

            // 3. 获取getBjName方法的对象
            Method method = clazz.getMethod(methodName, Map.class);

            // 4. 调用getBjName方法
            return method.invoke(demoClassInstance, dataMap);
        } catch (Exception e) {
            e.printStackTrace();
            throw new lideeYunJiException(e.getMessage());
        }

    }

    //计算
    public static String executeJavaExpress(String express, Map<String, Object> dataMap) {
        try {
            String expressTmp = express.replaceAll("\\#\\{([^}]+)\\}", "$1");
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<String, Object>();
            dataMap.forEach((key, val) -> {
                // 处理键值对
                context.put(key, val);
            });
            Object result = runner.execute(expressTmp, context, null, true, false);
            return Func.toStr(result);
        } catch (Exception e) {
            e.printStackTrace();
            throw new lideeYunJiException(e.getMessage());
        }
    }

    public static Object getfieldValObj(LideeYunJiFieldTypeEnum fieldTypeEnum, Object fieldVal) {
        Object fieldValObj = fieldVal;
        if (Func.equals(LideeYunJiFieldTypeEnum.BIGINT, fieldTypeEnum)) {
            fieldValObj = Func.toLong(fieldVal);
        } else {
            fieldValObj = Func.toStr(fieldVal);
        }
        return fieldValObj;
    }

    public static String sendPost(String url, Object body) throws Exception {
        String accept = HttpRequest.post(url)
                .body(Func.json2Str(body))
                .header("Content-Type", "application/json")
                .header("Accept", "application/json")
                .timeout(5000)
                .execute().body();
        if (FuncBase.isEmpty(accept)) {
            Thread.sleep(2000);//休息2秒
        }
        return accept;

    }

    /**
     * 处理虚拟化字段
     *
     * @param selectList
     * @param asList
     */
    public static void handleFieldFormatConfig(List<String> selectList, List<String> asList, List<FormFieldWebEntity> webEntityList) {
        if (isEmpty(webEntityList)) {
            return;
        }

        for (int i = 0; i < webEntityList.size(); i++) {
            FormFieldWebEntity web = webEntityList.get(i);
            String fieldCode = web.getFieldCode();
            String formatConfig = web.getFormatConfig();
            if (Func.isEmpty(formatConfig)) {
                continue;
            }
            WebFormatConfigModel webFormatConfigModel = Func.json2Bean(formatConfig, WebFormatConfigModel.class);
            if (Func.isEmpty(webFormatConfigModel)) {
                continue;
            }
            if (Func.isNotEmpty(webFormatConfigModel.getClass()) && Func.equals(webFormatConfigModel.getFormatType(), "sql")) {//子查询处理
                WebFormatConfigModel.Json formatJson = webFormatConfigModel.getFormatJson();
                WebFormatConfigModel.SqlModel sqlModel = formatJson.getSql();
                String sql = Func.getFormatExecuteSql(sqlModel);
                if (Func.isEmpty(sql)) {
                    continue;
                }

                selectList.add("(" + sql + ")" + " as \"" + fieldCode + "\"");
                asList.add(fieldCode);
            } else if (Func.isNotEmpty(webFormatConfigModel.getClass()) && Func.equals(webFormatConfigModel.getFormatType(), "fun")) {//sql函数处理
                String sql = webFormatConfigModel.getFormatJson().getFun();
                if (Func.isEmpty(sql)) {
                    continue;
                }

                selectList.add(sql + " as \"" + fieldCode + "\"");
                asList.add(fieldCode);
            }
        }
    }

    //复制表属性
    public static <T> List<T> copyDbFormFieldList(List list, Class<T> clazz) {
        List<T> fieldList = BeanUtil.copyToList(list, clazz);
        fieldList.stream().forEach(vo -> {
            DbFormFieldIdVo v = (DbFormFieldIdVo) vo;
            v.setId(null);//剔除id
        });
        return fieldList;
    }

    public static <T> List<T> copyReportFieldList(List list, Class<T> clazz) {
        List<T> fieldList = BeanUtil.copyToList(list, clazz);
        fieldList.stream().forEach(vo -> {
            ReportFieldVo v = (ReportFieldVo) vo;
            v.setId(null);//剔除id
        });
        return fieldList;
    }

    //将datamaplist 转为  ResultSet
    public static Map<String, String> dataMapList2ResultSet(List<Map<String, Object>> dataMapList) {
        // 使用Java 8的Stream API进行转换
        return dataMapList.stream()
                .filter(Objects::nonNull) // 过滤掉null值
                .collect(Collectors.toMap(
                        map -> Func.getMap2Str(map, "fieldCode").toLowerCase(), // 作为键
                        map -> Func.getMap2StrDefault(map, "fieldName", "")  // 作为值
                ));
    }

    public static Map<String, Object> getSaveOrUpdateMap(List<FormFieldEntity> fieldList, Map<String, Object> params) {
        // 使用 Stream API 优化代码
        Map<String, Object> dataMap = fieldList.stream()
                .filter(entity -> params.containsKey(entity.getFieldCode())) // 只处理 params 中存在的字段
                .filter(entity -> params.get(entity.getFieldCode()) != null) // 确保值不为 null
                .collect(Collectors.toMap(
                        entity -> entity.getFieldCode(),
                        entity -> {
                            Object o = params.get(entity.getFieldCode());

                            if (Func.isEmpty(o)) {
                                return o;
                            }
                            LideeYunJiFieldTypeEnum fieldTypeEnum = LideeYunJiFieldTypeEnum.getByFieldType(entity.getFieldType());
                            switch (fieldTypeEnum) {
                                case BIGINT:
                                    return new BigDecimal(Func.toStr(o)).longValue();
                                case INTEGER:
                                    return new BigDecimal(Func.toStr(o)).intValue();
                                case BIGDECIMAL:
                                    return new BigDecimal(Func.toStr(o));
                                case DATE:
                                    return DateUtil.parse(Func.toStr(o), "yyyy-MM-dd");
                                case DATETIME:
                                    return DateUtil.parse(Func.toStr(o), "yyyy-MM-dd HH:mm:ss");
                                case TIME:
                                    return DateUtil.parse(Func.toStr(o), "HH:mm:ss");
                                case BLOB:
                                    // 假设 BLOB 处理方式是将字符串转换为字节数组
                                    return Func.toStr(o).getBytes();
                                default:
                                    return o;
                            }

                        }
                ));
        return dataMap;
    }

    /**
     * 参数转换
     *
     * @param obj
     * @param fieldTypeEnum
     * @return
     */
    public static Object paramParse2Object(Object obj, LideeYunJiFieldTypeEnum fieldTypeEnum) {
        switch (fieldTypeEnum) {
            case BIGINT:
                return new BigDecimal(Func.toStr(obj)).longValue();
            case INTEGER:
                return new BigDecimal(Func.toStr(obj)).intValue();
            case BIGDECIMAL:
                return new BigDecimal(Func.toStr(obj));
            case DATE:
                return DateUtil.parse(Func.toStr(obj), "yyyy-MM-dd");
            case DATETIME:
                return DateUtil.parse(Func.toStr(obj), "yyyy-MM-dd HH:mm:ss");
            case TIME:
                return DateUtil.parse(Func.toStr(obj), "HH:mm:ss");
            case BLOB:
                // 假设 BLOB 处理方式是将字符串转换为字节数组
                return Func.toStr(obj).getBytes();
            default:
                return obj;
        }

    }

    public static void handlePlusDataList(List<Map<String, Object>> records, Map<String, LideeYunJiFieldTypeEnum> fieldTypeEnumMap) {
        ForkJoinPool pool = null;
        try {
            pool = FuncBase.lideeyunjiForkJoinPool();
            pool.submit(() -> records.parallelStream().forEach(recordMap -> {
                handlePlusDataMap(recordMap, fieldTypeEnumMap);
            })).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e.getMessage());
        } finally {
            if (pool != null) {
                pool.shutdown();
            }
        }
    }


    public static void handlePlusDataMap(Map<String, Object> recordMap, Map<String, LideeYunJiFieldTypeEnum> fieldTypeEnumMap) {
        recordMap.forEach((key, value) -> {
            LideeYunJiFieldTypeEnum fieldTypeEnum = fieldTypeEnumMap.get(key);
            if (value instanceof Clob) {//二进制文件转为string
                convertClob2String(recordMap, key, (Clob) value);
            } else if (value instanceof oracle.sql.TIMESTAMP) {//Oracle特有
                convertTIMESTAMP(recordMap, key, (TIMESTAMP) value, fieldTypeEnum);
            } else if (value instanceof Blob) {
                convertBlob2String(recordMap, key, (Blob) value);
            }
        });
    }

    private static void convertClob2String(Map<String, Object> recordMap, String key, Clob clob) {
        if (Func.isEmpty(clob)) {
            return;
        }
        try (Reader reader = clob.getCharacterStream();
             StringWriter writer = new StringWriter()) {
            int c;
            while ((c = reader.read()) != -1) {
                writer.write(c);
            }
            recordMap.put(key, writer.toString());
        } catch (Exception e) {
            // 处理可能发生的异常，例如IOException
            e.printStackTrace();
        }
    }

    private static void convertBlob2String(Map<String, Object> recordMap, String key, Blob blob) {
        if (Func.isEmpty(blob)) {
            return;
        }

        try (InputStream inputStream = blob.getBinaryStream();
             InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
             StringWriter writer = new StringWriter()) {

            int c;
            while ((c = reader.read()) != -1) {
                writer.write(c);
            }
            recordMap.put(key, writer.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //oracle
    private static void convertTIMESTAMP(Map<String, Object> recordMap, String key, TIMESTAMP val, LideeYunJiFieldTypeEnum fieldTypeEnum) {
        if (Func.isEmpty(val)) {
            return;
        }
        try {
            switch (fieldTypeEnum) {
                case DATE:
                    recordMap.put(key, val.dateValue());
                    break;
                case TIME:
                    recordMap.put(key, val.timeValue());
                    break;
                case DATETIME:
                    recordMap.put(key, val.toLocalDateTime());
            }
        } catch (Exception e) {
            // 处理可能发生的异常，例如IOException
            e.printStackTrace();
        }
    }

    public static String getButtonName(String buttonCode) {
        String buttonName = "";
        switch (buttonCode) {
            case "addBtn":
                buttonName = "新增";
                break;
            case "editBtn":
                buttonName = "编辑";
                break;
            case "viewBtn":
                buttonName = "查看";
                break;
            case "delBtn":
                buttonName = "删除";
                break;
            case "batchDelBtn":
                buttonName = "批量删除";
                break;
            case "importBtn":
                buttonName = "导入";
                break;
            case "exportBtn":
                buttonName = "导出";
                break;
        }
        return buttonName;
    }

    //替换参数
    public static String replaceParam(String executeSql, Map<String, Object> paramMap, String autoWhereSql, IlideeYunjiAdapter lideeYunJiAdapter) {

        //处理默认值
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_ID)) {
            paramMap.put(SqlParamEnum.lideeyunji_ID.getCode(), IdWorker.getId());
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_DATE_TIME)) {
            paramMap.put(SqlParamEnum.lideeyunji_DATE_TIME.getCode(), LocalDateTime.now().withNano(0));
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_DATE)) {
            paramMap.put(SqlParamEnum.lideeyunji_DATE.getCode(), LocalDate.now());
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_TIME)) {
            paramMap.put(SqlParamEnum.lideeyunji_TIME.getCode(), LocalTime.now().withNano(0));
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_IS_DELETED)) {
            paramMap.put(SqlParamEnum.lideeyunji_IS_DELETED.getCode(), 0);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_TENANT_ID)) {
            Long tenantId = lideeYunJiAdapter.getTenantId();
            paramMap.put(SqlParamEnum.lideeyunji_TENANT_ID.getCode(), tenantId);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_USER_ID)) {
            Long onlineUserId = lideeYunJiAdapter.getOnlineUserId();
            paramMap.put(SqlParamEnum.lideeyunji_USER_ID.getCode(), onlineUserId);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_USER_NAME)) {
            String onlineUserName = lideeYunJiAdapter.getOnlineUserName();
            paramMap.put(SqlParamEnum.lideeyunji_USER_NAME.getCode(), onlineUserName);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_USER_NICKNAME)) {
            String onlineUserNickName = lideeYunJiAdapter.getOnlineUserNickName();
            paramMap.put(SqlParamEnum.lideeyunji_USER_NICKNAME.getCode(), onlineUserNickName);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_USER_DEPT)) {
            Long onlineUserDeptId = lideeYunJiAdapter.getOnlineUserDeptId();
            paramMap.put(SqlParamEnum.lideeyunji_USER_DEPT.getCode(), onlineUserDeptId);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_USER_ALL_DEPT)) {
            lideeYunJiDeptParam param = new lideeYunJiDeptParam();
            param.setType("sub");
            List<lideeYunjiDept> deptList = lideeYunJiAdapter.getDeptList(param);
            String allDeptIds = deptList.stream()
                    .map(lideeYunjiDept::getDeptId)
                    .collect(Collectors.joining(","));
            paramMap.put(SqlParamEnum.lideeyunji_USER_ALL_DEPT.getCode(), allDeptIds);//当前登录人所有部
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_MAIN_ID)) {
            Long mainId = lideeYunJiUtils.getMap2Long(paramMap, "id");
            paramMap.put(SqlParamEnum.lideeyunji_MAIN_ID.getCode(), mainId);
        }
        if (SqlParamEnumIsExist(executeSql, SqlParamEnum.lideeyunji_AUTO_WHERE)) {
            executeSql = replacePlaceholder(executeSql, SqlParamEnum.lideeyunji_AUTO_WHERE, autoWhereSql);//动态where
        }

        return formatSql2EW(executeSql);
    }

    public static String formatSql2EW(String sql) {
        String replacedSql = sql.replaceAll("(?<!#\\{ew\\.)\\#\\{(\\w+)}", "#{ew.$1}");
        return replacedSql;
    }

    public static String fomatEnum(SqlParamEnum sqlParamEnum) {
        String FORMAT = "\\#\\{%s}";
        return String.format(FORMAT, sqlParamEnum.getCode());
    }

    public static String fomatSqlStr(String str) {
        String FORMAT = "\"%s\"";
        return String.format(FORMAT, str);
    }

    public static boolean SqlParamEnumIsExist(String executeSql, SqlParamEnum sqlParamEnum) {
        String FORMAT = "#{%s}";
        return executeSql.contains(String.format(FORMAT, sqlParamEnum.getCode()));
    }

    //替换占位符
    public static String replacePlaceholder(String executeSql, SqlParamEnum sqlParamEnum, String value) {
        if (FuncBase.isEmpty(value)) {
            return executeSql.replaceAll("#\\{" + SqlParamEnum.lideeyunji_AUTO_WHERE.getCode() + "}", "(1=1)");
        }
        return executeSql.replaceAll(fomatEnum(sqlParamEnum), value);//动态where
    }

    /**
     * 复制spring类型增强
     *
     * @param type           表类型 参考 TableType2Enum
     * @param oldEnhanceName 旧增强
     * @param newTableName   新表名
     */
    public static String copySpringEnhance(String type, String oldEnhanceName, String newTableName) {
        // 获取当前环境配置，只在本地开发环境进行复制
        String activeProfile = SpringUtils.getActiveProfile();
        if (Func.isNotEmpty(activeProfile) && !Func.equals(activeProfile, lideeYunjiCodeConstant.APPLICATION_LOCAL)) {
            return null;
        }
        // 获取原增强
        Object bean = null;
        try {
            bean = SpringUtils.getBean(oldEnhanceName);
        } catch (NoSuchBeanDefinitionException ignored) {
        }
        if (bean == null) {
            return null;
        }
        URL url = bean.getClass().getProtectionDomain().getCodeSource().getLocation();
        URI uri = null;
        try {
            uri = url.toURI();
        } catch (URISyntaxException ignored) {
        }
        if (uri == null) {
            return null;
        }
        String oldClassesPath = new File(uri).getPath();
        String oldClazzName = bean.getClass().getName();
        CopyEnhanceParam copyEnhanceParam = copyEnhanceFile(type, oldClassesPath, oldClazzName, newTableName);
        if (FuncBase.isEmpty(copyEnhanceParam)) {
            return null;
        }
        return copyEnhanceParam.getBeanName();
    }

    /**
     * 复制class类型增强
     */
    public static String copyClassEnhance(String type, String oldClazzName, String newTableName) {
        // 获取当前环境配置，只在本地开发环境进行复制
        String activeProfile = SpringUtils.getActiveProfile();
        if (Func.isNotEmpty(activeProfile) && !Func.equals(activeProfile, lideeYunjiCodeConstant.APPLICATION_LOCAL)) {
            return null;
        }
        Class<?> aClass = null;
        try {
            aClass = Class.forName(oldClazzName);
        } catch (ClassNotFoundException ignored) {
        }
        if (aClass == null) {
            return null;
        }
        CodeSource codeSource = aClass.getProtectionDomain().getCodeSource();
        URI uri = null;
        try {
            uri = codeSource.getLocation().toURI();
        } catch (URISyntaxException ignored) {
        }
        if (uri == null) {
            return null;
        }
        String oldClassesPath = new File(uri).getPath();
        CopyEnhanceParam copyEnhanceParam = copyEnhanceFile(type, oldClassesPath, oldClazzName, newTableName);
        if (FuncBase.isEmpty(copyEnhanceParam)) {
            return null;
        }
        return copyEnhanceParam.getReference();
    }

    /**
     * 复制文件
     */
    private static CopyEnhanceParam copyEnhanceFile(String type, String oldClassesPath, String oldClazzName, String newTableName) {
        // 要复制的增强的文件绝对地址
        String oldFilePath = new StringBuilder().append(StringUtils.substringBefore(oldClassesPath, lideeYunjiCodeConstant.CLASSES_DIR))
                .append(lideeYunjiCodeConstant.PROGRAM_DIR)
                .append(oldClazzName.replace(lideeYunjiCodeConstant.DOT, lideeYunjiCodeConstant.BACK_SLASH))
                .append(lideeYunjiCodeConstant.JAVA_SUFFIX).toString();
        // 要复制的增强的类名
        String oldClassName = StringUtils.substringAfterLast(oldClazzName, lideeYunjiCodeConstant.DOT);
        // 读取原增强
        List<String> readList = null;
        try {
            readList = Files.readAllLines(Paths.get(oldFilePath));
        } catch (IOException ignored) {
        }
        if (readList == null) {
            return null;
        }
        // 生成新增强java文件
        // 处理新增强bean名称、类名、绝对地址等
        String humpTable = StrUtil.toCamelCase(newTableName);
        String lowerCaseTable = humpTable.toLowerCase();
        // 新增强文件绝对地址
        String baseNewEnhancePath = new StringBuilder().append(lideeYunjiProperties.getEnhancePath())
                .append(lideeYunjiCodeConstant.BACK_SLASH)
                .append(type).toString();
        String newFilePathStr = new StringBuilder().append(lideeYunjiCodeConstant.USER_DIR)
                .append(lideeYunjiCodeConstant.BACK_SLASH)
                .append(baseNewEnhancePath)
                .append(lideeYunjiCodeConstant.BACK_SLASH)
                .append(lowerCaseTable)
                .append(lideeYunjiCodeConstant.BACK_SLASH)
                .append(humpTable)
                .append(StringUtils.substringAfterLast(oldFilePath, lideeYunjiCodeConstant.BACK_SLASH)).toString();
        Path newFilePath = Paths.get(newFilePathStr);
        // 判断文件名是否已经存在，存在则累加1
        int counter = 1;
        String basePath = StringUtils.substringBeforeLast(newFilePathStr, lideeYunjiCodeConstant.DOT);
        while (Files.exists(newFilePath)) {
            newFilePathStr = new StringBuilder().append(basePath).append(counter).append(lideeYunjiCodeConstant.JAVA_SUFFIX).toString();
            newFilePath = Paths.get(newFilePathStr);
            counter++;
        }
        // 新增强类名
        String newClassName = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(newFilePathStr, lideeYunjiCodeConstant.BACK_SLASH), lideeYunjiCodeConstant.DOT);
        // 新增强bean名称
        String newEnhanceName = StrUtil.lowerFirst(newClassName);
        // 替换指定内容
        String newPackageReference = new StringBuilder().append(StringUtils.substringAfter(baseNewEnhancePath, lideeYunjiCodeConstant.PROGRAM_DIR))
                .append(lideeYunjiCodeConstant.BACK_SLASH)
                .append(lowerCaseTable)
                .toString().replace(lideeYunjiCodeConstant.BACK_SLASH, lideeYunjiCodeConstant.DOT);
        String pattern1 = "(package)(" + StringUtils.substringBeforeLast(oldClazzName, lideeYunjiCodeConstant.DOT) + ")(;)";
        String pattern2 = "(\\s*@Component\\s*\\()((\\s*value\\s*=\\s*)|(\\s*))(\")(.+?)(\"\\s*\\))";
        String pattern3 = "(\\s*public\\s+class\\s+)" + oldClassName + "(\\s+implements)";
        String replace1 = "$1" + lideeYunjiCodeConstant.SPACE + newPackageReference + "$3";
        String replace2 = "$1$2$5" + newEnhanceName + "$7";
        String replace3 = "$1" + newClassName + "$2";
        AtomicBoolean flag1 = new AtomicBoolean(false);
        AtomicBoolean flag3 = new AtomicBoolean(false);
        List<String> writeList = readList.stream().map(item -> {
            String trim = item.replaceAll(lideeYunjiCodeConstant.SPACE, lideeYunjiCodeConstant.EMPTY);
            if (Pattern.compile(pattern1).matcher(trim).find()) {
                flag1.set(true);
                return Pattern.compile(pattern1).matcher(trim).replaceAll(replace1);
            } else if (Pattern.compile(pattern2).matcher(item).find()) {
                return Pattern.compile(pattern2).matcher(item).replaceAll(replace2);
            } else if (Pattern.compile(pattern3).matcher(item).find()) {
                flag3.set(true);
                return Pattern.compile(pattern3).matcher(item).replaceAll(replace3);
            }
            return item;
        }).collect(Collectors.toList());
        if (flag1.get() && flag3.get()) {
            try {
                // 创建文件
                Files.createDirectories(Paths.get(StringUtils.substringBeforeLast(newFilePathStr, lideeYunjiCodeConstant.BACK_SLASH)));
                Files.createFile(newFilePath);
                Files.write(newFilePath, writeList);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            // 未找到替换目标
            return null;
        }
        CopyEnhanceParam copyEnhanceParam = new CopyEnhanceParam();
        copyEnhanceParam.setBeanName(newEnhanceName);
        copyEnhanceParam.setReference(StringUtils.substringBeforeLast(StringUtils.substringAfter(newFilePathStr, lideeYunjiCodeConstant.PROGRAM_DIR), lideeYunjiCodeConstant.JAVA_SUFFIX)
                .replace(lideeYunjiCodeConstant.BACK_SLASH, lideeYunjiCodeConstant.DOT));
        return copyEnhanceParam;
    }


    //转为map
    public static Map<String, FormFieldDictEntity> getDictMap(List<FormFieldDictEntity> dictList) {
        return dictList.stream()
                .collect(Collectors.toMap(FormFieldDictEntity::getFieldCode, Function.identity()));
    }

    //转为map
    public static Map<String, FormFieldWebEntity> getWebMap(List<FormFieldWebEntity> webList) {
        return webList.stream()
                .collect(Collectors.toMap(FormFieldWebEntity::getFieldCode, Function.identity()));
    }

    //转为map
    public static Map<String, FormFieldQueryEntity> getQueryMap(List<FormFieldQueryEntity> queryList) {
        return queryList.stream()
                .collect(Collectors.toMap(FormFieldQueryEntity::getFieldCode, Function.identity()));
    }

    //转为map
    public static Map<String, FormFieldExportEntity> getExportMap(List<FormFieldExportEntity> exportList) {
        return exportList.stream()
                .collect(Collectors.toMap(FormFieldExportEntity::getFieldCode, Function.identity()));
    }

    //转为map
    public static Map<String, FormSummaryEntity> getSummaryBottomMap(List<FormSummaryEntity> summaryBottomList) {
        return summaryBottomList.stream()
                .collect(Collectors.toMap(FormSummaryEntity::getFieldCode, Function.identity()));
    }

    //转为map
    public static Map<String, FormFieldForeignkeyEntity> getForeignkeyMap(List<FormFieldForeignkeyEntity> foreignkeyList) {
        return foreignkeyList.stream()
                .collect(Collectors.toMap(FormFieldForeignkeyEntity::getFieldCode, Function.identity()));
    }

    public static void resetBaseTenantEntity(List list) {
        list.stream().forEach(vo -> {
            BaseTenantEntity v = (BaseTenantEntity) vo;
            v.setId(null);//剔除id
            v.setTenantId(null);
            v.setCreateTime(null);
            v.setCreateUser(null);
            v.setCreateDept(null);
            v.setUpdateTime(null);
            v.setUpdateUser(null);
            v.setIsDeleted(null);
        });
    }

    public static void resetBaseTenantEntity(BaseTenantEntity v) {
        v.setId(null);//剔除id
        v.setTenantId(null);
        v.setCreateTime(null);
        v.setCreateUser(null);
        v.setCreateDept(null);
        v.setUpdateTime(null);
        v.setUpdateUser(null);
        v.setIsDeleted(null);
    }

    private static String formatAreaStr(Object input) {
        if (input == null) return "";

        if (input instanceof List<?>) {
            List<?> list = (List<?>) input;
            if (!list.isEmpty() && list.get(0) instanceof List) {
                @SuppressWarnings("unchecked")
                List<List<String>> nestedList = (List<List<String>>) input;
                return nestedList.stream()
                        .map(subList -> String.join("/", subList))
                        .collect(Collectors.joining(","));
            } else if (list.get(0) instanceof String) {
                @SuppressWarnings("unchecked")
                List<String> stringList = (List<String>) input;
                return String.join("/", stringList);
            }
        } else if (input instanceof String) {
            String str = (String) input;
            List<String> parts = Arrays.asList(str.split(","));
            return String.join("/", parts);
        }

        return "";
    }

    /**
     * 将 JSON 字符串转为 List<List<String>>
     */
    public static String formatArea(String jsonStr) {
        if (JSONUtil.isTypeJSONArray(jsonStr)) {
            List<List> list = JSONUtil.toList(JSONUtil.parseArray(jsonStr), List.class);
            return formatAreaStr(list);
        }
        return formatAreaStr(jsonStr);
    }

    //处理分组
    public  static  void handleGroupBy(SqlInfoQueryWrapper.Wrapper wrapper, Map<String, Object> params){



    }




    //处理排序
    public static void handleOrderBy(SqlInfoQueryWrapper.Wrapper wrapper, Map<String, Object> params, String orderbyConfigStr) {
        Map<String, Object> seleOrderByMap = (Map<String, Object>) params.get(ParamEnum.REQUEST_PARAM_BODY.getCode());
        if (Func.isNotEmpty(seleOrderByMap)) {
            String column = lideeYunJiUtils.getMap2Str(seleOrderByMap, ParamEnum.COLUMN.getCode());
            String order = lideeYunJiUtils.getMap2Str(seleOrderByMap, ParamEnum.ORDER.getCode());
            if (FuncBase.isNotEmpty(column) && FuncBase.isNotEmpty(order) && (FuncBase.equals(order, "desc") || FuncBase.equals(order, "asc"))) {
                if (FuncBase.equals(order, "desc")) {
                    wrapper.orderByDesc(column);
                } else {
                    wrapper.orderByAsc(column);
                }
                return;
            }
        }


        String column = lideeYunJiUtils.getMap2Str(params, ParamEnum.COLUMN.getCode());
        String order = lideeYunJiUtils.getMap2Str(params, ParamEnum.ORDER.getCode());
        if (FuncBase.isNotEmpty(column) && FuncBase.isNotEmpty(order) && (FuncBase.equals(order, "desc") || FuncBase.equals(order, "asc"))) {
            if (FuncBase.equals(order, "desc")) {
                wrapper.orderByDesc(column);
            } else {
                wrapper.orderByAsc(column);
            }
            return;
        }
        if (Func.isEmpty(orderbyConfigStr)) {
            return;
        }

        //默认id 倒序排序
        List<OrderByModel> orderByList = JSONUtil.toList(orderbyConfigStr, OrderByModel.class);

        //遍历
        orderByList.forEach(model -> {
            String orderBy = model.getOrder();
            String orderByColumn = model.getColumn();
            switch (orderBy) {
                case "asc":
                    wrapper.orderByAsc(orderByColumn);
                    break;
                default:
                    wrapper.orderByDesc(orderByColumn);
            }
        });

    }

    //处理默认where
    public static void handleDefaultWhere(SqlInfoQueryWrapper.Wrapper wrapper, String whereConfig) {
        if (Func.isEmpty(whereConfig)) {
            return;
        }


        WhereModel whereModel = Func.json2Bean(whereConfig, WhereModel.class);
        if (Func.isEmpty(whereModel)) {
            return;
        }
        List<String> whereList = whereModel.getWhereList();
        if (Func.isEmpty(whereList)) {
            return;
        }


        String applySql = whereList.stream()
                .filter(wheresql -> !wheresql.trim().isEmpty()) // 过滤掉空或只含空白字符的字符串
                .collect(Collectors.joining(" AND "));

        if (Func.isEmpty(applySql)) {
            return;
        }

        //拼接
        wrapper.setWhere(where -> {
            where.apply(applySql);
        }).build();
    }


    //处理where
    public static void handleWhere(Long dbFormId, SqlInfoQueryWrapper.Wrapper wrapper, Map<String, Object> params) {
        LideeYunJiMapper lideeYunJiMapper = SpringUtils.getBean(LideeYunJiMapper.class);

        String allQueryField = Func.getMap2Str(params, ParamEnum.ALL_QUERY_FIELD.getCode());
        List<Map<String, String>> whereFieldMapList = null;
        if (Func.isNotEmpty(allQueryField) && Func.equals(allQueryField, "Y")) {
            //特殊情况，是全部放开
            whereFieldMapList = lideeYunJiMapper.getAllDbWhereFieldList(dbFormId);
        } else {
            whereFieldMapList = lideeYunJiMapper.getDbWhereFieldList(dbFormId);
        }
        handleWhere(whereFieldMapList, wrapper, params);
    }

    public static void handleWhere(List<Map<String, String>> whereFieldMapList, SqlInfoQueryWrapper.Wrapper wrapper, Map<String, Object> params) {
        List<Long> excelExportIdList = (List<Long>) params.get(ParamEnum.lideeyunji_EXPORT_IDS.getCode());
        if (Func.isNotEmpty(excelExportIdList)) {
            wrapper.setWhere(where -> {
                where.in("id", excelExportIdList);
            });
        }
        //开启查询的列
        if (FuncBase.isEmpty(whereFieldMapList)) {
            return;
        }
        //如果是多选的时候，要做特殊处理，因为多选的时候 ，数据库存储的是 11,22,33
        String moreSelectFieldListStr = (String) params.get(ParamEnum.MORE_SELECT_FIELD.getCode());
        List<String> moreSelectFieldList = null;
        if (FuncBase.isNotEmpty(moreSelectFieldListStr)) {
            moreSelectFieldList = FuncBase.toStrList(moreSelectFieldListStr);
        }


        for (Map<String, String> whereFieldMap : whereFieldMapList) {
            String field_code = whereFieldMap.get("field_code");//字段
            String field_type = whereFieldMap.get("field_type");//类型
            String query_mode = whereFieldMap.get("query_mode");//EQ LIKE
            LideeYunJiFieldTypeEnum fieldTypeEnum = LideeYunJiFieldTypeEnum.getByFieldType(field_type);

            boolean moreSelectFlag = FuncBase.isNotEmpty(moreSelectFieldList) && moreSelectFieldList.contains(field_code);

            Object obj = params.get(field_code);
            if (FuncBase.isEmpty(obj)) {
                continue;
            }
            //类型转换 111,22,33
            if (FuncBase.equals(query_mode, QueryModelEnum.EQ.getCode()) ||//精确
                    FuncBase.equals(query_mode, QueryModelEnum.NE.getCode())) {//不等于
                if (moreSelectFlag) {//在多选里面
                    Object finalObj = Func.paramParse2Object(obj, fieldTypeEnum);
                    wrapper.setWhere(where -> {
                        where.and(param -> {
                            if (FuncBase.equals(query_mode, QueryModelEnum.NE.getCode())) {
                                param.ne(field_code, finalObj)
                                        .notLikeLeft(field_code, "," + finalObj)
                                        .notLikeRight(field_code, finalObj + ",")
                                        .notLike(field_code, "," + finalObj + ",");
                            } else {
                                param.eq(field_code, finalObj)
                                        .or().likeLeft(field_code, "," + finalObj)
                                        .or().likeRight(field_code, finalObj + ",")
                                        .or().like(field_code, "," + finalObj + ",");
                            }
                        });
                    });
                } else {
                    Object finalObj = Func.paramParse2Object(obj, fieldTypeEnum);
                    wrapper.setWhere(where -> {
                        if (FuncBase.equals(query_mode, QueryModelEnum.NE.getCode())) {
                            where.ne(field_code, finalObj);
                        } else {
                            where.eq(field_code, finalObj);
                        }
                    });
                }

            } else if (FuncBase.equals(query_mode, QueryModelEnum.RANGE.getCode())) {//范围
                String listStr = FuncBase.toStr(obj);
                List<String> paramList = FuncBase.toStrList(listStr);// 1<=x<2
                Object leftVal = paramList.get(0);
                Object rightVal = null;
                if (paramList.size() > 1) {
                    leftVal = paramList.get(0);
                    rightVal = paramList.get(1);
                }
                //有可能是null字符串
                Object finalLeftVal1tmp = null;
                if (Func.isNotEmpty(leftVal) && !Func.equals(leftVal, "null")) {
                    finalLeftVal1tmp = Func.paramParse2Object(leftVal, fieldTypeEnum);
                }
                Object finalRightVal1tmp = null;
                if (Func.isNotEmpty(rightVal) && !Func.equals(rightVal, "null")) {
                    finalRightVal1tmp = Func.paramParse2Object(rightVal, fieldTypeEnum);
                }

                Object finalLeftVal1 = finalLeftVal1tmp;
                Object finalRightVal1 = finalRightVal1tmp;

                if (FuncBase.isNotEmpty(finalLeftVal1) && FuncBase.isNotEmpty(finalRightVal1)) {
                    wrapper.setWhere(where -> {
                        where.between(field_code, finalLeftVal1, finalRightVal1);//区间
                    });
                } else if (FuncBase.isNotEmpty(finalLeftVal1)) {//>=
                    wrapper.setWhere(where -> {
                        where.ge(field_code, finalLeftVal1);
                    });

                } else if (FuncBase.isNotEmpty(finalRightVal1)) {//<=
                    wrapper.setWhere(where -> {
                        where.le(field_code, finalRightVal1);
                    });
                }
            } else if (FuncBase.equals(query_mode, QueryModelEnum.IN.getCode())) {//IN
                String listStr = FuncBase.toStr(obj);
                List<String> paramList = FuncBase.toStrList(listStr);// 多个值

                wrapper.setWhere(where -> {
                    where.and(param -> {
                        for (String obj2 : paramList) {
                            Object finalObj = Func.paramParse2Object(obj2, fieldTypeEnum);
                            param.or().eq(field_code, finalObj)
                                    .or().likeLeft(field_code, "," + finalObj)
                                    .or().likeRight(field_code, finalObj + ",")
                                    .or().like(field_code, "," + finalObj + ",");
                        }
                    });
                });
            } else if (FuncBase.equals(query_mode, QueryModelEnum.MORE_IN.getCode())) {//多选
                String listStr = FuncBase.toStr(obj);
                List<String> paramList = FuncBase.toStrList(listStr);// 多个值
                List<Object> paramListObjList = new ArrayList<>();
                for (String obj2 : paramList) {
                    Object finalObj = Func.paramParse2Object(obj2, fieldTypeEnum);
                    paramListObjList.add(finalObj);
                }
                wrapper.setWhere(where -> {
                    where.in(field_code, paramListObjList);
                });
            } else {
                Object objVal = Func.paramParse2Object(obj, fieldTypeEnum);
                wrapper.setWhere(where -> {
                    if (objVal instanceof DateTime) {
                        where.eq(field_code, objVal);
                    } else {
                        where.like(field_code, objVal);
                    }
                });
            }
        }
        if(params.containsKey("Group by")){
            String[] str=params.get("Group by").toString().split(",");
            wrapper.groupByColumns(str);
        }


    }


    /**
     * 获取自动构建where的语句
     *
     * @return
     */
    public static String getSqlAutoWhereSql(FormEntity formEntity, Map<String, Object> params) {

        SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper();
        Func.handleWhere(formEntity.getId(), wrapper,params);
        //排序
        Func.handleOrderBy(wrapper, params, formEntity.getOrderbyConfig());

        SqlFormatModel sqlFormatModel = wrapper.buildSql();

        String whereSql = sqlFormatModel.getSql();
        if (FuncBase.isEmpty(whereSql)) {
            return whereSql;
        }
        Map<String, Object> paramMap = sqlFormatModel.getDataMap();
        if (Func.isNotEmpty(paramMap)) {
            params.putAll(paramMap);
        }
        if(whereSql.startsWith("WHERE") || whereSql.startsWith(" WHERE")){//没有条件
            whereSql = whereSql.substring(6);//因为是where开头要去掉
        }else{
            whereSql = " 1=1 " + whereSql;
        }
        return whereSql;
    }

    public static String getJdbcType(String fieldType){
        LideeYunJiFieldTypeEnum lideeYunJiFieldTypeEnum = LideeYunJiFieldTypeEnum.getByFieldType(fieldType);
        if (lideeYunJiFieldTypeEnum != null) {
            switch (lideeYunJiFieldTypeEnum) {
                case INTEGER:
                    return "INTEGER";
                case DATE:
                    return "DATE";
                case DATETIME:
                    return "TIMESTAMP";
                case TIME:
                    return "TIME";
                case BIGINT:
                    return "BIGINT";
                case BIGDECIMAL:
                    return "DECIMAL";
                default:
                   return "VARCHAR";
            }
        }
        return "VARCHAR";

    }
}

