<?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.MmsFailAgainSendMapper">
	<resultMap id="BaseResultMap" type="MmsChannelInfo">
		<id column="ID" jdbcType="INTEGER" property="id" />
		<result column="CHANNEL_NAME" jdbcType="VARCHAR" property="channelName" />
		<result column="STATUS" jdbcType="VARCHAR" property="status" />
		<result column="IS_SUPPORT_UNICOM" jdbcType="INTEGER" property="isSupportUnicom" />
		<result column="IS_SUPPORT_MOBILE" jdbcType="INTEGER" property="isSupportMobile" />
		<result column="IS_SUPPORT_TELECOM" jdbcType="INTEGER" property="isSupportTelecom" />
		<result column="MOBILE_PREFIX" jdbcType="VARCHAR" property="mobilePrefix" />
		<result column="UNICOM_PREFIX" jdbcType="VARCHAR" property="unicomPrefix" />
		<result column="TELECOM_PREFIX" jdbcType="VARCHAR" property="telecomPrefix" />
		<result column="IS_MOBILE_EXTEND" jdbcType="INTEGER" property="isMobileExtend" />
		<result column="IS_UNICOM_EXTEND" jdbcType="INTEGER" property="isUnicomExtend" />
		<result column="IS_TELECOM_EXTEND" jdbcType="INTEGER" property="isTelecomExtend" />
		<result column="CH_DESC" jdbcType="VARCHAR" property="chDesc" />
		<result column="PA_URL" jdbcType="VARCHAR" property="paUrl" />
		<result column="PA_LOCATION" jdbcType="INTEGER" property="paLocation" />
		<result column="LOGINNAME" jdbcType="VARCHAR" property="loginname" />
		<result column="PASSWORD" jdbcType="VARCHAR" property="password" />
		<result column="ACCESSNUMBER" jdbcType="VARCHAR" property="accessnumber" />
		<result column="IP" jdbcType="VARCHAR" property="ip" />
		<result column="PORT" jdbcType="VARCHAR" property="port" />
		<result column="CARRIER_SPEED" jdbcType="VARCHAR" property="carrierSpeed" />
		<result column="CARRIER_SP_SIGN" jdbcType="VARCHAR" property="carrierSpSign" />
		<result column="PROTOCOL_TYPE" jdbcType="VARCHAR" property="protocolType" />
	</resultMap>
	<select id="listPageSmsFailAgain" resultType="cn.roadm.bo.MmsFailAgainSend">
		select fa.id,fa.spid,sp.sp_name,fa.taskid,fa.errorcode,fa.oldchannel,fa.newchannel,fa.otype,fa.status,
		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
		from mms_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.MmsFailAgainSend">
		insert into mms_fail_again_send(spid,taskid,starttime,endtime,errorcode,
		oldchannel,newchannel,otype,createtime,creator,status,againType, length,province,extendNum)
		value(#{spid},#{taskid},#{starttime},#{endtime},#{errorcode},
		#{oldchannel},#{newchannel},#{otype},now(),#{creator},0,#{againType}, #{length}, #{province},#{extendNum})
	</insert>

	<update id="updateFailAgainStatus" parameterType="cn.roadm.bo.MmsFailAgainSend">
		update mms_fail_again_send set status=#{status} where id=#{id}
	</update>

	<select id="getChannelInfo" resultMap="BaseResultMap">
		select id,channel_name from mms_send_channel_info where status = '1'
	</select>

	<select id="getChannelGroup" resultType="cn.roadm.bo.MmsChannelGroup">
		select id,name from mms_channel_group where status = '1'
	</select>
</mapper>
