<?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.sampleAndConsumableManagement.mapper.FdSampleStorageMapper">

    <select id="findByPage" resultType="org.jeecg.modules.sampleAndConsumableManagement.entity.FdSampleStorage">
            SELECT
                ss.id,
                ss.del_flag,
                ss.tracking_code,
                pf.contract_code,
                pf.customer_name,
                ss.create_time,
                pfc.compound,
                ss.primary_sample_number,
                pf.project_file_no
            FROM
                fd_sample_storage ss
                LEFT JOIN fd_project_file pf ON ss.pk_project_file = pf.id
                LEFT JOIN fd_storage_place sp ON ss.pk_primary_sample_storage_place = sp.id
                LEFT JOIN fd_project_file_compound pfc ON ss.pk_project_file = pfc.project_id
                 ${ew.customSqlSegment}
    </select>

    <!--根据合同查询相关信息-->
    <select id="getSampleStorageByConId" resultType="org.jeecg.modules.sampleAndConsumableManagement.entity.FdSampleStorage">
        SELECT
            pf.id as pkProjectFile,
            pf.contract_id as pkContract,
            pf.contract_party as pkContractParty,
            pf.customer_id as pkBidParty,
            pf.customer_name as bidPartyName,
            pf.contract_type as contractType,
            pf.bd as businessAffairsBd,
            pf.assistant as aiologicalAnalysis,
            pf.clinical_pm as clinicalPm,
            pf.clinical_code as clinicalCode,
            pf.project_name as projectName,
            pf.matrix_type as substrateType,
            c.code as contractCode,
            cus.name as bidPartyName,
            cus.abbreviation as bidPartyNameAbbreviation,
            pf.compound,
            perbd.name as businessAffairsBdName,
            perass.name as aiologicalAnalysisName,
            perclipm.name as clinicalPmName,
            perpm.name as bioanalysisPmName,
            pf.project_file_no,
            pf.investigator as bioanalysisPm
        FROM
            fd_project_file pf
            LEFT JOIN fd_contract c ON c.id = pf.contract_id
            left join fd_customer cus on cus.id=pf.customer_id
            left join fd_personnel perbd on perbd.id=pf.bd
            left join fd_personnel perass on perass.id=pf.bioanalytical_pm
            left join fd_personnel perclipm on perclipm.id=pf.clinical_pm
            left join fd_personnel perpm on perpm.id=pf.investigator
        where
            c.del_flag='0'
            and pf.id=#{0}
    </select>
</mapper>