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

    <select id="listPageSpMmsLocalSign" parameterType="cn.roadm.bo.VideoSmsSign"
            resultType="cn.roadm.bo.VideoSmsSign">
        select
        sl.id,
        sl.spid,
        sl.ext,
        sl.sign,
        sl.content,
        sl.remark,
        sl.createtime
        from  sign_local sl
        where 1=1
        <if test="id!=null and id>0">
            and sl.id=#{id}
        </if>
        <if test="spid!=null and spid>0">
            and sl.spid=#{spid}
        </if>
        <if test="content!=null and content!=''">
            and sl.content=#{content}
        </if>
        <if test="sign!=null and sign!=''">
            and sl.sign=#{sign}
        </if>
        <if test="remark!=null and remark!=''">
            and sl.remark=#{remark}
        </if>
        <if test="ext!=null and ext!=''">
            and sl.ext=#{ext}
        </if>
        <if test="createtime!=null and createtime!=''">
            and sl.createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
        order by sl.createtime desc
    </select>

    <select id="getMmsContent" parameterType="cn.roadm.bo.VideoSmsSign" resultType="cn.roadm.bo.VideoSmsSign">
        select id,content,sign,spid,ext from sign_local WHERE id=#{id}
    </select>

    <select id="getSpMmsChannnelSign" parameterType="cn.roadm.bo.VideoSmsSign"
            resultType="cn.roadm.bo.VideoSmsSign">
        select *  from  sign_remote tr
        where tr.channelid=#{channelid}  and tr.local_signid=#{local_signid}  limit 1
    </select>

    <insert id="insertSignRemote" parameterType="cn.roadm.bo.VideoSmsSign" useGeneratedKeys="true" keyProperty="id">
        insert into sign_remote(channelid,createtime,status,remote_signid,local_signid,sign)
        values(#{channelid},now(),#{status},#{remote_signid},#{local_signid},#{sign});
    </insert>

    <update id="updateSignRemote" parameterType="cn.roadm.bo.VideoSmsSign">
        update sign_remote set remote_signid=#{remote_signid} where local_signid=#{local_signid} and channelid=#{channelid}
    </update>
    <update id="updateFailSignRemote" parameterType="cn.roadm.bo.VideoSmsSign">
        UPDATE sign_remote set status=0,reason =#{remote_templateid} where local_signid=#{local_signid} and channelid=#{channelid}
    </update>
    <update id="updateStatusSignRemote" parameterType="cn.roadm.bo.VideoSmsSign">
        UPDATE sign_remote set status =#{status} where remote_signid=#{remote_signid} and channelid=#{channelid}
    </update>
    <select id="findByRemoteSign" parameterType="cn.roadm.bo.VideoSmsSign" resultType="cn.roadm.bo.VideoSmsSign">
        select channelid,sign,remote_signid from sign_remote where remote_signid=#{remote_signid} and channelid=#{channelid} and status=2
    </select>

    <insert id="insertMmsLocalSign"  parameterType="cn.roadm.bo.VideoSmsSign">
		insert into
		sign_local(id,spid,createtime,content,sign,ext,remark)
		values(#{id},#{spid},sysdate(),#{content},#{sign},#{ext},#{remark})
	</insert>

    <select id="listPageSpMmsRemoteSign" parameterType="cn.roadm.bo.VideoSmsSign"
            resultType="cn.roadm.bo.VideoSmsSign">
        select
        sm.id,
        sm.channelid,
        sm.status,
        sm.remote_signid,
        sm.local_signid,
        sm.createtime,
        sl.sign,
        sl.ext,
        sm.reason
        from  sign_remote sm left join  sign_local sl
        on sm.local_signid = sl.id
        where 1=1
        <if test="id!=null and id>0">
            and sm.id=#{id}
        </if>
        <if test="channelid!=null and channelid>0">
            and sm.channelid=#{channelid}
        </if>
        <if test="remote_signid!=null and remote_signid!=''">
            and sm.remote_signid=#{remote_signid}
        </if>
        <if test="local_signid!=null and local_signid!=''">
            and sm.local_signid=#{local_signid}
        </if>
        <if test="status!=null and status!=''">
            and sm.status=#{status}
        </if>
        <if test="sign!=null and sign!=''">
            and sl.sign=#{sign}
        </if>
        <if test="createtime!=null and createtime!=''">
            and sm.createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
        order by sm.createtime desc
    </select>

    <delete id="deleteRemoteSignById" parameterType="string">
        delete from  sign_remote where id=#{id}
    </delete>
</mapper>
