<?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="org.jeecg.modules.financeManage.mapper.FdHandoverfeeMapper">
    <delete id="deleteById" parameterType="java.lang.String">
        UPDATE fd_handoverfee SET del_flag=1 WHERE id=#{id}
    </delete>

       <select id="findContractByCode" resultType="org.jeecg.modules.projectManagement.entity.FdProjectFile">
        SELECT
            a.id,
            a.contract_id,
            f.id AS customerId,
            f.credit_period as creditPeriod,
            a.customer_name AS customerName,
            d.`code` AS contractCode,
            a.contract_party,
            i.item_text  as contractPartyName,
            a.abbreviation,
            a.project_name,
            a.contract_type,
            a.sign_date,
            a.bd as bdId,
            g.name as bd,
            a.project_manager_id AS clinicalPmId,
            h.name AS clinicalPm,
            a.del_flag,
            a.create_time,
            a.status,
            d.total_amount as totalAmount,
            d.final_total_amount as finalTotalAmount,
            d.currency_type as currencyType,
            d.currency_type_name as currencyTypeName,
            d.project_description as contractDescription,
            a.project_file_no,
            d.payer_name
        FROM
            fd_project_file a
            LEFT JOIN fd_contract d ON a.contract_id = d.id
            LEFT JOIN fd_customer f ON a.customer_id = f.id
            LEFT join fd_personnel g on a.bd = g.id
            LEFT JOIN fd_personnel h on a.project_manager_id = h.id
            LEFT JOIN sys_dict_item i ON a.contract_party = i.item_value AND i.dict_id = "8c9b5d1ec447fda422f4a656af8055e2"

             where a.id =#{code}
    </select>
    
    <select id="selectContract" resultType="org.jeecg.modules.financeManage.entity.FdHandoverfee">
        SELECT code as contractCode from fd_contract d where status in('1','3') and d.del_flag ='0'
    </select>

    <select id="selectClause" resultType="org.jeecg.modules.financeManage.entity.FdHandoverfeeB">
        SELECT c.total_amount as contractAmountAll,b.item_text as milepost,a.payment_percent as estimator
        from fd_contract_clause a
        LEFT JOIN sys_dict_item b ON a.description = b.item_value
        LEFT JOIN fd_contract c ON a.contract_id = c.id
        where b.dict_id='42b3aadca10162b6225bae7b80c4b346'
        and c.code = #{code} and a.del_flag='0'

    </select>
    
    <select id="findHandoverfeeByCode" resultType="org.jeecg.modules.basedata.entity.FdPassFeeClassProject">
        SELECT
			pro.id,
			pro.NAME,
			pro.CODE,
			pro.ENABLE,
			pro.pk_pass_fee_class,
			cla.NAME AS className
		FROM
			fd_pass_fee_class_project pro
			LEFT JOIN fd_pass_fee_class cla ON pro.pk_pass_fee_class = cla.id
			WHERE pro.CODE = #{0}
    </select>

    <select id="fingMoreCode" resultType="int">
        select count(1) from fd_handoverfee where CODE =#{code} and del_flag=0
        <if test="id != '' and id != null">
            and id != #{id}
        </if>
        ;
    </select>
    
    <update id="toExamine">
        UPDATE fd_handoverfee SET state = #{state} where id =#{id}
    </update>
</mapper>