<?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.RenewalsDao">
	
	<resultMap type="com.ym.mec.collectfee.entity.Renewals" id="Renewals">
		<result column="id" property="id" />
		<result column="user_id" property="userId" />
		<result column="branch_id" property="branchId" />
		<result column="class_id" property="classId" />
		<result column="way" property="way" />
		<result column="pay" property="pay" />
		<result column="change_mode" property="changeMode" />
		<result column="price" property="price" />
		<result column="buy" property="buy" />
		<result column="order_id" property="orderId" />
		<result column="branch_id" property="branchId" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="Renewals" >
		SELECT * FROM renewals WHERE id = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="Renewals">
		SELECT * FROM renewals ORDER BY id
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.collectfee.entity.Renewals" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO renewals (id,user_id,branch_id,class_id,way,pay,change_mode,price,buy,order_id) VALUES(#{id},#{userId},#{branchId},#{classId},#{way},#{pay},#{changeMode},#{price},#{buy},#{orderId})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.collectfee.entity.Renewals">
		UPDATE renewals SET user_id = #{userId},price = #{price},class_id = #{classId},buy = #{buy},pay = #{pay},id = #{id},change_mode = #{changeMode},order_id = #{orderId},way = #{way} WHERE id = #{id} 
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM renewals WHERE id = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="Renewals" parameterType="map">
		SELECT * FROM renewals ORDER BY id <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM renewals
	</select>

	<insert id="renewalsInsert" parameterType="java.util.ArrayList">
		INSERT INTO `renewals` (id,user_id,branch_id,class_id,course_id,way,pay,change_mode,price,buy,order_id) VALUES
		<foreach collection="renewalses" item="item" index="index" separator=",">
			(#{item.id},#{item.userId},#{item.branchId},#{item.classId},#{item.courseId},#{item.way},#{item.pay},#{item.changeMode},#{item.price},#{item.buy},#{item.orderId})
		</foreach>
	</insert>

	<!-- 根据order_id获取小课信息 -->
	<select id="getRenewalsByOrderId" resultMap="Renewals">
		SELECT * FROM `renewals` WHERE order_id = #{orderId} limit 1
	</select>
</mapper>
