<?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.employee.mapper.PrivilageCpUserDOMapper">
    <insert id="insertCpUserCustomerRelation">
        insert into op_cp_user_customer_relation (customer_user_id,cp_user_id)values (#{customerUserId},#{cpUserId})
    </insert>

    <select id="selectCpUserCustomerRelation" resultType="com.kiisoo.ic.employee.entity.CpUserCustomerRelationDO">
        select customer_user_id as customerUserId,cp_user_id as cpUserId,cp_id as cpId from op_cp_user_customer_relation
        where customer_user_id = #{customerUserId}
        and cp_user_id = #{cpUserId}
        limit 1
    </select>
    <select id="selectCpUserCustomerRelationByCpId" resultType="java.lang.String">
        select customer_user_id as customerUserId
        from op_cp_user_customer_relation
        where cp_user_id = #{cpUserId}
    </select>

    <select id="selectAllCount" resultType="java.lang.Long">
        select count(id) from op_seller_customer_relation
    </select>

    <select id="selectDistinctAllCount" resultType="java.lang.Long">
        select count(distinct customer_id) from op_seller_customer_relation
    </select>

    <select id="selectStoreCount" resultType="java.lang.Long">
        select count(id) from op_cp_user_customer_relation where cp_user_id = #{cpUserId}
    </select>

    <select id="selectDistinctStoreCount" resultType="java.lang.Long">
        select count(distinct customer_user_id) from op_cp_user_customer_relation where cp_user_id = #{cpUserId}
    </select>


    <select id="selectStoresCount" resultType="java.lang.Long">
        select count(id) from op_cp_user_customer_relation where cp_user_id in
        <foreach collection="cpUserIds" separator="," item="item" close=")" index="index" open="(">
            #{item}
        </foreach>
    </select>

    <select id="selectDistinctStoresCount" resultType="java.lang.Long">
        select count(distinct customer_user_id) from op_cp_user_customer_relation where cp_user_id in
        <foreach collection="cpUserIds" separator="," item="item" close=")" index="index" open="(">
            #{item}
        </foreach>
    </select>
    <select id="selectStoresCountById" resultType="java.lang.Long">
        select count(id) from op_seller_customer_relation where store_id in
        <foreach collection="shopIds" separator="," item="item" close=")" index="index" open="(">
            #{item}
        </foreach>
    </select>

    <select id="selectDistinctStoresCountById" resultType="java.lang.Long">
        select count(distinct customer_id) from op_seller_customer_relation where store_id in
        <foreach collection="shopIds" separator="," item="item" close=")" index="index" open="(">
            #{item}
        </foreach>
    </select>


    <select id="selectCustomerIdsByCpUserId" resultType="java.lang.String">
        select distinct customer_user_id from op_cp_user_customer_relation where cp_user_id = #{cpUserId}
    </select>

    <delete id="deleteCount">
        delete from op_cp_user_customer_relation where customer_user_id = #{customerUserId} and cp_user_id = #{cpUserId}
    </delete>

</mapper>
