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

import cn.com.ty.lift.ud.userInvoice.mapper.entity.UserInvoice;
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 用户发票抬头 查询条件
 * 
 * @author Xson
 * @date 2020-05-21
 */
@Data
@ApiModel(description = "用户发票抬头 查询条件")
public final class UserInvoiceQuery extends BasePageQuery {

    /**
     * 类型 1个人2企业
     */
    @ApiModelProperty("类型 1个人2企业")
    private Integer type;

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

    /**
     * 电话 电话
     */
    @ApiModelProperty("电话 电话")
    private String telephone;

    /**
     * 用户id
     */
    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("是否默认")
    private Integer isDefault;

    /**
     * 查询条件
     * 
     * @return
     */
    @Override
    public Wrapper condition() {
        LambdaQueryWrapper<UserInvoice> query = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            query.like(UserInvoice::getName, name);
        }
        if (StringUtils.isNotBlank(telephone)) {
            query.like(UserInvoice::getTelephone, telephone);
        }
        if (null != isDefault) {
            query.eq(UserInvoice::getIsDefault, isDefault);
        }
        if (null != userId) {
            query.eq(UserInvoice::getUserId, userId);
        }
        if (null != type) {
            query.eq(UserInvoice::getType, type);
        }
        return query;
    }

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

}
