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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfTaxEntity" id="tbCfTaxMap">
        <result property="taxId" column="tax_id"/>
        <result property="categoryId" column="category_id"/>
        <result property="categoryName" column="category_name"/>
        <result property="mixAmount" column="mix_amount"/>
        <result property="taxRate" column="tax_rate"/>
        <result property="enableFlag" column="enable_flag"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfTaxEntity">
		select
			`tax_id`,
			`category_id`,
			`category_name`,
			`mix_amount`,
			`tax_rate`,
			`enable_flag`
		from tb_cf_tax
		where tax_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfTaxEntity">
		select
    		`tax_id`,
    		`category_id`,
    		`category_name`,
    		`mix_amount`,
    		`tax_rate`,
    		`enable_flag`
		from tb_cf_tax
		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 tax_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_tax
		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.TbCfTaxEntity">
		insert into tb_cf_tax(
			`tax_id`,
			`category_id`,
			`category_name`,
			`mix_amount`,
			`tax_rate`,
			`enable_flag`)
		values(
			#{taxId},
			#{categoryId},
			#{categoryName},
			#{mixAmount},
			#{taxRate},
			#{enableFlag})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfTaxEntity">
		update tb_cf_tax 
		<set>
			<if test="categoryId != null">`category_id` = #{categoryId}, </if>
			<if test="categoryName != null">`category_name` = #{categoryName}, </if>
			<if test="mixAmount != null">`mix_amount` = #{mixAmount}, </if>
			<if test="taxRate != null">`tax_rate` = #{taxRate}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}</if>
		</set>
		where tax_id = #{taxId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_tax where tax_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_tax where tax_id in 
		<foreach item="taxId" collection="array" open="(" separator="," close=")">
			#{taxId}
		</foreach>
	</delete>

	<select id="getAvailableFee" resultType="com.diaoyun.zion.chinafrica.entity.TbCfTaxEntity">
        select * from tb_cf_tax where enable_flag=1
    </select>

</mapper>