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.AdTv;

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

/**
 * <p>
 *   电视管理表
 * </p>
 *
 * @author admin
 * @since 2020-07-01
 */
@Data
public class AdTvListForm implements Serializable {

    private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "需要排除的剧")
    private String ids;

    @ApiModelProperty(value = "电视剧名称")
    private String name;

    @ApiModelProperty(value = "一级体裁")
    private String firstTheme;

    @ApiModelProperty(value = "二级体裁")
    private String secondTheme;

    private Integer pageSize;
    private Integer pageNo;
    
	public AdTvListForm page() {
		this.pageSize = this.pageSize != null && this.pageSize > 0 ? this.pageSize : 10;
		this.pageNo = this.pageNo != null && this.pageNo > 0 ? (this.pageNo - 1) * this.pageSize : 0;
		return this;
	}
    
    /**
	 * 实体转换
     * @return
     */
    public LambdaQueryWrapper<AdTv> toAdTvQueryWrapper(){
    	LambdaQueryWrapper<AdTv> queryWrapper = new LambdaQueryWrapper<AdTv>();       
    	if(StringUtils.isNotBlank(name)){
    		queryWrapper.like(AdTv::getName, name.trim());
    	}
    	if(StringUtils.isNotBlank(firstTheme)){
    		queryWrapper.eq(AdTv::getFirstTheme, firstTheme.trim());
    	}
    	if(StringUtils.isNotBlank(secondTheme)){
    		queryWrapper.eq(AdTv::getSecondTheme, firstTheme.trim());
    	}
    	if (StringUtils.isNotBlank(ids)){
    		String[] idsArr = ids.split(",");
			for (String v : idsArr) {
				queryWrapper.ne(AdTv::getId, Integer.parseInt(v));
			}
		}
    	queryWrapper.eq(AdTv::getStatus, 0);//正常
    	queryWrapper.orderByDesc(AdTv::getId);
    	return queryWrapper;
    }  
}
