<?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.system.mapper.NewsMapper">
    
    <resultMap type="News" id="NewsResult">
        <result property="newsId"       column="news_id"       />
        <result property="title"        column="title"         />
        <result property="image"        column="image"         />
        <result property="summary"      column="summary"       />
        <result property="content"      column="content"       />
        <result property="publishTime"  column="publish_time"  />
        <result property="publishBy"    column="publish_by"    />
        <result property="status"       column="status"        />
        <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="selectNewsVo">
        select news_id, title, image, summary, cast(content as char) as content, publish_time, publish_by, status, create_by, create_time, update_by, update_time, remark 
		from news
    </sql>
    
    <select id="selectNewsById" parameterType="Long" resultMap="NewsResult">
        <include refid="selectNewsVo"/>
        where news_id = #{newsId}
    </select>
    
    <select id="selectNewsList" parameterType="News" resultMap="NewsResult">
        <include refid="selectNewsVo"/>
        <where>
			<if test="title != null and title != ''">
				AND title like concat('%', #{title}, '%')
			</if>
			<if test="publishBy != null and publishBy != ''">
				AND publish_by like concat('%', #{publishBy}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''">
				AND date_format(publish_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
			</if>
			<if test="params.endTime != null and params.endTime != ''">
				AND date_format(publish_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
			</if>
		</where>
    </select>
    
    <insert id="insertNews" parameterType="News">
        insert into news (
			<if test="title != null and title != '' ">title, </if>
			<if test="image != null and image != '' ">image, </if>
			<if test="summary != null and summary != '' ">summary, </if>
			<if test="content != null and content != '' ">content, </if>
			<if test="publishTime != null ">publish_time, </if>
			<if test="publishBy != null and publishBy != '' ">publish_by, </if>
			<if test="status != null and status != '' ">status, </if>
			<if test="remark != null and remark != ''">remark,</if>
 			<if test="createBy != null and createBy != ''">create_by,</if>
 			create_time
 		)values(
			<if test="title != null and title != ''">#{title}, </if>
			<if test="image != null and image != ''">#{image}, </if>
			<if test="summary != null and summary != ''">#{summary}, </if>
			<if test="content != null and content != ''">#{content}, </if>
			<if test="publishTime != null">#{publishTime}, </if>
			<if test="publishBy != null and publishBy != ''">#{publishBy}, </if>
			<if test="status != null and status != ''">#{status}, </if>
			<if test="remark != null and remark != ''">#{remark},</if>
 			<if test="createBy != null and createBy != ''">#{createBy},</if>
 			sysdate()
		)
    </insert>
	 
    <update id="updateNews" parameterType="News">
        update news 
        <set>
            <if test="title != null and title != ''">title = #{title}, </if>
            <if test="image != null">image = #{image}, </if>
            <if test="summary != null">summary = #{summary}, </if>
            <if test="content != null">content = #{content}, </if>
            <if test="publishTime != null">publish_time = #{publishTime}, </if>
            <if test="publishBy != null">publish_by = #{publishBy}, </if>
            <if test="status != null and status != ''">status = #{status}, </if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
 			update_time = sysdate()
        </set>
        where news_id = #{newsId}
    </update>
	
    <delete id="deleteNewsById" parameterType="Long">
        delete from news where news_id = #{newsId}
    </delete>
    
    <delete id="deleteNewsByIds" parameterType="Long">
        delete from news where news_id in 
        <foreach item="newsId" collection="array" open="(" separator="," close=")">
            #{newsId}
        </foreach>
    </delete>
    
</mapper>
