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

import cn.com.ty.lift.ud.appmenu.mapper.entity.Appmenu;
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.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 AppmenuQuery extends BasePageQuery {


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

    /**
     * 路由
     */
    @ApiModelProperty("路由")
    private String router;

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



    /**
     * 查询条件
     * @return
     */
    @Override
    public Wrapper condition() {
        LambdaQueryWrapper<Appmenu> query = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
			query.like(Appmenu::getName, name);
		}
        if (StringUtils.isNotBlank(router)) {
			query.like(Appmenu::getRouter, router);
		}
		if (null != getSort()) {
			if (getSort().getOrder().indexOf("asc") != -1 || getSort().getOrder().indexOf("ASC") != -1) {
				query.orderByAsc(Appmenu::getCreateTime);
			} else {
				query.orderByDesc(Appmenu::getCreateTime);
			}
		}
        return query;
    }

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

}

