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

import java.util.Date;

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.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 cn.com.ty.lift.ud.shopping.mapper.entity.ShoppingEntity;
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 LiftFileQuery extends BasePageQuery {

    /**
     * 数据id
     */
    @ApiModelProperty("数据id")
    private Integer dataId;

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

    /**
     * 类型 1:tsg2:品牌资料3:系统资料
     */
    @ApiModelProperty("类型 1:tsg2:品牌资料3:系统资料")
    private Integer dataTable;

    /**
     * 资料分类
     */
    @ApiModelProperty("资料分类")
    private Integer catagoryId;

    /**
     * 文件名
     */
    @ApiModelProperty("文件名")
    private String name;

    /**
     * 状态 0:正常1:屏蔽
     */
    @ApiModelProperty("状态 0:正常1:屏蔽")
    private Integer statuz;

    /**
     * 开始时间
     */
    @ApiModelProperty("开始时间")
    private Date startTime;

    /**
     * 结束时间
     */
    @ApiModelProperty("结束时间")
    private Date endTime;

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

    /**
     * 查询条件
     * 
     * @return
     */
    @Override
    public Wrapper condition() {
        QueryWrapper<LiftFileEntity> query = new QueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            query.like("a.name", name);
        }
        if (StringUtils.isNotBlank(brandName)) {
            query.like("b.name", brandName);
        }
        if (null != dataTable) {
            query.eq("a.data_table", dataTable);
        }
        if (null != dataId) {
            query.eq("a.data_id", dataId);
        }
        if (null != brandId) {
            query.eq("a.brand_id", brandId);
        }
        if (null != catagoryId) {
            query.eq("a.catagory_id", catagoryId);
        }
        if (null != statuz) {
            query.eq("a.statuz", statuz);
        }
        if (null != startTime && null != endTime) {
            query.between("a.create_time", startTime, endTime);
        }
        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());
            }
        }
        // if (null != getSort()) {
        // if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
        // query.orderByAsc(LiftFileEntity::getCreateTime);
        // } else {
        // query.orderByDesc(LiftFileEntity::getCreateTime);
        // }
        // }
        return query;
    }

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

}
