<?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.fs.company.mapper.CompanyUserChangeApplyMapper">

    <resultMap id="applyMap" type="CompanyUserChangeApplyVO">
    </resultMap>

    <sql id="applySQL">
        select
            cuca.*,
            fu.avatar    fromAvatar,
            fu.user_name fromName,
            tu.avatar    toAvatar,
            tu.user_name toName
        from company_user_change_apply cuca
        left join company_user fu on fu.user_id = cuca.`from`
        left join company_user tu on tu.user_id = cuca.`to`
    </sql>

    <!-- 查询申请列表 -->
    <select id="selectApplyListByMap" resultMap="applyMap">
        <include refid="applySQL"/>
        <where>
            <if test="map.status != null">
                cuca.status = #{map.status}
            </if>
            <if test="map.companyId != null">
                and cuca.company_id = #{map.companyId}
            </if>
        </where>
    </select>

    <!-- 查询申请详情 -->
    <select id="detailById" resultMap="applyMap">
        <include refid="applySQL"/>
        where cuca.id = #{id}
    </select>
</mapper>