<?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.CompanyUserChangeApplyUserMapper">

    <!-- 查询申请记录关联用户 -->
    <select id="getApplyUsers" resultType="com.fs.company.vo.CompanyUserChangeApplyUserVO">
        select
            fu.user_id,
            fu.nickname as userName
        from company_user_change_apply_user cucau
        inner join fs_user fu on fu.user_id = cucau.user_id
        where cucau.apply_id = #{applyId}
    </select>

    <!-- 修改申请记录关联用户销售 -->
    <update id="changeUser">
        update fs_user fu
        inner join company_user_change_apply_user cucau on cucau.user_id = fu.user_id
        left join company_user_change_apply cuca on cuca.id = cucau.apply_id
        set fu.company_user_id = cuca.`to`
        where cuca.id = #{applyId}
    </update>
</mapper>