<?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.hzs.system.sys.mapper.SysLogininforMapper">

    <resultMap type="com.hzs.common.domain.system.sys.SysLogininfor" id="SysLogininforResult">
        <id property="infoId" column="info_id"/>
        <result property="userName" column="user_name"/>
        <result property="status" column="status"/>
        <result property="ipaddr" column="ipaddr"/>
        <result property="msg" column="msg"/>
        <result property="accessTime" column="access_time"/>
    </resultMap>

    <insert id="insertLogininfor" parameterType="SysLogininfor">
        insert into sys_logininfor (user_name, status, ipaddr, msg, access_time)
        values (#{userName}, #{status}, #{ipaddr}, #{msg}, sysdate)
    </insert>

    <select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
        select info_id, user_name, ipaddr, status, msg, access_time from sys_logininfor
        <where>
            <if test="ipaddr != null and ipaddr != ''">
                AND ipaddr like '%' || #{ipaddr} || '%'
            </if>
            <if test="status != null ">
                AND status = #{status}
            </if>
            <if test="userName != null and userName != ''">
                AND user_name like '%' || #{userName} || '%'
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and access_time &gt;= to_date(#{params.beginTime}, 'yyyy-mm-dd')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and access_time &lt;= to_date(#{params.endTime} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
            </if>
        </where>
        order by info_id desc
    </select>

</mapper>
