<?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.CommunityNewsMapper">
    
    <resultMap type="CommunityNews" id="CommunityNewsResult">
        <result property="communityId"    column="community_id"    />
        <result property="communityTitle"    column="community_title"    />
        <result property="communityType"    column="community_type"    />
        <result property="communityContent"    column="community_content"    />
        <result property="status"    column="status"    />
        <result property="publishTime"    column="publish_time"    />
        <result property="author"    column="author"    />
        <result property="source"    column="source"    />
        <result property="coverImage"    column="cover_image"    />
        <result property="viewCount"    column="view_count"    />
        <result property="isTop"    column="is_top"    />
        <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="selectCommunityNewsVo">
        select community_id, community_title, community_type, community_content, status, publish_time, author, source, cover_image, view_count, is_top, create_by, create_time, update_by, update_time, remark from community_news
    </sql>

    <select id="selectCommunityNewsList" parameterType="CommunityNews" resultMap="CommunityNewsResult">
        <include refid="selectCommunityNewsVo"/>
        <where>  
            <if test="communityTitle != null  and communityTitle != ''"> and community_title = #{communityTitle}</if>
            <if test="communityType != null  and communityType != ''"> and community_type = #{communityType}</if>
            <if test="communityContent != null  and communityContent != ''"> and community_content = #{communityContent}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="publishTime != null "> and publish_time = #{publishTime}</if>
            <if test="author != null  and author != ''"> and author = #{author}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="coverImage != null  and coverImage != ''"> and cover_image = #{coverImage}</if>
            <if test="viewCount != null "> and view_count = #{viewCount}</if>
            <if test="isTop != null  and isTop != ''"> and is_top = #{isTop}</if>
        </where>
    </select>
    
    <select id="selectCommunityNewsByCommunityId" parameterType="Long" resultMap="CommunityNewsResult">
        <include refid="selectCommunityNewsVo"/>
        where community_id = #{communityId}
    </select>

    <insert id="insertCommunityNews" parameterType="CommunityNews" useGeneratedKeys="true" keyProperty="communityId">
        insert into community_news
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="communityTitle != null and communityTitle != ''">community_title,</if>
            <if test="communityType != null and communityType != ''">community_type,</if>
            <if test="communityContent != null">community_content,</if>
            <if test="status != null">status,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="author != null">author,</if>
            <if test="source != null">source,</if>
            <if test="coverImage != null">cover_image,</if>
            <if test="viewCount != null">view_count,</if>
            <if test="isTop != null">is_top,</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="communityTitle != null and communityTitle != ''">#{communityTitle},</if>
            <if test="communityType != null and communityType != ''">#{communityType},</if>
            <if test="communityContent != null">#{communityContent},</if>
            <if test="status != null">#{status},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="author != null">#{author},</if>
            <if test="source != null">#{source},</if>
            <if test="coverImage != null">#{coverImage},</if>
            <if test="viewCount != null">#{viewCount},</if>
            <if test="isTop != null">#{isTop},</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="updateCommunityNews" parameterType="CommunityNews">
        update community_news
        <trim prefix="SET" suffixOverrides=",">
            <if test="communityTitle != null and communityTitle != ''">community_title = #{communityTitle},</if>
            <if test="communityType != null and communityType != ''">community_type = #{communityType},</if>
            <if test="communityContent != null">community_content = #{communityContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
            <if test="author != null">author = #{author},</if>
            <if test="source != null">source = #{source},</if>
            <if test="coverImage != null">cover_image = #{coverImage},</if>
            <if test="viewCount != null">view_count = #{viewCount},</if>
            <if test="isTop != null">is_top = #{isTop},</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 community_id = #{communityId}
    </update>

    <delete id="deleteCommunityNewsByCommunityId" parameterType="Long">
        delete from community_news where community_id = #{communityId}
    </delete>

    <delete id="deleteCommunityNewsByCommunityIds" parameterType="String">
        delete from community_news where community_id in 
        <foreach item="communityId" collection="array" open="(" separator="," close=")">
            #{communityId}
        </foreach>
    </delete>
</mapper>