<?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.suelec.permission.dao.SysLogDao">
  <resultMap id="BaseResultMap" type="com.suelec.permission.pojo.SysLog">
    <result column="id" jdbcType="VARCHAR" property="id" />
    <result column="user_id" jdbcType="VARCHAR" property="userId" />
    <result column="username" jdbcType="VARCHAR" property="username" />
    <result column="operation" jdbcType="VARCHAR" property="operation" />
    <result column="time" jdbcType="INTEGER" property="time" />
    <result column="method" jdbcType="VARCHAR" property="method" />
    <result column="params" jdbcType="VARCHAR" property="params" />
    <result column="ip" jdbcType="VARCHAR" property="ip" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <insert id="insert" parameterType="com.suelec.permission.pojo.SysLog">
    insert into sys_log (id, user_id, username, 
      `operation`, `time`, `method`, 
      params, ip, create_time
      )
    values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, 
      #{operation,jdbcType=VARCHAR}, #{time,jdbcType=INTEGER}, #{method,jdbcType=VARCHAR}, 
      #{params,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR}, #{create_time,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.suelec.permission.pojo.SysLog">
    insert into sys_log
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="username != null">
        username,
      </if>
      <if test="operation != null">
        `operation`,
      </if>
      <if test="time != null">
        `time`,
      </if>
      <if test="method != null">
        `method`,
      </if>
      <if test="params != null">
        params,
      </if>
      <if test="ip != null">
        ip,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="operation != null">
        #{operation,jdbcType=VARCHAR},
      </if>
      <if test="time != null">
        #{time,jdbcType=INTEGER},
      </if>
      <if test="method != null">
        #{method,jdbcType=VARCHAR},
      </if>
      <if test="params != null">
        #{params,jdbcType=VARCHAR},
      </if>
      <if test="ip != null">
        #{ip,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <!-- 分页与条件查询所有数据 -->
  <select id="selectAll" resultType="SysLog" parameterType="com.suelec.permission.vo.req.LogPageReqVo">
    select *
    from sys_log
    <where>
      <if test="operation != null and operation != ''">
        and operation like concat('%',#{operation},'%')
      </if>
      <if test="username != null and username != ''">
        and username like concat('%',#{username},'%')
      </if>
      <if test="startTime != null and startTime != ''">
        and create_time &gt;= #{startTime}
      </if>
      <if test="endTime != null and endTime != ''">
        and create_time &lt;= #{endTime}
      </if>
    </where>
    order by create_time desc
  </select>

  <!-- 删除日志（包括批量删除） -->
  <delete id="batchDeletedLog">
    delete
    from sys_log
    where id in
    <foreach collection="list" open="(" close=")" separator="," item="item">
      #{item}
    </foreach>
  </delete>
</mapper>