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

    <select id="getContractList" resultType="org.jeecg.modules.projectManagement.entity.FdContract">
        	SELECT
                fpf.contract_id as id,
                fc.CODE,
                fpf.id as projectFileId
            FROM
                fd_clinical_budget fcb
                LEFT JOIN fd_contract fc ON fc.id = fcb.contract_id
                left join fd_project_file fpf on fpf.contract_id=fc.id
            WHERE fcb.del_flag = '0'
            GROUP BY
                fpf.contract_id,
                fc.CODE
            ORDER BY
                fpf.create_time DESC
    </select>

    <select id="getByProjectId" resultType="org.jeecg.modules.financeManage.entity.FdClinicalIncome">
        SELECT
            fc.contract_party as contractPartyId,
            fpf.customer_id as curstomerId,
            fpf.customer_name as curstomerName,
            fc.code,
            fc.sign_date,
            fc.project_name,
            fc.project_description,
            fc.currency_type as currencyTypeId,
            fc.currency_type_name as currencyTypeName,
            fc.id as contractId,
            fpf.id as projectFileId,
	        fcb.id as clinicalBudgetId,
	        fc.tax_rate,
	        fpf.status as projectFileStatus
        FROM
            fd_project_file fpf
            LEFT JOIN fd_contract fc ON fpf.contract_id = fc.id
	        Left join fd_clinical_budget fcb on fcb.contract_id=fc.id
        WHERE
            fpf.del_flag = '0'
            AND fc.del_flag='0' and fcb.del_flag='0'
            AND fpf.id=#{projectFildId}
    </select>

    <select id="getByProjectIdBatch" resultType="org.jeecg.modules.financeManage.entity.FdClinicalIncome">
        SELECT
        fc.contract_party as contractPartyId,
        fpf.customer_id as curstomerId,
        fpf.customer_name as curstomerName,
        fc.code,
        fc.sign_date,
        fc.project_name,
        fc.project_description,
        fc.currency_type as currencyTypeId,
        fc.currency_type_name as currencyTypeName,
        fc.id as contractId,
        fpf.id as projectFileId,
        fcb.id as clinicalBudgetId,
        fc.tax_rate,
        fpf.status as projectFileStatus
        FROM
        fd_project_file fpf
        LEFT JOIN fd_contract fc ON fpf.contract_id = fc.id
        Left join fd_clinical_budget fcb on fcb.contract_id=fc.id
        WHERE
        fpf.del_flag = '0'
        AND fc.del_flag='0' and fcb.del_flag='0'
        AND fpf.id IN
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <update id="updateFdClincalIncomeBatchByCode" parameterType="java.util.List">
        <foreach collection="list" item="clincalIncome" index="index" open="" close="" separator=";">
            UPDATE fd_clinical_income
            <set>
                ethical_fee = #{clincalIncome.ethicalFee},
                crc_fee=#{clincalIncome.crcFee},
                recruit_fee=#{clincalIncome.recruitFee},
                reimbursement_and_other=#{clincalIncome.reimbursementAndOther},
                cumulative_work_export=#{clincalIncome.cumulativeWorkExport}
            </set>
            WHERE
            code = #{clincalIncome.code}
        </foreach>
    </update>

    <select id="exportMain" resultType="org.jeecg.modules.financeManage.entity.FdClinicalIncome">
        SELECT
            *
        FROM
            fd_clinical_income
        WHERE
            del_flag = '0'
            AND settlement_status_id = '1'
        ORDER BY
            create_time DESC
    </select>

</mapper>