package com.yunzhupaas.onlinedev.util.onlineDevUtil;

import com.yunzhupaas.base.entity.DataInterfaceEntity;
import com.yunzhupaas.base.entity.VisualdevEntity;
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
import com.yunzhupaas.base.model.ColumnDataModel;
import com.yunzhupaas.base.model.Template6.ColumnListField;
import com.yunzhupaas.base.model.VisualDevJsonModel;
import com.yunzhupaas.base.model.VisualWebTypeEnum;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.database.model.superQuery.SuperJsonModel;
import com.yunzhupaas.database.model.superQuery.SuperQueryJsonModel;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.model.OnlineDevData;
import com.yunzhupaas.model.visualJson.FieLdsModel;
import com.yunzhupaas.model.visualJson.FormDataModel;
import com.yunzhupaas.model.visualJson.TableModel;
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
import com.yunzhupaas.model.visualJson.analysis.FormModel;
import com.yunzhupaas.model.visualJson.config.ConfigModel;
import com.yunzhupaas.onlinedev.model.OnlineDevEnum.MultipleControlEnum;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.StringUtil;
import com.yunzhupaas.util.XSSEscape;
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
import org.apache.commons.collections4.MapUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 在线开发公用
 *
 * @author 云筑产品开发平台组
 * @version V3.1.0
 * @copyright 深圳市乐程软件有限公司（http://www.szlecheng.cn）
 * @date 2024/7/28
 */
public class OnlinePublicUtils {
    /**
     * 判断有表无表
     *
     * @return
     */
    public static Boolean isUseTables(String tableJson) {
        if (!StringUtil.isEmpty(tableJson) && !OnlineDevData.TABLE_CONST.equals(tableJson)) {
            return true;
        }
        return false;
    }

    /**
     * map key转小写
     *
     * @param requestMap
     * @return
     */
    public static Map<String, Object> mapKeyToLower(Map<String, ?> requestMap) {
        // 非空校验
        if (requestMap.isEmpty()) {
            return null;
        }
        // 初始化放转换后数据的Map
        Map<String, Object> responseMap = new HashMap<>(16);
        // 使用迭代器进行循环遍历
        Set<String> requestSet = requestMap.keySet();
        Iterator<String> iterator = requestSet.iterator();
        iterator.forEachRemaining(obj -> {
            // 判断Key对应的Value是否为Map
            if ((requestMap.get(obj) instanceof Map)) {
                // 递归调用，将value中的Map的key转小写
                responseMap.put(obj.toLowerCase(), mapKeyToLower((Map) requestMap.get(obj)));
            } else {
                // 直接将key小写放入responseMap
                responseMap.put(obj.toLowerCase(), requestMap.get(obj));
            }
        });

        return responseMap;
    }

