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.LiftFaultCodeEntity;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftFileEntity;
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 LiftFaultCodeQuery extends BasePageQuery {

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

    /**
     * 品牌名称
     */
    @ApiModelProperty("品牌名称")
    private String brandName;

    /**
     * 错误代码
     */
    @ApiModelProperty("错误代码")
    private String code;

    /**
     * 主页展示 0是1否
     */
    @ApiModelProperty("主页展示 0是1否")
    private Integer topFlag;

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

    /**
     * 查询条件
     * 
     * @return
     */
    @Override
    public Wrapper condition() {
        QueryWrapper<LiftFaultCodeEntity> query = new QueryWrapper<>();
        if (StringUtils.isNotBlank(brandName)) {
            query.like("b.name", brandName);
        }
        if (null != brandId) {
            query.eq("a.brand_id", brandId);
        }
        if (null != topFlag) {
            query.eq("a.top_flag", topFlag);
        }
        if (null != statuz) {
            query.eq("a.statuz", statuz);
        }
        if (StringUtils.isNotBlank(code)) {
            query.like("a.code", code);
        }
        query.eq("1", 1);
        if (null == getSort()) {
            query.orderByAsc("a.sort").orderByDesc("a.create_time");
        }else {
            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<LiftFaultCodeEntity> page = new Page<>(getPageNum(), getPageSize());
        return page;
    }

}
