<?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.sckw.system.dao.KwsUserLoginDao">
    <insert id="saveBatch" parameterType="com.sckw.system.model.KwsUserLogin">
      insert into kws_user_login
      <trim prefix="(" suffix=")" suffixOverrides=",">
        `id`,
        `pid`,
        `ip`,
        `user_agent`,
        `user_id`,
        `token`,
        `valid_time`,
        `first`,
        `lock`,
        `type`,
        `out_time`,
        `source`,
        `create_by`,
        `create_time`,
        `update_by`,
        `update_time`,
        `del_flag`
      </trim>
      values
      <foreach collection="list" item="item" separator=",">
        <trim prefix="(" suffix=")" suffixOverrides=",">
          #{item.id, jdbcType=BIGINT},
          #{item.pid, jdbcType=VARCHAR},
          #{item.ip, jdbcType=VARCHAR},
          #{item.userAgent, jdbcType=VARCHAR},
          #{item.userId, jdbcType=BIGINT},
          #{item.token, jdbcType=VARCHAR},
          #{item.validTime, jdbcType=VARCHAR},
          #{item.first, jdbcType=INTEGER},
          #{item.lock, jdbcType=INTEGER},
          #{item.type, jdbcType=INTEGER},
          #{item.outTime, jdbcType=TIMESTAMP},
          #{item.source, jdbcType=VARCHAR},
          #{item.createBy, jdbcType=BIGINT},
          #{item.createTime, jdbcType=TIMESTAMP},
          #{item.updateBy, jdbcType=BIGINT},
          #{item.updateTime, jdbcType=TIMESTAMP},
          #{item.delFlag, jdbcType=INTEGER}
        </trim>
      </foreach>
  </insert>

  <insert id="insert">
    insert into kws_user_login
    <trim prefix="(" suffix=")" suffixOverrides=",">
      `id`,
      `pid`,
      `ip`,
      `user_agent`,
      `user_id`,
      `token`,
      `valid_time`,
      `first`,
      `lock`,
      `type`,
      `out_time`,
      `source`,
      `create_by`,
      `create_time`,
      `update_by`,
      `update_time`,
      `del_flag`
    </trim>
        values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      #{id, jdbcType=BIGINT},
      #{pid, jdbcType=VARCHAR},
      #{ip, jdbcType=VARCHAR},
      #{userAgent, jdbcType=VARCHAR},
      #{userId, jdbcType=BIGINT},
      #{token, jdbcType=VARCHAR},
      #{validTime, jdbcType=VARCHAR},
      #{first, jdbcType=INTEGER},
      #{lock, jdbcType=INTEGER},
      #{type, jdbcType=INTEGER},
      #{outTime, jdbcType=TIMESTAMP},
      #{source, jdbcType=VARCHAR},
      #{createBy, jdbcType=BIGINT},
      #{createTime, jdbcType=TIMESTAMP},
      #{updateBy, jdbcType=BIGINT},
      #{updateTime, jdbcType=TIMESTAMP},
      #{delFlag, jdbcType=INTEGER}
    </trim>

  </insert>


  <select id="findAllByUserId" resultType="com.sckw.system.model.KwsUserLogin">
    select *
      from kws_user_login
     where user_id = #{userId}
     <if test="startTime != null">
       and create_time >= #{startTime}
     </if>
     <if test="endTime != null">
       and create_time &lt; date_add(#{endTime}, INTERVAL 1 DAY)
     </if>
     order by create_time desc
  </select>

  <select id="currentDayLogin" resultType="com.sckw.system.model.KwsUserLogin">
    select a.*
      from kws_user_login a
     where a.user_id = #{userId}
       and a.create_time >= current_date()
     order by a.create_time
     limit 1
  </select>
</mapper>