<?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="placeSqlMapper">
	<sql id="base_column">
		id,
		name
	</sql>
	
	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.Place">
		select
		<include refid="base_column"/>
		from t_place
	</select>
	
	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.Place">
		select
		<include refid="base_column"/>
		from t_place
		where id = #{id}
	</select>
	
	<select id="countByParams" parameterType="map" resultType="int">
		select count(id) from t_place 
		<where>
		<if test="placeName != null">
			name like #{placeName}
		</if>
		</where>
	</select>
	
	<select id="findByParams" parameterType="map" resultType="Place">
		select <include refid="base_column"/> from t_place 
		<where>
		<if test="placeName != null">
			name like #{placeName}
		</if>
		</where>
		limit #{pager.offset}, #{pager.limit}
	</select>
	
	<insert id="add" parameterType="Place">
	insert into t_place(name) values(#{name})
	</insert>
	
	<select id="findUnclassfiedPlace" resultType="Place">
	select <include refid="base_column"/> from t_place
	where id not in(select place_id from t_place_class)
	limit #{offset}, #{limit}
	</select>
	
	<select id="countUnclassfiedPlace" resultType="int">
		select count(id) from t_place
		where id not in(select place_id from t_place_class)
	</select>
	
	
	<select id="findPlaceByPlaceClassId" parameterType="long" resultType="Place">
		select t_place.id as id, t_place.name as name from t_place
		where id in (select place_id from t_place_class where class_id = #{placeClassId})
	</select>
	
	<select id="queryPlaceNameByClassId" parameterType="java.lang.Long" resultType="java.lang.String">
		select tp.name name from t_place tp,t_place_class tpc where tp.id = tpc.place_id and tpc.class_id = #{classId}
	</select>
	
	<select id="queryPlace" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.Place">
		select id,name from t_place order by id limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="queryPlaceCount" resultType="java.lang.Integer">
		select count(id) from t_place
	</select>
</mapper>