<?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.huijy.management.mapper.ContentMapper">

    <resultMap type="Content" id="ContentResult">
        <result property="contentId"    column="content_id"    />
        <result property="serviceInfo"    column="service_info"    />
        <result property="title"    column="title"    />
        <result property="author"    column="author"    />
        <result property="showPictures"    column="show_pictures"    />
        <result property="briefContent"    column="brief_content"    />
        <result property="content"    column="content"    />
        <result property="createTime"    column="create_time"    />
        <result property="createAt"    column="create_at"    />
        <result property="auditFlag"    column="audit_flag"    />
        <result property="auditAt"    column="audit_at"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="auditMsg"    column="audit_msg"    />
        <result property="releaseFlag"    column="release_flag"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="releaseAt"    column="release_at"    />
        <result property="endAuditAt"    column="end_audit_at"    />
        <result property="endAuditTime"    column="end_audit_time"    />
        <result property="endAuditMsg"    column="end_audit_msg"    />
        <result property="browseNum"    column="browse_num"    />
    </resultMap>

    <sql id="selectContentVo">
        select content_id, service_info, title, author, show_pictures, brief_content, content, create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg,browse_num from t_content
    </sql>

    <sql id="selectListContentVo">
        select content_id, service_info, title, author, show_pictures, brief_content,create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg,browse_num from t_content
    </sql>

    <select id="selectContentList" parameterType="Content" resultMap="ContentResult">
        <include refid="selectListContentVo"/>
        <where>
            <if test="serviceInfo != null  and serviceInfo != ''"> and service_info = #{serviceInfo}</if>
            <if test="auditFlag != null  and auditFlag != ''"> and audit_flag = #{auditFlag}</if>
            <if test="releaseFlag != null  and releaseFlag != ''"> and release_flag = #{releaseFlag}</if>
        </where>
        order by audit_flag,release_flag desc ,release_time desc
    </select>

    <select id="selectContentByContentId" parameterType="Long" resultMap="ContentResult">
        <include refid="selectContentVo"/>
        where content_id = #{contentId}
    </select>

    <insert id="insertContent" parameterType="Content" useGeneratedKeys="true" keyProperty="contentId">
        insert into t_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serviceInfo != null">service_info,</if>
            <if test="title != null">title,</if>
            <if test="author != null">author,</if>
            <if test="showPictures != null">show_pictures,</if>
            <if test="briefContent != null">brief_content,</if>
            <if test="content != null">content,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createAt != null">create_at,</if>
            <if test="auditFlag != null">audit_flag,</if>
            <if test="auditAt != null">audit_at,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="auditMsg != null">audit_msg,</if>
            <if test="releaseFlag != null">release_flag,</if>
            <if test="releaseTime != null">release_time,</if>
            <if test="releaseAt != null">release_at,</if>
            <if test="endAuditAt != null">end_audit_at,</if>
            <if test="endAuditTime != null">end_audit_time,</if>
            <if test="endAuditMsg != null">end_audit_msg,</if>
            <if test="browseNum != null">browse_num,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serviceInfo != null">#{serviceInfo},</if>
            <if test="title != null">#{title},</if>
            <if test="author != null">#{author},</if>
            <if test="showPictures != null">#{showPictures},</if>
            <if test="briefContent != null">#{briefContent},</if>
            <if test="content != null">#{content},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="auditFlag != null">#{auditFlag},</if>
            <if test="auditAt != null">#{auditAt},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="auditMsg != null">#{auditMsg},</if>
            <if test="releaseFlag != null">#{releaseFlag},</if>
            <if test="releaseTime != null">#{releaseTime},</if>
            <if test="releaseAt != null">#{releaseAt},</if>
            <if test="endAuditAt != null">#{endAuditAt},</if>
            <if test="endAuditTime != null">#{endAuditTime},</if>
            <if test="endAuditMsg != null">#{endAuditMsg},</if>
            <if test="browseNum != null">#{browseNum},</if>
         </trim>
    </insert>

    <update id="updateContent" parameterType="Content">
        update t_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="serviceInfo != null">service_info = #{serviceInfo},</if>
            <if test="title != null">title = #{title},</if>
            <if test="author != null">author = #{author},</if>
            <if test="showPictures != null">show_pictures = #{showPictures},</if>
            <if test="briefContent != null">brief_content = #{briefContent},</if>
            <if test="content != null">content = #{content},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="auditFlag != null">audit_flag = #{auditFlag},</if>
            <if test="auditAt != null">audit_at = #{auditAt},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="auditMsg != null">audit_msg = #{auditMsg},</if>
            <if test="releaseFlag != null">release_flag = #{releaseFlag},</if>
            <if test="releaseTime != null">release_time = #{releaseTime},</if>
            <if test="releaseAt != null">release_at = #{releaseAt},</if>
            <if test="endAuditAt != null">end_audit_at = #{endAuditAt},</if>
            <if test="endAuditTime != null">end_audit_time = #{endAuditTime},</if>
            <if test="endAuditMsg != null">end_audit_msg = #{endAuditMsg},</if>
            <if test="browseNum != null">browse_num = #{browseNum},</if>
        </trim>
        where content_id = #{contentId}
    </update>

    <delete id="deleteContentByContentId" parameterType="Long">
        delete from t_content where content_id = #{contentId}
    </delete>

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

    <update id="updateBrowseNumById" parameterType="Long">
        update t_content t set t.browse_num = t.browse_num+1 where t.content_id = #{contentId}
    </update>
</mapper>
