package cn.com.ty.lift.ud.dataBank.controller.query;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.com.ty.lift.ud.common.BasePageQuery;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftCategoryEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 资料分类 查询条件
 * 
 * @author Xson
 * @date 2020-04-23
 */
@Data
@ApiModel(description = "资料分类 查询条件")
public final class LiftCategoryQuery extends BasePageQuery {

    /**
     * 父id
     */
    @ApiModelProperty("父id")
    private Integer pid;

    /**
     * 品牌
     */
    @ApiModelProperty("品牌")
    private Long brandId;

    /**
     * 分类名
     */
    @ApiModelProperty("分类名")
    private String name;

    /**
     * 是否只查二级
     */
    @ApiModelProperty("是否只查二级")
    private Integer serchTwo;

    /**
     * 状态 0:上架1:下架
     */
    @ApiModelProperty("状态 0:上架1:下架")
    private Integer statuz;

    /**
     * 品牌名
     */
    @ApiModelProperty("品牌名")
    private String brandName;
    
    /**
     * 查询条件
     * 
     * @return
     */
    @Override
    public Wrapper condition() {
        QueryWrapper<LiftCategoryEntity> query = new QueryWrapper<>();
        if (StringUtils.isNotBlank(brandName)) {
            query.like("b.name", brandName);
        }
        if (serchTwo == 1) {
            query.ne("a.pid", 0);
        }
        if (StringUtils.isNotBlank(name)) {
            query.like("a.name", name);
        }
        if (null != statuz) {
            query.eq("a.statuz", statuz);
        }
        if (null != brandId) {
            query.eq("a.brand_id", brandId);
        }
        if (null != pid) {
            query.eq("a.pid", pid);
        }
        query.eq("1", 1);
        if (null != getSort()) {
            if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
                query.orderByAsc("a."+getSort().getOrderBy());
            } else {
                query.orderByDesc("a."+getSort().getOrderBy());
            }
        }
        return query;
    }

    /**
     * 分页条件
     * 
     * @return
     */
    @Override
    public IPage page() {
        Page<LiftCategoryEntity> page = new Page<>(getPageNum(), getPageSize());
        return page;
    }

}
