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

    <resultMap type="PublishImage" id="PublishImageResult">
        <result property="imageId"    column="image_id"    />
        <result property="publishId"    column="publish_id"    />
        <result property="url"    column="url"    />
        <result property="faceImg"    column="face_img"    />
        <result property="type"    column="type"    />
        <result property="sorting"    column="sorting"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectPublishImageVo">
        select image_id, publish_id, url, face_img, type, sorting, del_flag, create_by, create_time, update_by, update_time, column1, column2, column3 from publish_image
    </sql>

    <select id="selectPublishImageList" parameterType="PublishImage" resultMap="PublishImageResult">
        <include refid="selectPublishImageVo"/>
        <where>
            del_flag = '0'
            <if test="publishId != null "> and publish_id = #{publishId}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="faceImg != null  and faceImg != ''"> and face_img = #{faceImg}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="sorting != null "> and sorting = #{sorting}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>

    <select id="selectPublishImageByImageId" parameterType="Long" resultMap="PublishImageResult">
        <include refid="selectPublishImageVo"/>
        where image_id = #{imageId}
    </select>

    <insert id="insertPublishImage" parameterType="PublishImage" useGeneratedKeys="true" keyProperty="imageId">
        insert into publish_image
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="publishId != null">publish_id,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="faceImg != null">face_img,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="sorting != null">sorting,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="publishId != null">#{publishId},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="faceImg != null">#{faceImg},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="sorting != null">#{sorting},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updatePublishImage" parameterType="PublishImage">
        update publish_image
        <trim prefix="SET" suffixOverrides=",">
            <if test="publishId != null">publish_id = #{publishId},</if>
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="faceImg != null">face_img = #{faceImg},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="sorting != null">sorting = #{sorting},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where image_id = #{imageId}
    </update>

    <delete id="deletePublishImageByImageId" parameterType="Long">
        delete from publish_image where image_id = #{imageId}
    </delete>

    <delete id="deletePublishImageByImageIds" parameterType="String">
        delete from publish_image where image_id in
        <foreach item="imageId" collection="array" open="(" separator="," close=")">
            #{imageId}
        </foreach>
    </delete>

    <insert id="insertBatch" parameterType="GoodsImage" >
        insert into publish_image
        (publish_id, url, face_img, type, sorting,  create_by, create_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.publishId}, #{item.url}, #{item.faceImg}, #{item.type}, #{item.sorting}, #{item.createBy}, #{item.createTime})
        </foreach>
    </insert>
</mapper>
