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

	

	<select id="getlistPageSignNotRegisterChannel" resultType="SignNotRegisterChannel">
		SELECT snrc.id,snrc.spid,snrc.oldchannel,snrc.newchannel,date_format(snrc.createtime,'%Y-%m-%d %H:%m:%s') createtime,ifnull(si.sp_name,"全部") spName  from sms_sign_not_register_channel snrc left join sms_sp_info si
		on snrc.spid=si.id
		<where>
			<if test="oldchannel!=null and oldchannel!=''">
				and snrc.oldchannel=#{oldchannel}
			</if>
			<if test="newchannel!=null and newchannel!=''">
				and snrc.newchannel=#{newchannel}
			</if>
			<if test="starttime!=null and starttime!='' and endtime!=null and endtime!=''">
			and snrc.createtime BETWEEN #{starttime} and DATE_SUB(#{endtime} ,INTERVAL -1 DAY)
			</if>
		</where>
		
		ORDER BY snrc.id DESC
	</select>
	
	<select id="getSignNotRegisterChannel" resultType="SignNotRegisterChannel">
		SELECT snrc.id,snrc.spid,snrc.oldchannel,snrc.newchannel,date_format(snrc.createtime,'%Y-%m-%d %H:%m:%s') createtime,si.sp_name spName  from sms_sign_not_register_channel snrc left join sms_sp_info si
		on snrc.spid=si.id
		<where>
			and snrc.spid=#{spId} and snrc.oldchannel=#{oldchannel}
		</where>
		limit 1
	</select>
	<select id="getChannelList" resultType="String">
		select channel_name from sms_send_channel_info
	</select>
	
	<update id="updateNotChannel">
		 update
       `sms_sign_not_register_channel`
        <set>
            <if test="spId!=null">
                spid=#{spId},
            </if>
            <if test="oldchannel!=null and oldchannel!= ''">
                oldchannel=#{oldchannel},
            </if>
            <if test="newchannel!=null and newchannel!= ''">
                newchannel=#{newchannel},
            </if>
        </set>
        where
        id=#{id}
	</update>
	
	<insert id="insertNotChannel" useGeneratedKeys="true" keyProperty="id">
		INSERT INTO `sms_sign_not_register_channel` (`spid`, `oldchannel`, `newchannel`, `createtime`) VALUES (#{spId}, #{oldchannel}, #{newchannel}, now())
	</insert>
	
	<delete id="deleteNotChannel">
		delete from sms_sign_not_register_channel where id=#{id}
	</delete>
	
	<select id="getNotRegisterById" resultType="SignNotRegisterChannel">
		SELECT snrc.id,snrc.spid,snrc.oldchannel,snrc.newchannel,ifnull(si.sp_name,"全部") spName  from sms_sign_not_register_channel snrc left join sms_sp_info si
		on snrc.spid=si.id
		<where>
			and snrc.id=#{id}
		</where>
	</select>
</mapper>