<?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.mapper.ChatBotsMapper">
    <resultMap id="CspAgentMap" type="cn.roadm.bo.csp.CspAgent">
        <id column="id" property="id"/>
        <result column="api_type" property="apiType"/>
        <result column="csp_code" property="cspCode"/>
        <result column="agent_code" property="agentCode"/>
        <result column="agent_name" property="agentName"/>
        <result column="agent_region" property="agentRegion"/>
        <result column="service_code" property="serviceCode"/>
        <result column="status" property="status"/>
        <result column="agent_appid" property="agentAppid"/>
        <result column="agent_token" property="agentToken"/>
        <result column="agent_publickey" property="agentPublickey"/>
        <result column="plat_appid" property="platAppid"/>
        <result column="plat_token" property="platToken"/>
        <result column="plat_publickey" property="platPublickey"/>
        <result column="plat_privatekey" property="platPrivatekey"/>
        <result column="request_url" property="requestUrl"/>
        <result column="send_url" property="sendUrl"/>
        <result column="reply_channel" property="replyChannel"/>
        <result column="aim_publickey" property="aimPublickey"/>
        <result column="aim_privatekey" property="aimPrivatekey"/>
        <result column="auditer" property="auditer"/>
        <result column="auditer_msg" property="auditerMsg"/>
        <result column="debug_phone" property="debugPhone"/>
        <result column="extend_nosign" property="extendNosign"/>
        <result column="extend_chatbot" property="extendChatbot"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="region_name" property="regionName"/>
        <result column="csp_key" property="cspKey"/>
        <result column="csp_token" property="cspToken"/>
        <result column="back_address" property="backAddress"/>
        <result column="file_upload_address" property="fileUploadAddress"/>
        <result column="agreement" property="agreement"/>
        <result column="url" property="url"/>
    </resultMap>

    <resultMap id="CspChatbotMap" type="cn.roadm.bo.csp.CspChatBot">
        <id column="id" property="id"/>
        <result column="agent_id" property="agentId"/>
        <result column="nosign_customer_id" property="nosignCustomerId"/>
        <result column="name" property="name"/>
        <result column="service_code" property="serviceCode"/>
        <result column="chatbotId" property="chatbotId"/>
        <result column="service_type" property="serviceType"/>
        <result column="logo" property="logo"/>
        <result column="background_image" property="backgroundImage"/>
        <result column="sign" property="sign"/>
        <result column="bubble_color" property="bubbleColor"/>
        <result column="service_phone" property="servicePhone"/>
        <result column="actual_send_Industry" property="actualSendIndustry"/>
        <result column="chatbot_email" property="chatbotEmail"/>
        <result column="chatbot_official_website" property="chatbotOfficialWebsite"/>
        <result column="office_address" property="officeAddress"/>
        <result column="terms_service_url" property="termsServiceUrl"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="entity_attachment" property="entityAttachment"/>
        <result column="debug_phone" property="debugPhone"/>
        <result column="auditer" property="auditer"/>
        <result column="auditer_date" property="auditerDate"/>
        <result column="auditer_msg" property="auditerMsg"/>
        <result column="welcome" property="welcome"/>
        <result column="remark" property="remark"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="eTag" property="eTag"/>
        <result column="portServiceType" property="portServiceType"/>
        <result column="adMarketTndustryType" property="adMarketTndustryType"/>
        <result column="logoLocal" property="logoLocal"/>
        <result column="provider" property="provider"/>
        <result column="showProvider" property="showProvider"/>
        <result column="ipWhiteList" property="ipWhiteList"/>
        <result column="serviceDescription" property="serviceDescription"/>
        <result column="smsNumber" property="smsNumber"/>
        <result column="accredit1" property="accredit1"/>
        <result column="accreditLocal1" property="accreditLocal1"/>
        <result column="accredit2" property="accreditLocal2"/>
        <result column="accreditLocal2" property="accreditLocal2"/>
        <result column="accredit3" property="accredit3"/>
        <result column="accreditLocal3" property="accreditLocal3"/>
        <result column="accredit4" property="accredit4"/>
        <result column="accreditLocal4" property="accreditLocal4"/>
        <result column="accredit5" property="accredit5"/>
        <result column="accreditLocal5" property="accreditLocal5"/>
        <result column="accessTagNo" property="accessTagNo"/>
        <result column="apiType" property="apiType"/>
        <result column="chatbotEditFlag" property="chatbotEditFlag"/>
        <result column="agreement" property="agreement"/>
        <result column="token" property="token"/>
        <result column="url" property="url"/>
        <result column="appId" property="appId"/>
        <result column="appKey" property="appKey"/>
        <result column="isOnLineFlag" property="isOnLineFlag"/>

    </resultMap>

    <resultMap id="CspNoSignCustomerMap" type="cn.roadm.bo.csp.CspNoSignCustomer">
        <id column="id" property="id"/>
        <result column="save_type" property="saveType"/>
        <result column="customerNum" property="customerNum"/>
        <result column="agentId" property="agentId"/>
        <result column="service_type" property="serviceType"/>
        <result column="name" property="name"/>
        <result column="attachments" property="attachments"/>
        <result column="contact" property="contact"/>
        <result column="contact_mobile" property="contactMobile"/>
        <result column="email" property="email"/>
        <result column="service_code" property="serviceCode"/>
        <result column="contract_scan" property="contractScan"/>
        <result column="contract_code" property="contractCode"/>
        <result column="contract_name" property="contractName"/>
        <result column="contract_effective_date" property="contractEffectiveDate"/>
        <result column="contract_expiration_date" property="contractExpirationDate"/>
        <result column="contract_renew_date" property="contractRenewDate"/>
        <result column="contract_auto_type" property="contractAutoType"/>
        <result column="credit_code" property="creditCode"/>
        <result column="responsible_person" property="responsiblePerson"/>
        <result column="id_card_type" property="idCardType"/>
        <result column="id_card" property="idCard"/>
        <result column="auditer" property="auditer"/>
        <result column="auditer_msg" property="auditerMsg"/>
        <result column="auditer_date" property="auditerDate"/>
        <result column="remark" property="remark"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="agent_name" property="agentName"/>
        <result column="eTag" property="eTag"/>
        <result column="apiType" property="apiType"/>
        <result column="ecGrade" property="ecGrade"/>
        <result column="operatorCard" property="operatorCard"/>
        <result column="introduce" property="introduce"/>
        <result column="serviceIcon" property="serviceIcon"/>
        <result column="workPhone" property="workPhone"/>
        <result column="businessLicense" property="businessLicense"/>
        <result column="businessAddress" property="businessAddress"/>
        <result column="serviceIconLocal" property="serviceIconLocal"/>
        <result column="businessLicenseLocal" property="businessLicenseLocal"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
        <result column="area" property="area"/>
        <result column="operatorIdentityFrontPic" property="operatorIdentityFrontPic"/>
        <result column="operatorIdentityFrontPicLocal" property="operatorIdentityFrontPicLocal"/>
        <result column="operatorIdentityBackPic" property="operatorIdentityBackPic"/>
        <result column="operatorIdentityBackPicLocal" property="operatorIdentityBackPicLocal"/>
        <result column="accessory" property="accessory"/>
        <result column="accessoryLocal" property="accessoryLocal"/>
        <result column="legalName" property="legalName"/>
        <result column="legalIdentification" property="legalIdentification"/>
        <result column="identificationFrontPic" property="identificationFrontPic"/>
        <result column="identificationFrontPicLocal" property="identificationFrontPicLocal"/>
        <result column="identificationBackPic" property="identificationBackPic"/>
        <result column="identificationBackPicLocal" property="identificationBackPicLocal"/>
        <result column="cspEcNo" property="cspEcNo"/>
    </resultMap>

    <resultMap id="CspChatBotListMap" type="cn.roadm.bo.csp.CspChatBotListDTO">
        <id column="id" property="id"/>
        <result column="agent_id" property="agentNumber"/>
        <result column="agent_name" property="agentName"/>
