<?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.ym.mec.auth.dal.dao.SysUserLoginDao">

    <resultMap type="com.ym.mec.auth.api.entity.SysUserLogin" id="SysUserLogin">
        <result column="user_id_" property="userId"/>
        <result column="login_count_" property="loginCount"/>
        <result column="last_login_time_" property="lastLoginTime"/>
        <result column="last_login_ip_" property="lastLoginIp"/>
        <result column="fail_count_" property="failCount"/>
        <result column="lock_time_" property="lockTime"/>
        <result column="lock_date_" property="lockDate"/>
        <result column="tenant_id_" property="tenantId"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="SysUserLogin">
		SELECT * FROM sys_user_login WHERE user_id_ = #{userId}
	</select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="SysUserLogin">
		SELECT * FROM sys_user_login ORDER BY user_id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.auth.api.entity.SysUserLogin" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        <!--
        <selectKey resultClass="int" keyProperty="id" >
        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
        </selectKey>
        -->
        INSERT INTO sys_user_login
        (user_id_,login_count_,last_login_time_,last_login_ip_,fail_count_,lock_time_,lock_date_,tenant_id_)
        VALUES(#{userId},#{loginCount},#{lastLoginTime},#{lastLoginIp},#{failCount},#{lockTime},#{lockDate},#{tenantId})
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.auth.api.entity.SysUserLogin">
        UPDATE sys_user_login
        <set>
            <if test="failCount != null">
                fail_count_ = #{failCount},
            </if>
            <if test="lastLoginIp != null">
                last_login_ip_ = #{lastLoginIp},
            </if>
            <if test="lockTime != null">
                lock_time_ = #{lockTime},
            </if>
            <if test="loginCount != null">
                login_count_ = #{loginCount},
            </if>
            <if test="lastLoginTime != null">
                last_login_time_ = #{lastLoginTime},
            </if>
            <if test="lockDate != null">
                lock_date_ = #{lockDate},
            </if>
        </set>
        WHERE user_id_ = #{userId} and tenant_id_ = #{tenantId}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
		DELETE FROM sys_user_login WHERE user_id_ = #{userId}
	</delete>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="SysUserLogin" parameterType="map">
        SELECT * FROM sys_user_login where tenant_id_ = #{tenantId} ORDER BY user_id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_user_login where tenant_id_ = #{tenantId}
	</select>

    <select id="findLoginByUserId" resultMap="SysUserLogin">
		SELECT * FROM sys_user_login WHERE user_id_ = #{userId}
	</select>
</mapper>
