<?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.BranchDao">
	
	<resultMap type="com.ym.mec.collectfee.entity.Branch" id="Branch">
		<result column="branch_id_" property="branchId" />
		<result column="branch_name_" property="branchName" />
		<result column="province_" property="province" />
		<result column="city_" property="city" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="Branch" >
		SELECT * FROM branch WHERE branch_id_ = #{branchId} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="Branch">
		SELECT * FROM branch ORDER BY branch_id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.collectfee.entity.Branch" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO branch (branch_id_,branch_name_,province_,city_) VALUES(#{branchId},#{branchName},#{province},#{city})
	</insert>

    <insert id="batchInsert" parameterType="java.util.List">
		INSERT INTO branch (branch_id_,branch_name_,province_,city_) VALUES
		<foreach collection="branches" item="item" index="index" separator=",">
			(#{item.branchId},#{item.branchName},#{item.province},#{item.city})
		</foreach>
	</insert>

    <!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.collectfee.entity.Branch">
		UPDATE branch
		<set>
			<if test="city != null">
				city_ = #{city},
			</if>
			<if test="branchName != null">
				branch_name_ = #{branchName},
			</if>
			<if test="province != null">
				province_ = #{province}
			</if>
		</set>
		WHERE branch_id_ = #{branchId}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM branch WHERE branch_id_ = #{branchId} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="Branch" parameterType="map">
		SELECT * FROM branch ORDER BY branch_id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="findCount" resultType="int">
		SELECT COUNT(*) FROM branch
	</select>

	<select id="findBranchByList" resultMap="Branch">
		SELECT * FROM branch WHERE branch_id_ IN
		<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
			#{item.branchId}
		</foreach>
	</select>
</mapper>
