<?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.zcxk.dao.LoginLogMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.LoginLog" id="LoginLogMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="companyId" column="company_id" jdbcType="INTEGER"/>
        <result property="departmentId" column="department_id" jdbcType="INTEGER"/>
        <result property="type" column="type" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="loginIp" column="login_ip" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 基本字段 -->
    <sql id="Base_Column_List">
        id, name, phone, company_id, department_id, type, create_time, login_ip    </sql>

    <!-- 查询单个 -->
    <select id="selectById" resultMap="LoginLogMap">
        select
        <include refid="Base_Column_List"/>
        from uims_login_log
        where id = #{id}
    </select>


    <!-- 查询全部 -->
    <select id="selectAll" resultMap="LoginLogMap">
        select
        <include refid="Base_Column_List"/>
        from uims_login_log
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="LoginLogMap">
        select
        <include refid="Base_Column_List"/>
        from uims_login_log
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="phone != null and phone != ''">
                and phone = #{phone}
            </if>
            <if test="companyId != null">
                and company_id = #{companyId}
            </if>
            <if test="departmentId != null">
                and department_id = #{departmentId}
            </if>
            <if test="type != null and type != ''">
                and type = #{type}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="loginIp != null and loginIp != ''">
                and login_ip = #{loginIp}
            </if>
        </where>
    </select>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_login_log(id, tenant_id, name, phone, company_id, department_id, type, create_time, login_ip)
        values ( #{id}, #{tenantId}, #{name}, #{phone}, #{companyId}, #{departmentId}, #{type}, #{createTime}, #{loginIp})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_login_log(id, tenant_id,name, phone, company_id, department_id, type, create_time, login_ip)
        values
        <foreach collection="loginLogs" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.tenantId}, #{item.name}, #{item.phone}, #{item.companyId}, #{item.departmentId}, #{item.type},
            #{item.createTime}, #{item.loginIp} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims.uims_login_log
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="phone != null and phone != ''">
                phone = #{phone},
            </if>
            <if test="companyId != null">
                company_id = #{companyId},
            </if>
            <if test="departmentId != null">
                department_id = #{departmentId},
            </if>
            <if test="type != null and type != ''">
                type = #{type},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="loginIp != null and loginIp != ''">
                login_ip = #{loginIp},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from uims_login_log where id = #{id}
    </delete>

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*) from uims_login_log
    </select>
    <select id="selectPage" resultMap="LoginLogMap">
        select
        <include refid="Base_Column_List"/>
        from uims_login_log
        <where>
            <if test="loginLog.name != null and loginLog.name != ''">
                and name = #{loginLog.name}
            </if>
            <if test="loginLog.phone != null and loginLog.phone != ''">
                and phone = #{loginLog.phone}
            </if>
            <if test="loginLog.companyId != null">
                and company_id = #{loginLog.companyId}
            </if>
            <if test="loginLog.departmentId != null">
                and department_id = #{loginLog.departmentId}
            </if>
            <if test="loginLog.type != null and loginLog.type != ''">
                and type = #{loginLog.type}
            </if>
            <if test="loginLog.createTime != null">
                and create_time = #{loginLog.createTime}
            </if>
            <if test="loginLog.loginIp != null and loginLog.loginIp != ''">
                and login_ip = #{loginLog.loginIp}
            </if>
        </where>
    </select>
</mapper>