<?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.biz.dal.dao.MusicMarginDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MusicMargin" id="MusicMargin">
		<result column="id_" property="id" />
		<result column="type_" property="type" />
		<result column="date_" property="date" />
		<result column="organ_" property="organ" />
		<result column="school_" property="school" />
		<result column="user_id_" property="userId" />
		<result column="username_" property="username" />
		<result column="init_" property="init" />
		<result column="payment_" property="payment" />
		<result column="refund_" property="refund" />
		<result column="refund_flag_" property="refundFlag" />
		<result column="balance_" property="balance" />
		<result column="margin_type_" property="marginType" />
		<result column="match_" property="match" />
		<result column="memo_" property="memo" />
		<result column="process_no_" property="processNo" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="MusicMargin" >
		SELECT * FROM music_margin WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="MusicMargin">
		SELECT * FROM music_margin ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicMargin" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO music_margin (id_,type_,date_,organ_,school_,user_id_,username_,init_,payment_,refund_,refund_flag_,balance_,margin_type_,match_,memo_,process_no_) VALUES(#{id},#{type},#{date},#{organ},#{school},#{userId},#{username},#{init},#{payment},#{refund},#{refundFlag},#{balance},#{marginType},#{match},#{memo},#{processNo})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicMargin">
		UPDATE music_margin <set>
<if test="school != null">
school_ = #{school},
</if>
<if test="id != null">
id_ = #{id},
</if>
<if test="balance != null">
balance_ = #{balance},
</if>
<if test="memo != null">
memo_ = #{memo},
</if>
<if test="organ != null">
organ_ = #{organ},
</if>
<if test="username != null">
username_ = #{username},
</if>
<if test="refundFlag != null">
refund_flag_ = #{refundFlag},
</if>
<if test="userId != null">
user_id_ = #{userId},
</if>
<if test="payment != null">
payment_ = #{payment},
</if>
<if test="refund != null">
refund_ = #{refund},
</if>
<if test="init != null">
init_ = #{init},
</if>
<if test="match != null">
match_ = #{match},
</if>
<if test="processNo != null">
process_no_ = #{processNo},
</if>
<if test="marginType != null">
margin_type_ = #{marginType},
</if>
<if test="type != null">
type_ = #{type},
</if>
<if test="date != null">
date_ = #{date},
</if>
</set> WHERE id_ = #{id} 
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM music_margin WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MusicMargin" parameterType="map">
		SELECT * FROM music_margin
		ORDER BY id_
		<include refid="global.limit"/>
	</select>
	<sql id="queryPageSql">
		<where>
			<if test="refundFlag != null">
				AND refund_flag_ = #{refundFlag}
			</if>
			<if test="search != null and search != ''">
				AND (username_ LIKE CONCAT('%',#{search},'%') OR user_id_ = #{search})
			</if>
		</where>
	</sql>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM music_margin
	</select>
</mapper>
