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

import java.math.BigDecimal;
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.recruitmentInfos.mapper.entity.RecruitmentInfoEntity;
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 RecruitmentInfoQuery extends BasePageQuery {

    public static  String APP = "app";
	/**
     * 热门推荐 1:否0:是
     */
    @ApiModelProperty("热门推荐 0:否1:是")
     private Integer hotFlag;
    
	/**
     * 工作地点
     */
    @ApiModelProperty("工作地点")
    private String address;
    
    /**
     * 岗位
     */
    @ApiModelProperty("岗位")
    private String job;

    /**
     * 公司
     */
    @ApiModelProperty("公司")
     private String companyId;

    /**
     * 公司名称
     */
    @ApiModelProperty("公司名称")
     private String companyName;
    
    /**
     * 审核 0通过1未通过
     */
    @ApiModelProperty("审核 0通过1未通过")
     private Integer checkFlag;

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

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    private Date starDate;


    /**
     * 更新时间
     */
    @ApiModelProperty("更新时间")
    private Date endDate;

    @ApiModelProperty("薪资范围")
    private BigDecimal minSalary;
    
    @ApiModelProperty("薪资范围")
    private BigDecimal maxSalary;
    
    /**
     * 平台
     */
    @ApiModelProperty("平台")
    private String platform;
    
    @ApiModelProperty("省")
    private String provinceName;
    
    @ApiModelProperty("市")
    private String cityName;
    
    /**
     * 查询条件
     * @return
     */
    @Override
    public Wrapper condition() {
    	QueryWrapper<RecruitmentInfoEntity> query = new QueryWrapper<>();
        if (StringUtils.isNotBlank(job)) {
            query.like("rinfo.job", job);
        }
        if (StringUtils.isNotBlank(companyName)) {
            query.like("c.name", companyName);
        }
        if (StringUtils.isNotBlank(address)) {
            query.like("rinfo.address", address);
        }
        if (null != hotFlag) {
            query.eq("rinfo.hot_flag", hotFlag);
        }
        if (StringUtils.isNotBlank(provinceName)) {
            query.eq("rinfo.province_name", provinceName);
        }
        if (StringUtils.isNotBlank(cityName)) {
            query.eq("rinfo.city_name", cityName);
        }
        if (null != companyId) {
            query.eq("c.id", companyId);
        }
        if (null != checkFlag) {
            query.eq("rinfo.check_flag", checkFlag);
        }

        if (null != minSalary && null != maxSalary) {
            query.ge("rinfo.upper_salary", minSalary).le("rinfo.lower_salary", maxSalary);
        }
        if (null != minSalary && null== maxSalary) {
            query.ge("rinfo.lower_salary", minSalary);
        }
        if(null != starDate && null != endDate){
            query.between("rinfo.create_time", starDate, endDate);
        }
        query.eq("1", 1);
        if(APP.equals(platform)){
            query.eq("rinfo.statuz", 1);
            query.eq("rinfo.check_flag", 1);
            //先按按置顶排序，再按浏览量
            query.orderByDesc("rinfo.hot_flag")
                    .orderByDesc("rinfo.browse_num")
                    .orderByDesc("rinfo.create_time");
        }else{
            if (null != statuz) {
                query.eq("rinfo.statuz", statuz);
            }
            //按创建时间倒序
            query.orderByDesc("rinfo.create_time");
        }
        return query;
    }

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

}

