package cn.estsh.i3plus.pojo.base.tool;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
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 DdlPreparedPack {

    /**
     * 封装日期
     *
     * @param startDate  开始日期
     * @param endDate    开始日期和结束日期，以逗号分隔（分为开始时间和结束时间）
     * @param columnName HQL里对应的时间字段
     * @param packBean   封装的HQL对象
     * @param isShowTime 是否包含时分秒
     */
    public static void timeBuilder(String startDate, String endDate, String columnName,
                                   DdlPackBean 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(columnName, " and model." + columnName + " >= :m_" + columnName, startDate);
        packBean.addColumnQuery("s_" + columnName, " and model." + columnName + " <= :m_s_" + columnName, endDate);
    }

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

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

            String[] time = date.split(",");
            if (time.length == 1) {
                //只有开始日期，没有结束日期
                packBean.addColumnQuery(columnName, " and model." + columnName + " like :m_" + 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(columnName, " and model." + columnName + " >= :m_" + columnName, time[0]);
                packBean.addColumnQuery("s_" + columnName, " and model." + columnName + " <= :m_s_" + columnName, time[1]);
            } else {
                if (showTaday) {
                    if (isShowTime) {
                        packBean.addColumnQuery(columnName, " and model." + columnName + " >= :m_" + columnName, today + " 00:00:00");
                        packBean.addColumnQuery("s_" + columnName, " and model." + columnName + " <= :m_s_" + columnName, today + " 23:59:59");
                    } else {
                        packBean.addColumnQuery(columnName, " and model." + columnName + " >= :m_" + columnName, today);
                        packBean.addColumnQuery("s_" + columnName, " and model." + columnName + " <= :m_s_" + columnName, today);
                    }
                }
            }
        }
    }


    /**
     * 封装日期
     *
     * @param date            日期，需要和时间字段的值格式相同
     * @param startColumnName HQL里对应的开始时间字段
     * @param endColumnName   HQL里对应的结束时间字段
     * @param packBean        封装的HQL
     * @param isShowTime      是否包含时分秒
     */
    public static void getTimeBetweenCol(String date, String startColumnName, String endColumnName,
                                         DdlPackBean 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(null, " and '" + date + "' between substring(model." + startColumnName
                    + ",1,10) and substring(model." + endColumnName + ",1,10)", null);
            return;
        } else if (date.trim().length() <= 11) {
            date += " 00:00:00";
        }
        packBean.addColumnQuery(null, " and '" + date + "' between model." + startColumnName
                + " and model." + endColumnName, null);
    }

    /**
     * 封装String对象成order by排序
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getOrderByPack(Object order[], String[] columnName, DdlPackBean 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 += " model." + 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(String val, String columnName, DdlPackBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " like :m_" + columnName, "%" + val + "%");
        }
    }

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

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

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

    /**
     * 封装String对象成equal语句,不封装空值，空字符串
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringEqualPack(String val, String columnName, DdlPackBean packBean) {
        if (val != null && val.trim().length() > 0) {
            getStringEqualAndAllowBlankPack(val, columnName, packBean);
        }
    }

    /**
     * 封装String对象成equal语句,封装空值，空字符串
     *
     * @param val 条件
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringEqualAndAllowBlankPack(String val, String columnName, DdlPackBean packBean) {
        packBean.addColumnQuery(columnName, " and model." + columnName + " = :m_" + columnName, val);
    }

    /**
     * 不建议使用该方法，其他方法已满足需要
     * @see #getStringLikerPack(java.lang.String, java.lang.String, cn.estsh.i3plus.pojo.base.bean.DdlPackBean)
     * @see #getStringLikerPackOr(java.lang.String, java.lang.String, cn.estsh.i3plus.pojo.base.bean.DdlPackBean)
     * @see #getStringLeftLikerPack(java.lang.String, java.lang.String, cn.estsh.i3plus.pojo.base.bean.DdlPackBean)
     * @see #getStringRightLikerPack(java.lang.String, java.lang.String, cn.estsh.i3plus.pojo.base.bean.DdlPackBean)
     * @param columnName 列名
     * @param packBean
     */
    @Deprecated
    public static void getStringLikePack(String val, String columnName, DdlPackBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " like  :m_" + columnName, val);
        }
    }

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

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

    /**
     * 判断字段为空
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringNullPack(String columnName, DdlPackBean packBean) {
        packBean.addColumnQuery(null, " and ( model." + columnName +
                " is  null or  model." + columnName + " ='')", null);
    }
    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringNotBlanklPack(String columnName, DdlPackBean packBean) {
        packBean.addColumnQuery(null, " and (model." + columnName + " is not null  and model." + columnName + " !='')", null);
    }
    /**
     * 封装String对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getStringEqualPackOr(String val, String columnName, DdlPackBean packBean) {
        if (val != null && val.trim().length() > 0) {
            packBean.addColumnQuery(columnName, " or model." + columnName + " = :m_" + columnName, val);
        }
    }

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

    /**
     * 两个字段不相等
     *
     * @param firstColumnName 列名
     * @param packBean
     */
    public static void getNotEqueals(String firstColumnName, String twoColumnName, DdlPackBean packBean) {
        packBean.addColumnQuery(null, " and UPPER(model." + firstColumnName + ")!= UPPER(model." + twoColumnName+")", null);
    }
    /**
     * 封装long或者int的负整数对象成equal语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNegativeNumEqualPack(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " = :m_" + columnName, data);
        }
    }

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

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

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

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

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

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

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

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

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

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

    /**
     * 封装double对象成大于等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberBiggerEqualPackContainsZero(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " >= :m_" + columnName, data);
        }
    }

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

    /**
     * 封装double对象成小于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberSmallerPackContainsZero(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " < :m_" + columnName, data);
        }
    }

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

    /**
     * 封装double对象成小于等于语句
     *
     * @param columnName 列名
     * @param packBean
     */
    public static void getNumberSmallerEqualPackContainsZero(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " <= :m_" + columnName, data);
        }
    }

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

    /**
     * 封装in查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInPack(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and model." + columnName + " in (:m_" + columnName + ")", data);
        }
    }

    /**
     * 两个提交用or拼接
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotOrIsNull(Object data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " and (model." + columnName + " in (:m_" + columnName + ") " +
                    "or   model." + columnName + " is null)", data);
        }
    }


    /**
     * 封装in查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getOrInPack(String data, String columnName, DdlPackBean packBean) {
        if (data != null) {
            packBean.addColumnQuery(columnName, " or model." + columnName + " in (:m_" + columnName + ")", data);
        }
    }

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

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

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

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


    /**
     * 封装not in List查询语句
     *
     * @param data
     * @param columnName
     * @param sufColumnName
     * @param packBean
     */
    public static void getNotInPackList(List<?> data, String columnName, String sufColumnName, DdlPackBean packBean) {
        if (data != null && data.size() > 0) {
            String destColumnName = columnName;
            if (!StringUtil.isEmpty(sufColumnName)) {
                destColumnName = destColumnName + "_" + System.currentTimeMillis();
            }
            packBean.addColumnQuery(destColumnName, " and model." + columnName + " not in (:m_" + destColumnName + ")", data);
        }
    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getInOrPackString(String data, String columnName, DdlPackBean 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(columnName, " or model." + columnName + " in (:m_" + columnName + ")", data);
        }
    }


    /**
     * 多个字段列or查询
     *
     * @param data
     * @param columnNames
     * @param columnNamesKey
     * @param packBean
     */
    public static void getMultOrPackString(String data, List<String> columnNames, String columnNamesKey, DdlPackBean packBean) {
        StringBuffer sbf = new StringBuffer(" and ( ");
        if (StringUtil.isEmpty(columnNamesKey)) {
            columnNamesKey = "mult_column_name";
        }
        for (int i = 0; i < columnNames.size(); i++) {
            String columnName = columnNames.get(i);
            sbf.append(" model." + columnName + "=:m_" + columnNamesKey);
            if (i == columnNames.size() - 1) {
                continue;
            }
            sbf.append(" or ");
        }
        sbf.append(" )");
        packBean.addColumnQuery(columnNamesKey, sbf.toString(), data);

    }

    /**
     * 封装in String查询语句
     *
     * @param data
     * @param columnName
     * @param packBean
     */
    public static void getNotInPackString(String data, String columnName, DdlPackBean 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(columnName, " and " + columnName + " not in (:m_" + columnName + ")", data);
        }
    }

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

    /**
     * 为空查询
     *
     * @param columnName
     * @param packBean
     */
    public static void getIsNull(String columnName, DdlPackBean packBean) {
        packBean.addColumnQuery(columnName, " and (model." + columnName + " is null or model." + columnName + " = '')", null);

    }

    /**
     * 不为空查询
     *
     * @param columnName
     * @param packBean
     */
    public static void getIsNotNull(String columnName, DdlPackBean packBean) {
        packBean.addColumnQuery(columnName, " and (model." + columnName + " is not null and model." + columnName + " != '')", null);

    }

    /**
     * 转换排序列
     *
     * @param columnName 列名
     * @param basisType  基本类型
     * @return
     * @see CommonEnumUtil.BASIS_TYPE
     */
    public static String getOrderColConvertType(String columnName, int basisType) {
        String name = " model." + 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;
    }

}
