<?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.cku.dao.CkuMatchHotelMapper" >
  <resultMap id="BaseResultMap" type="com.cku.model.CkuMatchHotel" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="hotel_phone" property="hotelPhone" jdbcType="VARCHAR" />
    <result column="hotel_longitude" property="hotelLongitude" jdbcType="VARCHAR" />
    <result column="hotel_latitude" property="hotelLatitude" jdbcType="VARCHAR" />
    <result column="hotel_address" property="hotelAddress" jdbcType="VARCHAR" />
    <result column="hotel_name" property="hotelName" jdbcType="VARCHAR" />
    <result column="hotel_info" property="hotelInfo" jdbcType="VARCHAR" />
    <result column="hotel_line" property="hotelLine" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <collection property="ckuImageList" ofType="com.cku.model.CkuImage" column="matchHotelId" >
    	<id column="image_id" property="imageId" />
    	<result column="image_min_url" property="imageMinUrl" />
    	<result column="image_max_url" property="imageMaxUrl" />
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
    id, hotel_phone, hotel_longitude, hotel_latitude, hotel_address, hotel_name, hotel_info, 
    hotel_line, create_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    *
    from cku_match_hotel hotel,cku_image image
    where  hotel.id=image.match_hotel_id and id = #{id,jdbcType=INTEGER}
  </select>
 <select id="selectById" resultMap="BaseResultMap">
 select 
 	<include refid="Base_Column_List" />
 	from cku_match_hotel where id=#{id}
 </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from cku_match_hotel
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.cku.model.CkuMatchHotel" >
    insert into cku_match_hotel (id, hotel_phone, hotel_longitude, 
      hotel_latitude, hotel_address, hotel_name, 
      hotel_info, hotel_line, create_time
      )
    values (#{id,jdbcType=INTEGER}, #{hotelPhone,jdbcType=VARCHAR}, #{hotelLongitude,jdbcType=VARCHAR}, 
      #{hotelLatitude,jdbcType=VARCHAR}, #{hotelAddress,jdbcType=VARCHAR}, #{hotelName,jdbcType=VARCHAR}, 
      #{hotelInfo,jdbcType=VARCHAR}, #{hotelLine,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.cku.model.CkuMatchHotel" >
    insert into cku_match_hotel
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="hotelPhone != null" >
        hotel_phone,
      </if>
      <if test="hotelLongitude != null" >
        hotel_longitude,
      </if>
      <if test="hotelLatitude != null" >
        hotel_latitude,
      </if>
      <if test="hotelAddress != null" >
        hotel_address,
      </if>
      <if test="hotelName != null" >
        hotel_name,
      </if>
      <if test="hotelInfo != null" >
        hotel_info,
      </if>
      <if test="hotelLine != null" >
        hotel_line,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="hotelPhone != null" >
        #{hotelPhone,jdbcType=VARCHAR},
      </if>
      <if test="hotelLongitude != null" >
        #{hotelLongitude,jdbcType=VARCHAR},
      </if>
      <if test="hotelLatitude != null" >
        #{hotelLatitude,jdbcType=VARCHAR},
      </if>
      <if test="hotelAddress != null" >
        #{hotelAddress,jdbcType=VARCHAR},
      </if>
      <if test="hotelName != null" >
        #{hotelName,jdbcType=VARCHAR},
      </if>
      <if test="hotelInfo != null" >
        #{hotelInfo,jdbcType=VARCHAR},
      </if>
      <if test="hotelLine != null" >
        #{hotelLine,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.cku.model.CkuMatchHotel" >
    update cku_match_hotel
    <set >
      <if test="hotelPhone != null" >
        hotel_phone = #{hotelPhone,jdbcType=VARCHAR},
      </if>
      <if test="hotelLongitude != null" >
        hotel_longitude = #{hotelLongitude,jdbcType=VARCHAR},
      </if>
      <if test="hotelLatitude != null" >
        hotel_latitude = #{hotelLatitude,jdbcType=VARCHAR},
      </if>
      <if test="hotelAddress != null" >
        hotel_address = #{hotelAddress,jdbcType=VARCHAR},
      </if>
      <if test="hotelName != null" >
        hotel_name = #{hotelName,jdbcType=VARCHAR},
      </if>
      <if test="hotelInfo != null" >
        hotel_info = #{hotelInfo,jdbcType=VARCHAR},
      </if>
      <if test="hotelLine != null" >
        hotel_line = #{hotelLine,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cku.model.CkuMatchHotel" >
    update cku_match_hotel
    set hotel_phone = #{hotelPhone,jdbcType=VARCHAR},
      hotel_longitude = #{hotelLongitude,jdbcType=VARCHAR},
      hotel_latitude = #{hotelLatitude,jdbcType=VARCHAR},
      hotel_address = #{hotelAddress,jdbcType=VARCHAR},
      hotel_name = #{hotelName,jdbcType=VARCHAR},
      hotel_info = #{hotelInfo,jdbcType=VARCHAR},
      hotel_line = #{hotelLine,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <!--********************************************************* 自定义********************************************* -->
  <resultMap id="getHotelByMatchMap" type="com.cku.model.CkuMatchHotel" extends="BaseResultMap" >
		<collection property="ckuImageList" javaType="list" ofType="com.cku.model.CkuImage">
			<id property="imageId" column="image_id"/>
			<result property="imageMinUrl" column="image_min_url"/>
			<result property="imageMaxUrl" column="image_max_url"/>
		</collection>
  </resultMap>
  <!-- SQL SERVER -->
  <select id="getHotel" resultMap="getHotelByMatchMap" parameterType="java.lang.Integer" >
    SELECT
		mh.*, ci.image_min_url,
		ci.image_max_url
	FROM
		cku_match_hotel_relation mhr
	RIGHT JOIN cku_match_hotel mh ON mh.id = mhr.hotel_id
	LEFT JOIN cku_image ci ON mh.id = ci.match_hotel_id
	WHERE
		mhr.show_location = #{showLocation}
  </select>
  
    <select id="getList" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
	SELECT * FROM cku_match_hotel 
	where 1= 1 
	<if test="name != '' and  name != null" >
		and hotel_name like '%${name}%'
    </if>
	<if test="address != '' and  address != null" >
		and hotel_address like '%${address}%'
    </if>
	ORDER BY ID DESC limit ${count},${limit}
  </select>
  <select id="getCount" resultType="java.lang.Long" parameterType="java.lang.Integer" >
    SELECT
		count(*)
	FROM cku_match_hotel 
	WHERE 1=1 
	<if test="name != '' and  name != null" >
		and hotel_name like '%${name}%'
    </if>
	<if test="address != '' and  address != null" >
		and hotel_address like '%${address}%'
    </if>
  </select>

</mapper>