<?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.kmall.common.dao.SysLogDao">

	<select id="queryObject" resultType="com.kmall.common.entity.SysLogEntity">
		select * from sys_log where id = #{value}
	</select>

	<select id="queryList" resultType="com.kmall.common.entity.SysLogEntity">
		select * from sys_log
		<where>
			<if test="key != null and key.trim() != ''">
				and `username` like concat('%',#{key},'%') or `operation` like concat('%',#{key},'%')
			</if>
			<if test="operation != null and operation.trim() != ''">
				`operation` like concat('%',#{operation},'%')
			</if>
		</where>
		order by create_date desc
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from sys_log
		<where>
			<if test="key != null and key.trim() != ''">
                `username` like concat('%',#{key},'%') or `operation` like concat('%',#{key},'%')
			</if>
			<if test="operation != null and operation.trim() != ''">
				and `operation` like concat('%',#{operation},'%')
			</if>
		</where>
	</select>
	 
	<insert id="save" parameterType="com.kmall.common.entity.SysLogEntity" useGeneratedKeys="true" keyProperty="id">
		insert into sys_log
		(
			`username`, 
			`operation`, 
			`method`, 
			`params`, 
			`ip`, 
			`create_date`
		)
		values
		(
			#{username}, 
			#{operation}, 
			#{method}, 
			#{params}, 
			#{ip}, 
			#{createDate}
		)
	</insert>
	 
	<update id="update" parameterType="com.kmall.common.entity.SysLogEntity">
		update sys_log 
		<set>
			<if test="username != null">`username` = #{username}, </if>
			<if test="operation != null">`operation` = #{operation}, </if>
			<if test="method != null">`method` = #{method}, </if>
			<if test="params != null">`params` = #{params}, </if>
			<if test="ip != null">`ip` = #{ip} </if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from sys_log where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from sys_log where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>