<?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.ruoyi.mall.mapper.MallImgMapper">

    <resultMap type="MallImg" id="MallImgResult">
        <result property="id"    column="id"    />
        <result property="resId"    column="res_id"    />
        <result property="type"    column="type"    />
        <result property="img"    column="img"    />
        <result property="sort"    column="sort"    />
        <result property="createAt"    column="create_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallImgVo">
        select id, res_id, type, img, sort, create_at, del_flag from mall_img
    </sql>

    <select id="selectMallImgList" parameterType="MallImg" resultMap="MallImgResult">
        <include refid="selectMallImgVo"/>
        <where>
            <if test="resId != null  and resId != ''"> and res_id = #{resId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>

    <select id="selectMallImgById" parameterType="Long" resultMap="MallImgResult">
        <include refid="selectMallImgVo"/>
        where id = #{id}
    </select>
    <select id="selectMallImgUrlVoList" parameterType="MallImg" resultType="String">
        select img from mall_img
        where res_id = #{resId}
        and type = #{type}
    </select>

    <insert id="insertMallImg" parameterType="MallImg" useGeneratedKeys="true" keyProperty="id">
        insert into mall_img
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="resId != null">res_id,</if>
            <if test="type != null">type,</if>
            <if test="img != null">img,</if>
            <if test="sort != null">sort,</if>
            <if test="createAt != null">create_at,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="resId != null">#{resId},</if>
            <if test="type != null">#{type},</if>
            <if test="img != null">#{img},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallImg" parameterType="MallImg">
        update mall_img
        <trim prefix="SET" suffixOverrides=",">
            <if test="resId != null">res_id = #{resId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="img != null">img = #{img},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallImgById" parameterType="Long">
        delete from mall_img where id = #{id}
    </delete>

    <delete id="deleteMallImgByIds" parameterType="String">
        delete from mall_img where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteMallImgByImgVO" parameterType="MallImg">
        delete from mall_img where res_id = #{resId} and type = #{type};
    </delete>

    <delete id="batchDeleteMallImgByResId">
        <foreach collection="list" item="item" index="index" separator=";">
            delete from mall_img
            where res_id = #{item.id}
        </foreach>
    </delete>

    <insert id="batchInsertMallImgByList">
        <foreach collection="list" item="item" separator=";">
            insert into mall_img
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.resId != null">res_id,</if>
                <if test="item.type != null">type,</if>
                <if test="item.img != null">img,</if>
                <if test="item.sort != null">sort,</if>
                <if test="item.createAt != null">create_at,</if>
                <if test="item.delFlag != null">del_flag,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="item.resId != null">#{item.resId},</if>
                <if test="item.type != null">#{item.type},</if>
                <if test="item.img != null">#{item.img},</if>
                <if test="item.sort != null">#{item.sort},</if>
                <if test="item.createAt != null">#{item.createAt},</if>
                <if test="item.delFlag != null">#{item.delFlag},</if>
            </trim>
        </foreach>
    </insert>
</mapper>
