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

import java.util.Date;

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

/**
 * 用户协议 查询条件
 * 
 * @author Xson
 * @date 2020-05-13
 */
@Data
@ApiModel(description = "用户协议 查询条件")
public final class UserAgreementQuery extends BasePageQuery {

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

    /**
     * 创建人
     */
    @ApiModelProperty("创建人")
     private String createUserName;
    
    /**
     * 创建人id
     */
    @ApiModelProperty("创建人id")
     private Long createUserId;

    /**
     * 状态
     */
    @ApiModelProperty("状态")
    private Integer statuz;

    /**
     * 类型
     */
    @ApiModelProperty("类型")
    private Integer type;

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


    /**
     * 查询条件
     * @return
     */
    @Override
    public Wrapper condition() {
    	QueryWrapper<UserAgreement> query = new QueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            query.like("ua.name", name);
        }
        if (StringUtils.isNotBlank(createUserName)) {
            query.like("ui.name", createUserName);
        }
        if(null != createUserId) {
        	query.eq("ua.create_user_id", createUserId);
        }
        if(null != type) {
        	query.eq("us.type", type);
        }
        if(null != startTime && null != endTime) {
        	query.between("ua.create_time", startTime,endTime);
        }
        if(null != statuz) {
        	query.eq("ua.statuz", statuz);
        }
        query.eq("1",1);
        if (null != getSort()) {
            if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
                query.orderByAsc("ua." + getSort().getOrderBy());
            } else {
                query.orderByDesc("ua." + getSort().getOrderBy());
            }
        }
        return query;
    }

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

}

