<?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="net.chenlin.dp.modules.sys.dao.SysLogMapper">
	
	<select id="listForPage" resultType="net.chenlin.dp.modules.sys.entity.SysLogEntity">
		SELECT
			id,
			user_id,
			username,
			operation,
			time,
			method,
			params,
			ip,
			gmt_create
		FROM
			sys_log
		<where>
			<if test=" startDate != null and startDate != '' and endDate != null and endDate != '' ">
				AND DATE_FORMAT( gmt_create, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
			</if>
			<if test="username != null and username.trim() != ''">
				AND username LIKE concat('%',#{username},'%')
				OR operation LIKE concat('%',#{username},'%')
			</if>
		</where>
		ORDER BY
			gmt_create DESC
	</select>
	
	<insert id="save">
		INSERT INTO sys_log (
			user_id,
			username,
			operation,
			time,
			method,
			params,
			ip,
			gmt_create
		)
		VALUES (
			#{userId},
			#{username}, 
			#{operation},
			#{time}, 
			#{method}, 
			#{params}, 
			#{ip}, 
			NOW()
		)
	</insert>
	
	<delete id="batchRemove">
		DELETE
		FROM
			sys_log
		WHERE
			id IN
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>
	
	<delete id="batchRemoveAll">
		DELETE
		FROM
			sys_log
	</delete>

</mapper>