<?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.fs.company.mapper.CompanyLogininforMapper">
    
    <resultMap type="CompanyLogininfor" id="CompanyLogininforResult">
        <result property="infoId"    column="info_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="userName"    column="user_name"    />
        <result property="ipaddr"    column="ipaddr"    />
        <result property="loginLocation"    column="login_location"    />
        <result property="browser"    column="browser"    />
        <result property="os"    column="os"    />
        <result property="status"    column="status"    />
        <result property="msg"    column="msg"    />
        <result property="loginTime"    column="login_time"    />
    </resultMap>

    <sql id="selectCompanyLogininforVo">
        select info_id, company_id, user_name, ipaddr, login_location, browser, os, status, msg, login_time from company_logininfor
    </sql>

    <select id="selectCompanyLogininforList" parameterType="CompanyLogininfor" resultMap="CompanyLogininforResult">
        <include refid="selectCompanyLogininforVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="ipaddr != null  and ipaddr != ''"> and ipaddr = #{ipaddr}</if>
            <if test="loginLocation != null  and loginLocation != ''"> and login_location = #{loginLocation}</if>
            <if test="browser != null  and browser != ''"> and browser = #{browser}</if>
            <if test="os != null  and os != ''"> and os = #{os}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                and date_format(login_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                and date_format(login_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectCompanyLogininforById" parameterType="Long" resultMap="CompanyLogininforResult">
        <include refid="selectCompanyLogininforVo"/>
        where info_id = #{infoId}
    </select>
        
    <insert id="insertCompanyLogininfor" parameterType="CompanyLogininfor" useGeneratedKeys="true" keyProperty="infoId">
        insert into company_logininfor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="ipaddr != null">ipaddr,</if>
            <if test="loginLocation != null">login_location,</if>
            <if test="browser != null">browser,</if>
            <if test="os != null">os,</if>
            <if test="status != null">status,</if>
            <if test="msg != null">msg,</if>
            <if test="loginTime != null">login_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="ipaddr != null">#{ipaddr},</if>
            <if test="loginLocation != null">#{loginLocation},</if>
            <if test="browser != null">#{browser},</if>
            <if test="os != null">#{os},</if>
            <if test="status != null">#{status},</if>
            <if test="msg != null">#{msg},</if>
            <if test="loginTime != null">#{loginTime},</if>
         </trim>
    </insert>

    <update id="updateCompanyLogininfor" parameterType="CompanyLogininfor">
        update company_logininfor
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="ipaddr != null">ipaddr = #{ipaddr},</if>
            <if test="loginLocation != null">login_location = #{loginLocation},</if>
            <if test="browser != null">browser = #{browser},</if>
            <if test="os != null">os = #{os},</if>
            <if test="status != null">status = #{status},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="loginTime != null">login_time = #{loginTime},</if>
        </trim>
        where info_id = #{infoId}
    </update>

    <delete id="deleteCompanyLogininforById" parameterType="Long">
        delete from company_logininfor where info_id = #{infoId}
    </delete>

    <delete id="deleteCompanyLogininforByIds" parameterType="String">
        delete from company_logininfor where info_id in 
        <foreach item="infoId" collection="array" open="(" separator="," close=")">
            #{infoId}
        </foreach>
    </delete>
    
</mapper>