<?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.ghy.goods.mapper.GoodsImgsMapper">

    <resultMap id="GoodsImgsResult" type="com.ghy.goods.domain.GoodsImgs">
        <result property="goodsImgsId" column="goods_imgs_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="imgUrl" column="img_url"/>
        <result property="imgType" column="img_type"/>
    </resultMap>

    <sql id="selectGoodsImgs">
        SELECT goods_imgs_id, goods_id, img_url, img_type
        FROM goods_imgs
    </sql>

    <select id="qryGoodsImgs" parameterType="com.ghy.goods.domain.GoodsImgs" resultMap="GoodsImgsResult">
        <include refid="selectGoodsImgs"/>
        <where>
            <if test="goodsId != null">
                AND goods_id = #{goodsId}
            </if>
            <if test="remark != null and imgType != ''">
                AND remark = #{remark}
            </if>
            <if test="imgType != null">
                AND img_type = #{imgType}
            </if>
        </where>
    </select>

    <delete id="delete">
        DELETE FROM goods_imgs WHERE goods_imgs_id IN
        <foreach collection="array" item="goodsImgsId" open="(" separator="," close=")">
            #{goodsImgsId}
        </foreach>
    </delete>

    <delete id="deleteByGoodsId">
        DELETE
        FROM goods_imgs
        WHERE goods_id = #{goodsId}
    </delete>

    <select id="selectByGoodsId" resultMap="GoodsImgsResult">
        <include refid="selectGoodsImgs"/>
        <where>
            <if test="goodsId != null and goodsId != 0">
                AND goods_id = #{goodsId}
            </if>
        </where>
    </select>

    <insert id="batchInsert" parameterType="list">
        INSERT INTO
        goods_imgs
            (
            goods_id,
            img_url,
            img_type,
            remark,
            create_by,
            create_time
            )
        VALUES
        <foreach collection="goodsImgs" separator="," item="goodsImg">
            (
            #{goodsImg.goodsId},
            #{goodsImg.imgUrl},
            #{goodsImg.imgType},
            #{goodsImg.remark},
            #{goodsImg.createBy},
            sysdate()
            )
        </foreach>
    </insert>

    <update id="batchUpdate" parameterType="com.ghy.goods.domain.GoodsImgs">
        <foreach collection="array" item="goodsImgs">
            UPDATE goods_imgs
            <set>
                <if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
                <if test="imgUrl != null and imgUrl != ''">img_url = #{imgUrl},</if>
                <if test="imgType != null and imgType != ''">img_type = #{imgType},</if>
                update_time = sysdate()
            </set>
            WHERE goods_imgs_id = #{goodsImgsId};
        </foreach>
    </update>

</mapper>
