<?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.xingxi.business.NewsPic.mapper.NewsPicMapper">
    <resultMap type="NewsPic" id="NewsPicResult">
        <result property="id"    column="id"    />
        <result property="newsUrl"    column="newsUrl"    />
        <result property="newsId"    column="newsId"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectNewsPic">
        select id, newsUrl, newsId, delFlag, createUser, createTime, updateUser, updateTime from t_news_pic
    </sql>

    <sql id="selectNewsPicExt">
        select
            ${tableAlias}.id,
            ${tableAlias}.newsUrl,
            ${tableAlias}.newsId,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_news_pic ${tableAlias}
    </sql>

    <select id="selectNewsPicList" parameterType="NewsPic" resultMap="NewsPicResult">
        <include refid="selectNewsPic"/>
        <where>  
            <if test="newsUrl != null  and newsUrl != ''"> and newsUrl = #{newsUrl}</if>
            <if test="newsId != null "> and newsId = #{newsId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectNewsPicById" parameterType="Long" resultMap="NewsPicResult">
        <include refid="selectNewsPic"/>
        where id = #{id}
    </select>
        
    <insert id="insertNewsPic" parameterType="NewsPic" useGeneratedKeys="true" keyProperty="id">
        insert into t_news_pic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="newsUrl != null">newsUrl,</if>
            <if test="newsId != null">newsId,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="newsUrl != null">#{newsUrl},</if>
            <if test="newsId != null">#{newsId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertNewsPic">
        insert into t_news_pic( newsUrl, newsId, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.newsUrl}, #{item.newsId}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateNewsPic" parameterType="NewsPic">
        update t_news_pic
        <trim prefix="SET" suffixOverrides=",">
            <if test="newsUrl != null">newsUrl = #{newsUrl},</if>
            <if test="newsId != null">newsId = #{newsId},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNewsPicById" parameterType="Long">
        delete from t_news_pic where id = #{id}
    </delete>

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

    <update id="logicDeleteNewsPicById" parameterType="Long">
        update t_news_pic
            set delFlag = '1'
        where id = #{id}
    </update>

    <update id="logicDeleteNewsPicByIds" parameterType="String">
        update t_news_pic
        set delFlag = '1'
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <update id="logicDeleteNewsPicByCondition" parameterType="NewsPic">
        update t_news_pic
        set delFlag = '1'
        <where>
            <if test="newsUrl != null  and newsUrl != ''"> and newsUrl = #{newsUrl}</if>
            <if test="newsId != null "> and newsId = #{newsId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>