<?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.restful.dao.AkUserDao" >



    <update id="insertUserInfo">

	  MERGE INTO TD_AK_USER_INFO a USING (SELECT #{cid}  as channel , #{userid}  as userid FROM DUAL) b
			ON(a.channel = b.channel and a.userid=b.userid)
			WHEN MATCHED THEN UPDATE
			SET CHANNELINFO = #{channelinfo},ADDRESS =#{address},NICKNAME = #{nickname},ID=TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval,INSERTTIME=sysdate
			WHEN NOT MATCHED THEN
			INSERT (ID,CHANNEL,CHANNELINFO,USERID,ADDRESS,NICKNAME,INSERTTIME)
		    VALUES (TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval,#{cid},#{channelinfo},#{userid},#{address},#{nickname},SYSDATE)

    </update>

    <select id="queryUserInfo" resultType="java.util.Map">
    select USERID ,CHANNELINFO ,ADDRESS  ,to_char(INSERTTIME,'yyyy-MM-dd hh24:mi:ss') ,NICKNAME　from TD_AK_USER_INFO
    where userid=#{userid}  and channel=#{cid} order by inserttime desc
    </select>
</mapper>