CustomerBaseRelationMapper.xml 4.13 KB
<?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="cn.com.glsx.entmicro.mapper.CustomerBaseRelationMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.CustomerBaseRelation">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="customer_base_id" jdbcType="VARCHAR" property="customerBaseId"/>
        <result column="customer_id" jdbcType="INTEGER" property="customerId"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
        <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="join_scene" jdbcType="TINYINT" property="joinScene"/>
        <result column="join_time" jdbcType="TIMESTAMP" property="joinTime"/>
        <result column="group_nickname" jdbcType="VARCHAR" property="groupNickname"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, customer_base_id, customer_id, created_by, created_time, updated_by, updated_time,
        del_flag, join_scene, join_time, group_nickname, `type`
    </sql>

    <update id="deleteByCustomerBaseId">
    update scrm_customer_base_relation set del_flag = -1,updated_time = now() where customer_base_id = #{customerBaseId}
  </update>
    <update id="deletelist">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update scrm_customer_base_relation
            set del_flag = -1,
            quit_scene=#{item.quitScene},
            updated_time=NOW(),
            quit_time=NOW()
            where
            customer_base_id = #{item.customerBaseId}
            and
            customer_id = #{item.customerId}
        </foreach>
    </update>
    <update id="updatelist">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update scrm_customer_base_relation
            set
            updated_time=NOW(),
            join_scene=#{item.joinScene},
            join_time=#{item.joinTime},
            type=#{item.type},
            group_nickname=#{item.groupNickname},
            invitor=#{item.invitor},
            del_flag=0
            where
            customer_base_id = #{item.customerBaseId}
            and
            customer_id = #{item.customerId}
        </foreach>
    </update>
    <select id="findByCustomerId" resultMap="BaseResultMap">
    select * from scrm_customer_base_relation where
<!--        del_flag =0 and -->
        customer_base_id=#{customerBaseId}
  </select>
    <select id="findFirstCustomerByCustomerId" resultType="cn.com.glsx.entmicro.entity.CustomerBaseRelation">
        select * from scrm_customer_base_relation where del_flag = 0 and customer_base_id=#{customerBaseId} and type = 2 order by join_time asc limit 1
    </select>
  <select id="getChatNum" resultType="cn.com.glsx.entmicro.model.response.ChatNumResponse">
    SELECT t.customer_base_id id, COUNT(1) customerNum FROM(
	    SELECT a.customer_base_id, a.customer_id FROM `scrm_customer_base_relation` a WHERE a.del_flag = 0 AND a.type = 2
	    AND a.customer_base_id IN
	    <foreach collection="idList" open="(" close=")" separator="," item="item">
            #{item,jdbcType=VARCHAR}
        </foreach>
    ) t GROUP BY t.customer_base_id
  </select>

    <select id="getNickNameByCustId" resultMap="BaseResultMap">
        select GROUP_CONCAT(distinct group_nickname) as group_nickname,
            customer_id
        from scrm_customer_base_relation
        where del_flag = 0
            and customer_id in
        <foreach collection="idList" open="(" item="item" separator="," close=")">
            #{item}
        </foreach>
        group by customer_id
    </select>
</mapper>