<?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.SmsFailAgainSendMapper">
	<select id="listPageSmsFailAgain" resultType="cn.roadm.bo.SmsFailAgainSend">
		select fa.id,fa.spid,sp.sp_name,fa.taskid,fa.errorcode,fa.sign,fa.oldchannel,fa.newchannel,fa.otype,fa.status,
		fa.content,fa.creator,fa.number,DATE_FORMAT(fa.starttime, '%Y-%m-%d %H:%i:%s') starttime,fa.againType,
		DATE_FORMAT(fa.endtime, '%Y-%m-%d %H:%i:%s') endtime,DATE_FORMAT(fa.createtime, '%Y-%m-%d %H:%i:%s') createtime, length,
		fa.province,fa.extendNum,fa.sms_type
		from sms_fail_again_send fa,sms_sp_info sp where fa.spid=sp.id 
		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like concat('%',#{sp_name},'%')
		</if>
		<if test="spid!=null and spid!=''">
			and sp.id =#{spid}
		</if> 
		<if test="oldchannel!='' and oldchannel!=null and oldchannel!= '-1'">
			and fa.oldchannel =#{oldchannel}
		</if>
		<if test="newchannel!='' and newchannel!=null and newchannel != '-1'">
			and fa.newchannel =#{newchannel}
		</if>
		<if test="createtime!=null and createtime!=''">
            and fa.createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
        <if test="createtime1!=null and createtime1!=''">
            and fa.createtime&lt;DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
		<if test="creator!=null and creator!=''">
			and fa.creator like concat('%',#{creator},'%')
		</if>
		<if test="status>-1 and status!='' and status!=null">
			and fa.status=#{status}
		</if>
		order by fa.createtime desc
	</select>
	
	<insert id="insertFailAgain" parameterType="cn.roadm.bo.SmsFailAgainSend">
		insert into sms_fail_again_send(spid,taskid,starttime,endtime,errorcode,sign,
		oldchannel,newchannel,otype,content,createtime,creator,status,againType, length,province,extendNum,sms_type)
		value(#{spid},#{taskid},#{starttime},#{endtime},#{errorcode},#{sign},
		#{oldchannel},#{newchannel},#{otype},#{content},now(),#{creator},0,#{againType}, #{length}, #{province},#{extendNum},#{sms_type})
	</insert>
	
	<update id="updateFailAgainStatus" parameterType="cn.roadm.bo.SmsFailAgainSend">
		update sms_fail_again_send set status=#{status} where id=#{id}
	</update>
</mapper>