<?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.ruoyi.shipping.mapper.TFeeInvoiceMapper">
    
    <resultMap type="TFeeInvoice" id="TFeeInvoiceResult">
        <result property="fId"    column="f_id"    />
        <result property="fPid"    column="f_pid"    />
        <result property="fFeeid"    column="f_feeid"    />
        <result property="fModel"    column="f_model"    />
        <result property="fSbu"    column="f_sbu"    />
        <result property="fNumber"    column="f_number"    />
        <result property="fUnitprice"    column="f_unitprice"    />
        <result property="fMoney"    column="f_money"    />
        <result property="fTaxrate"    column="f_taxrate"    />
        <result property="fTax"    column="f_tax"    />
        <result property="fAmount"    column="f_amount"    />
        <result property="fStatus"    column="f_status"    />
        <result property="fBillstatus" column="f_billstatus"/>
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTFeeInvoiceVo">
        select f_id, f_pid, f_feeid, f_model, f_sbu, f_number, f_unitprice, f_money, f_taxrate, f_tax, f_amount, f_status,f_billstatus, create_by, create_time, update_by, update_time, remarks from t_fee_invoice
    </sql>

    <select id="selectTFeeInvoiceList" parameterType="TFeeInvoice" resultMap="TFeeInvoiceResult">
        SELECT
        tf.f_id,
        tf.f_pid,
        tf.f_feeid,
        te.f_name fFeeName,
        tf.f_model,
        tf.f_sbu,
        pr.dict_label fSbuName,
        tf.f_number,
        tf.f_unitprice,
        tf.f_money,
        tf.f_taxrate,
        tf.f_tax,
        tf.f_amount,
        tf.f_status,
        tf.f_billstatus,
        tf.create_by,
        tf.create_time,
        tf.update_by,
        tf.update_time,
        tf.remarks
        FROM
        t_fee_invoice tf
        LEFT JOIN sys_dict_data pr ON pr.dict_value = tf.f_sbu AND pr.dict_type = 'data_unitfees'
        LEFT JOIN t_fees te ON tf.f_feeid = te.f_id
        <where>  
            <if test="fPid != null "> and tf.f_pid = #{fPid}</if>
            <if test="fFeeid != null "> and tf.f_feeid = #{fFeeid}</if>
            <if test="fModel != null  and fModel != ''"> and tf.f_model = #{fModel}</if>
            <if test="fSbu != null "> and tf.f_sbu = #{fSbu}</if>
            <if test="fNumber != null "> and tf.f_number = #{fNumber}</if>
            <if test="fUnitprice != null "> and tf.f_unitprice = #{fUnitprice}</if>
            <if test="fMoney != null "> and tf.f_money = #{fMoney}</if>
            <if test="fTaxrate != null "> and tf.f_taxrate = #{fTaxrate}</if>
            <if test="fTax != null "> and tf.f_tax = #{fTax}</if>
            <if test="fAmount != null "> and tf.f_amount = #{fAmount}</if>
            <if test="fStatus != null  and fStatus != ''"> and tf.f_status = #{fStatus}</if>
            <if test="fBillstatus != null  and fBillstatus != ''">and tf.f_billstatus = #{fBillstatus}</if>
            <if test="remarks != null  and remarks != ''"> and tf.remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTFeeInvoiceById" parameterType="Long" resultMap="TFeeInvoiceResult">
        <include refid="selectTFeeInvoiceVo"/>
        where f_id = #{fId}
    </select>
        
    <insert id="insertTFeeInvoice" parameterType="TFeeInvoice">
        insert into t_fee_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fPid != null">f_pid,</if>
            <if test="fFeeid != null">f_feeid,</if>
            <if test="fModel != null">f_model,</if>
            <if test="fSbu != null">f_sbu,</if>
            <if test="fNumber != null">f_number,</if>
            <if test="fUnitprice != null">f_unitprice,</if>
            <if test="fMoney != null">f_money,</if>
            <if test="fTaxrate != null">f_taxrate,</if>
            <if test="fTax != null">f_tax,</if>
            <if test="fAmount != null">f_amount,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="fBillstatus != null and fBillstatus != ''">f_billstatus,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fId != null">#{fId},</if>
            <if test="fPid != null">#{fPid},</if>
            <if test="fFeeid != null">#{fFeeid},</if>
            <if test="fModel != null">#{fModel},</if>
            <if test="fSbu != null">#{fSbu},</if>
            <if test="fNumber != null">#{fNumber},</if>
            <if test="fUnitprice != null">#{fUnitprice},</if>
            <if test="fMoney != null">#{fMoney},</if>
            <if test="fTaxrate != null">#{fTaxrate},</if>
            <if test="fTax != null">#{fTax},</if>
            <if test="fAmount != null">#{fAmount},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="fBillstatus != null and fBillstatus != ''">#{fBillstatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTFeeInvoice" parameterType="TFeeInvoice">
        update t_fee_invoice
        <trim prefix="SET" suffixOverrides=",">
            <if test="fPid != null">f_pid = #{fPid},</if>
            <if test="fFeeid != null">f_feeid = #{fFeeid},</if>
            <if test="fModel != null">f_model = #{fModel},</if>
            <if test="fSbu != null">f_sbu = #{fSbu},</if>
            <if test="fNumber != null">f_number = #{fNumber},</if>
            <if test="fUnitprice != null">f_unitprice = #{fUnitprice},</if>
            <if test="fMoney != null">f_money = #{fMoney},</if>
            <if test="fTaxrate != null">f_taxrate = #{fTaxrate},</if>
            <if test="fTax != null">f_tax = #{fTax},</if>
            <if test="fAmount != null">f_amount = #{fAmount},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="fBillstatus != null and fBillstatus != ''">f_billstatus = #{fBillstatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTFeeInvoiceById" parameterType="Long">
        delete from t_fee_invoice where f_id = #{fId}
    </delete>

    <delete id="deleteTFeeInvoiceByIds" parameterType="String">
        delete from t_fee_invoice where f_id in 
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>
    <delete id="deleteByFPid" parameterType="Long">
        delete from t_fee_invoice where f_pid = #{fId}
    </delete>
    <update id="tFeeInvoiceUpdate" parameterType="Long">
        update
            t_fee_invoice
        set f_billstatus = #{fettle}
        where
            f_pid = #{fPid}
    </update>
    
</mapper>