ScrmBatchMessagingMapper.xml 7.12 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.ScrmBatchMessagingMapper">
  <resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.wechatcloudcontrol.batchmessaging.BatchMessagingDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="INTEGER" property="id"/>
    <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="merchant_id"           jdbcType="INTEGER"    property="merchantId"/>
    <result column="msg_name"              jdbcType="VARCHAR"    property="msgName"/>
    <result column="msg_merchant_id"       jdbcType="INTEGER"    property="msgMerchantId"/>
    <result column="msg_merchant_name"     jdbcType="VARCHAR"    property="msgMerchantName"/>
    <result column="customer_count"        jdbcType="INTEGER"    property="customerCount"/>
    <result column="customer_type"         jdbcType="INTEGER"    property="customerType"/>
    <result column="label_crowd_id"        jdbcType="VARCHAR"    property="labelCrowdId"/>
    <result column="label_crowd_name"      jdbcType="VARCHAR"    property="labelCrowdName"/>
    <result column="content_uuid"          jdbcType="VARCHAR"    property="contentUuid"/>
    <result column="msg_state"             jdbcType="INTEGER"    property="msgState"/>
    <result column="msg_time"              jdbcType="TIMESTAMP"  property="msgTime"/>
    <result column="group_id"              jdbcType="VARCHAR"    property="groupId"/>
    <result column="group_name"            jdbcType="VARCHAR"    property="groupName"/>
    <result column="group_type"            jdbcType="VARCHAR"    property="groupType"/>
    <result column="combine_type"          jdbcType="INTEGER"    property="combineType"/>
    <result column="send_type"             jdbcType="INTEGER"    property="sendType"/>
    <result column="send_time"             jdbcType="TIMESTAMP"  property="sendTime"/>
    <result column="cloud_async_process"   jdbcType="BOOLEAN"    property="cloudAsyncProcess"/>
    <result column="err_msg"               jdbcType="VARCHAR"    property="errMsg"/>
  </resultMap>
  <resultMap id="BatchMessagingRecordResponseMap" type="cn.com.glsx.entmicro.model.response.wechatcloudcontrol.batchmessaging.BatchMessagingRecordResponse">
    <result column="created_time"        jdbcType="TIMESTAMP"  property="createTime"/>
    <result column="msg_name"            jdbcType="VARCHAR"    property="msgName"/>
    <result column="msg_merchant_name"   jdbcType="VARCHAR"    property="msgMerchant"/>
    <result column="customer_count"      jdbcType="INTEGER"    property="customerCount"/>
    <result column="label_crowd_name"    jdbcType="VARCHAR"    property="labelCrowdName"/>
    <result column="msg_state"           jdbcType="INTEGER"    property="sendState"/>
    <result column="send_time"           jdbcType="TIMESTAMP"  property="sendTime"/>
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
    -->
    id, created_by, created_time, updated_by, updated_time, del_flag, merchant_id, msg_name, msg_merchant_id, msg_merchant_name, customer_count,
    customer_type, label_crowd_id, label_crowd_name, content_uuid, msg_state, msg_time, group_id, group_name, group_type, combine_type, send_type,
    send_time, cloud_async_process, err_msg
  </sql>

  <select id="selectUseridBefEncryptionByOneId" resultType="cn.com.glsx.entmicro.entity.wechatcloudcontrol.batchmessaging.CloudEncryptionIdRelation">
    select es.id_bef_encryption cloudStaffId,sc.userid_bef_encryption cloudCustomerId from scrm_customer sc
    LEFT JOIN entmicro_customer_follow ecf on ecf.customer_id = sc.id and ecf.del_flag = 0
    LEFT JOIN entmicro_staff es on es.id = ecf.staff_id AND es.del_flag = 0
    LEFT JOIN entmicro_staff_depart_relation edr on edr.staff_id = es.id and edr.del_flag = 0
    WHERE sc.del_flag = 0
      and sc.userid_bef_encryption is not null
      and es.login_status = 1
      and edr.relevance_merchant=#{merchantId}
    <if test="oneIdList != null and oneIdList.size > 0">
      and sc.one_id in
      <foreach collection="oneIdList" index="index" open="(" close=")" separator="," item="id">
        #{id}
      </foreach>
    </if>
    <if test="staffIdList != null and staffIdList.size > 0">
      and es.id in
      <foreach collection="staffIdList" index="index" open="(" close=")" separator="," item="id">
        #{id}
      </foreach>
    </if>
    <if test="customerIdList != null and customerIdList.size > 0">
      and sc.id in
      <foreach collection="customerIdList" index="index" open="(" close=")" separator="," item="id">
        #{id}
      </foreach>
    </if>
    <if test="staffCloudIdList != null and staffCloudIdList.size > 0">
      and es.id_bef_encryption in
      <foreach collection="staffCloudIdList" index="index" open="(" close=")" separator="," item="id">
        #{id}
      </foreach>
    </if>
    <if test="customerCloudIdList != null and customerCloudIdList.size > 0">
      and sc.userid_bef_encryption in
      <foreach collection="customerCloudIdList" index="index" open="(" close=")" separator="," item="id">
        #{id}
      </foreach>
    </if>
    group by sc.userid_bef_encryption
  </select>

  <select id="selectBatchMessagingByCondition" resultMap="BatchMessagingRecordResponseMap">
    select
    sbm.id msgId,
    sbm.msg_name msgName,
    sbm.msg_merchant_name msgMerchant,
    sbm.customer_count customerCount,
    sbm.label_crowd_name labelCrowdName,
    sbm.created_time createTime,
    sbm.msg_state sendState,
    count(sbms.id) successCompletion,
    sbm.send_time
    from scrm_batch_messaging sbm
    left join scrm_batch_messaging_send sbms on sbm.id = sbms.msg_id and sbms.del_flag = 0 and sbms.send_state = 1
    where sbm.del_flag = 0
    <if test="merchantId != null">
      AND sbm.merchant_id = #{merchantId}
    </if>
    <if test="msgName != null and msgName != ''">
      AND sbm.msg_name like '%${msgName}%'
    </if>
    <if test="msgMerchantName != null and msgMerchantName != ''">
      AND sbm.msg_merchant_name like '%${msgMerchantName}%'
    </if>
    <if test="startTime != null">
      AND sbm.msg_time <![CDATA[>=]]> #{startTime,jdbcType=DATE}
    </if>
    <if test="endTime != null">
      AND sbm.msg_time <![CDATA[<=]]> #{endTime,jdbcType=DATE}
    </if>
    group by sbm.id
    order by sbm.created_time DESC
  </select>

  <select id="selectBatchMessagingIdByRequestKey" resultType="java.lang.Integer">
    select sbm.id
    from scrm_batch_messaging sbm
           left join scrm_batch_messaging_send sbms on sbm.id = sbms.msg_id and sbms.del_flag = 0
    where sbm.del_flag = 0
    <if test="msgState != null">
      AND sbm.msg_state = #{msgState}
    </if>
      and sbms.request_key = #{requestKey}
    group by sbm.id
  </select>
</mapper>