<?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.salpa.subject.mapper.OperationLogMapper">

    <resultMap type="com.salpa.subject.domain.MonitorOperationLog" id="MonitorOperationLogResult">
        <id     property="id"            column="id"             />
        <id     property="operatorUserId"            column="operator_user_id"             />
        <result property="operatorUsername"          column="operator_username"           />
        <result property="operatorNickname"   column="operator_nickname"    />
        <result property="operationModule"              column="operation_module"                />
        <result property="operationCode"             column="operation_code"              />
        <result property="operationName"             column="operation_name"              />
        <result property="operationResponse"             column="operation_response"              />
        <result property="success"             column="is_success"              />
        <result property="involvedProjectId"             column="involved_project_id"              />
        <result property="createAt"             column="create_at"              />
    </resultMap>

    <insert id="addOperationLog" parameterType="MonitorOperationLog" useGeneratedKeys="true" keyProperty="id">
        insert into monitor_operation_log(
        <if test="operatorUserId != null">operator_user_id,</if>
        <if test="operatorUsername != null and operatorUsername != ''">operator_username,</if>
        <if test="operatorNickname != null and operatorNickname != ''">operator_nickname,</if>
        <if test="operationModule != null and operationModule != ''">operation_module,</if>
        <if test="operationCode != null and operationCode != ''">operation_code,</if>
        <if test="operationName != null and operationName != ''">operation_name,</if>
        <if test="operationResponse != null and operationResponse != ''">operation_response,</if>
        is_success,
        <if test="involvedProjectId != null">involved_project_id</if>
        )values(
        <if test="operatorUserId != null">#{operatorUserId},</if>
        <if test="operatorUsername != null and operatorUsername != ''">#{operatorUsername},</if>
        <if test="operatorNickname != null and operatorNickname != ''">#{operatorNickname},</if>
        <if test="operationModule != null and operationModule != ''">#{operationModule},</if>
        <if test="operationCode != null and operationCode != ''">#{operationCode},</if>
        <if test="operationName != null and operationName != ''">#{operationName},</if>
        <if test="operationResponse != null and operationResponse != ''">#{operationResponse},</if>
        #{success},
        <if test="involvedProjectId != null">#{involvedProjectId}</if>
        )
    </insert>

    <select id="getList" resultMap="MonitorOperationLogResult">
        SELECT id,operator_user_id,operator_username,operator_nickname,operation_module,operation_code,operation_name,operation_response,is_success,involved_project_id,create_at
        FROM monitor_operation_log WHERE involved_project_id = #{projectId}
    </select>
</mapper>