<?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.community.huiju.dao.TpShopMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpShop" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="shop_name" property="shopName" jdbcType="VARCHAR" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />
    <result column="sort" property="sort" jdbcType="VARCHAR" />
    <result column="shop_type_id" property="shopTypeId" jdbcType="INTEGER" />
    <result column="shop_status" property="shopStatus" jdbcType="VARCHAR" />
    <result column="shop_tel" property="shopTel" jdbcType="VARCHAR" />
    <result column="shop_address" property="shopAddress" jdbcType="VARCHAR" />
    <result column="average_price" property="averagePrice" jdbcType="VARCHAR" />
    <result column="shop_longitude" property="shopLongitude" jdbcType="VARCHAR" />
    <result column="shop_latitude" property="shopLatitude" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="ResultMapWithBLOBs" type="com.community.huiju.model.TpShop" extends="BaseResultMap" >
    <result column="shop_introduction" property="shopIntroduction" jdbcType="LONGVARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, shop_name, remark, sort, shop_type_id, shop_status, shop_tel, shop_address, 
    average_price, shop_longitude, shop_latitude, create_date, create_user, update_date, 
    update_user
  </sql>
  <sql id="Blob_Column_List" >
    shop_introduction
  </sql>
  <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from tp_shop
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_shop
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpShop" >
    insert into tp_shop (id, community_id, shop_name, 
      remark, sort, shop_type_id, 
      shop_status, shop_tel, shop_address, 
      average_price, shop_longitude, shop_latitude, 
      create_date, create_user, update_date, 
      update_user, shop_introduction)
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{shopName,jdbcType=VARCHAR}, 
      #{remark,jdbcType=VARCHAR}, #{sort,jdbcType=VARCHAR}, #{shopTypeId,jdbcType=INTEGER}, 
      #{shopStatus,jdbcType=VARCHAR}, #{shopTel,jdbcType=VARCHAR}, #{shopAddress,jdbcType=VARCHAR}, 
      #{averagePrice,jdbcType=VARCHAR}, #{shopLongitude,jdbcType=VARCHAR}, #{shopLatitude,jdbcType=VARCHAR}, 
      #{createDate,jdbcType=TIMESTAMP}, #{createUser,jdbcType=INTEGER}, #{updateDate,jdbcType=TIMESTAMP}, 
      #{updateUser,jdbcType=INTEGER}, #{shopIntroduction,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpShop" >
    insert into tp_shop
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="shopName != null" >
        shop_name,
      </if>
      <if test="remark != null" >
        remark,
      </if>
      <if test="sort != null" >
        sort,
      </if>
      <if test="shopTypeId != null" >
        shop_type_id,
      </if>
      <if test="shopStatus != null" >
        shop_status,
      </if>
      <if test="shopTel != null" >
        shop_tel,
      </if>
      <if test="shopAddress != null" >
        shop_address,
      </if>
      <if test="averagePrice != null" >
        average_price,
      </if>
      <if test="shopLongitude != null" >
        shop_longitude,
      </if>
      <if test="shopLatitude != null" >
        shop_latitude,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="createUser != null" >
        create_user,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
      <if test="updateUser != null" >
        update_user,
      </if>
      <if test="shopIntroduction != null" >
        shop_introduction,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="shopName != null" >
        #{shopName,jdbcType=VARCHAR},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        #{sort,jdbcType=VARCHAR},
      </if>
      <if test="shopTypeId != null" >
        #{shopTypeId,jdbcType=INTEGER},
      </if>
      <if test="shopStatus != null" >
        #{shopStatus,jdbcType=VARCHAR},
      </if>
      <if test="shopTel != null" >
        #{shopTel,jdbcType=VARCHAR},
      </if>
      <if test="shopAddress != null" >
        #{shopAddress,jdbcType=VARCHAR},
      </if>
      <if test="averagePrice != null" >
        #{averagePrice,jdbcType=VARCHAR},
      </if>
      <if test="shopLongitude != null" >
        #{shopLongitude,jdbcType=VARCHAR},
      </if>
      <if test="shopLatitude != null" >
        #{shopLatitude,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null" >
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="shopIntroduction != null" >
        #{shopIntroduction,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpShop" >
    update tp_shop
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="shopName != null" >
        shop_name = #{shopName,jdbcType=VARCHAR},
      </if>
      <if test="remark != null" >
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="sort != null" >
        sort = #{sort,jdbcType=VARCHAR},
      </if>
      <if test="shopTypeId != null" >
        shop_type_id = #{shopTypeId,jdbcType=INTEGER},
      </if>
      <if test="shopStatus != null" >
        shop_status = #{shopStatus,jdbcType=VARCHAR},
      </if>
      <if test="shopTel != null" >
        shop_tel = #{shopTel,jdbcType=VARCHAR},
      </if>
      <if test="shopAddress != null" >
        shop_address = #{shopAddress,jdbcType=VARCHAR},
      </if>
      <if test="averagePrice != null" >
        average_price = #{averagePrice,jdbcType=VARCHAR},
      </if>
      <if test="shopLongitude != null" >
        shop_longitude = #{shopLongitude,jdbcType=VARCHAR},
      </if>
      <if test="shopLatitude != null" >
        shop_latitude = #{shopLatitude,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="shopIntroduction != null" >
        shop_introduction = #{shopIntroduction,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.community.huiju.model.TpShop" >
    update tp_shop
    set community_id = #{communityId,jdbcType=INTEGER},
      shop_name = #{shopName,jdbcType=VARCHAR},
      remark = #{remark,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=VARCHAR},
      shop_type_id = #{shopTypeId,jdbcType=INTEGER},
      shop_status = #{shopStatus,jdbcType=VARCHAR},
      shop_tel = #{shopTel,jdbcType=VARCHAR},
      shop_address = #{shopAddress,jdbcType=VARCHAR},
      average_price = #{averagePrice,jdbcType=VARCHAR},
      shop_longitude = #{shopLongitude,jdbcType=VARCHAR},
      shop_latitude = #{shopLatitude,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      shop_introduction = #{shopIntroduction,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpShop" >
    update tp_shop
    set community_id = #{communityId,jdbcType=INTEGER},
      shop_name = #{shopName,jdbcType=VARCHAR},
      remark = #{remark,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=VARCHAR},
      shop_type_id = #{shopTypeId,jdbcType=INTEGER},
      shop_status = #{shopStatus,jdbcType=VARCHAR},
      shop_tel = #{shopTel,jdbcType=VARCHAR},
      shop_address = #{shopAddress,jdbcType=VARCHAR},
      average_price = #{averagePrice,jdbcType=VARCHAR},
      shop_longitude = #{shopLongitude,jdbcType=VARCHAR},
      shop_latitude = #{shopLatitude,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectcommunityIdShop" resultMap="ResultMapWithBLOBs">
    select
    *
    from tp_shop
    <where>
      <if test="houseName != null and houseName != ''" >
         shop_name like concat('%',#{houseName},'%')
      </if>
      <if test="tpShopTypeId != null and tpShopTypeId != ''" >
       and shop_type_id = #{tpShopTypeId,jdbcType=INTEGER}
      </if>
      and community_id = #{communityId,jdbcType=INTEGER}
      and shop_status =1
      order by sort DESC,update_date desc
    </where>
  </select>

  <select id="shopSetting" resultType="string">
    select id from tp_shop_setting where community_id = #{communityId}
  </select>

  <select id="selectShopCommunity" resultMap="ResultMapWithBLOBs">
    select * from tp_shop WHERE community_id = #{communityId} and shop_status = 1  order by sort DESC,update_date desc  LIMIT 4
  </select>

</mapper>