<!--        <result column="nosign_customer_id" property="customerNumber"/>-->
        <result column="nosign_customer_name" property="customerName"/>
        <result column="chatbotId" property="chatBotId"/>
        <result column="sign" property="sign"/>
        <result column="remark" property="remark"/>
        <result column="status" property="status"/>
        <result column="customerNum" property="customerNum"/>
        <result column="name" property="chatBotName"/>
        <result column="auditer" property="auditer"/>
        <result column="auditer_msg" property="auditerMsg"/>
        <result column="apiType" property="apiType"/>
        <result column="appId" property="appId"/>
        <result column="appKey" property="appKey"/>
        <result column="isOnLineFlag" property="isOnLineFlag"/>

    </resultMap>

    <resultMap id="serviceCodeMap" type="cn.roadm.bo.csp.ServiceCodeBO">
        <result column="id" property="id"/>
        <result column="service_code" property="serviceCode"/>
        <result column="ext_code" property="extCode"/>
        <result column="customer_number" property="customerNumber"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <select id="listPageQueryCspAgent" resultMap="CspAgentMap" parameterType="cn.roadm.bo.csp.CspAgent">
        select id,
               api_type,
               csp_code,
               agent_code,
               agent_name,
               agent_region,
               service_code,
               status,
               agent_appid,
               agent_token,
               agent_publickey,
               plat_appid,
               plat_token,
               plat_publickey,
               plat_privatekey,
               request_url,
               send_url,
               reply_channel,
               aim_publickey,
               aim_privatekey,
               auditer,
               auditer_msg,
               debug_phone,
               extend_nosign,
               extend_chatbot,
               remark,
               csp_key,
               csp_token,
               back_address,
               file_upload_address,
               create_time,
               region_name,
               agreement,
               url
        from csp_agent
        <where>
            <if test="apiType != null and apiType != ''">
                and api_type = #{apiType}
            </if>
            <if test="agentCode != null and agentCode != ''">
                agent_code = #{agentCode}
            </if>
            <if test="agentName != null and agentName != ''">
                and agent_name like concat('%', #{agentName}, '%')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="queryAllCspAgent" resultMap="CspAgentMap" parameterType="cn.roadm.bo.csp.CspAgent">
        select id,
        api_type,
        csp_code,
        agent_code,
        agent_name,
        agent_region,
        service_code,
        status,
        agent_appid,
        agent_token,
        agent_publickey,
        plat_appid,
        plat_token,
        plat_publickey,
        plat_privatekey,
        request_url,
        send_url,
        reply_channel,
        aim_publickey,
        aim_privatekey,
        auditer,
        auditer_msg,
        debug_phone,
        extend_nosign,
        extend_chatbot,
        remark,
        csp_key,
        csp_token,
        back_address,
        file_upload_address,
        create_time,
        region_name,
        agreement,
        url
        from csp_agent
        <where>
            <if test="apiType != null and apiType != ''">
                and api_type = #{apiType}
            </if>
            <if test="agentCode != null and agentCode != ''">
                agent_code = #{agentCode}
            </if>
            <if test="agentName != null and agentName != ''">
                and agent_name like concat('%', #{agentName}, '%')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="queryAllNoSignCustomer" resultMap="CspNoSignCustomerMap" parameterType="cn.roadm.bo.csp.CspNoSignCustomer">
        select id,
               save_type,
               customerNum,
               agentId,
               service_type,
               name,
               attachments,
               contact,
               contact_mobile,
               email,
               service_code,
               contract_scan,
               contract_code,
               contract_name,
               contract_effective_date,
               contract_expiration_date,
               contract_renew_date,
               contract_auto_type,
               credit_code,
               responsible_person,
               id_card_type,
               id_card,
               auditer,
               auditer_msg,
               auditer_date,
               remark,
               status,
               create_time,
               apiType,
               ecGrade,
               operatorCard,
               introduce,
               serviceIcon,
               workPhone,
               businessLicense,
               businessAddress,
               serviceIconLocal,
               businessLicenseLocal,
               province,
               city,
               area,
               operatorIdentityFrontPic,
               operatorIdentityFrontPicLocal,
               operatorIdentityBackPic,
               operatorIdentityBackPicLocal,
               accessory,
               accessoryLocal,
               legalName,
               legalIdentification,
               identificationFrontPic,
               identificationFrontPicLocal,
               identificationBackPic,
               identificationBackPicLocal,
               cspEcNo,
               eTag
        from csp_nosign_customer
        where apiType = #{apiType} and cspEcNo is not null
    </select>

    <select id="getAgentConfigById" resultMap="CspAgentMap">
        select id,
               api_type,
               csp_code,
               agent_code,
               agent_name,
               agent_region,
               service_code,
               status,
               agent_appid,
               agent_token,
               agent_publickey,
               plat_appid,
               plat_token,
               plat_publickey,
               plat_privatekey,
               request_url,
               send_url,
               reply_channel,
               aim_publickey,
               aim_privatekey,
               auditer,
               auditer_msg,
               debug_phone,
               extend_nosign,
               extend_chatbot,
               remark,
               csp_key,
               csp_token,
               back_address,
               file_upload_address,
               create_time,
               agreement,
               url
        from csp_agent
        where id = #{id}
    </select>

    <select id="listAgentIdAndAgentName" resultType="cn.roadm.bo.csp.CspAgent">
        select id, agent_name as agentName, service_code as serviceCode
        from csp_agent
    </select>

    <select id="getNoSignCustomerConfigById" resultMap="CspNoSignCustomerMap">
        select id,
               save_type,
               customerNum,
               agentId,
               service_type,
               name,
               attachments,
               contact,
               contact_mobile,
               email,
               service_code,
               contract_scan,
               contract_code,
               contract_name,
               contract_effective_date,
               contract_expiration_date,
               contract_renew_date,
               contract_auto_type,
               credit_code,
               responsible_person,
               id_card_type,
               id_card,
               auditer,
               auditer_msg,
               auditer_date,
               remark,
               status,
               create_time,
               apiType,
               ecGrade,
               operatorCard,
               introduce,
               serviceIcon,
               workPhone,
               businessLicense,
               businessAddress,
               serviceIconLocal,
               businessLicenseLocal,
               province,
               city,
               area,
               operatorIdentityFrontPic,
               operatorIdentityFrontPicLocal,
               operatorIdentityBackPic,
               operatorIdentityBackPicLocal,
               accessory,
               accessoryLocal,
               legalName,
               legalIdentification,
               identificationFrontPic,
               identificationFrontPicLocal,
               identificationBackPic,
               identificationBackPicLocal,
               cspEcNo,
               eTag
        from csp_nosign_customer
        where id = #{id}
    </select>

    <select id="getNoSignCustomerConfigByNum" resultMap="CspNoSignCustomerMap">
        select id,
               save_type,
               customerNum,
               agentId,
               service_type,
               name,
               attachments,
               contact,
               contact_mobile,
               email,
               service_code,
               contract_scan,
               contract_code,
               contract_name,
               contract_effective_date,
               contract_expiration_date,
               contract_renew_date,
               contract_auto_type,
               credit_code,
               responsible_person,
               id_card_type,
               id_card,
               auditer,
               auditer_msg,
               auditer_date,
               remark,
               status,
               create_time,
               eTag
        from csp_nosign_customer
        where customerNum = #{num} and status != '999'
    </select>

    <select id="listPageQueryCspNoSignCustomer" resultMap="CspNoSignCustomerMap">
        select customer.id,
               save_type,
               agentId,
               customerNum,
               service_type,
               name,
               attachments,
               contact,
               contact_mobile,
               email,
               customer.service_code,
               contract_scan,
               contract_code,
               contract_name,
               contract_effective_date,
               contract_expiration_date,
               contract_renew_date,
               contract_auto_type,
               credit_code,
               responsible_person,
               id_card_type,
               id_card,
               customer.auditer,
               customer.auditer_msg,
               auditer_date,
               customer.remark,
               customer.status,
               customer.create_time,
               customer.apiType,
               customer.cspEcNo,
               agent.agent_name
        from csp_nosign_customer customer
                 left join csp_agent agent on customer.agentId = agent.id
        <where>
            <if test="agentId != null">
                agentId = #{agentId}
            </if>
            <if test="status != null and status != ''">
                and customer.status = #{status}
            </if>
            <if test="apiType != null and apiType != ''">
                and customer.apiType = #{apiType}
            </if>
            <if test="name != null and name != ''">
                and customer.name like concat('%', #{name}, '%')
            </if>
            <if test="serviceCode != null and serviceCode != ''">
                and customer.service_code like concat('%', #{serviceCode}, '%')
            </if>
            <if test="cspEcNo!=null and cspEcNo!=''">
                and cspEcNo = #{cspEcNo}
            </if>
            and customer.status != 999
        </where>
        order by create_time desc
    </select>

    <insert id="saveAgentConfig">
        insert into csp_agent (api_type, csp_code, agent_code, agent_name, agent_region, service_code, status,
                               agent_appid, agent_token, agent_publickey, plat_appid, plat_token, plat_publickey,
                               plat_privatekey, request_url, send_url, reply_channel, aim_publickey, aim_privatekey,
                               auditer, auditer_msg, debug_phone, extend_nosign, extend_chatbot, remark, create_time, region_name,
                               csp_key, csp_token, back_address, file_upload_address, agreement, url)
        values (#{apiType}, #{cspCode}, #{agentCode}, #{agentName}, #{agentRegion}, #{serviceCode}, #{status},
                #{agentAppid}, #{agentToken}, #{agentPublickey}, #{platAppid}, #{platToken}, #{platPublickey},
                #{platPrivatekey}, #{requestUrl}, #{sendUrl}, #{replyChannel}, #{aimPublickey}, #{aimPrivatekey},
                #{auditer}, #{auditerMsg}, #{debugPhone}, #{extendNosign}, #{extendChatbot}, #{remark}, now(), #{regionName},
                #{cspKey}, #{cspToken}, #{backAddress}, #{fileUploadAddress}, #{agreement}, #{url})
    </insert>

    <select id="listPageQueryChatBoyList" resultMap="CspChatBotListMap">
        select cb.id,
               cb.agent_id,
               ca.agent_name,
               cnc.customerNum,
               cnc.name as nosign_customer_name,
               cb.chatbotId,
               cb.name,
               cb.sign,
               cb.remark,
               cb.status,cb.auditer,cb.auditer_msg,cci.devAppId,cci.devToken,cb.apiType,cb.isOnLineFlag,
               cb.appId,cb.appKey
        from csp_chatbot cb
                 left join csp_agent ca on cb.agent_id = ca.id
                 left join csp_nosign_customer cnc on cb.nosign_customer_id = cnc.id
        left join csp_chatbot_info cci on cb.chatbotId = cci.chatbotId
        <where>
            <if test="agentName != null and agentName != '' ">
                ca.agent_name like concat('%', #{agentName}, '%')
            </if>
            <if test="chatBotId != null and chatBotId != '' ">
                and cb.chatbotId like concat('%', #{chatBotId}, '%')
            </if>
            <if test="chatBotName != null and chatBotName != ''">
                and cb.name like concat('%', #{chatBotName}, '%')
            </if>
            <if test="sign != null and sign != ''">
                and cb.sign like concat('%', #{sign}, '%')
            </if>
            <if test="status != null and status != 9998">
                and cb.status = #{status}
            </if>
            <if test="status != null and status == 9998">
                and cci.devToken is not null
            </if>
            <if test="apiType != null and apiType != '' ">
                and cb.apiType = #{apiType}
            </if>
        </where>
        order by cb.create_time desc
    </select>

    <select id="getChatBotConfigById" resultMap="CspChatbotMap">
        select id,
               agent_id,
               nosign_customer_id,
               name,
               service_code,
               chatbotId,
               service_type,
               logo,
               background_image,
               sign,
               bubble_color,
               service_phone,
               actual_send_Industry,
               chatbot_email,
               chatbot_official_website,
               office_address,
               terms_service_url,
               longitude,
               latitude,
               entity_attachment,
               debug_phone,
               auditer,
               auditer_date,
               auditer_msg,
               welcome,
               remark,
               status,
               create_time,eTag,portServiceType,adMarketTndustryType,
        customerName,customerContractFile,customerAttachment,remarkText,creditCode,representativeName,representativeCertificateType,
        representativeCertificateNumber,representativeTel,agentName,agentCertificateType,agentCertificateNumber,agentTel,
        institutionLicenceType,logoLocal,provider,showProvider,ipWhiteList,serviceDescription,smsNumber,accredit1,accreditLocal1,
        accredit2,accreditLocal2,accredit3,accreditLocal3,accredit4,accreditLocal4,accredit5,accreditLocal5,accessTagNo,apiType,
               chatbotEditFlag,agreement,token,url,appId,appKey,isOnLineFlag
        from csp_chatbot
        where id = #{id}
    </select>

    <insert id="saveNoSignCustomerConfig">
        insert into csp_nosign_customer (save_type, agentId, service_type, name, attachments, contact, contact_mobile,
                                         email, service_code, contract_scan, contract_code, contract_name,
                                         contract_effective_date, contract_expiration_date, contract_renew_date,
                                         contract_auto_type, credit_code, responsible_person, id_card_type, id_card,
                                         auditer, auditer_msg, auditer_date, remark, status, create_time,customerNum,eTag,
                                         apiType,cspEcNo)
        values (#{saveType}, #{agentId}, #{serviceType}, #{name}, #{attachments}, #{contact}, #{contactMobile},
                #{email}, #{serviceCode}, #{contractScan}, #{contractCode}, #{contractName}, #{contractEffectiveDate},
                #{contractExpirationDate}, #{contractRenewDate}, #{contractAutoType}, #{creditCode},
                #{responsiblePerson}, #{idCardType}, #{idCard}, #{auditer}, #{auditerMsg}, #{auditerDate}, #{remark},
                #{status}, now(),#{customerNum},#{eTag},#{apiType},#{cspEcNo})
    </insert>

    <insert id="saveTelecomNoSignCustomerConfig">
        insert into csp_nosign_customer (apiType, agentId, service_type, name, ecGrade, introduce, serviceIcon, serviceIconLocal,
                                         workPhone, businessLicense, businessLicenseLocal, businessAddress, province, city,
                                         area, contact, contact_mobile, email, operatorCard, operatorIdentityFrontPic, operatorIdentityFrontPicLocal,
                                         operatorIdentityBackPic, operatorIdentityBackPicLocal, accessory, accessoryLocal, contract_code,
                                         contract_name, contract_effective_date, contract_expiration_date, contract_renew_date, contract_auto_type,
                                         legalName, legalIdentification, identificationFrontPic, identificationFrontPicLocal, identificationBackPic,
                                         identificationBackPicLocal, remark, status, create_time, cspEcNo)
        values (#{apiType}, #{agentId}, #{serviceType}, #{name}, #{ecGrade}, #{introduce}, #{serviceIcon}, #{serviceIconLocal},
                #{workPhone}, #{businessLicense}, #{businessLicenseLocal}, #{businessAddress}, #{province}, #{city},
                #{area}, #{contact}, #{contactMobile}, #{email}, #{operatorCard}, #{operatorIdentityFrontPic}, #{operatorIdentityFrontPicLocal},
                #{operatorIdentityBackPic}, #{operatorIdentityBackPicLocal}, #{accessory}, #{accessoryLocal}, #{contractCode},
                #{contractName}, #{contractEffectiveDate}, #{contractExpirationDate}, #{contractRenewDate}, #{contractAutoType},
                #{legalName}, #{legalIdentification}, #{identificationFrontPic}, #{identificationFrontPicLocal}, #{identificationBackPic},
                #{identificationBackPicLocal}, #{remark}, #{status}, now(), #{cspEcNo})
    </insert>

    <insert id="saveTelecomNoSignCustomerHisConfig">
        insert into csp_nosign_customer_his (apiType, agentId, service_type, name, ecGrade, introduce, serviceIcon, serviceIconLocal,
                                         workPhone, businessLicense, businessLicenseLocal, businessAddress, province, city,
                                         area, contact, contact_mobile, email, operatorCard, operatorIdentityFrontPic, operatorIdentityFrontPicLocal,
                                         operatorIdentityBackPic, operatorIdentityBackPicLocal, accessory, accessoryLocal, contract_code,
                                         contract_name, contract_effective_date, contract_expiration_date, contract_renew_date, contract_auto_type,
                                         legalName, legalIdentification, identificationFrontPic, identificationFrontPicLocal, identificationBackPic,
                                         identificationBackPicLocal, remark, status, create_time, cspEcNo, id)
        values (#{apiType}, #{agentId}, #{serviceType}, #{name}, #{ecGrade}, #{introduce}, #{serviceIcon}, #{serviceIconLocal},
                #{workPhone}, #{businessLicense}, #{businessLicenseLocal}, #{businessAddress}, #{province}, #{city},
                #{area}, #{contact}, #{contactMobile}, #{email}, #{operatorCard}, #{operatorIdentityFrontPic}, #{operatorIdentityFrontPicLocal},
                #{operatorIdentityBackPic}, #{operatorIdentityBackPicLocal}, #{accessory}, #{accessoryLocal}, #{contractCode},
                #{contractName}, #{contractEffectiveDate}, #{contractExpirationDate}, #{contractRenewDate}, #{contractAutoType},
                #{legalName}, #{legalIdentification}, #{identificationFrontPic}, #{identificationFrontPicLocal}, #{identificationBackPic},
                #{identificationBackPicLocal}, #{remark}, #{status}, #{createTime}, #{cspEcNo}, #{hisId})
    </insert>

    <update id="updateNoSignCustomerConfig">
        update csp_nosign_customer
        set save_type                = #{saveType},
            agentId                  = #{agentId},
            service_type             = #{serviceType},
            name                     = #{name},
            attachments              = #{attachments},
            contact                  = #{contact},
            contact_mobile           = #{contactMobile},
            email                    = #{email},
            service_code             = #{serviceCode},
            contract_scan            = #{contractScan},
            contract_code            = #{contractCode},
            contract_name            = #{contractName},
            contract_effective_date  = #{contractEffectiveDate},
            contract_expiration_date = #{contractExpirationDate},
            contract_renew_date      = #{contractRenewDate},
            contract_auto_type       = #{contractAutoType},
            credit_code              = #{creditCode},
            responsible_person       = #{responsiblePerson},
            id_card_type             = #{idCardType},
            id_card                  = #{idCard},
            auditer                  = #{auditer},
            auditer_msg              = #{auditerMsg},
            auditer_date             = #{auditerDate},
            remark                   = #{remark},
            status                   = #{status}
        where id = #{id}
    </update>

    <update id="updateTelecomNoSignCustomerConfig">
        update csp_nosign_customer
        set service_type                = #{serviceType},
            name                        = #{name},
            ecGrade                     = #{ecGrade},
            introduce                   = #{introduce},
            serviceIcon                 = #{serviceIcon},
            serviceIconLocal            = #{serviceIconLocal},
            workPhone                   = #{workPhone},
            businessLicense             = #{businessLicense},
            businessLicenseLocal        = #{businessLicenseLocal},
            businessAddress             = #{businessAddress},
            province                    = #{province},
            city                        = #{city},
            area                        = #{area},
            contact                     = #{contact},
            contact_mobile              = #{contactMobile},
            email                       = #{email},
            operatorCard                = #{operatorCard},
            operatorIdentityFrontPic    = #{operatorIdentityFrontPic},
            operatorIdentityFrontPicLocal = #{operatorIdentityFrontPicLocal},
            operatorIdentityBackPic     = #{operatorIdentityBackPic},
            operatorIdentityBackPicLocal = #{operatorIdentityBackPicLocal},
            accessory                   = #{accessory},
            accessoryLocal              = #{accessoryLocal},
            contract_code               = #{contractCode},
            contract_name               = #{contractName},
            contract_effective_date     = #{contractEffectiveDate},
            contract_expiration_date    = #{contractExpirationDate},
            contract_renew_date         = #{contractRenewDate},
            contract_auto_type          = #{contractAutoType},
            legalName                   = #{legalName},
            legalIdentification         = #{legalIdentification},
            identificationFrontPic      = #{identificationFrontPic},
            identificationFrontPicLocal = #{identificationFrontPicLocal},
            identificationBackPic       = #{identificationBackPic},
            identificationBackPicLocal  = #{identificationBackPicLocal},
            hisId                       = #{hisId},
            remark                      = #{remark}
        where id = #{id}
    </update>


    <update id="updateAgentConfig">
        update csp_agent
        set api_type        = #{apiType},
            csp_code        = #{cspCode},
            agent_code      = #{agentCode},
            agent_name      = #{agentName},
            agent_region    = #{agentRegion},
            service_code    = #{serviceCode},
            status          = #{status},
            agent_appid     = #{agentAppid},
            agent_token     = #{agentToken},
            agent_publickey = #{agentPublickey},
            plat_appid      = #{platAppid},
            plat_token      = #{platToken},
            plat_publickey  = #{platPublickey},
            plat_privatekey = #{platPrivatekey},
            request_url     = #{requestUrl},
            send_url        = #{sendUrl},
            reply_channel   = #{replyChannel},
            aim_publickey   = #{aimPublickey},
            aim_privatekey  = #{aimPrivatekey},
            auditer         = #{auditer},
            auditer_msg     = #{auditerMsg},
            debug_phone     = #{debugPhone},
            extend_nosign   = #{extendNosign},
            extend_chatbot  = #{extendChatbot},
            remark          = #{remark},
            region_name     = #{regionName},
            csp_key         = #{cspKey},
            csp_token       = #{cspToken},
            back_address    = #{backAddress},
            file_upload_address = #{fileUploadAddress},
            agreement = #{agreement},
            url = #{url}
        where id = #{id}
    </update>

    <insert id="saveChatBotConfig">
        insert into csp_chatbot (agent_id, nosign_customer_id, name, service_code, chatbotId, service_type, logo,
                                 background_image, sign, bubble_color, service_phone, actual_send_Industry,
                                 chatbot_email, chatbot_official_website, office_address, terms_service_url, longitude,
                                 latitude, entity_attachment, debug_phone, auditer, auditer_date, auditer_msg, welcome,
                                 remark, status, create_time,eTag,portServiceType,adMarketTndustryType,customerName,
        customerContractFile,customerAttachment,remarkText,creditCode,representativeName,representativeCertificateType,
        representativeCertificateNumber,representativeTel,agentName,agentCertificateType,agentCertificateNumber,agentTel,
        institutionLicenceType)
        values (#{agentId}, #{nosignCustomerId}, #{name}, #{serviceCode}, #{chatbotId}, #{serviceType}, #{logo},
                #{backgroundImage}, #{sign}, #{bubbleColor}, #{servicePhone}, #{actualSendIndustry}, #{chatbotEmail},
                #{chatbotOfficialWebsite}, #{officeAddress}, #{termsServiceUrl}, #{longitude}, #{latitude},
                #{entityAttachment}, #{debugPhone}, #{auditer}, #{auditerDate}, #{auditerMsg}, #{welcome}, #{remark},
                #{status}, now(),#{eTag},#{portServiceType},#{adMarketTndustryType},#{customerName},#{customerContractFile}
        ,#{customerAttachment},#{remarkText},#{creditCode},#{representativeName},#{representativeCertificateType},
        #{representativeCertificateNumber},#{representativeTel},#{agentName},#{agentCertificateType},#{agentCertificateNumber}
        ,#{agentTel},#{institutionLicenceType})
    </insert>

    <insert id="saveTelecomChatBotConfig">
        insert into csp_chatbot (agent_id, nosign_customer_id, name, service_code, chatbotId, service_type, logo,
                                 logoLocal, sign, provider, showProvider, service_phone, ipWhiteList, chatbot_email,
                                 chatbot_official_website, office_address, terms_service_url, longitude, latitude,
                                 accredit1, accreditLocal1, accredit2, accreditLocal2, accredit3, accreditLocal3,
                                 accredit4, accreditLocal4, accredit5, accreditLocal5, debug_phone, auditer,
                                 auditer_date, auditer_msg, welcome, remark, status, create_time,eTag,portServiceType,
                                 adMarketTndustryType, serviceDescription, smsNumber, apiType, accessTagNo)
        values (#{agentId}, #{nosignCustomerId}, #{name}, #{serviceCode}, #{chatbotId}, #{serviceType}, #{logo},
                #{logoLocal}, #{sign}, #{provider}, #{showProvider}, #{servicePhone}, #{ipWhiteList}, #{chatbotEmail},
                #{chatbotOfficialWebsite}, #{officeAddress}, #{termsServiceUrl}, #{longitude}, #{latitude},
                #{accredit1}, #{accreditLocal1},#{accredit2}, #{accreditLocal2},#{accredit3}, #{accreditLocal3},
                #{accredit4}, #{accreditLocal4},#{accredit5}, #{accreditLocal5}, #{debugPhone}, #{auditer},
                #{auditerDate}, #{auditerMsg}, #{welcome}, #{remark},#{status}, now(),#{eTag},#{portServiceType},
                #{adMarketTndustryType}, #{serviceDescription}, #{smsNumber}, #{apiType}, #{accessTagNo})
    </insert>

    <insert id="saveTelecomChatBotHisConfig">
        insert into csp_chatbot_his (agent_id, nosign_customer_id, name, service_code, chatbotId, service_type, logo,
                                 logoLocal, sign, provider, showProvider, service_phone, ipWhiteList, chatbot_email,
                                 chatbot_official_website, office_address, terms_service_url, longitude, latitude,
                                 accredit1, accreditLocal1, accredit2, accreditLocal2, accredit3, accreditLocal3,
                                 accredit4, accreditLocal4, accredit5, accreditLocal5, debug_phone, auditer,
                                 auditer_date, auditer_msg, welcome, remark, status, create_time,eTag,portServiceType,
                                 adMarketTndustryType, serviceDescription, smsNumber, apiType, accessTagNo, id,
                                 agreement, token, url, appId, appKey, isOnLineFlag)
        values (#{agentId}, #{nosignCustomerId}, #{name}, #{serviceCode}, #{chatbotId}, #{serviceType}, #{logo},
                #{logoLocal}, #{sign}, #{provider}, #{showProvider}, #{servicePhone}, #{ipWhiteList}, #{chatbotEmail},
                #{chatbotOfficialWebsite}, #{officeAddress}, #{termsServiceUrl}, #{longitude}, #{latitude},
                #{accredit1}, #{accreditLocal1},#{accredit2}, #{accreditLocal2},#{accredit3}, #{accreditLocal3},
                #{accredit4}, #{accreditLocal4},#{accredit5}, #{accreditLocal5}, #{debugPhone}, #{auditer},
                #{auditerDate}, #{auditerMsg}, #{welcome}, #{remark},#{status}, now(),#{eTag},#{portServiceType},
                #{adMarketTndustryType}, #{serviceDescription}, #{smsNumber}, #{apiType}, #{accessTagNo}, #{hisId},
                #{agreement}, #{token}, #{url}, #{appId}, #{appKey}, #{isOnLineFlag})
    </insert>

    <update id="updateChatBotConfig">
        update csp_chatbot
        set agent_id                 = #{agentId},
            nosign_customer_id       = #{nosignCustomerId},
            name                     = #{name},
            service_code             = #{serviceCode},
            chatbotId                = #{chatbotId},
            service_type             = #{serviceType},
            logo                     = #{logo},
            background_image         = #{backgroundImage},
            sign                     = #{sign},
            bubble_color             = #{bubbleColor},
            service_phone            = #{servicePhone},
            actual_send_Industry     = #{actualSendIndustry},
            chatbot_email            = #{chatbotEmail},
            chatbot_official_website = #{chatbotOfficialWebsite},
            office_address           = #{officeAddress},
            terms_service_url        = #{termsServiceUrl},
            longitude                = #{longitude},
            latitude                 = #{latitude},
            entity_attachment        = #{entityAttachment},
            debug_phone              = #{debugPhone},
            auditer                  = #{auditer},
            auditer_date             = #{auditerDate},
            auditer_msg              = #{auditerMsg},
            welcome                  = #{welcome},
            remark                   = #{remark},
            status                   = #{status},
        portServiceType = #{portServiceType},
        adMarketTndustryType = #{adMarketTndustryType},
        customerName = #{customerName},
        customerContractFile = #{customerContractFile},
        customerAttachment = #{customerAttachment},
        remarkText = #{remarkText},
        creditCode = #{creditCode},
        representativeName = #{representativeName},
        representativeCertificateType = #{representativeCertificateType},
        representativeCertificateNumber = #{representativeCertificateNumber},
        representativeTel = #{representativeTel},
        agentName = #{agentName},
        agentCertificateType = #{agentCertificateType},
        agentCertificateNumber = #{agentCertificateNumber},
        agentTel = #{agentTel},
        institutionLicenceType = #{institutionLicenceType},
        eTag                   = #{eTag}
        where id = #{id}
    </update>

    <update id="updateTelecomChatBotConfig">
        update csp_chatbot
        set
            agent_id = #{agentId},
            nosign_customer_id = #{nosignCustomerId},
            name = #{name},
            service_code = #{serviceCode},
            service_type = #{serviceType},
            logo = #{logo},
            logoLocal = #{logoLocal},
            sign = #{sign},
            provider = #{provider},
            showProvider = #{showProvider},
            service_phone = #{servicePhone},
            ipWhiteList = #{ipWhiteList},
            chatbot_email = #{chatbotEmail},
            chatbot_official_website = #{chatbotOfficialWebsite},
            office_address = #{officeAddress},
            terms_service_url = #{termsServiceUrl},
            longitude = #{longitude},
            latitude = #{latitude},
            accredit1 = #{accredit1},
            accreditLocal1 = #{accreditLocal1},
            accredit2 = #{accredit2},
            accreditLocal2 = #{accreditLocal2},
            accredit3 = #{accredit3},
            accreditLocal3 = #{accreditLocal3},
            accredit4 = #{accredit4},
            accreditLocal4 = #{accreditLocal4},
            accredit5 = #{accredit5},
            accreditLocal5 = #{accreditLocal5},
            debug_phone = #{debugPhone},
            auditer = #{auditer},
            auditer_date = #{auditerDate},
            auditer_msg = #{auditerMsg},
            welcome = #{welcome},
            remark = #{remark},
            status = #{status},
            eTag = #{eTag},
            portServiceType = #{portServiceType},
            adMarketTndustryType = #{adMarketTndustryType},
            serviceDescription = #{serviceDescription},
            smsNumber = #{smsNumber},
            apiType = #{apiType},
            accessTagNo = #{accessTagNo},
            agreement = #{agreement},
            token = #{token},
            url = #{url},
            appId = #{appId},
            appKey = #{appKey},
            hisId = #{hisId}
        where id = #{id}
    </update>

    <select id="getChatBotFallBackChannels" resultType="java.util.Map">
        select ID as channelId, CHANNEL_NAME as channelName
        from sms_send_channel_info
        where STATUS = '1'
    </select>

    <select id="listQueryNoSignCustomer" resultMap="CspNoSignCustomerMap">
        select id, name, apiType
        from csp_nosign_customer
        <where>
            <if test="agentId != null">
                agentId = #{agentId}
            </if>
            and status != 999
        </where>
    </select>

    <update id="deleteNoSignCustomerById">
        update csp_nosign_customer
        set status = 999
        where id = #{id}
    </update>

    <update id="updateNoSignCustomerStatusById">
        update csp_nosign_customer
        set status = #{status}
        where id = #{id}
    </update>

    <update id="updateChatBotStatusById">
        update csp_chatbot
        set status = #{status}
        where id = #{id}
    </update>

    <select id="listChatbotSpBindList" resultType="cn.roadm.bo.csp.CspSpLinkDTO">
        select sp_id as spId, sp_name as spName, csp.chatbot_id as chatbotId, cb.name as chatbotName
        from csp_sp_link csp
                 left join sms_sp_info sp on csp.sp_id = sp.id
                 left join csp_chatbot cb on csp.chatbot_id = cb.chatbotId
        where csp.chatbot_id = #{chatbotId}
    </select>

    <select id="selectChatbotSpBindCount" resultType="int">
        select count(1)
        from csp_sp_link
        where chatbot_id = #{chatbotId}
    </select>

    <select id="getChatBotAgentServiceCodeByNoSignCustomerId" resultType="map">
        select a.customerNum as customerNum, b.service_code as serviceCode from csp_nosign_customer a left join csp_agent b on a.agentId = b.id where a.id = #{id}
    </select>

    <select id="listQuerySavedServiceCode" resultMap="serviceCodeMap">
        select id, service_code, ext_code, customer_number, status, create_time from csp_service_code where customer_number = #{customerNum} and `status` = 1
    </select>

    <insert id="saveAssignServiceCode">
        insert into csp_service_code (service_code, ext_code, customer_number, status, create_time)
        values (#{serviceCode}, #{extendNum}, #{customerNum}, 1, now())
    </insert>

    <select id="getCspTokenByChatbotId" resultType="java.lang.String">
        select csp_token from csp_chatbot_send_info where chatbot_id = #{chatBotId}
    </select>

    <select id="getDevTokenByChatbotId" resultType="java.lang.String">
        select devToken from csp_chatbot_info where chatbotId = #{chatBotId}
    </select>

    <update id="logoutChatBot">
        update csp_chatbot set status = 9999 where id = #{id}
    </update>

    <update id="updateChatBotState">
        update csp_chatbot set status = #{status} where id = #{id}
    </update>

    <update id="updateChatBotDebugInfo">
        update csp_chatbot set debug_phone = #{debugPhone} where id = #{id}
    </update>

    <delete id="deleteChatbotById">
        delete from csp_chatbot where id = #{id}
    </delete>

    <select id="getAllChatbotById" parameterType="int" resultMap="CspChatbotMap">
        select id,chatbotId,status from csp_chatbot where chatbotId = (select chatbotId from csp_chatbot where id = #{id})
    </select>

    <select id="getChatbotIdsByAgentId" parameterType="int" resultType="java.lang.Integer">
        select id from csp_chatbot where agent_id = #{agentId}
    </select>

    <delete id="deleteChannelChatbot">
        delete from sms_channel_sign_chatbot where chatbot = #{chatbotId}
    </delete>

    <update id="updateChatbotUrlConfigByIds">
        UPDATE csp_chatbot
        SET
        agreement = #{agreement},
        url = #{url}
        WHERE
        <if test="ids != null and ids.size() > 0">
            id IN
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </update>

</mapper>
