<?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.kmall.api.dao.ApiGoodsGalleryMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kmall.api.entity.GoodsGalleryVo" id="goodsGalleryMap">
        <result property="id" column="id"/>
        <result property="goods_id" column="goods_id"/>
        <result property="img_url" column="img_url"/>
        <result property="file_type" column="file_type"/>
        <result property="img_desc" column="img_desc"/>
        <result property="sort_order" column="sort_order"/>
    </resultMap>

    <select id="queryObject" resultMap="goodsGalleryMap">
		select * from mall_goods_gallery where id = #{value}
	</select>

    <select id="queryList" resultMap="goodsGalleryMap">
        select
        <if test="fields != null and fields != ''">
            ${fields}
        </if>
        <if test="fields == null or fields == ''">
            *
        </if>
        from mall_goods_gallery
        <where>
            <if test="goods_id != null">
                and goods_id = #{goods_id}
            </if>
        </where>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by sort_order asc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
		select count(*) from mall_goods_gallery
	</select>

    <insert id="save" parameterType="com.kmall.api.entity.GoodsGalleryVo" useGeneratedKeys="true" keyProperty="id">
		insert into mall_goods_gallery
		(
			`goods_id`, 
			`img_url`, 
			`img_desc`, 
			`sort_order`
		)
		values
		(
			#{goods_id},
			#{img_url},
			#{img_desc},
			#{sort_order}
		)
	</insert>

    <update id="update" parameterType="com.kmall.api.entity.GoodsGalleryVo">
        update mall_goods_gallery
        <set>
            <if test="goods_id != null">`goods_id` = #{goods_id},</if>
            <if test="img_url != null">`img_url` = #{img_url},</if>
            <if test="img_desc != null">`img_desc` = #{img_desc},</if>
            <if test="sort_order != null">`sort_order` = #{sort_order}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
		delete from mall_goods_gallery where id = #{value}
	</delete>

    <delete id="deleteBatch">
        delete from mall_goods_gallery where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>