<?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.frequency.worklike.mapper.WorkLikeMapper">
    
    <resultMap type="com.ruoyi.frequency.worklike.entity.WorkLike" id="WorkLikeResult">
        <result property="id"    column="id"    />
        <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="delFlag"    column="del_flag"    />
        <result property="type"    column="type"    />
        <result property="userType"    column="user_type"    />
        <result property="userId"    column="user_id"    />
        <result property="workId"    column="work_id"    />
    </resultMap>

    <sql id="selectWorkLikeVo">
        select id, create_by, create_time, update_by, update_time, del_flag, type, user_type, user_id, work_id from t_work_like
    </sql>

    <select id="selectWorkLikeList" parameterType="com.ruoyi.frequency.worklike.entity.WorkLike" resultMap="WorkLikeResult">
        <include refid="selectWorkLikeVo"/>
        <where>  
            <if test="type != null "> and type = #{type}</if>
            <if test="userType != null "> and user_type = #{userType}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="workId != null "> and work_id = #{workId}</if>
        </where>
    </select>
    
    <select id="selectWorkLikeById" parameterType="Long" resultMap="WorkLikeResult">
        <include refid="selectWorkLikeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWorkLike" parameterType="com.ruoyi.frequency.worklike.entity.WorkLike">
        insert into t_work_like
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="delFlag != null">del_flag,</if>
            <if test="type != null">type,</if>
            <if test="userType != null">user_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="workId != null">work_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="delFlag != null">#{delFlag},</if>
            <if test="type != null">#{type},</if>
            <if test="userType != null">#{userType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="workId != null">#{workId},</if>
         </trim>
    </insert>

    <update id="updateWorkLike" parameterType="com.ruoyi.frequency.worklike.entity.WorkLike">
        update t_work_like
        <trim prefix="SET" suffixOverrides=",">
            <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="delFlag != null">del_flag = #{delFlag},</if>
            <if test="type != null">type = #{type},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="workId != null">work_id = #{workId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkLikeById" parameterType="Long">
        delete from t_work_like where id = #{id}
    </delete>

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

    <update id="workLike" parameterType="com.ruoyi.controller.req.WorksLikeReq">
        insert into t_work_like
        (id, create_by, create_time, update_by, update_time, type, user_type, user_id, work_id)
        values
            (#{req.id},#{req.updateBy},#{req.updateTime},#{req.updateBy},#{req.updateTime},#{req.type},#{userVo.userType}, #{userVo.userId}, #{req.workId})
        ON DUPLICATE  KEY UPDATE
                              del_flag = IF( del_flag = 1, 3, 1 ),
                              update_time = #{req.updateTime},
                              update_by = #{req.updateBy};
    </update>
</mapper>