<?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.cyksj.mapper.corp.kf.CorpKfServicerSessionRecordMapper">


    <select id="getAvailableServicer" resultType="com.cyksj.model.dto.CorpKfServicerDto">
        select servicer_userid,count(1) as num
        from corp_kf_servicer_session_record
        where open_kf_id = #{openKfId}
          and service_state = 0
        group by servicer_userid
        order by num asc
    </select>

    <select id="selectSessionByCondition" resultType="com.cyksj.model.entity.CorpKfServicerSessionRecord">
        select * from corp_kf_servicer_session_record where open_kf_id = #{openKfId}
        and servicer_userid = #{servicerUserid}
        and service_state = 0
        <if test="transUserIds != null and transUserIds.size() > 0">
            and external_userid in
            <foreach collection="transUserIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="transNum!=null and transNum > 0">
            order by rand() limit #{transNum}
        </if>
    </select>
</mapper>