package com.zsc.edu.gateway.modules.system.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.system.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * 用户Query
 *
 * @author harry yao
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserQuery {

    /**
     * 用户名
     */
    public String username;

    /**
     * 手机号码
     */
    public String phone;

    /**
     * 电子邮件
     */
    public String email;

    /**
     * 启用状态
     */
    public Boolean enableState;

    /**
     * 角色集合
     */
    public Long roleId;

    /**
     * 部门集合
     */
    public Long deptId;


    public LambdaQueryWrapper<User> wrapper() {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.hasText(this.username), User::getUsername, this.username);
        queryWrapper.eq(StringUtils.hasText(this.phone), User::getPhone, this.phone);
        queryWrapper.eq(StringUtils.hasText(this.email), User::getEmail, this.email);
        queryWrapper.eq(Objects.nonNull(this.enableState), User::getEnableState, this.enableState);
        queryWrapper.eq(Objects.nonNull(this.deptId),User::getDeptId,this.deptId);
        queryWrapper.eq(Objects.nonNull(this.roleId),User::getRoleId,this.roleId);
        return queryWrapper;
    }

}
