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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity" id="tbCfFinanceMap">
        <result property="finaceId" column="finace_id"/>
        <result property="orderId" column="order_id"/>
        <result property="userId" column="user_id"/>
        <result property="payAccount" column="pay_account"/>
        <result property="payId" column="pay_id"/>
        <result property="payWayCode" column="pay_way_code"/>
        <result property="payTime" column="pay_Time"/>
        <result property="receiptUrl" column="receipt_url"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity">
		select
			`finace_id`,
			`order_id`,
			`user_id`,
			`pay_account`,
			`pay_id`,
			`pay_way_code`,
			`pay_Time`,
			`receipt_url`
		from tb_cf_finance
		where finace_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity">
		select
    		`finace_id`,
    		`order_id`,
    		`user_id`,
    		`pay_account`,
    		`pay_id`,
    		`pay_way_code`,
    		`pay_Time`,
    		`receipt_url`
		from tb_cf_finance
		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 finace_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_finance
		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.TbCfFinanceEntity">
		insert into tb_cf_finance(
			`finace_id`,
			`order_id`,
			`user_id`,
			`pay_account`,
			`pay_id`,
			`pay_way_code`,
			`pay_Time`,
			`receipt_url`)
		values(
			#{finaceId},
			#{orderId},
			#{userId},
			#{payAccount},
			#{payId},
			#{payWayCode},
			#{payTime},
			#{receiptUrl})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity">
		update tb_cf_finance 
		<set>
			<if test="orderId != null">`order_id` = #{orderId}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="payAccount != null">`pay_account` = #{payAccount}, </if>
			<if test="payId != null">`pay_id` = #{payId}, </if>
			<if test="payWayCode != null">`pay_way_code` = #{payWayCode}, </if>
			<if test="payTime != null">`pay_Time` = #{payTime}</if>
			<if test="receiptUrl != null">`receipt_url` = #{receiptUrl}</if>
		</set>
		where finace_id = #{finaceId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_finance where finace_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_finance where finace_id in 
		<foreach item="finaceId" collection="array" open="(" separator="," close=")">
			#{finaceId}
		</foreach>
	</delete>

</mapper>