<?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="com.chinacreator.video.mapper.SmsCheckDao">

    <select id="getNo" resultType="String">
       SELECT TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval SENO FROM DUAL       
    </select>

    <insert id="addRec" parameterType="Map">
       INSERT INTO td_tencentcheck_rec(
			ID,USERID,RESDATA,REQUEST,CHANNEL,INVOKEFACE,CALLBACKURL)
 		VALUES(#{id},#{userid,jdbcType=VARCHAR},#{resdata},#{request},#{channel},#{invokeface},#{callbackurl,jdbcType=VARCHAR})

    </insert>

    <update id="upRec" parameterType="Map">
		UPDATE td_tencentcheck_rec SET isviolate = #{isviolate},resultinfo = #{resultinfo},ischeck='0',requestid = #{requestid}
		WHERE ID = #{id}
	</update>

    <update id="upRec2" parameterType="Map">
		UPDATE td_tencentcheck_rec SET requestid = #{requestid},resultinfo = #{resultinfo},ischeck='0'
		WHERE ID = #{id}
	</update>

    <update id="upCallbackRec" parameterType="Map">
		UPDATE td_tencentcheck_rec SET hascallback = '0',callbackresult = #{callbackresult},callbacktime = sysdate,isviolate = #{isviolate}
		WHERE requestid = #{requestid} and invokeface = #{invokeface}
	</update>

	<select id="getCallbackUrl" parameterType="Map" resultType="HashMap">
		select CALLBACKURL, CHANNEL from td_tencentcheck_rec
		WHERE requestid = #{requestid} and invokeface = #{invokeface}
	</select>

	<update id="upNotifyRec" parameterType="Map">
		UPDATE td_tencentcheck_rec SET hasnotify = '0',notifyresult = #{notifyresult}
		WHERE requestid = #{requestid} and invokeface = #{invokeface}
	</update>

	<select id="getBussinesid" parameterType="Map" resultType="string">
		select bussinessid from td_tencentcheck_bussid where status = '0' and channel = #{channel}
		<if test="subchannel !=null and subchannel != ''">
			and subchannel = #{subchannel}
		</if>
		<if test="subchannel == null or subchannel==''">
			and subchannel is null
		</if>
	</select>

	<insert id="saveBussinesid" parameterType="Map">
		insert into td_tencentcheck_bussid (
			CHANNEL,SUBCHANNEL,BUSSINESSID)
 		VALUES(#{channel},#{subchannel,jdbcType=VARCHAR},#{bussinessid})
	</insert>

	<select id="getChannelName" parameterType="String" resultType="string">
		select name from TB_CHANNEL_ORG where status=0 and id =#{channel}
	</select>

	<insert id="addCallbackRec" parameterType="Map">
       INSERT INTO TD_TENCENTCHECK_CALLBACK(
			ID,CHANNEL,INVOKEFACE,CALLBACKURL,requestid,isviolate,callbackresult,hascallback)
 		VALUES(#{id},#{channel,jdbcType=VARCHAR},#{invokeface},#{callbackurl,jdbcType=VARCHAR},
 		#{requestid},#{isviolate},#{callbackresult},'0')
    </insert>

	<update id="upNotifyCallbackRec" parameterType="Map">
		UPDATE TD_TENCENTCHECK_CALLBACK SET hasnotify = '0',notifyresult = #{notifyresult},callbacktime = sysdate
		WHERE id = #{id}
	</update>

</mapper>