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

    <resultMap type="com.ruoyi.system.domain.CpsUsrContentRel" id="CpsUsrContentRelResult">
        <result property="id" column="id"/>
        <result property="openId" column="open_id"/>
        <result property="contentId" column="content_id"/>
        <result property="contentTitle" column="content_title"/>
        <result property="thumbnail" column="thumbnail"/>
        <result property="collectFlag" column="collect_flag"/>
        <result property="likeFlag" column="like_flag"/>
        <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="selectCpsUsrContentRelVo">
        select id,
               open_id,
               content_id,
               content_title,
               thumbnail,
               collect_flag,
               like_flag,
               update_time,
               create_time,
               create_by,
               update_by
        from cps_usr_content_rel
    </sql>

    <select id="selectCpsUsrContentRelList" parameterType="com.ruoyi.system.domain.CpsUsrContentRel"
            resultMap="CpsUsrContentRelResult">
        <include refid="selectCpsUsrContentRelVo"/>
        <where>
            <if test="openId != null  and openId != ''">and open_id = #{openId}</if>
            <if test="contentId != null ">and content_id = #{contentId}</if>
            <if test="contentTitle != null  and contentTitle != ''">and content_title = #{contentTitle}</if>
            <if test="thumbnail != null  and thumbnail != ''">and thumbnail = #{thumbnail}</if>
            <if test="collectFlag != null  and collectFlag != ''">and collect_flag = #{collectFlag}</if>
            <if test="likeFlag != null  and likeFlag != ''">and like_flag = #{likeFlag}</if>
        </where>
    </select>

    <select id="selectCpsUsrContentRelById" parameterType="Long" resultMap="CpsUsrContentRelResult">
        <include refid="selectCpsUsrContentRelVo"/>
        where id = #{id}
    </select>

    <insert id="insertCpsUsrContentRel" parameterType="com.ruoyi.system.domain.CpsUsrContentRel">
        insert into cps_usr_content_rel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="openId != null">open_id,</if>
            <if test="contentId != null">content_id,</if>
            <if test="contentTitle != null">content_title,</if>
            <if test="thumbnail != null">thumbnail,</if>
            <if test="collectFlag != null">collect_flag,</if>
            <if test="likeFlag != null">like_flag,</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="id != null">#{id},</if>
            <if test="openId != null">#{openId},</if>
            <if test="contentId != null">#{contentId},</if>
            <if test="contentTitle != null">#{contentTitle},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="collectFlag != null">#{collectFlag},</if>
            <if test="likeFlag != null">#{likeFlag},</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>
    <insert id="insertOrUpdateCpsUsrContent" parameterType="com.ruoyi.system.domain.CpsUsrContentRel">
        insert into cps_usr_content_rel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="openId != null">open_id,</if>
            <if test="contentId != null">content_id,</if>
            <if test="contentTitle != null">content_title,</if>
            <if test="thumbnail != null">thumbnail,</if>
            <if test="collectFlag != null">collect_flag,</if>
            <if test="likeFlag != null">like_flag,</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="id != null">#{id},</if>
            <if test="openId != null">#{openId},</if>
            <if test="contentId != null">#{contentId},</if>
            <if test="contentTitle != null">#{contentTitle},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="collectFlag != null">#{collectFlag},</if>
            <if test="likeFlag != null">#{likeFlag},</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>
        <trim prefix="ON DUPLICATE KEY UPDATE " suffixOverrides=",">
            <if test="contentTitle != null">content_title = values(content_title),</if>
            <if test="thumbnail != null">thumbnail = values(thumbnail),</if>
            <if test="collectFlag != null">collect_flag = values(collect_flag),</if>
            <if test="likeFlag != null">like_flag = values(like_flag),</if>
            update_time = now()
        </trim>
    </insert>
    <update id="updateCpsUsrContentRel" parameterType="com.ruoyi.system.domain.CpsUsrContentRel">
        update cps_usr_content_rel
        <trim prefix="SET" suffixOverrides=",">
            <if test="openId != null">open_id = #{openId},</if>
            <if test="contentId != null">content_id = #{contentId},</if>
            <if test="contentTitle != null">content_title = #{contentTitle},</if>
            <if test="thumbnail != null">thumbnail = #{thumbnail},</if>
            <if test="collectFlag != null">collect_flag = #{collectFlag},</if>
            <if test="likeFlag != null">like_flag = #{likeFlag},</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>

    <delete id="deleteCpsUsrContentRelById" parameterType="Long">
        delete
        from cps_usr_content_rel
        where id = #{id}
    </delete>

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