<?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.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper">

    <select id="selectCpUserByShops" resultType="com.kiisoo.ic.store.entity.StoreUserDTO">

        select distinct pcu.cp_user_id as cpUserId,pcu.qr_code as qrCodeAction,pcus.store_id as id,pcu.id as userId ,t.name,t.code
        from poi_store t join privilage_domain_entity t2 on t.id = t2.entity_id and t2.type = 3
        left join privilage_cp_user_store pcus on t.id = pcus.store_id
        left join privilage_cp_user pcu on pcus.cp_user_id = pcu.id and pcu.status in (1,4)
        <where>

            <if test="shopIds != null and shopIds.size > 0">
                pcus.store_id in
                <foreach collection="shopIds"  index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by  pcu.id desc

    </select>

    <select id="selectOneByCpUserId" resultType="java.lang.Long">
        select pcus.store_id
        from privilage_cp_user_store pcus ,privilage_cp_user pcu where pcus.cp_user_id = pcu.id and  pcu.status in (1,4)
        and pcu.cp_user_id = #{cpuserId}
        limit 1
    </select>

    <select id="selectCpUserIdByStoreId" resultType="java.lang.String">
        select pcu.cp_user_id
        from privilage_cp_user_store pcus ,privilage_cp_user pcu
        where pcus.cp_user_id = pcu.id and  pcu.status in (1,4)
        and pcus.store_id = #{storeId}
        limit 1
    </select>
    <select id="selectOneCpUser" resultType="com.kiisoo.ic.store.entity.PrivilageCpUserStoreDO">
        select t2.id,t2.store_id as storeId,t2.cp_user_id as cpUserId from privilage_cp_user t1,privilage_cp_user_store t2
        where t1.id = t2.cp_user_id
        and t1.cp_user_id = #{cpUser}
        limit 1
    </select>

</mapper>
