<?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.MemberFeeSettingDao">

	<resultMap type="com.ym.mec.biz.dal.entity.MemberFeeSetting"
		id="MemberFeeSetting">
		<result column="id_" property="id" />
		<result column="current_day_fee_" property="currentDayFee" />
		<result column="group_purchase_day_fee_" property="groupPurchaseDayFee" />
		<result column="original_day_fee_" property="originalDayFee" />
		<result column="current_month_fee_" property="currentMonthFee" />
		<result column="group_purchase_month_fee_" property="groupPurchaseMonthFee" />
		<result column="original_month_fee_" property="originalMonthFee" />
		<result column="current_quarterly_fee_" property="currentQuarterlyFee" />
		<result column="group_purchase_quarterly_fee_" property="groupPurchaseQuarterlyFee" />
		<result column="original_quarterly_fee_" property="originalQuarterlyFee" />
		<result column="current_half_year_fee_" property="currentHalfYearFee" />
		<result column="group_purchase_half_year_fee_" property="groupPurchaseHalfYearFee" />
		<result column="original_half_year_fee_" property="originalHalfYearFee" />
		<result column="current_year_fee_" property="currentYearFee" />
		<result column="group_purchase_year_fee_" property="groupPurchaseYearFee" />
		<result column="original_year_fee_" property="originalYearFee" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="MemberFeeSetting">
		SELECT * FROM
		member_fee_setting WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="MemberFeeSetting">
		SELECT * FROM member_fee_setting where tenant_id_ = #{tenantId}
		ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MemberFeeSetting"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO member_fee_setting
		(id_,current_day_fee_,group_purchase_day_fee_,original_day_fee_,current_month_fee_,group_purchase_month_fee_,original_month_fee_,current_quarterly_fee_,group_purchase_quarterly_fee_,original_quarterly_fee_,current_half_year_fee_,group_purchase_half_year_fee_,original_half_year_fee_,current_year_fee_,group_purchase_year_fee_,original_year_fee_,tenant_id_)
		VALUES(#{id},#{currentDayFee},#{groupPurchaseDayFee},#{originalDayFee},#{currentMonthFee},#{groupPurchaseMonthFee},#{originalMonthFee},#{currentQuarterlyFee},#{groupPurchaseQuarterlyFee},#{originalQuarterlyFee},#{currentHalfYearFee},#{groupPurchaseHalfYearFee},#{originalHalfYearFee},#{currentYearFee},#{groupPurchaseYearFee},#{originalYearFee},#{tenantId})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MemberFeeSetting">
		UPDATE member_fee_setting
		<set>
				original_half_year_fee_ = #{originalHalfYearFee},
				original_quarterly_fee_ = #{originalQuarterlyFee},
				original_day_fee_ = #{originalDayFee},
			<if test="id != null">
				id_ = #{id},
			</if>
				current_half_year_fee_ = #{currentHalfYearFee},
				current_quarterly_fee_ = #{currentQuarterlyFee},
				current_day_fee_ = #{currentDayFee},
				group_purchase_quarterly_fee_ = #{groupPurchaseQuarterlyFee},
				group_purchase_half_year_fee_ = #{groupPurchaseHalfYearFee},
				current_year_fee_ = #{currentYearFee},
				group_purchase_day_fee_ = #{groupPurchaseDayFee},
				group_purchase_month_fee_ = #{groupPurchaseMonthFee},
				group_purchase_year_fee_ = #{groupPurchaseYearFee},
				current_month_fee_ = #{currentMonthFee},
				original_month_fee_ = #{originalMonthFee},
				original_year_fee_ = #{originalYearFee}
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MemberFeeSetting"
		parameterType="map">
		SELECT * FROM member_fee_setting where tenant_id_ = #{tenantId} ORDER BY id_
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM
		member_fee_setting where tenant_id_ = #{tenantId}
	</select>
	
	<select id="findByRankIdAndOrganId" resultMap="MemberFeeSetting">
		SELECT mfs.* FROM
		member_rank_organization_fee_mapper mro
		LEFT JOIN member_fee_setting
		mfs ON mfs.id_ = mro.member_fee_setting_id_
		WHERE
		mro.member_rank_setting_id_ = #{rankId} AND mro.organ_id_ = #{organId}
	</select>
</mapper>
