<?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.ym.mec.common.log.dal.dao.AuditLogDao">
	<resultMap id="BaseResultMap" type="com.ym.mec.common.log.dal.model.AuditLog">
		<id column="id_" property="id" jdbcType="BIGINT" />
		<result column="username_" property="username" jdbcType="VARCHAR" />
		<result column="operate_name_" property="operateName" jdbcType="VARCHAR" />
		<result column="interface_url_" property="interfaceUrl"
			jdbcType="VARCHAR" />
		<result column="operate_time_" property="operateTime" jdbcType="TIMESTAMP" />
		<result column="input_params_" property="inputParams" jdbcType="LONGVARCHAR" />
		<result column="user_ip_" property="userIp" jdbcType="VARCHAR" />
	</resultMap>

	<sql id="Base_Column_List">
		id_, username_, operate_name_,
		interface_url_,input_params_,
		operate_time_, user_ip_
	</sql>

	<sql id="queryCondition">
		<where>
			<if test="operateName != null">
				and operate_name_ = #{operateName}
			</if>
			<if test="username != null">
				and username_ = #{username}
			</if>
			<if test="inputParams != null">
				and input_params_ like '%' #{inputParams} '%' 
			</if>
			<if test="startDate != null">
				and operate_time_ &gt;= #{startDate}
			</if>
			<if test="endDate != null">
				and operate_time_ &lt;= #{endDate}
			</if>
		</where>
	</sql>

	<select id="get" resultMap="BaseResultMap" parameterType="java.lang.Long">
		select
		<include refid="Base_Column_List" />
		from sys_audit_log
		where id_ = #{id,jdbcType=BIGINT}
	</select>

	<delete id="delete" parameterType="java.lang.Long">
		delete from
		sys_audit_log
		where
		id_ = #{id,jdbcType=BIGINT}
	</delete>
	<insert id="insert" parameterType="com.ym.mec.common.log.dal.model.AuditLog">
		insert into sys_audit_log
		(id_, username_, operate_name_,
		interface_url_,
		input_params_,operate_time_,
		user_ip_)
		values
		(#{id,jdbcType=BIGINT},
		#{username,jdbcType=VARCHAR},
		#{operateName,jdbcType=VARCHAR},
		#{interfaceUrl,jdbcType=VARCHAR},
		#{inputParams,jdbcType=LONGVARCHAR},
		#{operateTime,jdbcType=TIMESTAMP},
		#{userIp,jdbcType=VARCHAR})
	</insert>

	<update id="update" parameterType="com.ym.mec.common.log.dal.model.AuditLog">
		update sys_audit_log
		<set>
			<if test="username != null">
				username_ = #{username,jdbcType=VARCHAR},
			</if>
			<if test="operateName != null">
				operate_name_ = #{operateName,jdbcType=VARCHAR},
			</if>
			<if test="interfaceUrl != null">
				interface_url_ = #{interfaceUrl,jdbcType=VARCHAR},
			</if>
			<if test="operateTime != null">
				operate_time_ = #{operateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="userIp != null">
				user_ip_ = #{userIp,jdbcType=VARCHAR},
			</if>
			<if test="inputParams != null">
				input_params_ = #{inputParams,jdbcType=LONGVARCHAR},
			</if>
		</set>
		where id_ = #{id,jdbcType=BIGINT}
	</update>

	<select id="queryCount" parameterType="map" resultType="int">
		select count(*) from sys_audit_log
		<include refid="queryCondition" />
	</select>

	<select id="queryPage" parameterType="map" resultMap="BaseResultMap">
		select * from sys_audit_log
		<include refid="queryCondition" />
		order by operate_time_ desc
		<include refid="global.limit" />
	</select>

</mapper>