<?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.ym.mec.collectfee.dao.SchoolDao">
	
	<resultMap type="com.ym.mec.collectfee.entity.School" id="School">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="status_" property="status" />
		<result column="branch_id_" property="branchId" />
		<result column="branch_name_" property="branchName" />
		<result column="e_deposit__" property="eDeposit" />
		<result column="school_id_" property="schoolId" />
		<result column="city_id_" property="cityId" />
		<result column="school_name_" property="schoolName" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="School" >
		SELECT * FROM school WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="School" parameterType="map">
		SELECT * FROM school ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.collectfee.entity.School" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO school (city_id_,id_,name_,status_,branch_id_,branch_name_,e_deposit__,school_id_,school_name_,create_time_,update_time_)
		VALUES(#{cityId},#{id},#{name},#{status},#{branchId},#{branchName},#{eDeposit},#{schoolId},#{schoolName},#{createTime},#{updateTime})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.collectfee.entity.School">
		UPDATE school
		<set>
			<if test="status != null">
				status_ = #{status},
			</if>
			<if test="schoolId != null">
				school_id_ = #{schoolId},
			</if>
			<if test="cityId != null">
				city_id_ = #{cityId},
			</if>
			<if test="eDeposit != null">
				e_deposit__ = #{eDeposit},
			</if>
			<if test="schoolName != null">
				school_name_ = #{schoolName},
			</if>
			<if test="branchId != null">
				branch_id_ = #{branchId},
			</if>
			<if test="updateTime != null">
				update_time_ = #{updateTime},
			</if>
			<if test="branchName != null">
				branch_name_ = #{branchName},
			</if>
			<if test="name != null">
				name_ = #{name},
			</if>
		</set>
		WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM school WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="School" parameterType="map">
		SELECT * FROM school <include refid="schoolPage"/> ORDER BY id_ <include refid="global.limit"/>
	</select>



	<sql id="schoolPage">
		<where>
			<if test="name != null and name != ''">
				name_ LIKE '%#{name}%'
			</if>
			<if test="status != null">
				AND status_ = #{status}
			</if>
			<if test="branchId != null">
				AND branch_id_ = #{branchId}
			</if>
		</where>
	</sql>
	
	<!-- 查询当前表的总记录数 -->
	<select id="findCount" resultType="int">
		SELECT COUNT(*) FROM school <include refid="schoolPage"/>
	</select>
</mapper>
