package com.ruansi.wflow.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruansi.system.api.domain.SysUser;
import com.ruansi.wflow.bean.entity.WflowUsers;
import com.ruansi.wflow.bean.vo.OrgTreeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : willian fu
 * @date : 2022/6/27
 */
public interface WflowUsersMapper extends BaseMapper<SysUser> {

    /**
     * 查询该部门下的所有用户
     * @param deptId 部门ID
     * @return 用户列表 type为固定值user
     */
    @Select("SELECT ou.user_id id, ou.nick_name name, ou.avatar " +
            "FROM sys_user ou LEFT JOIN sys_dept oud ON ou.dept_id = oud.dept_id " +
            "WHERE  (oud.dept_id = #{deptId} OR oud.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) )) ")
    List<OrgTreeVo> selectUsersByDept(@Param("deptId") String deptId);

    /**
     * 通过拼音搜索用户，全拼和拼音首字母模糊搜索
     * @param py 拼音
     * @return 搜索的用户列表 type为固定值user
     */
    @Select("SELECT ou.user_id id, ou.nick_name name, ou.avatar FROM sys_user ou " +
            "WHERE ou.user_name LIKE '%${py}%' or nick_name LIKE '%${py}%' ")
    List<OrgTreeVo> selectUsersByPy(@Param("py") String py);
}
