<?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.qualityControl.mapper.FdQcBiologicalAnalysisVerificationMapper">
    <select id="queryQcBiologicalByConId" resultType="org.jeecg.modules.qualityControl.entity.FdQcBiologicalAnalysisVerification">
        SELECT
            pf.id AS pkProjectFile,
            pf.contract_id AS pkContract,
            pf.project_name AS projectName,
            pf.customer_id AS pkBidParty,
            pf.customer_name AS bidPartyName,
            pf.abbreviation AS bidPartyNameAbbreviation,
            pf.contract_party AS pkContractParty,
            c.`code` AS contractCode,
            c.sign_date AS contractSignDate,
            pf.contract_type AS analysisType,
            pf.bioanalytical_pm AS bioanalyticalPi,
            pf.assistant AS associateBioanalyticalPi,
            pf.matrix_type AS matrix,
            pf.bd AS bd,
            p.name as bdName,
            pf.investigator AS investigator,
            pf.clinical_pm AS clinicalPm,
            c.tax_rate as taxRate,
            c.total_amount as totalAmount,
            c.project_description as contractDescription,
            c.final_total_amount,
            pf.project_file_no
        FROM
            fd_project_file pf
            LEFT JOIN fd_contract c ON c.id = pf.contract_id
            LEFT JOIN fd_personnel p on p.id = pf.bd
        WHERE
            c.del_flag = '0'
            and pf.id=#{0}
    </select>

    <select id="findByPage" resultType="org.jeecg.modules.qualityControl.entity.FdQcBiologicalAnalysisVerification">
      SELECT
        qav.*,
        pf.personnel_with_authority_ids as personnelWithAuthorityIds,
        fqv.code as verifiCode,
        fp.name as responsibleQcName
      FROM fd_qc_biological_analysis_verification qav
      LEFT JOIN fd_project_file pf on qav.pk_project_file=pf.id
      LEFT JOIN fd_qc_validation fqv on fqv.pk_qc_validation=qav.id
      left join fd_personnel fp on fp.id=qav.responsible_qc
      ${ew.customSqlSegment}
    </select>

    <select id="getByVerifiCodeAndType" resultType="org.jeecg.modules.qualityControl.entity.FdQcBiologicalAnalysisVerification">
        SELECT
            qav.*,
            fqv.code as verifiCode
          FROM fd_qc_biological_analysis_verification qav
          LEFT JOIN fd_qc_validation fqv on fqv.pk_qc_validation=qav.id
        WHERE
        qav.del_flag='0'
        and qav.pk_project_file=#{fdQcBiologicalAnalysisVerification.pkProjectFile}
        AND qav.analysis_type=#{fdQcBiologicalAnalysisVerification.analysisType}
        AND fqv.code=#{fdQcBiologicalAnalysisVerification.verifiCode}
        AND qav.verification_type=#{fdQcBiologicalAnalysisVerification.verificationType}
    </select>
</mapper>