<?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.SpPushConfigMapper">

    <resultMap id="SpPushConfigMap" type="cn.roadm.admin.dto.SpPushConfigDO">
        <id property="spId" column="sp_id"/>
        <result property="spName" column="sp_name"/>
        <result property="replyUrl" column="reply_url"/>
        <result property="mmsReplyUrl" column="mms_reply_url"/>
        <result property="reportUrl" column="report_url"/>
        <result property="yuexinPush" column="yuexin_push"/>
        <result property="pushLimit" column="push_limit"/>
        <result property="mmsSignReportPush" column="mms_sign_report_push"/>
        <result property="pushFlag" column="push_flag"/>
        <result property="pushFormat" column="push_buyun"/>
    </resultMap>


    <select id="listPageQuerySpPushConfig" resultMap="SpPushConfigMap">
        select s.sp_name, g.sp_id, g.reply_url, g.mms_reply_url, g.report_url,g.yuexin_push, g.mms_sign_report_push, g.push_flag,
        g.push_limit, g.push_buyun from
        sms_api_setting g, sms_sp_info s
        <where>
            s.id = g.sp_id
            and s.status != 2
            <if test="params.spName != null and params.spName != ''">
                and s.sp_name like CONCAT('%',#{params.spName},'%')
            </if>
            <if test="params.spId != null and params.spId != ''">
                and s.id=#{params.spId}
            </if>
        </where>
        order by g.SP_ID desc
    </select>

    <select id="getSpPushConfigDetail" resultMap="SpPushConfigMap">
        select s.sp_name, g.sp_id, g.reply_url, g.mms_reply_url, g.report_url,g.yuexin_push, g.mms_sign_report_push, g.push_flag,
        g.push_limit, g.push_buyun from
        sms_api_setting g, sms_sp_info s
        <where>
            s.id = g.sp_id
            and s.status != 2
            and s.id=#{spId}
        </where>
    </select>

    <update id="updateSpPushConfig">
        update sms_api_setting set REPLY_URL = #{replyUrl}, mms_reply_url = #{mmsReplyUrl}, REPORT_URL = #{reportUrl},
        yuexin_push = #{yuexinPush}, mms_sign_report_push = #{mmsSignReportPush}, PUSH_FLAG = #{pushFlag}, push_limit = #{pushLimit},
        PUSH_BUYUN = #{pushFormat} where SP_ID = #{spId}
    </update>
</mapper>