<?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.bootdo.common.dao.LogDao">

	<select id="get" resultType="com.bootdo.common.domain.LogDO">
		select `id`,`user_id`,`username`,`operation`,`time`,`method`,`params`,`ip`,`gmt_create` from sys_log where id = #{value}
	</select>

	<select id="list" resultType="com.bootdo.common.domain.LogDO">
		select `id`,`user_id`,`username`,`operation`,`time`,`method`,`params`,`ip`,`gmt_create` from sys_log
        <where>  
		  		  <if test="id != null and id != ''"> and id = #{id} </if>
		  		  <if test="userId != null and userId != ''"> and user_id = #{userId} </if>
		  		  <if test="username != null and username != ''"> and username = #{username} </if>
		  		  <if test="operation != null and operation != ''"> and operation = #{operation} </if>
		  		  <if test="time != null and time != ''"> and time = #{time} </if>
		  		  <if test="method != null and method != ''"> and method = #{method} </if>
		  		  <if test="params != null and params != ''"> and params = #{params} </if>
		  		  <if test="ip != null and ip != ''"> and ip = #{ip} </if>
		  		  <if test="gmtCreate != null and gmtCreate != ''"> and gmt_create = #{gmtCreate} </if>
		  		</where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="count" resultType="int">
		select count(*) from sys_log
		 <where>  
		  		  <if test="id != null and id != ''"> and id = #{id} </if>
		  		  <if test="userId != null and userId != ''"> and user_id = #{userId} </if>
		  		  <if test="username != null and username != ''"> and username = #{username} </if>
		  		  <if test="operation != null and operation != ''"> and operation = #{operation} </if>
		  		  <if test="time != null and time != ''"> and time = #{time} </if>
		  		  <if test="method != null and method != ''"> and method = #{method} </if>
		  		  <if test="params != null and params != ''"> and params = #{params} </if>
		  		  <if test="ip != null and ip != ''"> and ip = #{ip} </if>
		  		  <if test="gmtCreate != null and gmtCreate != ''"> and gmt_create = #{gmtCreate} </if>
		  		</where>
	</select>
	 
	<insert id="save" parameterType="com.bootdo.common.domain.LogDO" useGeneratedKeys="true" keyProperty="id">
		insert into sys_log
		(
			`user_id`, 
			`username`, 
			`operation`, 
			`time`, 
			`method`, 
			`params`, 
			`ip`, 
			`gmt_create`,
			`sys_flag`
		)
		values
		(
			#{userId}, 
			#{username}, 
			#{operation}, 
			#{time}, 
			#{method}, 
			#{params}, 
			#{ip}, 
			#{gmtCreate},
			#{sysFlag}
		)
	</insert>
	 
	<update id="update" parameterType="com.bootdo.common.domain.LogDO">
		update sys_log 
		<set>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="username != null">`username` = #{username}, </if>
			<if test="operation != null">`operation` = #{operation}, </if>
			<if test="time != null">`time` = #{time}, </if>
			<if test="method != null">`method` = #{method}, </if>
			<if test="params != null">`params` = #{params}, </if>
			<if test="ip != null">`ip` = #{ip}, </if>
			<if test="gmtCreate != null">`gmt_create` = #{gmtCreate}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="remove">
		delete from sys_log where id = #{value}
	</delete>
	
	<delete id="batchRemove">
		delete from sys_log where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>