<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nbclass.szxgl.mapper.QywxUserMapper">
  <resultMap id="BaseResultMap" type="com.nbclass.szxgl.model.QywxUser">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
    <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" />
    <result column="UserID" jdbcType="VARCHAR" property="userid" />
    <result column="Name" jdbcType="VARCHAR" property="name" />
    <result column="Department" jdbcType="VARCHAR" property="department" />
    <result column="Mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="Position" jdbcType="VARCHAR" property="position" />
    <result column="Gender" jdbcType="SMALLINT" property="gender" />
    <result column="Email" jdbcType="VARCHAR" property="email" />
    <result column="Status" jdbcType="SMALLINT" property="status" />
    <result column="Avatar" jdbcType="VARCHAR" property="avatar" />
    <result column="EnglishName" jdbcType="VARCHAR" property="englishname" />
    <result column="IsLeader" jdbcType="SMALLINT" property="isleader" />
    <result column="Telephone" jdbcType="VARCHAR" property="telephone" />
    <result column="ExtAttr" jdbcType="VARCHAR" property="extattr" />
  </resultMap>

  <select id="findByUserId" parameterType="java.lang.String" resultType="map">
		SELECT Department, IsLeader, Avatar FROM qywx_user WHERE UserID = #{userId}
	</select>

    <select id="findAllByDepartment" parameterType="java.lang.String" resultType="map">
		 SELECT UserID, NAME, Avatar FROM qywx_user WHERE IsLeader = 1 AND Department IN (SELECT ParentId FROM qywx_party WHERE Id  IN ( #{depId} ))
	</select>

  <select id="findByDepartment" parameterType="java.lang.String" resultType="map">
	    <!--SELECT UserID, NAME, Avatar FROM qywx_user WHERE IsLeader = 1 AND Department IN (#{depId})-->
        <!--用户有多个部门的情况，存储形式逗号分隔，FIND_IN_SET精准匹配某一个-->
        SELECT UserID, NAME, Avatar FROM qywx_user WHERE IsLeader = 1 AND FIND_IN_SET(#{depId}, Department)
	</select>

	<select id="findSuperiorLeadersByDepartment" parameterType="java.lang.String" resultType="map">
		 SELECT UserID, NAME, Avatar FROM qywx_user WHERE IsLeader = 1 AND Department IN (SELECT ParentId FROM qywx_party WHERE Id IN (#{depId}) )
	</select>

    <select id="getUserInfoByUserIds" parameterType="java.util.List" resultType="map">
        SELECT UserID as userId, NAME as userName, Avatar as avatar FROM qywx_user
        WHERE UserID IN
        <foreach item="item" collection="userIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

</mapper>

