<?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.yifu.cloud.plus.v1.yifu.archives.mapper.MSetttleCustomerUserMapper">
    <resultMap id="mSetttleCustomerUserMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.MSetttleCustomerUser">
        <id property="id" column="id"/>
        <result property="customerId" column="customer_id"/>
        <result property="settleId" column="settle_id"/>
        <result property="userId" column="user_id"/>
    </resultMap>
    <sql id="Base_Column_List">
             a.id,
             a.customer_id,
             a.settle_id,
             a.user_id
    </sql>
    <sql id="mSetttleCustomerUser_where">
        <if test="mSetttleCustomerUser != null">
            <if test="mSetttleCustomerUser.id != null and mSetttleCustomerUser.id.trim() != ''">
                AND a.id = #{mSetttleCustomerUser.id}
            </if>
            <if test="mSetttleCustomerUser.customerId != null and mSetttleCustomerUser.customerId.trim() != ''">
                AND a.customer_id = #{mSetttleCustomerUser.customerId}
            </if>
            <if test="mSetttleCustomerUser.settleId != null and mSetttleCustomerUser.settleId.trim() != ''">
                AND a.settle_id = #{mSetttleCustomerUser.settleId}
            </if>
            <if test="mSetttleCustomerUser.userId != null and mSetttleCustomerUser.userId.trim() != ''">
                AND a.user_id = #{mSetttleCustomerUser.userId}
            </if>
        </if>
    </sql>
    <!--mSetttleCustomerUser简单分页查询-->
    <select id="getMSetttleCustomerUserPage" resultMap="mSetttleCustomerUserMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM m_setttle_customer_user a
        <where>
            1=1
            <include refid="mSetttleCustomerUser_where"/>
        </where>
    </select>
    <select id="getCustomerUser" resultType="com.yifu.cloud.plus.v1.yifu.archives.vo.MSetttleCustomerUserVo">
        select a.user_id,GROUP_CONCAT(DISTINCT b.CUSTOMER_NAME) as CUSTOMER_NAME from m_setttle_customer_user a
		left join t_settle_domain b on a.customer_id = b.CUSTOMER_ID
        where a.user_id in
        <foreach item="item" index="index" collection="userIdList" open="(" separator="," close=")">
            '${item}'
        </foreach>
        GROUP BY a.user_id
    </select>
    <select id="getCustomerCount" resultType="java.lang.Integer">
        SELECT count(DISTINCT customer_id) from m_setttle_customer_user a ;
    </select>
	<select id="getSettlePermissionForB" resultType="java.lang.String">
		SELECT DISTINCT settle_id from m_setttle_customer_user a  where a.user_id=#{userId}
	</select>
</mapper>
