<?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.hzs.system.sys.mapper.SysOperationLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.sys.SysOperationLog">
        <id column="PK_ID" property="pkId"/>
        <result column="USER_ID" property="userId"/>
        <result column="OPERATION_TIME" property="operationTime"/>
        <result column="OPERATION_MODULE" property="operationModule"/>
        <result column="OPERATION_METHOD" property="operationMethod"/>
        <result column="OPERATION_PARAM" property="operationParam"/>
        <result column="IPADDR" property="ipaddr"/>
        <result column="URI" property="uri"/>
        <result column="REMARK" property="remark"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
    </resultMap>

    <!-- 插入日志 -->
    <insert id="insertLog">
        insert into SYS_OPERATION_LOG
        (PK_ID,
         USER_ID,
         OPERATION_MODULE,
         OPERATION_BUSINESS,
         OPERATION_METHOD,
         OPERATION_PARAM,
         IPADDR,
         URI,
         REMARK,
         PK_COUNTRY,
         OPERATION_RESULT)
        values (SYS_OPERATION_LOG_SEQ.nextval,
                #{param.userId},
                #{param.operationModule},
                #{param.operationBusiness},
                #{param.operationMethod},
                #{param.operationParam},
                #{param.ipaddr},
                #{param.uri},
                #{param.remark},
                #{param.pkCountry},
                #{param.operationResult, jdbcType=VARCHAR})
    </insert>

    <!-- 查询列表 -->
    <select id="queryList" resultType="com.hzs.common.domain.system.sys.ext.SysOperationLogExt">
        select
        sol.pk_id,
        sol.operation_time,
        sol.operation_module,
        sol.operation_method,
        sol.operation_business,
        sol.operation_param,
        sol.ipaddr,
        sol.operation_result,
        su.user_name
        from SYS_OPERATION_LOG sol
        inner join sys_user su
        on su.user_id = sol.user_id
        where sol.pk_country = #{pkCountry}
        and sol.DEL_FLAG=0
        <if test="param.ipAddr != null and param.ipAddr != ''">
            and su.IPADDR = #{param.ipAddr}
        </if>
        <if test="param.userName != null and param.userName != ''">
            and su.USER_NAME like #{param.userName} || '%'
        </if>
        <if test="param.operationModule != null and param.operationModule != ''">
            and sol.OPERATION_MODULE = #{param.operationModule}
        </if>
        <if test="param.operationMethod != null and param.operationMethod != ''">
            and sol.OPERATION_METHOD = #{param.operationMethod}
        </if>
        <if test="param.operationTime != null">
            and sol.OPERATION_TIME >= #{param.operationTime[0]}
            and #{param.operationTime[1]} >= sol.OPERATION_TIME
        </if>
        <if test="param.userId != null">
            and sol.user_id = #{param.userId}
        </if>
        order by sol.operation_time desc
    </select>


<!--    批量删除操作日志-->
    <update id="delBatchSyslog">
        update SYS_OPERATION_LOG set del_flag = 1, modified_time = sysdate, PK_MODIFIED = #{syslog.pkModified}
        where pk_id in
        <foreach collection="syslog.pkIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>

</mapper>
