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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.ItemUser">
        <result column="id" property="id" />
        <result column="created" property="created" />
        <result column="item_id" property="itemId" />
        <result column="user_id" property="userId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        created,
        item_id, user_id
    </sql>

    <select id="userList" parameterType="com.dayou.vo.ItemStageUserVO" resultType="com.dayou.vo.ItemStageUserVO">
        SELECT
            t1.id,
            t1.weight,
            t.name as userName,
            t.user_id
        FROM
            (
                SELECT
                    u.name,
                    iu.user_id
                FROM
                    item_user iu
                        LEFT JOIN user u ON u.id = iu.user_id
                WHERE
                    iu.item_id = #{itemStageUserVO.itemId}
                  AND u.deleted = 0
            ) t
                LEFT JOIN ( SELECT * FROM item_stage_user isu WHERE isu.stage_id = #{itemStageUserVO.stageId} ) t1 ON t.user_id = t1.user_id
     </select>
</mapper>
