<?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.vetti.hotake.mapper.HotakeSecuritySecurityLogsMapper">
    
    <resultMap type="HotakeSecuritySecurityLogs" id="HotakeSecuritySecurityLogsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventDescription"    column="event_description"    />
        <result property="ipAddress"    column="ip_address"    />
        <result property="userAgent"    column="user_agent"    />
        <result property="location"    column="location"    />
        <result property="status"    column="status"    />
        <result property="metadata"    column="metadata"    />
        <result property="delFlag"    column="del_flag"    />
        <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="selectHotakeSecuritySecurityLogsVo">
        select id, user_id, event_type, event_description, ip_address, user_agent, 
               location, status, metadata,
               del_flag, create_by, create_time, update_by, update_time, remark 
        from hotake_security_security_logs
    </sql>

    <select id="selectHotakeSecuritySecurityLogsList" parameterType="HotakeSecuritySecurityLogs" resultMap="HotakeSecuritySecurityLogsResult">
        <include refid="selectHotakeSecuritySecurityLogsVo"/>
        <where>
            del_flag = '0'
            <if test="userId != null"> and user_id = #{userId}</if>
            <if test="eventType != null and eventType != ''"> and event_type = #{eventType}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectHotakeSecuritySecurityLogsById" parameterType="Long" resultMap="HotakeSecuritySecurityLogsResult">
        <include refid="selectHotakeSecuritySecurityLogsVo"/>
        where id = #{id} and del_flag = '0'
    </select>
        
    <insert id="insertHotakeSecuritySecurityLogs" parameterType="HotakeSecuritySecurityLogs" useGeneratedKeys="true" keyProperty="id">
        insert into hotake_security_security_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="eventType != null">event_type,</if>
            <if test="eventDescription != null">event_description,</if>
            <if test="ipAddress != null">ip_address,</if>
            <if test="userAgent != null">user_agent,</if>
            <if test="location != null">location,</if>
            <if test="status != null">status,</if>
            <if test="metadata != null">metadata,</if>
            <if test="delFlag != null">del_flag,</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="userId != null">#{userId},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="eventDescription != null">#{eventDescription},</if>
            <if test="ipAddress != null">#{ipAddress},</if>
            <if test="userAgent != null">#{userAgent},</if>
            <if test="location != null">#{location},</if>
            <if test="status != null">#{status},</if>
            <if test="metadata != null">#{metadata},</if>
            <if test="delFlag != null">#{delFlag},</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="updateHotakeSecuritySecurityLogs" parameterType="HotakeSecuritySecurityLogs">
        update hotake_security_security_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="eventDescription != null">event_description = #{eventDescription},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</if>
            <if test="userAgent != null">user_agent = #{userAgent},</if>
            <if test="location != null">location = #{location},</if>
            <if test="status != null">status = #{status},</if>
            <if test="metadata != null">metadata = #{metadata},</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 id = #{id}
    </update>

    <delete id="deleteHotakeSecuritySecurityLogsById" parameterType="Long">
        update hotake_security_security_logs set del_flag = '2' where id = #{id}
    </delete>

    <delete id="deleteHotakeSecuritySecurityLogsByIds" parameterType="String">
        update hotake_security_security_logs set del_flag = '2' where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
