<?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.younike.system.mapper.GoodsServerMapper">

    <update id="removeGoodsServerByGoodsId" parameterType="Long">
        update goods_server
        set del_flag = 1
        where goods_id = #{goodsId}
    </update>

    <insert id="insertBatch" parameterType="GoodsServer" >
        insert into goods_server
        (goods_id, server_id, goods_server_price, server_img_url, create_by, create_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.goodsId}, #{item.serverId}, #{item.goodsServerPrice}, #{item.serverImgUrl}, #{item.createBy}, #{item.createTime})
        </foreach>
        ;
    </insert>

    <resultMap type="GoodsServerVO" id="GoodsServerVOResult">
        <result property="goodsId"    column="goods_id"    />
        <result property="serverId"    column="server_id"    />
        <result property="goodsServerPrice"    column="goods_server_price"    />
        <result property="realName"    column="real_name"    />
        <result property="phone"    column="phone"    />
        <result property="serverLevel"    column="server_level"    />
        <result property="serverImgUrl"    column="server_img_url"    />
    </resultMap>
    <select id="goodsServerList" resultMap="GoodsServerVOResult">
        select gs.goods_id, gs.server_id, gs.goods_server_price, gs.server_img_url, su.real_name, su.phone,su.server_level
        from goods_server gs
        left join server_user su on gs.server_id = su.server_id
        <where>
            gs.del_flag = 0
            and su.del_flag = 0
            and gs.goods_id in
            <foreach collection="list" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </where>
    </select>

</mapper>
