<?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.ruoyi.group.mapper.CustGroupMemberMapper">

    <select id="selectCustGroupMemberList" resultType="CustGroupMemberVO">
        SELECT
            cgm.id,
            cgm.group_id,
            cgm.cust_type,
            cgm.cust_id,
            cgm.cust_name,
            cgm.cust_idc,
            cgm.social_credit_code,
            cgm.create_time
        FROM ibs_cust_group_member cgm
        <where>
            cgm.group_id = #{groupId}
            AND cgm.del_flag = '0'
            <if test="dto != null and dto.custType != null and dto.custType != ''">
                AND cgm.cust_type = #{dto.custType}
            </if>
            <if test="dto != null and dto.custName != null and dto.custName != ''">
                AND cgm.cust_name LIKE CONCAT('%', #{dto.custName}, '%')
            </if>
        </where>
        ORDER BY cgm.create_time ASC
    </select>

    <!-- 批量插入客群客户（INSERT IGNORE，遇到重复键自动跳过） -->
    <insert id="batchInsertMembers">
        INSERT IGNORE INTO ibs_cust_group_member
            (group_id, cust_type, cust_id, cust_name, cust_idc, social_credit_code, create_by, create_time, del_flag, manual_remove)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.groupId}, #{item.custType}, #{item.custId}, #{item.custName}, #{item.custIdc}, #{item.socialCreditCode}, #{item.createBy}, NOW(), '0', '0')
        </foreach>
    </insert>

</mapper>
