package cn.estsh.i3plus.pojo.mdm.sqlpack;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.MdmEnumUtil;
import cn.estsh.i3plus.pojo.mdm.bean.base.DdlPackMdmModelBean;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Description : 数据库脚本封装方法，封装成预加载hql，HqlPack仅限用于一些特定的sql，可能造成性能低下
 * example： name = :name
 * @Reference :
 * @Author : alwaysfrin
 * @CreateDate : 2019-03-29
 * @Modify:
 **/
public class DdlMdmModelPreparedPack {

    /**
     * 封装日期
     *
     * @param startDate  开始日期
     * @param endDate    开始日期和结束日期，以逗号分隔（分为开始时间和结束时间）
     * @param columnName HQL里对应的时间字段
     * @param packBean   封装的HQL对象
     * @param isShowTime 是否包含时分秒
     */
    public static void timeBuilder(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String startDate, String endDate, String columnName,
                                   DdlPackMdmModelBean packBean, boolean isShowTime) {
        if (startDate == null || startDate.trim().length() == 0) {
            startDate = "1900-01-01";
        } else {
            startDate = startDate.trim();
        }
        if (isShowTime && startDate.trim().length() <= 11) {
            startDate += " 00:00:00";
        }
        if (endDate == null || endDate.trim().length() == 0) {
            endDate = "2100-01-01";
        } else {
            endDate = endDate.trim();
        }
        if (isShowTime && endDate.trim().length() <= 11) {
            endDate += " 23:59:59";
        }

        packBean.addColumnQuery(entityType, columnName
                , " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName
                , startDate);
        packBean.addColumnQuery(entityType, "s_" + columnName
                , " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName
                , endDate);
    }

