<?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.SysUserLikeMapper">
    
    <resultMap type="SysUserLike" id="SysUserLikeResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="targetId"    column="target_id"    />
        <result property="targetType"    column="target_type"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSysUserLikeVo">
        select id, user_id, target_id, target_type, status, create_time, update_time from sys_user_like
    </sql>

    <select id="selectSysUserLikeList" parameterType="SysUserLike" resultMap="SysUserLikeResult">
        <include refid="selectSysUserLikeVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="targetId != null "> and target_id = #{targetId}</if>
            <if test="targetType != null  and targetType != ''"> and target_type = #{targetType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectSysUserLikeById" parameterType="Long" resultMap="SysUserLikeResult">
        <include refid="selectSysUserLikeVo"/>
        where id = #{id}
    </select>
    <select id="selectSysUserLikeByUserIdAndTargetId" resultType="list" resultMap="SysUserLikeResult">
        select l.*
        from sys_user_like l
        inner join user_work w on l.target_id = w.work_id
        where l.user_id = #{userId}
        order by l.create_time desc

    </select>

    <insert id="insertSysUserLike" parameterType="SysUserLike" useGeneratedKeys="true" keyProperty="id">
        insert into sys_user_like
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="targetId != null">target_id,</if>
            <if test="targetType != null and targetType != ''">target_type,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="targetId != null">#{targetId},</if>
            <if test="targetType != null and targetType != ''">#{targetType},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSysUserLike" parameterType="SysUserLike">
        update sys_user_like
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="targetId != null">target_id = #{targetId},</if>
            <if test="targetType != null and targetType != ''">target_type = #{targetType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysUserLikeById" parameterType="Long">
        delete from sys_user_like where id = #{id}
    </delete>

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