<?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="kr.co.i4way.mapper.mssql_brd.MssqlBrdMapper">

	<update id="setRecLicenseInfo"> 
	    MERGE INTO TBL_LICENSE A USING (
		<foreach item="item" collection="list" open="" close="" index="index" separator="UNION" >
			SELECT #{item.solution_type} as solution_type
				,#{item.server_id} as server_id
				,#{item.server_name} as server_name
				,#{item.server_type} as server_type
				,#{item.server_type_name} as server_type_name
				,#{item.license_cnt} as license_cnt
				,#{item.used_cnt} as used_cnt
		</foreach>
		) B ON (A.solution_type = B.solution_type AND A.server_id = B.server_id)
		WHEN MATCHED THEN 
			UPDATE 
				SET 
					server_name = B.server_name  
			  		, A.server_type = B.server_type
			  		, A.server_type_name = B.server_type_name
			  		, A.license_cnt = B.license_cnt
			  		, A.used_cnt = B.used_cnt 
		WHEN NOT MATCHED THEN
			INSERT 
	    		(solution_type
	    		,server_id
	           	,server_name 
	           	,server_type
	           	,server_type_name
	           	,license_cnt
	           	,used_cnt)
			VALUES 
	    	(B.solution_type
	    	, B.server_id
	    	, B.server_name
	    	, B.server_type
	    	, B.server_type_name
	    	, B.license_cnt
	    	, B.used_cnt
	    	);
	</update>

	<update id="setGenesysLicenseInfo"  parameterType="kr.co.i4way.cst.model.RecLicenseVo"> 
		UPDATE TBL_LICENSE SET 
			license_cnt = #{license_cnt}
			,used_cnt = #{used_cnt}
		WHERE solution_type = #{solution_type}
		AND server_id = #{server_id}
	</update>

	<insert id="insertWeatherInfo"> 
		INSERT INTO TBL_WEATHER (region_cd,do_nm,gu_nm,dong_nm,latitude,longitude,check_time,weather_icon,weather_nm
								,current_temp,humidity,dewdrop,wind_direct,wind_speed,rain,snow,lnd_air_pres,spg_air_pres
								,sunrise,sunset,visible) VALUES
		<foreach item="item" collection="list" index="index" separator="," >
		(
			#{item.region_cd,jdbcType=VARCHAR}
			,#{item.do_nm,jdbcType=VARCHAR}
			,#{item.gu_nm,jdbcType=VARCHAR}
			,#{item.dong_nm,jdbcType=VARCHAR}
			,#{item.latitude,jdbcType=VARCHAR}
			,#{item.longitude,jdbcType=VARCHAR}
			,#{item.check_time,jdbcType=VARCHAR}
			,#{item.weather_icon,jdbcType=VARCHAR}
			,#{item.weather_nm,jdbcType=VARCHAR}
			,#{item.current_temp,jdbcType=VARCHAR}
			,#{item.humidity,jdbcType=VARCHAR}
			,#{item.dewdrop,jdbcType=VARCHAR}
			,#{item.wind_direct,jdbcType=VARCHAR}
			,#{item.wind_speed,jdbcType=VARCHAR}
			,#{item.rain,jdbcType=VARCHAR}
			,#{item.snow,jdbcType=VARCHAR}
			,#{item.lnd_air_pres,jdbcType=VARCHAR}
			,#{item.spg_air_pres,jdbcType=VARCHAR}
			,#{item.sunrise,jdbcType=VARCHAR}
			,#{item.sunset,jdbcType=VARCHAR}
			,#{item.visible,jdbcType=VARCHAR}
		)
		</foreach>
	</insert>
	
	<insert id="insertWeatherHistory"> 
	<![CDATA[
		INSERT INTO TBL_WEATHER_HISTORY
		SELECT * FROM TBL_WEATHER
		WHERE region_cd = '42'
	]]>
	</insert>

	<update id="deleteWeatherInfo"> 
		DELETE FROM TBL_WEATHER
	</update>
</mapper>