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

	<insert id="operchannelorginfo" parameterType="HashMap" >
			MERGE INTO TB_CHANNEL_ORG_BOYUAN A USING (SELECT #{subchannelcode} SUBCHANNELCODE, #{channel} CHANNEL FROM DUAL) B
			ON(A.SUBCHANNELCODE = B.SUBCHANNELCODE AND A.CHANNEL = B.CHANNEL)
			WHEN MATCHED THEN UPDATE 
			SET STATUS = #{status}, UPDTIME = SYSDATE, SUBCHANNELNAME = #{subchannelname}, SUBCHANNELKEY = #{subchannelkey}
			WHEN NOT MATCHED THEN 
			INSERT(ID, CHANNEL, SUBCHANNELCODE, SUBCHANNELNAME, SUBCHANNELKEY, STATUS) 
			VALUES (TO_CHAR(SYSDATE,'yyyyMMddhh24miss')||SEQ_COMMON6.NEXTVAL,
			#{channel}, #{subchannelcode}, #{subchannelname}, #{subchannelkey}, #{status})
	</insert>

    <select id="getchannelorginfo" parameterType="string" resultType="HashMap">
		SELECT ID, CHANNEL, SUBCHANNELCODE, SUBCHANNELNAME, SUBCHANNELKEY, STATUS, TO_CHAR(INSERTTIME, 'YYYYMMDDHH24MISS') INSERTTIME, TO_CHAR(UPDTIME, 'YYYYMMDDHH24MISS') UPDTIME
		FROM TB_CHANNEL_ORG_BOYUAN WHERE CHANNEL = #{channel} AND SUBCHANNELCODE = #{subchannelcode}
	</select>

</mapper>