<?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.ics.system.mapper.OperLogMapper">

	<resultMap type="com.ics.system.domain.OperLog" id="SysOperLogResult">
		<id     property="id"         	  column="id"        	  />
		<result property="title"          column="title"          />
		<result property="businessType"   column="business_type"  />
		<result property="method"         column="method"         />
		<result property="requestMethod"  column="request_method" />
		<result property="operatorType"   column="operator_type"  />
		<result property="operName"       column="oper_name"      />
		<result property="deptName"       column="dept_name"      />
		<result property="operUrl"        column="oper_url"       />
		<result property="operIp"         column="oper_ip"        />
		<result property="operLocation"   column="oper_location"  />
		<result property="operParam"      column="oper_param"     />
		<result property="status"         column="status"         />
		<result property="errorMsg"       column="error_msg"      />
		<result property="operTime"       column="oper_time"      />
	</resultMap>

	<sql id="selectOperLogVo">
        SELECT id,
			   title,
			   business_type,
			   method,
			   request_method,
			   operator_type,
			   oper_name,
			   dept_name,
			   oper_url,
			   oper_ip,
			   oper_location,
			   oper_param,
			   status,
			   error_msg,
			   oper_time
		FROM sys_oper_log
    </sql>
    
	<insert id="insertOperlog" parameterType="com.ics.system.domain.OperLog">
		INSERT INTO sys_oper_log(
			title,
			business_type,
			method,
			request_method,
			operator_type,
			oper_name,
			dept_name,
			oper_url,
			oper_ip,
			oper_location,
			oper_param,
			status,
			error_msg,
			oper_time
		) VALUES (
			#{title},
			#{businessType},
			#{method},
			#{requestMethod},
			#{operatorType},
			#{operName},
			#{deptName},
			#{operUrl},
			#{operIp},
			#{operLocation},
			#{operParam},
			#{status},
			#{errorMsg},
			sysdate()
		)
	</insert>
	
	<select id="selectOperLogList" parameterType="com.ics.system.domain.OperLog" resultMap="SysOperLogResult">
		<include refid="selectOperLogVo"/>
		<where>
			<if test="title != null and title != ''">
				AND title LIKE concat('%', #{title}, '%')
			</if>
			<if test="businessType != null">
				AND business_type = #{businessType}
			</if>
			<if test="status != null">
				AND status = #{status}
			</if>
			<if test="operName != null and operName != ''">
				AND oper_name LIKE concat('%', #{operName}, '%')
			</if>
			<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
				AND date_format(oper_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
			</if>
			<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
				AND date_format(oper_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
			</if>
		</where>
	</select>
	
	<delete id="deleteOperLogByIds" parameterType="String">
 		DELETE FROM sys_oper_log WHERE id IN
 		<foreach collection="array" item="id" open="(" separator="," close=")">
 			#{id}
        </foreach> 
 	</delete>
 	
 	<select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult">
		<include refid="selectOperLogVo"/>
		WHERE id = #{id}
	</select>
	
	<update id="cleanOperLog">
        TRUNCATE TABLE sys_oper_log
    </update>

</mapper> 