DracChannelCodeMapper.xml 14.1 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.DracChannelCodeMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.DracChannelCode">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="code_state" jdbcType="VARCHAR" property="codeState"/>
        <result column="code_remark" jdbcType="VARCHAR" property="codeRemark"/>
        <result column="auto_add" jdbcType="INTEGER" property="autoAdd"/>
        <result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
        <result column="auto_welcome" jdbcType="INTEGER" property="autoWelcome"/>
        <result column="config_id" jdbcType="VARCHAR" property="configId"/>
        <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
        <result column="qr_add_time" jdbcType="TIMESTAMP" property="qrAddTime"/>
        <result column="code_system" jdbcType="INTEGER" property="codeSystem"/>
        <result column="code_uuid" jdbcType="VARCHAR" property="codeUuid"/>
        <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="INTEGER" property="delFlag"/>
        <result column="tagging" jdbcType="BLOB" property="tagging"/>
        <result column="code_name" jdbcType="VARCHAR" property="codeName"/>
    </resultMap>

    <!--列表-->
    <resultMap id="pageResultMap" type="cn.com.glsx.entmicro.model.response.DracChannelCodeListResponse">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="code_state" jdbcType="VARCHAR" property="codeState"/>
        <result column="code_remark" jdbcType="VARCHAR" property="codeRemark"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
        <result column="auto_add" jdbcType="INTEGER" property="autoAdd"/>
        <result column="config_id" jdbcType="VARCHAR" property="configId"/>
        <result column="code_uuid" jdbcType="VARCHAR" property="codeUuid"/>
        <result column="tagging" jdbcType="BLOB" property="tagging"/>
        <result column="staff_name" jdbcType="VARCHAR" property="staffName"/>
        <result column="code_name" jdbcType="VARCHAR" property="codeName"/>
        <result column="auto_welcome" jdbcType="INTEGER" property="autoWelcome"/>
        <result column="att_content" jdbcType="VARCHAR" property="attContent"/>
    </resultMap>

    <!--详情-->
    <resultMap id="detailResultMap" type="cn.com.glsx.entmicro.model.response.DracChannelCodeDetailResponse">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="code_state" jdbcType="VARCHAR" property="codeState"/>
        <result column="code_remark" jdbcType="VARCHAR" property="codeRemark"/>
        <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
        <result column="auto_add" jdbcType="INTEGER" property="autoAdd"/>
        <result column="config_id" jdbcType="VARCHAR" property="configId"/>
        <result column="auto_welcome" jdbcType="INTEGER" property="autoWelcome"/>
        <result column="code_uuid" jdbcType="VARCHAR" property="codeUuid"/>
        <result column="tagging" jdbcType="BLOB" property="tagging"/>
        <result column="code_name" jdbcType="VARCHAR" property="codeName"/>
        <result column="auto_welcome" jdbcType="INTEGER" property="autoWelcome"/>
        <result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
    </resultMap>

    <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="cn.com.glsx.entmicro.entity.DracChannelCode">
        <!--
          WARNING - @mbg.generated
        -->
        <result column="tagging" jdbcType="LONGVARCHAR" property="tagging"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, code_state, code_remark, auto_add, merchant_id, auto_welcome, config_id, qr_code,
        qr_add_time, code_system, code_uuid, created_by, created_time, updated_by, updated_time,
        del_flag, code_name, tagging
    </sql>
    <sql id="Blob_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        tagging
    </sql>


    <select id="findDracChannelCodeByName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        drac_channel_code
        where del_flag = 0
        <if test="condition.codeName != null and condition.codeName != ''">
           and code_name = #{condition.codeName}
        </if>
           and merchant_id = #{condition.merchantId}
    </select>

    <select id="findDracChannelCodeByState" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        drac_channel_code
        where del_flag = 0
        <if test="condition.codeState != null and condition.codeState != ''">
            and code_state = #{condition.codeState}
        </if>
    </select>

    <!--删除渠道活码-->
    <update id="deleteChannelCode">
        update drac_channel_code
        set del_flag = -1,
            updated_time = NOW()
        where id = #{codeId}
            and merchant_id = #{merchantId}
  </update>

    <!--活码列表-PC端-->
    <select id="listChannelCode" resultMap="pageResultMap">
        SELECT * from
        (SELECT dcc.id,
                dcc.code_name,
                dcc.code_remark,
                dcc.code_state,
                dcc.config_id,
                dcc.code_uuid,
                dcc.auto_add,
                dcc.created_time,
                dcc.qr_code,
                dcc.tagging,
                dcc.auto_welcome,
                dcc.created_by,
                GROUP_CONCAT(DISTINCT dccfs.staff_name order by dccfs.created_time desc) staff_name
        FROM drac_channel_code dcc
            LEFT JOIN `drac_channel_code_follow_staff` dccfs ON dcc.id = dccfs.code_id AND dccfs.del_flag = 0
            LEFT JOIN `entmicro_staff_depart_relation` esdr ON esdr.id = dccfs.staff_id AND esdr.del_flag = 0
        WHERE dcc.del_flag = 0
        <if test="condition.codeState != null and condition.codeState.size() > 0">
            and dcc.code_state in
            <foreach collection="condition.codeState" separator="," item="state" open="(" close=")">
                #{state}
            </foreach>
        </if>
            AND dcc.code_system = 0
            AND dcc.merchant_id = #{condition.merchantId}
        GROUP BY dcc.id
        ORDER BY dcc.created_time DESC ) t
        <where>
            <if test="condition.staffName != null and condition.staffName != ''">
                t.staff_name LIKE CONCAT('%',#{condition.staffName},'%')
            </if>
            <if test="condition.codeNameAndRemark != null and condition.codeNameAndRemark != ''">
                and concat(ifnull(code_name, ''), ifnull(code_remark, '')) like concat('%',#{condition.codeNameAndRemark},'%')
            </if>
        </where>
    </select>

    <!--活码列表-企微端-->
    <select id="listEntmicroChannelCode" resultMap="pageResultMap">
        select * from
        (select t1.id,
                t1.code_name,
                    t1.code_remark,
                    t1.qr_code,
                    GROUP_CONCAT(t2.staff_name order by t2.created_time desc) staff_name
            from drac_channel_code t1
                left join drac_channel_code_follow_staff t2 on t1.id=t2.code_id
                left join entmicro_staff_depart_relation t3 on t2.staff_id=t3.id
            where t1.del_flag = 0
                and t2.del_flag = 0
            <if test="condition.uuid != null and condition.uuid != ''">
                and t3.user_oneid=#{condition.uuid}
            </if>
                and t1.merchant_id = #{condition.merchantId}
                and code_system = 0
            group by t1.id
            order by t1.created_time desc) t
        <where>
            <if test="condition.codeNameOrStaffName != null and condition.codeNameOrStaffName != ''">
                CONCAT(code_name, staff_name) like '%${condition.codeNameOrStaffName}%'
            </if>
        </where>
    </select>

    <!--获取活码详情-->
    <select id="getChannelCodeDetail" resultMap="detailResultMap">
        select id,          code_name,
            code_remark,    created_time,
            qr_code,        tagging,
            code_uuid,      config_id,
            auto_add,       auto_welcome,
            code_state,     merchant_id
        from drac_channel_code
        where  del_flag = 0
        <if test="codeUuid != null">
           and code_uuid = #{codeUuid}
        </if>
        <if test="id != null">
            and id = #{id}
        </if>
        <if test="qrCode != null and qrCode != ''">
            and qr_code = #{qrCode}
        </if>
    </select>

    <!--当前活码的员工列表-->
    <select id="getChannelCodeStaffList" resultType="cn.com.glsx.entmicro.model.response.drainage.DracScrmStaCodeDetailStaffListResponse">
        select t3.id staffId,
             t2.staff_name staffName,
             t2.created_time createdTime,
             (case when t2.del_flag = -1 or t3.del_flag = -1
                then -1 else 0 end) status,
             t1.created_time createDate,
             t1.merchant_id merchantId,
            (CASE WHEN t2.updated_time IS NOT NULL
                THEN t2.updated_time ELSE t3.updated_time END) deleteDate,
             t1.code_state codeState
        from drac_channel_code t1
            left join drac_channel_code_follow_staff t2
                on t1.id = t2.code_id
            left join entmicro_staff_depart_relation t3
                on t2.staff_id = t3.id
        where t1.del_flag = 0
            and t1.code_state = #{codeState}
        group by t3.id
        order by t1.created_time desc
    </select>

    <select id="getPageByCodeIds" resultType="cn.com.glsx.entmicro.model.response.drainage.DracStatisticCodeResponse">
        select id, code_name as codeName,
            code_state as codeState
        from drac_channel_code
        where code_system = 0
        <if test="codeIds != null and codeIds.size>0">
            and code_state in
            <foreach collection="codeIds" open="(" close=")" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="keyWord != null and keyWord != ''">
            and code_name like '%${keyWord}%'
        </if>
            and merchant_id = #{merchantId}
        order by created_time desc
    </select>

    <!--查询所有活码-->
    <select id="listAllChannelCode" resultMap="pageResultMap">
        select <include refid="Base_Column_List"/>
        from drac_channel_code
        where del_flag = 0
        and merchant_id = #{merchantId}
    </select>
    <select id="findCodesList" resultType="cn.com.glsx.entmicro.model.response.drainage.DracStatisticCodeResponse">
        select id, code_name as codeName,
        code_state as codeState
        from drac_channel_code
        where del_flag = 0
        <if test="dracScrmStatisticCodeDefaultRequest.codeIds != null and dracScrmStatisticCodeDefaultRequest.codeIds.size>0">
            and code_state in
            <foreach collection="dracScrmStatisticCodeDefaultRequest.codeIds" open="(" close=")" item="item" separator=",">
                #{item}
            </foreach>
        </if>
            and code_system = 0
    </select>

    <!--无忧服务活码列表-->
    <select id="getFreeChannelCode" resultMap="pageResultMap">
        SELECT dcc.id,
               dcc.code_name,
               dswc.att_content,
               GROUP_CONCAT(dccfs.staff_name ORDER BY dccfs.created_time DESC) AS staff_name,
               dcc.tagging,
               dcc.qr_code
        FROM `drac_channel_code` dcc
            LEFT JOIN `drac_scrm_welcome_config` dswc ON dcc.code_uuid = dswc.business_uuid AND dswc.del_flag = 0 AND dswc.att_type = 7
            LEFT JOIN `drac_channel_code_follow_staff` dccfs ON dccfs.code_id = dcc.id AND dccfs.del_flag = 0
        WHERE dcc.del_flag = 0
          AND (CASE WHEN JSON_VALID(att_content)
              THEN CAST(JSON_EXTRACT(dswc.att_content, '$.marketingType')AS UNSIGNED) = 6
              ELSE NULL END)
          and dcc.merchant_id = #{merchantId}
        GROUP BY dcc.id
    </select>

    <!--查询系统活码-->
    <select id="getChannelState" resultMap="BaseResultMap">
      SELECT
        code_name,
        code_state
      FROM
        drac_channel_code
      WHERE code_system = 0
      and code_state in
      <foreach collection="stateList" open="(" item="item" separator="," close=")">
          #{item}
      </foreach>
    </select>

    <select id="getCodeStaffList" resultType="cn.com.glsx.entmicro.model.response.DracChannelCodeStaffRpcResponse">
        SELECT es.`id` id,
	          es.`staff_name` staffName,
	          GROUP_CONCAT(DISTINCT ed.`department_name`) departmentName,
              es.user_id userId,
	          dcc.code_name codeName,
	          dcc.`qr_code` qrCode
        FROM `drac_channel_code_follow_staff` dccfs
        LEFT JOIN `drac_channel_code` dcc ON dcc.id = dccfs.`code_id`
        LEFT JOIN `entmicro_staff_depart_relation` esdr ON esdr.id = dccfs.`staff_id`
        LEFT JOIN `entmicro_staff` es ON esdr.staff_id = es.`id`
        LEFT JOIN `entmicro_department` ed ON ed.id = esdr.`department_id`
        WHERE esdr.`relevance_merchant` = #{merchant}
            AND esdr.`del_flag` = 0
            AND dccfs.`del_flag` = 0
            AND es.`del_flag` = 0
            <if test="departmentId != null">
                AND esdr.department_id = #{departmentId}
            </if>
            <if test="staffName != null and staffName != ''">
                AND es.`staff_name` LIKE '%${staffName}%'
            </if>
        GROUP BY es.`id`
    </select>
</mapper>