<?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.ytpm.summary.dao.LoginRecordMapper">

    <insert id="insertOne" parameterType="com.ytpm.app.model.YtDyzLoginRecord">
        insert into yt_dyz_login_record
        (
         record_id,
         user_id,
         login_time,
         device_brand,
         device_model,
         login_ip,
         operator,
         ip_addr,
         phone_json
        )
        values
        (
         #{recordId},
         #{userId},
         #{loginTime},
         #{deviceBrand},
         #{deviceModel},
         #{loginIp},
         #{operator},
         #{ipAddr},
         #{phoneJson}
         );
    </insert>
    <select id="getLoginRecords" resultType="com.ytpm.app.model.YtDyzLoginRecord">
        select
            record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
        from yt_dyz_login_record
        where user_id = #{userId}
    </select>

    <select id="queryLoginCount" resultType="String">
        select ydlr.user_id
        from yt_dyz_login_record ydlr
        left join yt_dyz_user ydu on ydlr.user_id=ydu.user_id
        <where>
            <if test="startTime != null">
                AND ydlr.login_time >= #{startTime}
            </if>
            <if test="endTime != null">
                AND ydlr.login_time &lt;= #{endTime}
            </if>
            <choose>
                <when test="appIdList == null or appIdList.isEmpty()">
                    AND 1 = 0
                </when>
                <otherwise>
                    AND ydu.app_id IN
                    <foreach collection="appIdList" item="item"
                             open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                </otherwise>
            </choose>
        </where>
        group by user_id
    </select>
    <select id="getLoginRecordByIds" resultType="com.ytpm.app.model.YtDyzLoginRecord">
        select
            record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
        from yt_dyz_login_record
        where user_id in
        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>


</mapper>