    /**
     * 获取map中第一个数据值
     *
     * @param map 数据源
     * @return
     */
    public static Object getFirstOrNull(Map<String, Object> map) {
        Object obj = null;
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            obj = entry.getValue();
            if (obj != null) {
                break;
            }
        }
        return obj;
    }

    /**
     * 去除列表里无用的控件
     *
     * @param fieldsModelList
     * @return
     */
    public static void removeUseless(List<FieLdsModel> fieldsModelList) {
        for (int i = 0; i < fieldsModelList.size(); i++) {
            if (fieldsModelList.get(i).getConfig().getYunzhupaasKey() == null) {
                continue;
            }
            if (fieldsModelList.get(i).getConfig().getYunzhupaasKey().equals(YunzhupaasKeyConsts.CHILD_TABLE)) {
                continue;
            }
        }
    }

    /**
     * 递归控件
     *
     * @param allFields
     * @param fieLdsModelList
     * @return
     */
    public static void recursionFields(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
        for (FieLdsModel fieLdsModel : fieLdsModelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaasKey = config.getYunzhupaasKey();
            if (YunzhupaasKeyConsts.CHILD_TABLE.equals(yunzhupaasKey)) {
                allFields.add(fieLdsModel);
                continue;
            } else {
                if (config.getChildren() != null) {
                    recursionFields(allFields, config.getChildren());
                } else {
                    if (yunzhupaasKey == null) {
                        continue;
                    }
                    allFields.add(fieLdsModel);
                }
            }
        }
    }

    /**
     * 判断字符串是否有某个字符存在
     *
     * @param var1 完整字符串
     * @param var2 统计字符
     * @return
     */
    public static Boolean getMultiple(String var1, String var2) {
        if (var1.startsWith(var2)) {
            return true;
        }
        return false;
    }

    /**
     * 数据字典处理（从缓存中取出）
     *
     * @param dataList
     * @param swapModel
     * @return
     */
    public static Map<String, Object> getDataMap(List<Map<String, Object>> dataList, FieLdsModel swapModel) {
        String label = swapModel.getProps() != null ? swapModel.getProps().getLabel() : "";
        String value = swapModel.getProps() != null ? swapModel.getProps().getValue() : "";
        Map<String, Object> dataInterfaceMap = new HashMap<>();
        dataList.stream().forEach(data -> {
            dataInterfaceMap.put(String.valueOf(data.get(value)), String.valueOf(data.get(label)));
        });
        return dataInterfaceMap;
    }

    /**
     * 获取时间(+8)
     *
     * @param date
     * @param format
     * @return
     */
    public static String getDateByFormat(Long date, String format) {
        DateTimeFormatter ftf = DateTimeFormatter.ofPattern(format);
        String dateString = ftf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.of("+8")));
        return dateString;
    }

    /**
     * 递归表单控件
     *
     * @param modelList   所有控件
     * @param mainFields  主表
     * @param childFields 子表
     * @param models      二维码 条形码
     */
    public static void recurseFiled(List<FieLdsModel> modelList, List<FieLdsModel> mainFields,
            List<FieLdsModel> childFields, List<FormModel> models) {
        for (FieLdsModel fieLdsModel : modelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaaskey = config.getYunzhupaasKey();
            List<FieLdsModel> childrenList = config.getChildren();
            boolean isYunzhupaasKey = StringUtil.isEmpty(yunzhupaaskey);
            List<String> keyList = new ArrayList() {
                {
                    this.add(FormEnum.collapseItem.getMessage());
                    this.add(FormEnum.collapseItem.getMessage());
                    this.add(FormEnum.row.getMessage());
                    this.add(FormEnum.card.getMessage());
                    this.add(FormEnum.tab.getMessage());
                    this.add(FormEnum.collapse.getMessage());
                    this.add(FormEnum.tableGrid.getMessage());
                    this.add(FormEnum.tableGridTr.getMessage());
                    this.add(FormEnum.tableGridTd.getMessage());
                }
            };
            if (keyList.contains(yunzhupaaskey) || isYunzhupaasKey) {
                if (childrenList.size() > 0) {
                    recurseFiled(childrenList, mainFields, childFields, models);
                } else {
                    mainFields.add(fieLdsModel);
                }
            } else if (FormEnum.table.getMessage().equals(yunzhupaaskey)) {
                childFields.add(fieLdsModel);
            } else if (FormEnum.groupTitle.getMessage().equals(yunzhupaaskey)
                    || FormEnum.divider.getMessage().equals(yunzhupaaskey)
                    || FormEnum.YUNZHUPAASText.getMessage().equals(yunzhupaaskey)) {

            } else if (FormEnum.QR_CODE.getMessage().equals(yunzhupaaskey)
                    || FormEnum.BARCODE.getMessage().equals(yunzhupaaskey)) {
                FormModel formModel = JsonUtil.getJsonToBean(fieLdsModel, FormModel.class);
                models.add(formModel);
            } else {
                mainFields.add(fieLdsModel);
            }
        }
    }

    /**
     * 递归控件
     *
     * @return
     */
    public static void recursionFormFields(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
        for (FieLdsModel fieLdsModel : fieLdsModelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaasKey = config.getYunzhupaasKey();
            if (YunzhupaasKeyConsts.CHILD_TABLE.equals(yunzhupaasKey)) {
                allFields.add(fieLdsModel);
                continue;
            } else {
                if (config.getChildren() != null) {
                    recursionFormFields(allFields, config.getChildren());
                } else {
                    allFields.add(fieLdsModel);
                }
            }
        }
    }

    /**
     * 递归控件(取出所有子集)
     *
     * @return
     */
    public static void recursionFormChildFields(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
        for (FieLdsModel fieLdsModel : fieLdsModelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaasKey = config.getYunzhupaasKey();
            if (YunzhupaasKeyConsts.CHILD_TABLE.equals(yunzhupaasKey)) {
                String childVmodel = fieLdsModel.getVModel();
                for (FieLdsModel child : Optional.ofNullable(fieLdsModel.getConfig().getChildren())
                        .orElse(new ArrayList<>())) {
                    if (child.getVModel() != null) {
                        child.setVModel(childVmodel + "-" + child.getVModel());
                        allFields.add(child);
                    }
                }
            } else {
                if (config.getChildren() != null) {
                    recursionFormChildFields(allFields, config.getChildren());
                } else {
                    if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
                        allFields.add(fieLdsModel);
                    }
                }
            }
        }
    }

    public static void recurseOnlineFiled(List<FieLdsModel> modelList, List<FieLdsModel> mainFields,
            List<FieLdsModel> childFields) {
        for (FieLdsModel fieLdsModel : modelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaaskey = config.getYunzhupaasKey();
            List<FieLdsModel> childrenList = config.getChildren();
            boolean isYunzhupaasKey = StringUtil.isEmpty(yunzhupaaskey);
            if (FormEnum.row.getMessage().equals(yunzhupaaskey) || FormEnum.card.getMessage().equals(yunzhupaaskey)
                    || FormEnum.tab.getMessage().equals(yunzhupaaskey)
                    || FormEnum.collapse.getMessage().equals(yunzhupaaskey)
                    || isYunzhupaasKey) {
                if (childrenList.size() > 0) {
                    recurseOnlineFiled(childrenList, mainFields, childFields);
                } else {
                    mainFields.add(fieLdsModel);
                }
            } else if (FormEnum.table.getMessage().equals(yunzhupaaskey)) {
                childFields.add(fieLdsModel);
            } else if (FormEnum.groupTitle.getMessage().equals(yunzhupaaskey)
                    || FormEnum.divider.getMessage().equals(yunzhupaaskey)
                    || FormEnum.YUNZHUPAASText.getMessage().equals(yunzhupaaskey)) {

            } else {
                mainFields.add(fieLdsModel);
            }
        }
    }

    /**
     * @param redisMap   缓存集合
     * @param modelData  数据
     * @param isMultiple 是否多选
     * @return
     */
    public static String getDataInMethod(Map<String, Object> redisMap, Object modelData, Boolean isMultiple) {
        if (redisMap == null || redisMap.isEmpty()) {
            return modelData.toString();
        }
        String Separator = isMultiple ? ";" : "/";
        String s2;
        if (OnlinePublicUtils.getMultiple(String.valueOf(modelData),
                MultipleControlEnum.MULTIPLE_JSON_TWO.getMultipleChar())) {
            String[][] data = JsonUtil.getJsonToBean(String.valueOf(modelData), String[][].class);
            List<String> addList = new ArrayList<>();
            for (String[] AddressData : data) {
                List<String> adList = new ArrayList<>();
                for (String s : AddressData) {
                    adList.add(String.valueOf(redisMap.get(s)));
                }
                addList.add(String.join("/", adList));
            }
            s2 = String.join(";", addList);
        } else if (OnlinePublicUtils.getMultiple(String.valueOf(modelData),
                MultipleControlEnum.MULTIPLE_JSON_ONE.getMultipleChar())) {
            List<String> modelDataList = JsonUtil.getJsonToList(String.valueOf(modelData), String.class);
            modelDataList = modelDataList.stream().map(s -> String.valueOf(redisMap.get(s)))
                    .collect(Collectors.toList());
            s2 = String.join(Separator, modelDataList);
        } else {
            String[] modelDatas = String.valueOf(modelData).split(",");
            StringBuilder dynamicData = new StringBuilder();
            for (int i = 0; i < modelDatas.length; i++) {
                modelDatas[i] = String
                        .valueOf(Objects.nonNull(redisMap.get(modelDatas[i])) ? redisMap.get(modelDatas[i]) : "");
                dynamicData.append(modelDatas[i] + Separator);
            }
            s2 = dynamicData.deleteCharAt(dynamicData.length() - 1).toString();
        }
        return StringUtil.isEmpty(s2) ? modelData.toString() : s2;
    }

    public static List<String> getDataNoSwapInMethod(Object modelData) {
        List<String> dataValueList = new ArrayList<>();
        if (OnlinePublicUtils.getMultiple(String.valueOf(modelData),
                MultipleControlEnum.MULTIPLE_JSON_ONE.getMultipleChar())) {
            List<String> modelDataList = JsonUtil.getJsonToList(String.valueOf(modelData), String.class);
            dataValueList = modelDataList;
        } else {
            String[] modelDatas = String.valueOf(modelData).split(",");
            for (int i = 0; i < modelDatas.length; i++) {
                dataValueList.add(modelDatas[i]);
            }
        }
        return dataValueList;
    }

    public static VisualDevJsonModel getVisualJsonModel(VisualdevEntity entity) {
        VisualDevJsonModel jsonModel = new VisualDevJsonModel();
        if (entity.getColumnData() != null) {
            jsonModel.setColumnData(JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class));
        }
        if (entity.getAppColumnData() != null) {
            jsonModel.setAppColumnData(JsonUtil.getJsonToBean(entity.getAppColumnData(), ColumnDataModel.class));
        }
        FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
        jsonModel.setFormData(formDataModel);
        if (!VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType())) {
            jsonModel.setFormListModels(JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class));
        }
        jsonModel.setVisualTables(JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class));
        jsonModel.setId(entity.getId());
        jsonModel.setDbLinkId(entity.getDbLinkId());
        jsonModel.setFullName(entity.getFullName());
        jsonModel.setType(entity.getType());
        jsonModel.setWebType(entity.getWebType());
        return jsonModel;
    }

    public static VisualDevJsonModel getVisualJsonModel(VisualdevReleaseEntity entity) throws WorkFlowException {
        if (entity == null)
            throw new WorkFlowException(MsgCode.VS412.get());
        VisualDevJsonModel jsonModel = new VisualDevJsonModel();
        if (entity.getColumnData() != null) {
            jsonModel.setColumnData(JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class));
        }
        if (entity.getAppColumnData() != null) {
            jsonModel.setAppColumnData(JsonUtil.getJsonToBean(entity.getAppColumnData(), ColumnDataModel.class));
        }
        FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
        jsonModel.setFormData(formDataModel);
        if (!VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType())) {
            jsonModel.setFormListModels(JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class));
        }
        jsonModel.setVisualTables(JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class));
        jsonModel.setId(entity.getId());
        jsonModel.setDbLinkId(entity.getDbLinkId());
        jsonModel.setFullName(entity.getFullName());
        jsonModel.setType(entity.getType());
        jsonModel.setWebType(entity.getWebType());
        return jsonModel;
    }

    /**
     * @param mapList
     * @return List<Map < String, Object>>
     * @Date 21:51 2020/11/11
     * @Description 将map中的所有key转化为小写
     */
    public static List<Map<String, Object>> toLowerKeyList(List<Map<String, Object>> mapList) {
        List<Map<String, Object>> newMapList = new ArrayList<>();
        for (Map<String, Object> map : mapList) {
            Map<String, Object> resultMap = new HashMap(16);
            Set<String> sets = map.keySet();
            for (String key : sets) {
                resultMap.put(key.toLowerCase(), map.get(key));
            }
            newMapList.add(resultMap);
        }
        return newMapList;
    }

    /**
     * 字符串转数组
     *
     * @param value 值
     * @return
     */
    public static Object getDataConversion(Object value) {
        Object dataValue = getDataConversion(null, value, false, "/");
        return dataValue;
    }

    /**
     * 字符串转数组
     *
     * @param redis 转换对象
     * @param value 值
     * @return
     */
    public static Object getDataConversion(Map<String, Object> redis, Object value, boolean isMultiple,
            String separator) {
        Object dataValue = value;
        boolean iszhuanhuan = redis != null;
        try {
            List<List> list = JsonUtil.getJsonToList(String.valueOf(value), List.class);
            dataValue = list;
            if (iszhuanhuan) {
                // 一级分隔符
                StringJoiner joiner = new StringJoiner(",");
                for (List listChild : list) {
                    StringJoiner aa = new StringJoiner(separator);
                    for (Object object : listChild) {
                        String value1 = redis.get(String.valueOf(object)) != null
                                ? String.valueOf(redis.get(String.valueOf(object)))
                                : "";
                        if (StringUtil.isNotEmpty(value1)) {
                            aa.add(value1);
                        }
                    }
                    joiner.add(aa.toString());
                }
                dataValue = joiner.toString();
            }
        } catch (Exception e) {
            try {
                List<String> list = JsonUtil.getJsonToList(String.valueOf(value), String.class);
                dataValue = list;
                if (iszhuanhuan) {
                    if (isMultiple) {// 一级分隔符
                        separator = ",";
                    }
                    StringJoiner joiner = new StringJoiner(separator);
                    for (Object listChild : list) {
                        String value1 = redis.get(String.valueOf(listChild)) != null
                                ? String.valueOf(redis.get(String.valueOf(listChild)))
                                : "";
                        if (StringUtil.isNotEmpty(value1)) {
                            joiner.add(value1);
                        }
                    }
                    dataValue = joiner.toString();
                }
            } catch (Exception e1) {
                dataValue = String.valueOf(value);
                if (iszhuanhuan) {
                    dataValue = redis.get(String.valueOf(value)) != null
                            ? String.valueOf(redis.get(String.valueOf(value)))
                            : "";
                }
            }
        }
        return dataValue;
    }

    /**
     * 视图sql条件拼接
     *
     * @param info
     * @param queryCondition
     * @param parameterMap
     * @return
     */
    public static void getViewQuerySql(DataInterfaceEntity info, List<FieLdsModel> queryCondition,
            Map<String, String> parameterMap, Map<String, Object> extraMap) {
        if (Objects.equals(info.getType(), 1) && queryCondition.size() > 0) {
            String searchSqlStr = "";
            for (FieLdsModel item : queryCondition) {
                switch (item.getSearchType()) {
                    case 1:
                        if (StringUtil.isNotEmpty(searchSqlStr)) {
                            searchSqlStr += " and t." + item.getVModel() + " = '"
                                    + XSSEscape.escape(item.getFieldValue()) + "'";
                        } else {
                            searchSqlStr = "t." + item.getVModel() + " = '" + XSSEscape.escape(item.getFieldValue())
                                    + "'";
                        }
                        break;
                    case 2:
                        if (StringUtil.isNotEmpty(searchSqlStr)) {
                            searchSqlStr += " and t." + item.getVModel() + " like '%"
                                    + XSSEscape.escape(item.getFieldValue()) + "%'";
                        } else {
                            searchSqlStr = "t." + item.getVModel() + " like '%" + XSSEscape.escape(item.getFieldValue())
                                    + "%'";
                        }
                        break;
                    case 3:// between
                        if (StringUtil.isNotEmpty(searchSqlStr)) {
                            searchSqlStr += " and t." + item.getVModel() + " between '"
                                    + XSSEscape.escape(String.valueOf(item.getFieldValueOne()))
                                    + "' and '" + XSSEscape.escape(String.valueOf(item.getFieldValueTwo())) + "'";
                        } else {
                            searchSqlStr = "t." + item.getVModel() + " between '"
                                    + XSSEscape.escape(String.valueOf(item.getFieldValueOne()))
                                    + "' and '" + XSSEscape.escape(String.valueOf(item.getFieldValueTwo())) + "'";
                        }
                        break;
                    case 4:// 包含
                        List<String> dataList = item.getDataList();
                        if (dataList.size() > 0) {
                            if (StringUtil.isNotEmpty(searchSqlStr)) {
                                searchSqlStr += " and (";
                            } else {
                                searchSqlStr += " 1=1 and (";
                            }
                            int n = 0;
                            for (String value : dataList) {
                                if (n > 0) {
                                    searchSqlStr += " or t." + item.getVModel() + " like '%" + value + "%'";
                                } else {
                                    searchSqlStr += "t." + item.getVModel() + " like '%" + value + "%'";
                                }
                                n++;
                            }
                            searchSqlStr += ") ";
                        }
                        break;
                    default:
                        break;
                }
            }

            // 页签条件额外拼接
            if (MapUtils.isNotEmpty(extraMap)) {
                for (String key : extraMap.keySet()) {
                    if (StringUtil.isNotEmpty(searchSqlStr)) {
                        searchSqlStr += " and t." + key + " = '" + XSSEscape.escape(extraMap.get(key).toString()) + "'";
                    } else {
                        searchSqlStr = "t." + key + " = '" + XSSEscape.escape(extraMap.get(key).toString()) + "'";
                    }
                }
            }
            parameterMap.put("searchSqlStr", searchSqlStr);
        }
    }

    /**
     * 视图非sql条件过滤
     *
     * @param info
     * @param queryCondition
     * @param dataRes
     * @return
     */
    public static List<Map<String, Object>> getViewQueryNotSql(DataInterfaceEntity info,
            List<FieLdsModel> queryCondition, List<Map<String, Object>> dataRes, Map<String, Object> extraMap) {
        // 是否包含页签参数
        boolean hasExtra = false;
        String key = "";
        if (MapUtils.isNotEmpty(extraMap)) {
            hasExtra = true;
            List<String> keyList = new ArrayList<>(extraMap.keySet());
            key = keyList.get(0);
        }
        List<Map<String, Object>> dataInterfaceList = new ArrayList<>();
        if (!Objects.equals(info.getType(), 1) && queryCondition.size() > 0) {
            for (Map<String, Object> map : dataRes) {
                if (OnlinePublicUtils.mapCompar(queryCondition, map)) {
                    if (hasExtra) {
                        if (Objects.equals(map.get(key), extraMap.get(key)))
                            dataInterfaceList.add(map);
                    } else {
                        dataInterfaceList.add(map);
                    }
                }
            }
        } else {
            for (Map<String, Object> map : dataRes) {
                if (hasExtra) {
                    if (Objects.equals(map.get(key), extraMap.get(key)))
                        dataInterfaceList.add(map);
                } else {
                    dataInterfaceList.add(map);
                }
            }
        }
        return dataInterfaceList;
    }

    /**
     * 判断两个map有相同key-value
     *
     * @return
     * @copyright 深圳市乐程软件有限公司
     * @date 2023/1/5
     */
    public static boolean mapCompar(List<FieLdsModel> searchList, Map<String, Object> hashMap2) {
        boolean isChange = false;
        for (FieLdsModel item : searchList) {
            String realValue = hashMap2.get(item.getVModel()) == null ? "" : (String) hashMap2.get(item.getVModel());
            switch (item.getSearchType()) {
                case 2:
                    if (realValue.indexOf(item.getFieldValue()) >= 0) {
                        isChange = true;
                    }
                    break;
                case 3:// between
                    List<String> longList = new ArrayList() {
                        {
                            add(YunzhupaasKeyConsts.NUM_INPUT);
                            add(YunzhupaasKeyConsts.DATE);
                        }
                    };
                    if (longList.contains(item.getConfig().getYunzhupaasKey())) {
                        Long valueLong = Long.parseLong(realValue);
                        Long valueLongOne = (Long) item.getFieldValueOne();
                        Long valueLongTwo = (Long) item.getFieldValueTwo();
                        if (valueLong >= valueLongOne && valueLong <= valueLongTwo) {
                            isChange = true;
                        }
                    } else {
                        String valueLongOne = (String) item.getFieldValueOne();
                        String valueLongTwo = (String) item.getFieldValueTwo();
                        if (realValue.compareTo(valueLongOne) >= 0 && realValue.compareTo(valueLongTwo) <= 0) {
                            isChange = true;
                        }
                    }
                    break;
                case 4:// 包含
                    List<String> dataList = item.getDataList();
                    for (String value : dataList) {
                        isChange = value.indexOf(realValue) >= 0;
                    }
                    if (isChange) {
                        return true;
                    }
                    break;
                default:// 1,其他条件都按等于查询
                    isChange = item.getFieldValue().equals(realValue);
                    break;
            }
        }
        return isChange;
    }

    /**
     * 获取所有有使用的表
     *
     * @return
     */
    public static List<String> getAllTableName(List<ColumnListField> modelList, List<SuperJsonModel> listQuery,
            Map<String, String> fieldTableMap) {
        List<String> list = new ArrayList<>();

        for (ColumnListField item : modelList) {
            String table = StringUtil.isNotEmpty(item.getConfig().getRelationTable())
                    ? item.getConfig().getRelationTable()
                    : item.getConfig().getTableName();
            if (StringUtil.isBlank(table)) {
                table = fieldTableMap.get(item.getConfig().getParentVModel());
            }
            list.add(table);
        }
        for (SuperJsonModel superJsonModel : listQuery) {
            if (superJsonModel.getConditionList() != null && superJsonModel.getConditionList().size() > 0) {
                List<SuperQueryJsonModel> conditionList = superJsonModel.getConditionList();
                for (SuperQueryJsonModel sqj : conditionList) {
                    if (sqj.getGroups() != null && sqj.getGroups().size() > 0) {
                        List<FieLdsModel> groups = sqj.getGroups();
                        for (FieLdsModel item : groups) {
                            String table = StringUtil.isNotEmpty(item.getConfig().getRelationTable())
                                    ? item.getConfig().getRelationTable()
                                    : item.getConfig().getTableName();
                            list.add(table);
                        }
                    }
                }
            }
        }
        return list.stream().distinct().collect(Collectors.toList());
    }

    /**
     * 递归控件(取出所有子集=-字段不变)
     *
     * @return
     */
    public static void getAllFields(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
        for (FieLdsModel fieLdsModel : fieLdsModelList) {
            ConfigModel config = fieLdsModel.getConfig();
            String yunzhupaasKey = config.getYunzhupaasKey();
            if (YunzhupaasKeyConsts.CHILD_TABLE.equals(yunzhupaasKey)) {
                allFields.addAll(config.getChildren());
            } else {
                if (config.getChildren() != null) {
                    getAllFields(allFields, config.getChildren());
                } else {
                    if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
                        allFields.add(fieLdsModel);
                    }
                }
            }
        }
    }
}
