<?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.CpsContentInfoMapper">

    <resultMap type="com.ruoyi.system.domain.CpsContentInfo" id="CpsContentInfoResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="content" column="content"/>
        <result property="thumbnail" column="thumbnail"/>
        <result property="likeCnt" column="like_cnt"/>
        <result property="collectedCnt" column="collected_cnt"/>
        <result property="contentType" column="content_type"/>
        <result property="deptId" column="dept_id"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectCpsContentInfoVo">
        select id,
               title,
               content,
               thumbnail,
               content_type,
               like_cnt,
               collected_cnt,
               dept_id,
               update_time,
               create_time,
               create_by,
               update_by
        from cps_content_info
    </sql>

    <select id="selectCpsContentInfoList" parameterType="com.ruoyi.system.domain.CpsContentInfo"
            resultMap="CpsContentInfoResult">
        select id, title, thumbnail, content_type,like_cnt, collected_cnt,dept_id, update_time, create_time, create_by,
        update_by from cps_content_info
        <where>
            <if test="title != null  and title != ''">and title like concat('%', #{title}, '%')</if>
            <if test="content != null  and content != ''">and content like concat('%', #{content}, '%')</if>
            <if test="contentType != null ">and content_type = #{contentType}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectCpsContentInfoById" parameterType="Long" resultMap="CpsContentInfoResult">
        <include refid="selectCpsContentInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertCpsContentInfo" parameterType="com.ruoyi.system.domain.CpsContentInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into cps_content_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="thumbnail != null">thumbnail,</if>
            <if test="contentType != null">content_type,</if>
            <if test="dept_id !=null">dept_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="contentType != null">#{contentType},</if>
            <if test="dept_id !=null">#{dept_id},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateCpsContentInfo" parameterType="com.ruoyi.system.domain.CpsContentInfo">
        update cps_content_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="thumbnail != null">thumbnail = #{thumbnail},</if>
            <if test="contentType != null">content_type = #{contentType},</if>
            <if test="deptId !=null">dept_id = #{deptId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateCollectContent" parameterType="java.lang.Long">
        update cps_content_info
        set collected_cnt = collected_cnt + 1,
            update_time   = now()
        where id = #{id}
    </update>
    <update id="updateDisCollectContent" parameterType="java.lang.Long">
        update cps_content_info
        set collected_cnt = collected_cnt - 1,
            update_time   = now()
        where id = #{id}
    </update>
    <update id="updateLikeContent" parameterType="java.lang.Long">
        update cps_content_info
        set like_cnt    = like_cnt + 1,
            update_time = now()
        where id = #{id}
    </update>

    <update id="updateDisLikeContent" parameterType="java.lang.Long">
        update cps_content_info
        set like_cnt    = like_cnt - 1,
            update_time = now()
        where id = #{id}
    </update>

    <delete id="deleteCpsContentInfoById" parameterType="Long">
        delete
        from cps_content_info
        where id = #{id}
    </delete>

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