<?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.aucma.system.mapper.SysPortLogMapper">

    <resultMap type="SysPortLog" id="SysPortLogResult">
            <result property="objId"    column="obj_id"    />
            <result property="factoryCode"    column="factory_code"    />
            <result property="logTitle"    column="log_title"    />
            <result property="logMethod"    column="log_method"    />
            <result property="operationParam"    column="operation_param"    />
            <result property="resultOne"    column="result_one"    />
            <result property="resultTwo"    column="result_two"    />
            <result property="resultThree"    column="result_three"    />
            <result property="errorMsg"    column="error_msg"    />
            <result property="operationUser"    column="operation_user"    />
            <result property="operationTime"    column="operation_time"    />
    </resultMap>

    <sql id="selectSysPortLogVo">
        select obj_id, factory_code, log_title, log_method, operation_param,
               result_one, result_two, result_three, error_msg, operation_user, operation_time from sys_port_log
    </sql>

    <select id="selectSysPortLogList" parameterType="SysPortLog" resultMap="SysPortLogResult">
        <include refid="selectSysPortLogVo"/>
        <where>
            <if test="factoryCode != null  and factoryCode != ''"> and factory_code like concat(concat('%', #{factoryCode}), '%')</if>
            <if test="logTitle != null  and logTitle != ''"> and log_title like concat(concat('%', #{logTitle}), '%')</if>
            <if test="logMethod != null  and logMethod != ''"> and log_method like concat(concat('%', #{logMethod}), '%')</if>
            <if test="operationParam != null  and operationParam != ''"> and operation_param = #{operationParam}</if>
            <if test="resultOne != null  and resultOne != ''"> and result_one = #{resultOne}</if>
            <if test="resultTwo != null  and resultTwo != ''"> and result_two = #{resultTwo}</if>
            <if test="resultThree != null  and resultThree != ''"> and result_three = #{resultThree}</if>
            <if test="errorMsg != null  and errorMsg != ''"> and error_msg = #{errorMsg}</if>
            <if test="operationUser != null  and operationUser != ''"> and operation_user = #{operationUser}</if>
            <if test="params.beginOperationTime != null and params.beginOperationTime != '' and params.endOperationTime != null and params.endOperationTime != ''">
             and operation_time between to_date(#{params.beginOperationTime},'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endOperationTime},'yyyy-mm-dd hh24:mi:ss')</if>
        </where>
        order by operation_time desc
    </select>

    <select id="selectSysPortLogByObjId" parameterType="Long" resultMap="SysPortLogResult">
            <include refid="selectSysPortLogVo"/>
            where obj_id = #{objId}
    </select>

    <insert id="insertSysPortLog" parameterType="SysPortLog">
            <selectKey keyProperty="objId" resultType="long" order="BEFORE">
                SELECT seq_sys_port_log.NEXTVAL as objId FROM DUAL
            </selectKey>
        insert into sys_port_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="objId != null">obj_id,</if>
                <if test="factoryCode != null">factory_code,</if>
                <if test="logTitle != null">log_title,</if>
                <if test="logMethod != null">log_method,</if>
                <if test="operationParam != null">operation_param,</if>
                <if test="resultOne != null">result_one,</if>
                <if test="resultTwo != null">result_two,</if>
                <if test="resultThree != null">result_three,</if>
                <if test="errorMsg != null">error_msg,</if>
                <if test="operationUser != null">operation_user,</if>
                <if test="operationTime != null">operation_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="objId != null">#{objId},</if>
                <if test="factoryCode != null">#{factoryCode},</if>
                <if test="logTitle != null">#{logTitle},</if>
                <if test="logMethod != null">#{logMethod},</if>
                <if test="operationParam != null">#{operationParam},</if>
                <if test="resultOne != null">#{resultOne},</if>
                <if test="resultTwo != null">#{resultTwo},</if>
                <if test="resultThree != null">#{resultThree},</if>
                <if test="errorMsg != null">#{errorMsg},</if>
                <if test="operationUser != null">#{operationUser},</if>
                <if test="operationTime != null">#{operationTime},</if>
        </trim>
    </insert>

    <update id="updateSysPortLog" parameterType="SysPortLog">
        update sys_port_log
        <trim prefix="SET" suffixOverrides=",">
                    <if test="factoryCode != null">factory_code = #{factoryCode},</if>
                    <if test="logTitle != null">log_title = #{logTitle},</if>
                    <if test="logMethod != null">log_method = #{logMethod},</if>
                    <if test="operationParam != null">operation_param = #{operationParam},</if>
                    <if test="resultOne != null">result_one = #{resultOne},</if>
                    <if test="resultTwo != null">result_two = #{resultTwo},</if>
                    <if test="resultThree != null">result_three = #{resultThree},</if>
                    <if test="errorMsg != null">error_msg = #{errorMsg},</if>
                    <if test="operationUser != null">operation_user = #{operationUser},</if>
                    <if test="operationTime != null">operation_time = #{operationTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteSysPortLogByObjId" parameterType="Long">
        delete from sys_port_log where obj_id = #{objId}
    </delete>

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