package com.mosty.base.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mosty.common.base.util.StringUtils;

/**
 * QueryWrapper 工具类
 */
public class QueryWrapperUtils {

    public static String DEFAULT_SORT = "XT_CJSJ";

    public static String ORDER_ASC_STRING = "asc";

    public static String ORDER_DESC_STRING = "desc";

    public static Boolean IS_ORDER_ASC = false;

    /**
     * 组装排序字段
     * @param qw QueryWrapper
     * @param sort 排序字段
     * @param order 排序方式
     */
    public static void buildQueryWrapperOrder(QueryWrapper qw, String sort, String order){
        boolean isOrderAsc = IS_ORDER_ASC;
        if(StringUtils.isBlank(sort)){
            sort = DEFAULT_SORT;
        }
        if(QueryWrapperUtils.ORDER_ASC_STRING.equals(sort)){
            isOrderAsc = true;
        }

        if(isOrderAsc){
            qw.orderByAsc(sort);
        } else {
            qw.orderByDesc(sort);
        }
    }


}
