package com.ylcm.sys.form;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ylcm.sys.domain.AdProduct;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * <p>
 * 媒体管理表
 * </p>
 *
 * @author admin
 * @since 2020-07-01
 */
@Data
public class AdProductListForm implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "产品名")
    private String productName;

    @ApiModelProperty(value = "品牌")
    private String brandName;

    @ApiModelProperty(value = "一级行业")
    private String firstInd;

    @ApiModelProperty(value = "二级行业")
    private String secondInd;

    private Integer pageSize = 10;
    private Integer pageNo = 1;
    
    
    public AdProductListForm page(){
        this.pageSize = this.pageSize != null && this.pageSize > 0 ? this.pageSize:20;
        this.pageNo = this.pageNo != null && this.pageNo > 0 ? (this.pageNo - 1)*this.pageSize : 0;
        return this;
    }
    
    /**
             * 实体转换
     * @return
     */
    public LambdaQueryWrapper<AdProduct> toAdProductQueryWrapper(){
    	LambdaQueryWrapper<AdProduct> queryWrapper = new LambdaQueryWrapper<AdProduct>();       
    	if(StringUtils.isNotBlank(productName)){
    		queryWrapper.like(AdProduct::getProductName, productName.trim());
    	}
    	if(StringUtils.isNotBlank(brandName)){
    		queryWrapper.like(AdProduct::getBrandName, brandName.trim());
    	}
    	if(StringUtils.isNotBlank(firstInd)){
    		queryWrapper.eq(AdProduct::getFirstInd, firstInd.trim());
    	}
    	if(StringUtils.isNotBlank(secondInd)){
    		queryWrapper.eq(AdProduct::getSecondInd, secondInd.trim());
    	}
    	queryWrapper.orderByDesc(AdProduct::getId);
    	return queryWrapper;
    }
    
	/**
	 * 实体转换
	 * 
	 * @return
	 */
	public LambdaQueryWrapper<AdProduct> toAdProductQueryBrandNameWrapper() {
		LambdaQueryWrapper<AdProduct> queryWrapper = new LambdaQueryWrapper<AdProduct>();
		queryWrapper.eq(AdProduct::getProductName, productName.trim());
		if (StringUtils.isNotBlank(brandName)) {
			queryWrapper.like(AdProduct::getBrandName, brandName.trim());
		}
		queryWrapper.orderByAsc(AdProduct::getBrandName);
		return queryWrapper;
	}
}
