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.LambdaQueryWrapper;
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.LiftControlEntity;
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 LiftControlQuery extends BasePageQuery {

    /**
     * 品牌
     */
    @ApiModelProperty("品牌")
    private String name;
    /**
     * 品牌
     */
    @ApiModelProperty("品牌")
    private Integer brandId;
    /**
     * 状态 0:上架1:下架
     */
    @ApiModelProperty("状态 0:上架1:下架")
    private Integer statuz;

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

    /**
     * 查询条件
     * 
     * @return
     */
    @Override
    public Wrapper condition() {
        LambdaQueryWrapper<LiftControlEntity> query = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            query.like(LiftControlEntity::getName, name);
        }
        if (null != brandId) {
            query.eq(LiftControlEntity::getBrandId, brandId);
        }
        if (null != topFlag) {
            query.eq(LiftControlEntity::getTopFlag, topFlag);
        }
        if (null != statuz) {
            query.eq(LiftControlEntity::getStatuz, statuz);
        }
        // if (null == getSort()) {
        query.orderByDesc(LiftControlEntity::getSort).orderByDesc(LiftControlEntity::getCreateTime);
        // }
        // if (null != getSort()) {
        // if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
        // query.orderByAsc(LiftControlEntity::getSort);
        // } else {
        // query.orderByDesc(LiftControlEntity::getSort);
        // }
        // }
        return query;
    }

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

}
