<?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.ho.user.mapper.SysLogMapper">

  <sql id="Base_Column_List">
    id,group_id,dept_id, user_id, username, `operation`, `time`, `method`, params, ip, create_time
  </sql>



  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultType="com.ho.user.api.entity.SysLog">
    select 
    <include refid="Base_Column_List" />
    from sys_log
    where id = #{id,jdbcType=BIGINT}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from sys_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.ho.user.api.entity.SysLog">
    insert into sys_log (id,`group_id`,`dept_id`, user_id, username,
      `operation`, `time`, `method`, 
      params, ip, create_time
      )
    values (#{id,jdbcType=BIGINT},#{groupId,jdbcType=INTEGER},#{deptId,jdbcType=INTEGER} #{userId,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR},
      #{operation,jdbcType=VARCHAR}, #{time,jdbcType=INTEGER}, #{method,jdbcType=VARCHAR}, 
      #{params,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>

  <insert id="insertSelective" parameterType="com.ho.user.api.entity.SysLog">
    insert into sys_log
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="groupId != null">
          group_id,
      </if>
      <if test="deptId != null">
          dept_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=BIGINT},
      </if>
      <if test="groupId != null">
        #{groupId,jdbcType=INTEGER},
      </if>
      <if test="deptId != null">
        #{deptId,jdbcType=INTEGER},
      </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>

  <update id="updateByPrimaryKeySelective" parameterType="com.ho.user.api.entity.SysLog">
    update sys_log
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null">
        #{groupId,jdbcType=INTEGER},
      </if>
      <if test="deptId != null">
        #{deptId,jdbcType=INTEGER},
      </if>
      <if test="username != null">
        username = #{username,jdbcType=VARCHAR},
      </if>
      <if test="operation != null">
        `operation` = #{operation,jdbcType=VARCHAR},
      </if>
      <if test="time != null">
        `time` = #{time,jdbcType=INTEGER},
      </if>
      <if test="method != null">
        `method` = #{method,jdbcType=VARCHAR},
      </if>
      <if test="params != null">
        params = #{params,jdbcType=VARCHAR},
      </if>
      <if test="ip != null">
        ip = #{ip,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.ho.user.api.entity.SysLog">
    update sys_log
    set group_id = #{groupId,jdbcType=INTEGER},
        dept_id = #{deptId,jdbcType=INTEGER},
        user_id = #{userId,jdbcType=VARCHAR},
        username = #{username,jdbcType=VARCHAR},
       `operation` = #{operation,jdbcType=VARCHAR},
       `time` = #{time,jdbcType=INTEGER},
       `method` = #{method,jdbcType=VARCHAR},
       params = #{params,jdbcType=VARCHAR},
       ip = #{ip,jdbcType=VARCHAR},
       create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="selectAll" resultType="com.ho.user.api.entity.SysLog">
    select <include refid="Base_Column_List"/>
    from sys_log
    <where>
      <if test="depts != null and depts.size() != 0">
              AND dept_id in
      <foreach collection="depts" index="index" item="item" open="(" separator="," close=")">
        #{item.id}
      </foreach>
      </if>
      <if test="groupId != null and groupId !=''">
              AND group_id = #{groupId}
      </if>
      <if test="userId!=null and userId!='' ">
              AND user_id=#{userId}
      </if>
      <if test="username!=null and username!=''">
              AND username LIKE concat('%',#{username},'%')
      </if>
      <if test="operation!=null and operation!=''">
              AND operation LIKE concat('%',#{operation},'%')
      </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>
      order by create_time desc
    </where>
  </select>
  <select id="selectAllLogs" resultType="com.ho.user.api.entity.SysLog">
    select <include refid="Base_Column_List"/>
    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 item="item" collection="list" open="(" separator="," close=")">
      #{item}
    </foreach>
  </delete>
</mapper>