    /**
     * 封装日期
     *
     * @param startDate      开始日期
     * @param endDate        结束日期
     * @param columnName     列名
     * @param isLeftContain  左闭？
     * @param isRightContain 右闭？
     * @param packBean       HQL对象
     */
    public static void timeBuilder(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String startDate, String endDate, String columnName, boolean isLeftContain, boolean isRightContain, DdlPackMdmModelBean packBean) {
        if (isLeftContain) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, startDate.trim());
        } else {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, startDate.trim());
        }
        if (isRightContain) {
            packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, endDate.trim());
        } else {
            packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, endDate.trim());
        }
    }

    /**
     * 封装日期
     *
     * @param date       开始日期和结束日期，以逗号分隔（分为开始时间和结束时间）
     * @param columnName HQL里对应的时间字段
     * @param packBean   封装的HQL
     * @param showTaday  如果没有开始时间和结束时间，是否查询当天时间，还是查询所有时间。true:查询当天时间，false:查询所有
     * @param isShowTime 是否包含时分秒
     */
    public static void timeBuilder(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String date, String columnName, DdlPackMdmModelBean packBean, Boolean showTaday, boolean isShowTime) {
        if (date != null && date.trim().length() > 0) {
            String today = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
            if (date.trim().length() > 0 && (date.length() == 1 || ",".equals(date))) {
                //只有一个逗号
                date = "";
            }

            String[] time = date.split(",");
            if (time.length == 1) {
                //只有开始日期，没有结束日期
                packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " like :" + entityType.getAlias() + "_" + columnName, "%" + time[0] + "%");
            } else if (time.length == 2 && ((time[0] != null && time[0].trim().length() > 0)
                    || (time[1] != null & time[1].trim().length() > 0))) {
                if (time[0] == null || time[0].trim().length() == 0) {
                    time[0] = "1900-01-01";
                } else {
                    time[0] = time[0].trim();
                }
                if (isShowTime && time[0].trim().length() <= 11) {
                    time[0] += " 00:00:00";
                }
                if (time[1] == null || time[1].trim().length() == 0) {
                    time[1] = "2100-01-01";
                } else {
                    time[1] = time[1].trim();
                }
                if (isShowTime && time[1].trim().length() <= 11) {
                    time[1] += " 23:59:59";
                }
                packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, time[0]);
                packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, time[1]);
            } else {
                if (showTaday) {
                    if (isShowTime) {
                        packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, today + " 00:00:00");
                        packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, today + " 23:59:59");
                    } else {
                        packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " " +">= :" + entityType.getAlias() + "_" + columnName,today);
                        packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, today);
                    }
                }
            }
        }
    }


    /**
     * 封装日期
     *
     * @param date            日期，需要和时间字段的值格式相同
     * @param startColumnName HQL里对应的开始时间字段
     * @param endColumnName   HQL里对应的结束时间字段
     * @param packBean        封装的HQL
     * @param isShowTime      是否包含时分秒
     */
    public static void getTimeBetweenCol(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String date, String startColumnName, String endColumnName,
                                         DdlPackMdmModelBean packBean, boolean isShowTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (date == null || date.trim().length() == 0) {
            date = sdf.format(new Date());
        }
        if (!isShowTime) {
            date = date.substring(0, 10);
            packBean.addColumnQuery(entityType, null, " and '" + date + "' between substring(" + entityType.getAlias() + "." + startColumnName
                    + ",1,10) and substring(" + entityType.getAlias() + "." + endColumnName + ",1,10)", null);
            return;
        } else if (date.trim().length() <= 11) {
            date += " 00:00:00";
        }
        packBean.addColumnQuery(entityType, null, " and '" + date + "' between " + entityType.getAlias() + "." + startColumnName
                + " and " + entityType.getAlias() + "." + endColumnName, null);
    }

    /**
     * 封装String对象成order by排序
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getOrderByPack(MdmEnumUtil.HQL_ENTITY_TYPE[] entityTypes, Object order[], String[] columnName,
                                      DdlPackMdmModelBean packBean) {
        String sqlStr = "";
        String orderByStr = "";
        for (int i = 0; i < order.length; i++) {
            if (order[i] != null && order[i].toString().trim().length() > 0) {
                if (Integer.parseInt(order[i].toString()) == 1) {
                    order[i] = "asc";
                } else {
                    order[i] = "desc";
                }
                if (columnName[i].indexOf(" model.") == -1) {
                    sqlStr += entityTypes[i].getAlias() + "." + columnName[i];
                } else {
                    sqlStr += columnName[i];
                }
                sqlStr += " " + order[i].toString() + ",";
            }
        }

        if (sqlStr.length() > 0 && sqlStr.lastIndexOf(",") == sqlStr.length() - 1) {
            sqlStr = sqlStr.substring(0, sqlStr.length() - 1);
            orderByStr = " order by " + sqlStr;
        }

        packBean.setOrderByStr(orderByStr);
    }

    /**
     * 对象默认排序
     */
    public static void getOrderDefault(BaseBean bean) {
        if (bean != null && StringUtils.isBlank(bean.getOrderByParam())) {
            bean.setOrderByParam("modifyDatetime");
            bean.setAscOrDesc(CommonEnumUtil.ASC_OR_DESC.DESC.getValue());
        }
    }

    /**
     * 封装String对象成like语句
     *
     * @param val        对象值
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringLikerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " like :" + entityType.getAlias() + "_" + columnName, "%" + val + "%");
        }
    }

    /**
     * 封装String对象成like语句
     *
     * @param val        对象值
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringLikerPackOr(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " or " + entityType.getAlias() + "." + columnName + " like :" + entityType.getAlias() + "_" + columnName, "%" + val + "%");
        }
    }

    /**
     * 封装String对象成like语句(右侧模糊)
     *
     * @param val        对象值
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringRightLikerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " like :" + entityType.getAlias() + "_" + columnName, val + "%");
        }
    }

    /**
     * 封装String对象成like语句(左侧模糊)
     *
     * @param val        对象值
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringLeftLikerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " like :" + entityType.getAlias() + "_" + columnName, "%" + val);
        }
    }

    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, val);
        }
    }

    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringLikePack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " like  :" + entityType.getAlias() + "_" + columnName, val);
        }
    }

    /**
     * 封装String对象成不等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringNoEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " <> :" + entityType.getAlias() + "_" + columnName, val);
        }
    }

    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringNotNullPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String columnName, DdlPackMdmModelBean packBean) {
        packBean.addColumnQuery(entityType, null, " and " + entityType.getAlias() + "." + columnName + " is not null", null);
    }

    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringNotBlanklPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String columnName, DdlPackMdmModelBean packBean) {
        packBean.addColumnQuery(entityType, null, " and (" + entityType.getAlias() + "." + columnName + " is not null  and " + entityType.getAlias() + "." + columnName + " !='')", null);
    }

    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringEqualPackOr(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String val, String columnName, DdlPackMdmModelBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(entityType, columnName, " or " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, val);
        }
    }

    /**
     * 封装long或者int的正整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Long.parseLong(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 两个字段不相等
     *
     * @param firstColumnName 列名
     * @param packBean
     */
    public static void getNotEqueals(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String firstColumnName, String twoColumnName, DdlPackMdmModelBean packBean) {
        packBean.addColumnQuery(entityType, null, " and UPPER(" + entityType.getAlias() + "." + firstColumnName + ")!= UPPER(" + entityType.getAlias() + "." + twoColumnName + ")", null);
    }

    /**
     * 封装long或者int的负整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNegativeNumEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装long或者int的整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumEqualPackOr(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Long.parseLong(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " or " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装long或者int的整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumEqualPackOverZero(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装long或者int的整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumWithZeroEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) >= 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " = :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装String对象成大于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringBiggerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && !StringUtils.isEmpty(String.valueOf(data))) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装String对象成大于不等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringBiggerNotEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && !StringUtils.isEmpty(String.valueOf(data))) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " > :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装String对象成小于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringSmallerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && !StringUtils.isEmpty(String.valueOf(data))) {
            packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_s_" + columnName, data);
        }
    }

    /**
     * 封装String对象成小于不等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringSmallerNotEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && !StringUtils.isEmpty(String.valueOf(data))) {
            packBean.addColumnQuery(entityType, "s_" + columnName, " and " + entityType.getAlias() + "." + columnName + " < :" + entityType.getAlias() + "_s_" + columnName, data);
        }
    }

    /**
     * 封装double对象成大于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberBiggerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " > :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装double对象成大于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberBiggerPackContainsZero(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " > :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装double对象成大于等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberBiggerEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " >= :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装double对象成小于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberSmallerPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " < :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装double对象成小于等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberSmallerEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && Double.parseDouble(data.toString()) > 0) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " <= :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装long或者int的整数对象成equal语句(不等于)
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumNOEqualPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, columnName, " and " + entityType.getAlias() + "." + columnName + " <> :" + entityType.getAlias() + "_" + columnName, data);
        }
    }

    /**
     * 封装in查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, "in_"+columnName,
                    " and " + entityType.getAlias() + "." + columnName + " in ( :" + entityType.getAlias() + "_in_" + columnName + " ) ", data);
        }
    }

    /**
     * 两个提交用or拼接
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotOrIsNull(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and (" + entityType.getAlias() + "." + columnName + " in (:" + entityType.getAlias() + "_in_" + columnName + ") " +
                    "or   " + entityType.getAlias() + "." + columnName + " is null)", data);
        }
    }


    /**
     * 封装in查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getOrInPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, "in_"+columnName," or " + entityType.getAlias() + "." + columnName + " in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInPackArray(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object[] data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.length > 0) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " in (:" + entityType.getAlias() + "_in_" + columnName + ")", Arrays.asList(data));
        }
    }

    /**
     * 封装not in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotInPackArray(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object[] data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.length > 0) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " not in (:" + entityType.getAlias() + "_in_" + columnName + ")", Arrays.asList(data));
        }
    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInPackList(MdmEnumUtil.HQL_ENTITY_TYPE entityType, List<?> data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.size() > 0) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 封装not in List查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotInPackList(MdmEnumUtil.HQL_ENTITY_TYPE entityType, List<?> data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.size() > 0) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " not in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInOrPackString(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.trim().length() > 0) {
            //判断最后一位是不是逗号
            if (data.lastIndexOf(",") != (data.length() - 1)) {
                data += ",";
            }
            String[] dataArray = data.substring(0, data.length() - 1).split(",");
            data = "";
            for (int i = 0; i < dataArray.length; i++) {
                if (i == dataArray.length - 1) {
                    data += "'" + dataArray[i] + "'";
                } else {
                    data += "'" + dataArray[i] + "',";
                }
            }
            packBean.addColumnQuery(entityType, "in_"+columnName, " or " + entityType.getAlias() + "." + columnName + " in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotInPackString(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null && data.trim().length() > 0) {
            //判断最后一位是不是逗号
            if (data.lastIndexOf(",") != (data.length() - 1)) {
                data += ",";
            }
            String[] dataArray = data.substring(0, data.length() - 1).split(",");
            data = "";
            for (int i = 0; i < dataArray.length; i++) {
                if (i == dataArray.length - 1) {
                    data += "'" + dataArray[i] + "'";
                } else {
                    data += "'" + dataArray[i] + "',";
                }
            }
            packBean.addColumnQuery(entityType,"in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " not in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 封装not in查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotInPack(MdmEnumUtil.HQL_ENTITY_TYPE entityType, Object data, String columnName, DdlPackMdmModelBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(entityType, "in_"+columnName, " and " + entityType.getAlias() + "." + columnName + " not in (:" + entityType.getAlias() + "_in_" + columnName + ")", data);
        }
    }

    /**
     * 转换排序列
     *
     * @param columnName 列名
     * @param basisType  基本类型
     * @return
     * @see CommonEnumUtil.BASIS_TYPE
     */
    public static String getOrderColConvertType(MdmEnumUtil.HQL_ENTITY_TYPE entityType, String columnName, int basisType) {
        String name = " " + entityType.getAlias() + "." + columnName;

        if (basisType == CommonEnumUtil.BASIS_TYPE.INT.getValue()) {
            name = " cast(" + name + " as integer)";
        } else if (basisType == CommonEnumUtil.BASIS_TYPE.DOUBLE.getValue()) {
            name = " cast(" + name + " as decimal)";
        } else if (basisType == CommonEnumUtil.BASIS_TYPE.LONG.getValue()) {
            name = " cast(" + name + " as long)";
        }
        return name;
    }
}
