<?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.ToCommunitiesMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.ToCommunities" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_name" property="communityName" jdbcType="VARCHAR" />
    <result column="community_alias" property="communityAlias" jdbcType="VARCHAR" />
    <result column="province_id" property="provinceId" jdbcType="INTEGER" />
    <result column="city_id" property="cityId" jdbcType="INTEGER" />
    <result column="district_id" property="districtId" jdbcType="INTEGER" />
    <result column="longitude" property="longitude" jdbcType="VARCHAR" />
    <result column="latitude" property="latitude" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_name, community_alias, province_id, city_id, district_id, longitude, 
    latitude
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from to_communities
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from to_communities
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.ToCommunities" >
    insert into to_communities (id, community_name, community_alias, 
      province_id, city_id, district_id, 
      longitude, latitude)
    values (#{id,jdbcType=INTEGER}, #{communityName,jdbcType=VARCHAR}, #{communityAlias,jdbcType=VARCHAR}, 
      #{provinceId,jdbcType=INTEGER}, #{cityId,jdbcType=INTEGER}, #{districtId,jdbcType=INTEGER}, 
      #{longitude,jdbcType=VARCHAR}, #{latitude,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.ToCommunities" >
    insert into to_communities
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityName != null" >
        community_name,
      </if>
      <if test="communityAlias != null" >
        community_alias,
      </if>
      <if test="provinceId != null" >
        province_id,
      </if>
      <if test="cityId != null" >
        city_id,
      </if>
      <if test="districtId != null" >
        district_id,
      </if>
      <if test="longitude != null" >
        longitude,
      </if>
      <if test="latitude != null" >
        latitude,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityName != null" >
        #{communityName,jdbcType=VARCHAR},
      </if>
      <if test="communityAlias != null" >
        #{communityAlias,jdbcType=VARCHAR},
      </if>
      <if test="provinceId != null" >
        #{provinceId,jdbcType=INTEGER},
      </if>
      <if test="cityId != null" >
        #{cityId,jdbcType=INTEGER},
      </if>
      <if test="districtId != null" >
        #{districtId,jdbcType=INTEGER},
      </if>
      <if test="longitude != null" >
        #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null" >
        #{latitude,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.ToCommunities" >
    update to_communities
    <set >
      <if test="communityName != null" >
        community_name = #{communityName,jdbcType=VARCHAR},
      </if>
      <if test="communityAlias != null" >
        community_alias = #{communityAlias,jdbcType=VARCHAR},
      </if>
      <if test="provinceId != null" >
        province_id = #{provinceId,jdbcType=INTEGER},
      </if>
      <if test="cityId != null" >
        city_id = #{cityId,jdbcType=INTEGER},
      </if>
      <if test="districtId != null" >
        district_id = #{districtId,jdbcType=INTEGER},
      </if>
      <if test="longitude != null" >
        longitude = #{longitude,jdbcType=VARCHAR},
      </if>
      <if test="latitude != null" >
        latitude = #{latitude,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.ToCommunities" >
    update to_communities
    set community_name = #{communityName,jdbcType=VARCHAR},
      community_alias = #{communityAlias,jdbcType=VARCHAR},
      province_id = #{provinceId,jdbcType=INTEGER},
      city_id = #{cityId,jdbcType=INTEGER},
      district_id = #{districtId,jdbcType=INTEGER},
      longitude = #{longitude,jdbcType=VARCHAR},
      latitude = #{latitude,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByCommunityName" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from to_communities
    where 1=1
    <if test="communityName != null and communityName != ''" >
      and community_name like concat('%',#{communityName,jdbcType=VARCHAR},'%')
    </if>
  </select>

  <select id="selectAndmin" resultType="int">
    SELECT u.id  FROM  tp_user u
    LEFT JOIN to_communities co ON u.login_name = co.login_name
    WHERE co.id = #{communityId,jdbcType=VARCHAR}
    AND u.community_id=#{communityId,jdbcType=VARCHAR}
  </select>
</mapper>