<?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.finance.mapper.TFeeDoMapper">

    <resultMap type="TFeeDo" id="TFeeDoResult">
        <result property="fId" column="f_id"/>
        <result property="fPid" column="f_pid"/>
        <result property="fActId" column="f_act_id"/>
        <result property="fLineno" column="f_lineno"/>
        <result property="fSrcid" column="f_srcid"/>
        <result property="fSrclineno" column="f_srclineno"/>
        <result property="fSrcpid" column="f_srcpid"/>
        <result property="fSrcdc" column="f_srcdc"/>
        <result property="fFeeid" column="f_feeid"/>
        <result property="fAmtdr" column="f_amtdr"/>
        <result property="fAmt" column="f_amt"/>
        <result property="fStatus" column="f_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="fAmtStl" column="f_amt_stl"/>
        <result property="createTime" column="create_time"/>
        <result property="fAmtBlc" column="f_amt_blc"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="fRemarks" column="f_remarks"/>
    </resultMap>

    <sql id="selectTFeeDoVo">
        select f_id, f_pid, f_act_id, f_lineno, f_srcid, f_srclineno, f_srcpid, f_srcdc, f_feeid, f_amtdr, f_amt, f_status, del_flag, create_by, f_amt_stl, create_time, f_amt_blc, update_by, update_time, f_remarks from t_fee_do
    </sql>

    <select id="selectTFeeDoList" parameterType="TFeeDo" resultMap="TFeeDoResult">
        <include refid="selectTFeeDoVo"/>
        <where>
            <if test="fPid != null ">and f_pid = #{fPid}</if>
            <if test="fActId != null ">and f_act_id = #{fActId}</if>
            <if test="fLineno != null ">and f_lineno = #{fLineno}</if>
            <if test="fSrcid != null ">and f_srcid = #{fSrcid}</if>
            <if test="fSrclineno != null ">and f_srclineno = #{fSrclineno}</if>
            <if test="fSrcpid != null ">and f_srcpid = #{fSrcpid}</if>
            <if test="fSrcdc != null  and fSrcdc != ''">and f_srcdc = #{fSrcdc}</if>
            <if test="fFeeid != null ">and f_feeid = #{fFeeid}</if>
            <if test="fAmtdr != null ">and f_amtdr = #{fAmtdr}</if>
            <if test="fAmt != null ">and f_amt = #{fAmt}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
            <if test="fAmtStl != null ">and f_amt_stl = #{fAmtStl}</if>
            <if test="fAmtBlc != null ">and f_amt_blc = #{fAmtBlc}</if>
            <if test="fRemarks != null  and fRemarks != ''">and f_remarks = #{fRemarks}</if>
        </where>
    </select>

    <select id="selectTFeeDoById" parameterType="Long" resultMap="TFeeDoResult">
        <include refid="selectTFeeDoVo"/>
        where f_id = #{fId}
    </select>
    <select id="selectTFeeDoByfPid" parameterType="Long" resultMap="TFeeDoResult">
        SELECT
            td.f_id,
            td.f_pid,
            td.f_act_id,
            td.f_lineno,
            td.f_srcid,
            td.f_srclineno,
            td.f_srcpid,
            td.f_srcdc,
            CASE

                WHEN td.f_srcdc = 'D' THEN
                    '收'
                WHEN td.f_srcdc = 'C' THEN
                    '付'
                END AS fSrcdcName,
            td.f_feeid,
            tf.f_name fFeeName,
            td.f_amtdr,
            td.f_amt,
            td.f_status,
            CASE
                WHEN td.f_status = '1' THEN '保存'
                WHEN td.f_status = '2' THEN '暂存'
                WHEN td.f_status = '3' THEN '审批驳回'
                WHEN td.f_status = '4' THEN '提交审核'
                WHEN td.f_status = '5' THEN '审核中'
                WHEN td.f_status = '6' THEN '审核完成'
                END
                AS fStatusName,
            td.del_flag,
            td.create_by,
            td.f_amt_stl,
            td.create_time,
            td.f_amt_blc,
            td.update_by,
            td.update_time,
            td.f_remarks,
            tw.f_currency fCurrency,
            tw.f_exrate fExrate,
            tw.src_bill_no srcBillNo,
            tw.f_mblno fMblno,
            tv.f_name boatName,
            ty.f_no voyageName,
            te.f_billtype fBilltype,
            tw.f_statement_no accountBillno,
            ty.f_ETD fBsdate
        FROM
            t_fee_do td
                LEFT JOIN t_fees tf ON td.f_feeid = tf.f_id
                LEFT JOIN t_warehousebillsfees tw ON td.f_srcid = tw.f_id
                LEFT JOIN t_warehousebills th ON td.f_srcpid = th.f_id
                LEFT JOIN t_vessel tv ON tv.f_id = th.f_vslid
                LEFT JOIN t_voyage ty ON ty.f_id = th.f_voyid
                LEFT JOIN t_fee te ON te.f_id = td.f_pid
        where td.f_pid = #{fPid}
    </select>

    <insert id="insertTFeeDo" parameterType="TFeeDo" useGeneratedKeys="true" keyProperty="fId">
        insert into t_fee_do
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fPid != null">f_pid,</if>
            <if test="fActId != null">f_act_id,</if>
            <if test="fLineno != null">f_lineno,</if>
            <if test="fSrcid != null">f_srcid,</if>
            <if test="fSrclineno != null">f_srclineno,</if>
            <if test="fSrcpid != null">f_srcpid,</if>
            <if test="fSrcdc != null">f_srcdc,</if>
            <if test="fFeeid != null">f_feeid,</if>
            <if test="fAmtdr != null">f_amtdr,</if>
            <if test="fAmt != null">f_amt,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="fAmtStl != null">f_amt_stl,</if>
            <if test="createTime != null">create_time,</if>
            <if test="fAmtBlc != null">f_amt_blc,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="fRemarks != null">f_remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fPid != null">#{fPid},</if>
            <if test="fActId != null">#{fActId},</if>
            <if test="fLineno != null">#{fLineno},</if>
            <if test="fSrcid != null">#{fSrcid},</if>
            <if test="fSrclineno != null">#{fSrclineno},</if>
            <if test="fSrcpid != null">#{fSrcpid},</if>
            <if test="fSrcdc != null">#{fSrcdc},</if>
            <if test="fFeeid != null">#{fFeeid},</if>
            <if test="fAmtdr != null">#{fAmtdr},</if>
            <if test="fAmt != null">#{fAmt},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="fAmtStl != null">#{fAmtStl},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="fAmtBlc != null">#{fAmtBlc},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="fRemarks != null">#{fRemarks},</if>
        </trim>
    </insert>

    <update id="updateTFeeDo" parameterType="TFeeDo">
        update t_fee_do
        <trim prefix="SET" suffixOverrides=",">
            <if test="fPid != null">f_pid = #{fPid},</if>
            <if test="fActId != null">f_act_id = #{fActId},</if>
            <if test="fLineno != null">f_lineno = #{fLineno},</if>
            <if test="fSrcid != null">f_srcid = #{fSrcid},</if>
            <if test="fSrclineno != null">f_srclineno = #{fSrclineno},</if>
            <if test="fSrcpid != null">f_srcpid = #{fSrcpid},</if>
            <if test="fSrcdc != null">f_srcdc = #{fSrcdc},</if>
            <if test="fFeeid != null">f_feeid = #{fFeeid},</if>
            <if test="fAmtdr != null">f_amtdr = #{fAmtdr},</if>
            <if test="fAmt != null">f_amt = #{fAmt},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="fAmtStl != null">f_amt_stl = #{fAmtStl},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="fAmtBlc != null">f_amt_blc = #{fAmtBlc},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="fRemarks != null">f_remarks = #{fRemarks},</if>
        </trim>
        where f_id = #{fId}
    </update>

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

    <delete id="deleteTFeeDoByIds" parameterType="String">
        delete from t_fee_do where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

    <delete id="deleteByFPid" parameterType="Long">
        delete from t_fee_do where f_pid = #{fId}
    </delete>

    <update id="tfeeDoFollowUpdate" parameterType="Long">
        update
            t_fee_do
        set f_status = #{fettle}
        where
            f_pid = #{fPid}
    </update>

</mapper>