<?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.diaoyun.zion.chinafrica.dao.TbCfFeeDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity" id="tbCfFeeMap">
        <result property="feeId" column="fee_id"/>
        <result property="feeType" column="fee_type"/>
        <result property="enableFlag" column="enable_flag"/>
        <result property="feePercent" column="fee_percent"/>
        <result property="feeRate" column="fee_rate"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity">
		select
			`fee_id`,
			`fee_type`,
			`enable_flag`,
			`fee_percent`,
			`fee_rate`
		from tb_cf_fee
		where fee_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity">
		select
    		`fee_id`,
    		`fee_type`,
    		`enable_flag`,
    		`fee_percent`,
    		`fee_rate`
		from tb_cf_fee
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by fee_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_fee
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity">
		insert into tb_cf_fee(
			`fee_id`,
			`fee_type`,
			`enable_flag`,
			`fee_percent`,
			`fee_rate`)
		values(
			#{feeId},
			#{feeType},
			#{enableFlag},
			#{feePercent},
			#{feeRate})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity">
		update tb_cf_fee 
		<set>
			<if test="feeType != null">`fee_type` = #{feeType}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}, </if>
			<if test="feePercent != null">`fee_percent` = #{feePercent}, </if>
			<if test="feeRate != null">`fee_rate` = #{feeRate}</if>
		</set>
		where fee_id = #{feeId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_fee where fee_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_fee where fee_id in 
		<foreach item="feeId" collection="array" open="(" separator="," close=")">
			#{feeId}
		</foreach>
	</delete>
	
	<!--获取当前生效的手续费设置 理论上只有一个-->
	<select id="getAvailableFee" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity">
		select
    		`fee_id`,
    		`fee_type`,
    		`enable_flag`,
    		`fee_percent`
		from tb_cf_fee
		WHERE enable_flag=1
	</select>

	<!--获取当前生效的手人民币转成美元 理论上只有一个-->
	<select id="getRateFee" resultMap="tbCfFeeMap">
		select
			`fee_id`,
    		`fee_type`,
    		`enable_flag`,
    		`fee_percent`,
    		`fee_rate`
		from tb_cf_fee
		WHERE enable_flag=1
	</select>

</mapper>