<?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.roadm.admin.mapper.MmsSendChannelInfoMapper">
    <select id="getChannelGroupList" resultType="cn.roadm.admin.table.MmsChannelGroupTable">
        select `id`,
               `network`,
               `name`,
               `platform`,
               `biz`,
               `strategy`,
               `channels`,
               `weight`,
               `overstocks`,
               `modifyTime`
        from mms_channel_group g
        <where>
            g.status = '1'
            <if test="otype != null and otype != ''">
                and g.network = #{otype}
            </if>
        </where>
    </select>

    <select id="getChannelConfig" resultType="cn.roadm.admin.table.MmsSpChannelConfigTable">
        select cg.id            as id,
               cg.opertor_type  as opertorType,
               cg.channelId     as channelId,
               cg.sp_id         as spId,
               cg.createtime,
               cg.channel_group as channelGroup
        from mms_sp_channel_config cg
        <where>
            <if test="id != null and id > 0">
                cg.id = #{id}
            </if>
            <if test="channelid != null and channelid > 0">
                and cg.channelId = #{channelid}
            </if>
            <if test="spId != null and spId > 0">
                and cg.sp_id = #{spId}
            </if>
            <if test="opertorType != null and opertorType > 0">
                and cg.opertor_type = #{opertorType}
            </if>
            <if test="channelGroup != null and channelGroup > 0">
                and cg.channel_group = #{channelGroup}
            </if>
        </where>
    </select>

    <select id="listPageMmsVideoChannel" resultType="cn.roadm.admin.dto.MmsVideoChannelListRowDTO">
        select sc.id,
               sc.channel_name                                         as channelName,
               (case
                    when sc.protocol_type in ('4', '04') then 'HTTP'
                    when sc.protocol_type in ('5', '05') then 'MM7'
                    else concat('协议', sc.protocol_type) end)       as protocolType,
               sc.is_support_unicom                                    as isSupportUnicom,
               sc.is_support_mobile                                    as isSupportMobile,
               sc.is_support_telecom                                   as isSupportTelecom,
               sc.mobile_prefix                                        as accessNumber,
               cast(sc.status as char)                                 as status,
               sc.`desc`                                               as `desc`,
               sc.pa_url                                               as paUrl,
               cast(null as signed)                                    as connectStatus
        from mms_send_channel_info sc
        <where>
            (sc.protocol_type + 0) &lt; 20
            <if test="req.id != null">
                and sc.id = #{req.id}
            </if>
            <if test="req.name != null and req.name != ''">
                and sc.channel_name like concat('%', #{req.name}, '%')
            </if>
            <if test="req.status != null and req.status &gt;= 0">
                and cast(sc.status as signed) = #{req.status}
            </if>
            <if test="req.businessManager != null and req.businessManager != ''">
                and sc.business_manager = #{req.businessManager}
            </if>
            <if test="req.linkProperties != null">
                and sc.link_properties = #{req.linkProperties}
            </if>
        </where>
    </select>

    <select id="getMmsVideoChannelDetail" resultType="cn.roadm.admin.dto.MmsVideoChannelDetailVO">
        select a.id,
               a.channel_name            as name,
               a.mobile_prefix           as accessNumber,
               cast(a.status as char)    as status,
               a.pa_url                  as paUrl,
               a.protocol_type           as protocolType,
               a.batchsize,
               a.access_key              as accessKey,
               a.http_response           as httpResponse,
               a.`desc`,
               a.price,
               a.is_support_unicom       as isSupportUnicom,
               a.is_support_mobile       as isSupportMobile,
               a.is_support_telecom      as isSupportTelecom,
               a.is_support_international as isSupportInternational,
               p.templateCode,
               p.channelTemplatevar,
               b.templateDefaultVar,
               a.cooperate_company       as cooperateCompany,
               a.supplier_id             as supplierId,
               a.attract_limit           as attractLimit,
               a.link_properties         as linkProperties,
               a.business_manager        as businessManager
        from mms_send_channel_info a
                 left join mms_http_channel_template_config p on a.id = p.channelid
                 left join mms_http_channel_template b on p.templateCode = b.templateCode
        where a.id = #{id}
        limit 1
    </select>

    <delete id="deleteMmsHttpTemplateConfigByChannelId">
        delete
        from mms_http_channel_template_config
        where channelid = #{channelId}
    </delete>

    <insert id="insertMmsHttpTemplateConfig">
        insert into mms_http_channel_template_config (channelid, templateCode, channelTemplatevar, createtime)
        values (#{channelId}, #{templateCode}, #{channelTemplatevar}, now())
    </insert>

    <select id="listMmsVideoChannelOptions" resultType="cn.roadm.admin.controller.vo.PageSelectOptionsVO">
        select sc.id    as value,
               concat(sc.id, ' ', sc.channel_name) as label
        from mms_send_channel_info sc
        <where>
            (sc.protocol_type + 0) &lt; 20
            <if test="status != null and status &gt;= 0">
                and cast(sc.status as signed) = #{status}
            </if>
        </where>
        order by sc.id desc
    </select>
</mapper>
