<?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.goldenwater.slgc.mapper.CmsArticleMapper">

    <resultMap type="CmsArticle" id="CmsArticleResult">
        <result property="aid" column="AID"/>
        <result property="bizDept" column="BIZ_DEPT"/>
        <result property="cateId" column="CATE_ID"/>
        <result property="title" column="TITLE"/>
        <result property="subtitle" column="SUBTITLE"/>
        <result property="keyword" column="KEYWORD"/>
        <result property="isImage" column="IS_IMAGE"/>
        <result property="thumbnail" column="THUMBNAIL"/>
        <result property="source" column="SOURCE"/>
        <result property="summary" column="SUMMARY"/>
        <result property="status" column="STATUS"/>
        <result property="pubUser" column="PUB_USER"/>
        <result property="pubDate" column="PUB_DATE"/>
        <result property="dueDate" column="DUE_DATE"/>
        <result property="auditUser" column="AUDIT_USER"/>
        <result property="auditDate" column="AUDIT_DATE"/>
        <result property="isTop" column="IS_TOP"/>
        <result property="isDel" column="IS_DEL"/>
        <result property="isComment" column="IS_COMMENT"/>
        <result property="viewCount" column="VIEW_COUNT"/>
        <result property="commentCount" column="COMMENT_COUNT"/>
        <result property="content" column="CONTENT" jdbcType="LONGVARCHAR"/>
        <result property="pubPlatform" column="PUB_PLATFORM"/>
        <result property="titleColor" column="TITLE_COLOR"/>
        <result property="type" column="TYPE"/>
    </resultMap>

    <sql id="selectCmsArticleVo">
        select AID, BIZ_DEPT, CATE_ID, TITLE, SUBTITLE, KEYWORD, IS_IMAGE, THUMBNAIL,
               SOURCE, SUMMARY, STATUS, PUB_USER, PUB_DATE, DUE_DATE, AUDIT_USER,
               AUDIT_DATE, IS_TOP, IS_DEL, IS_COMMENT, VIEW_COUNT, COMMENT_COUNT,
               CONTENT, PUB_PLATFORM, TITLE_COLOR, TYPE
        from BIZ_CMS_ARTICLE
    </sql>

    <select id="selectCmsArticleList" parameterType="CmsArticle" resultMap="CmsArticleResult">
        <include refid="selectCmsArticleVo"/>
        <where>
            <if test="title != null and title != ''">
                and TITLE like concat('%', #{title}, '%')
            </if>
            <if test="cateId != null and cateId != ''">
                and CATE_ID = #{cateId}
            </if>
            <if test="keyword != null and keyword != ''">
                and KEYWORD like concat('%', #{keyword}, '%')
            </if>
            <if test="status != null and status != ''">
                and STATUS = #{status}
            </if>
            <if test="bizDept != null and bizDept != ''">
                and BIZ_DEPT = #{bizDept}
            </if>
            <if test="type != null and type != ''">
                and TYPE = #{type}
            </if>
        </where>
        order by PUB_DATE desc
    </select>

    <select id="selectCmsArticleById" parameterType="String" resultMap="CmsArticleResult">
        <include refid="selectCmsArticleVo"/>
        where AID = #{aid}
    </select>

    <delete id="deleteCmsArticleById" parameterType="String">
        delete from BIZ_CMS_ARTICLE where AID = #{aid}
    </delete>

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

    <insert id="insertCmsArticle" parameterType="CmsArticle">
        insert into BIZ_CMS_ARTICLE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="aid != null">AID,</if>
            <if test="bizDept != null">BIZ_DEPT,</if>
            <if test="cateId != null">CATE_ID,</if>
            <if test="title != null">TITLE,</if>
            <if test="subtitle != null">SUBTITLE,</if>
            <if test="keyword != null">KEYWORD,</if>
            <if test="isImage != null">IS_IMAGE,</if>
            <if test="thumbnail != null">THUMBNAIL,</if>
            <if test="source != null">SOURCE,</if>
            <if test="summary != null">SUMMARY,</if>
            <if test="status != null">STATUS,</if>
            <if test="pubUser != null">PUB_USER,</if>
            <if test="pubDate != null">PUB_DATE,</if>
            <if test="dueDate != null">DUE_DATE,</if>
            <if test="auditUser != null">AUDIT_USER,</if>
            <if test="auditDate != null">AUDIT_DATE,</if>
            <if test="isTop != null">IS_TOP,</if>
            <if test="isDel != null">IS_DEL,</if>
            <if test="isComment != null">IS_COMMENT,</if>
            <if test="viewCount != null">VIEW_COUNT,</if>
            <if test="commentCount != null">COMMENT_COUNT,</if>
            <if test="content != null">CONTENT,</if>
            <if test="pubPlatform != null">PUB_PLATFORM,</if>
            <if test="titleColor != null">TITLE_COLOR,</if>
            <if test="type != null">TYPE,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="aid != null">#{aid},</if>
            <if test="bizDept != null">#{bizDept},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="title != null">#{title},</if>
            <if test="subtitle != null">#{subtitle},</if>
            <if test="keyword != null">#{keyword},</if>
            <if test="isImage != null">#{isImage},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="source != null">#{source},</if>
            <if test="summary != null">#{summary},</if>
            <if test="status != null">#{status},</if>
            <if test="pubUser != null">#{pubUser},</if>
            <if test="pubDate != null">#{pubDate},</if>
            <if test="dueDate != null">#{dueDate},</if>
            <if test="auditUser != null">#{auditUser},</if>
            <if test="auditDate != null">#{auditDate},</if>
            <if test="isTop != null">#{isTop},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="isComment != null">#{isComment},</if>
            <if test="viewCount != null">#{viewCount},</if>
            <if test="commentCount != null">#{commentCount},</if>
            <if test="content != null">#{content, jdbcType=LONGVARCHAR},</if>
            <if test="pubPlatform != null">#{pubPlatform},</if>
            <if test="titleColor != null">#{titleColor},</if>
            <if test="type != null">#{type},</if>
        </trim>
    </insert>

    <update id="updateCmsArticle" parameterType="CmsArticle">
        update BIZ_CMS_ARTICLE
        <trim prefix="SET" suffixOverrides=",">
            <if test="bizDept != null">BIZ_DEPT = #{bizDept},</if>
            <if test="cateId != null">CATE_ID = #{cateId},</if>
            <if test="title != null">TITLE = #{title},</if>
            <if test="subtitle != null">SUBTITLE = #{subtitle},</if>
            <if test="keyword != null">KEYWORD = #{keyword},</if>
            <if test="isImage != null">IS_IMAGE = #{isImage},</if>
            <if test="thumbnail != null">THUMBNAIL = #{thumbnail},</if>
            <if test="source != null">SOURCE = #{source},</if>
            <if test="summary != null">SUMMARY = #{summary},</if>
            <if test="status != null">STATUS = #{status},</if>
            <if test="pubUser != null">PUB_USER = #{pubUser},</if>
            <if test="pubDate != null">PUB_DATE = #{pubDate},</if>
            <if test="dueDate != null">DUE_DATE = #{dueDate},</if>
            <if test="auditUser != null">AUDIT_USER = #{auditUser},</if>
            <if test="auditDate != null">AUDIT_DATE = #{auditDate},</if>
            <if test="isTop != null">IS_TOP = #{isTop},</if>
            <if test="isDel != null">IS_DEL = #{isDel},</if>
            <if test="isComment != null">IS_COMMENT = #{isComment},</if>
            <if test="viewCount != null">VIEW_COUNT = #{viewCount},</if>
            <if test="commentCount != null">COMMENT_COUNT = #{commentCount},</if>
            <if test="content != null">CONTENT = #{content, jdbcType=LONGVARCHAR},</if>
            <if test="pubPlatform != null">PUB_PLATFORM = #{pubPlatform},</if>
            <if test="titleColor != null">TITLE_COLOR = #{titleColor},</if>
            <if test="type != null">TYPE = #{type},</if>
        </trim>
        where AID = #{aid}
    </update>

    <insert id="batchInsert" parameterType="java.util.List">
        insert into BIZ_CMS_ARTICLE (AID, BIZ_DEPT, CATE_ID, TITLE, SUBTITLE, KEYWORD, IS_IMAGE,
            THUMBNAIL, SOURCE, SUMMARY, STATUS, PUB_USER, PUB_DATE, DUE_DATE, AUDIT_USER,
            AUDIT_DATE, IS_TOP, IS_DEL, IS_COMMENT, VIEW_COUNT, COMMENT_COUNT,
            CONTENT, PUB_PLATFORM, TITLE_COLOR, TYPE)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.aid}, #{item.bizDept}, #{item.cateId}, #{item.title}, #{item.subtitle},
             #{item.keyword}, #{item.isImage}, #{item.thumbnail}, #{item.source},
             #{item.summary}, #{item.status}, #{item.pubUser}, #{item.pubDate},
             #{item.dueDate}, #{item.auditUser}, #{item.auditDate}, #{item.isTop},
             #{item.isDel}, #{item.isComment}, #{item.viewCount}, #{item.commentCount},
             #{item.content, jdbcType=LONGVARCHAR}, #{item.pubPlatform}, #{item.titleColor}, #{item.type})
        </foreach>
    </insert>

    <update id="batchUpdate" parameterType="java.util.List">
        <foreach collection="list" item="item" separator=";">
            update BIZ_CMS_ARTICLE
            <set>
                <if test="item.bizDept != null">BIZ_DEPT = #{item.bizDept},</if>
                <if test="item.cateId != null">CATE_ID = #{item.cateId},</if>
                <if test="item.title != null">TITLE = #{item.title},</if>
                <if test="item.subtitle != null">SUBTITLE = #{item.subtitle},</if>
                <if test="item.keyword != null">KEYWORD = #{item.keyword},</if>
                <if test="item.isImage != null">IS_IMAGE = #{item.isImage},</if>
                <if test="item.thumbnail != null">THUMBNAIL = #{item.thumbnail},</if>
                <if test="item.source != null">SOURCE = #{item.source},</if>
                <if test="item.summary != null">SUMMARY = #{item.summary},</if>
                <if test="item.status != null">STATUS = #{item.status},</if>
                <if test="item.pubUser != null">PUB_USER = #{item.pubUser},</if>
                <if test="item.pubDate != null">PUB_DATE = #{item.pubDate},</if>
                <if test="item.dueDate != null">DUE_DATE = #{item.dueDate},</if>
                <if test="item.auditUser != null">AUDIT_USER = #{item.auditUser},</if>
                <if test="item.auditDate != null">AUDIT_DATE = #{item.auditDate},</if>
                <if test="item.isTop != null">IS_TOP = #{item.isTop},</if>
                <if test="item.isDel != null">IS_DEL = #{item.isDel},</if>
                <if test="item.isComment != null">IS_COMMENT = #{item.isComment},</if>
                <if test="item.viewCount != null">VIEW_COUNT = #{item.viewCount},</if>
                <if test="item.commentCount != null">COMMENT_COUNT = #{item.commentCount},</if>
                <if test="item.content != null">CONTENT = #{item.content, jdbcType=LONGVARCHAR},</if>
                <if test="item.pubPlatform != null">PUB_PLATFORM = #{item.pubPlatform},</if>
                <if test="item.titleColor != null">TITLE_COLOR = #{item.titleColor},</if>
                <if test="item.type != null">TYPE = #{item.type},</if>
            </set>
            where AID = #{item.aid}
        </foreach>
    </update>

    <select id="selectTodayPublishedCount" resultType="int">
        select count(*) from BIZ_CMS_ARTICLE
        where STATUS = '1' and to_char(PUB_DATE, 'yyyy-mm-dd') = to_char(sysdate, 'yyyy-mm-dd')
    </select>

</mapper>
