<?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="MdeHotelBrandMapper">
	<resultMap type="com.wechat.model.dbEntity.MdeHotelBrand"
		id="MdeHotelBrand">
		<id column="brand_id" property="brandId" />
		<result column="brand_name_cn" property="brandNameCn" />
		<result column="brand_name_en" property="brandNameEn" />
		<result column="international" property="international" />
		<result column="sort_id" property="sortId" />
		<result column="version_no" property="versionNo" />
		<result column="remarks" property="remarks" />
		<result column="del_flag" property="delFlag" />
		<result column="create_by" property="createBy" />
		<result column="create_date" property="createDate" />
		<result column="update_by" property="updateBy" />
		<result column="update_date" property="updateDate" />
		<result column="brandName" property="brandName"/>
	</resultMap>
	<sql id="mdeHotelBrandColumns">
		a.brand_id AS "brandId",
		a.brand_name_cn AS "brandNameCn",
		a.brand_name_en AS "brandNameEn",
		a.international AS "international",
		a.sort_id AS "sortId",
		a.version_no AS "versionNo",
		a.remarks AS
		"remarks",
		a.del_flag AS "delFlag",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate"
	</sql>

	<sql id="mdeHotelBrandJoins">
	</sql>

	<select id="getHotelByInternational" 
		resultMap="MdeHotelBrand">
		SELECT
			a.BRAND_NAME_CN AS "brandNameCn",
			a.BRAND_NAME_EN AS "brandNameEn",
			a.international AS "international",
			<choose>
				<when test="lang =='en'.toString()">
					a.BRAND_NAME_EN AS "brandName",
				</when>
				<otherwise>
					a.BRAND_NAME_CN AS "brandName",
				</otherwise>
			</choose>
			a.BRAND_ID AS "brandId"
		FROM
			mde_hotel_brand a 
		WHERE
			a.DEL_FLAG = 0
		<if test="international  != null and international  != ''">
		and a.international = #{international}
		</if> 
		order by a.SORT_ID
	</select>

	<select id="get" resultMap="MdeHotelBrand">
		SELECT
		<include refid="mdeHotelBrandColumns" />
		FROM mde_hotel_brand a
		<include refid="mdeHotelBrandJoins" />
		WHERE a.brand_id = #{id}
	</select>

	<select id="findList" resultMap="MdeHotelBrand">
		SELECT
		<include refid="mdeHotelBrandColumns" />
		FROM mde_hotel_brand a
		<include refid="mdeHotelBrandJoins" />
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when
				test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultMap="MdeHotelBrand">
		SELECT
		<include refid="mdeHotelBrandColumns" />
		FROM mde_hotel_brand a
		<include refid="mdeHotelBrandJoins" />
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when
				test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<insert id="insert">
		INSERT INTO mde_hotel_brand(
		brand_id,
		brand_name_cn,
		brand_name_en,
		international,
		sort_id,
		version_no,
		remarks,
		del_flag,
		create_by,
		create_date,
		update_by,
		update_date
		) VALUES (
		#{brandId},
		#{brandNameCn},
		#{brandNameEn},
		#{international},
		#{sortId},
		#{versionNo},
		#{remarks},
		#{delFlag},
		#{createBy.id},
		#{createDate},
		#{updateBy.id},
		#{updateDate}
		)
	</insert>

	<update id="update">
		UPDATE mde_hotel_brand SET
		brand_id = #{brandId},
		brand_name_cn = #{brandNameCn},
		brand_name_en = #{brandNameEn},
		international = #{international},
		sort_id = #{sortId},
		version_no = #{versionNo},
		remarks = #{remarks},
		update_by = #{updateBy.id},
		update_date = #{updateDate}
		WHERE brand_id = #{id}
	</update>

	<update id="delete">
		UPDATE mde_hotel_brand SET
		del_flag = #{DEL_FLAG_DELETE}
		WHERE brand_id = #{id}
	</update>

</mapper>