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

import cn.com.ty.lift.ud.appmenu.mapper.entity.AppuserMenu;
import cn.com.ty.lift.ud.common.BasePageQuery;

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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * app角色权限查询条件
 * 
 * @author Xson
 * @date 2020-06-04
 */
@Data
@ApiModel(description = "查询条件")
public final class AppuserMenuQuery extends BasePageQuery {

	private Long id;

	/**
	 * app角色
	 */
	@ApiModelProperty("app角色")
	private Integer userLevelId;

	/**
	 * 按钮id
	 */
	@ApiModelProperty("按钮id")
	private Integer appmenuId;

	/**
	 * 查询条件
	 * 
	 * @return
	 */
	@Override
	public Wrapper condition() {
		LambdaQueryWrapper<AppuserMenu> query = new LambdaQueryWrapper<>();
		if (null != appmenuId) {
			query.eq(AppuserMenu::getAppmenuId, appmenuId);
		}
		if (null != userLevelId) {
			query.eq(AppuserMenu::getUserLevelId, userLevelId);
		}
		if (null != getSort()) {
			if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
				query.orderByAsc(AppuserMenu::getCreateTime);
			} else {
				query.orderByDesc(AppuserMenu::getCreateTime);
			}
		}
		return query;
	}

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

}
