<?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.dayou.mapper.TeamMemberMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.TeamMember">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="member_id" property="memberId" />
        <result column="team_id" property="teamId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        member_id, team_id
    </sql>

    <select id="getLeader" resultType="com.dayou.entity.Team">
        SELECT
            distinct t.supervisor_id,
                     t.cultivate_id
        FROM
            team_member tm
                LEFT JOIN team t ON t.id = tm.team_id
                left join department d on d.id = t.department_id
        WHERE
            t.deleted = 0
          AND tm.deleted = 0
          AND tm.member_id = #{userId}
          and d.deleted = 0
          and d.name = #{departmentName}
    </select>
</mapper>
