<?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.post.mapper.PostNewsMapper">

    <resultMap type="PostNews" id="PostNewsResult">
        <result property="newsId"    column="news_id"    />
        <result property="newsTitle"    column="news_title"    />
        <result property="newsContent"    column="news_content"    />
        <result property="status"    column="STATUS"    />
        <result property="publisherId"    column="publisher_id"    />
        <result property="publisherBy"    column="publisher_by"    />
        <result property="userId"    column="user_id"    />
<!--        <result property="userPhone"    column="user_phone"    />-->
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectPostNewsVo">
        select news_id, news_title, cast(news_content as char) as news_content, STATUS, publisher_id, publisher_by, user_id, user_phone, create_by, create_time, update_by, update_time, remark from post_news
    </sql>

    <select id="selectPostNewsList" parameterType="PostNews" resultMap="PostNewsResult">
        <include refid="selectPostNewsVo"/>
        <where>
            <if test="newsTitle != null and newsTitle != ''">
                AND news_title like concat('%', #{newsTitle}, '%')
            </if>
        </where>
    </select>

    <select id="selectPostNewsByNewsId" parameterType="Integer" resultMap="PostNewsResult">
        <include refid="selectPostNewsVo"/>
        where news_id = #{newsId}
    </select>

    <insert id="insertPostNews" parameterType="PostNews" useGeneratedKeys="true" keyProperty="newsId">
        insert into post_news
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="newsTitle != null and newsTitle != ''">news_title,</if>
            <if test="newsContent != null">news_content,</if>
            <if test="status != null">STATUS,</if>
            <if test="publisherId != null">publisher_id,</if>
            <if test="publisherBy != null">publisher_by,</if>
            <if test="userId != null">user_id,</if>
            <if test="userPhone != null and userPhone != ''">user_phone,</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="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="newsTitle != null and newsTitle != ''">#{newsTitle},</if>
            <if test="newsContent != null">#{newsContent},</if>
            <if test="status != null">#{status},</if>
            <if test="publisherId != null">#{publisherId},</if>
            <if test="publisherBy != null">#{publisherBy},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userPhone != null and userPhone != ''">#{userPhone},</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="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updatePostNews" parameterType="PostNews">
        update post_news
        <trim prefix="SET" suffixOverrides=",">
            <if test="newsTitle != null and newsTitle != ''">news_title = #{newsTitle},</if>
            <if test="newsContent != null">news_content = #{newsContent},</if>
            <if test="status != null">STATUS = #{status},</if>
            <if test="publisherId != null">publisher_id = #{publisherId},</if>
            <if test="publisherBy != null">publisher_by = #{publisherBy},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userPhone != null and userPhone != ''">user_phone = #{userPhone},</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="remark != null">remark = #{remark},</if>
        </trim>
        where news_id = #{newsId}
    </update>

    <delete id="deletePostNewsByNewsId" parameterType="Integer">
        delete from post_news where news_id = #{newsId}
    </delete>

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

    <select id="selectViewDetails" parameterType="Integer" resultMap="PostNewsResult">
        select news_title,create_time,news_content from post_news where news_id = #{newsId}
    </select>

    <select id="checkContentUnique" parameterType="String" resultMap="PostNewsResult">
        select news_id, news_content from post_news where news_content = #{newsContent} limit 1
    </select>

    <select id="checkTitleUnique" parameterType="String" resultMap="PostNewsResult">
        select news_id, news_title from post_news where news_title = #{newsTitle} limit 1
    </select>
</mapper>