<?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="digital.laboratory.platform.reagent.mapper.AcceptanceRecordFormMapper">

    <resultMap id="acceptanceRecordFormMap" type="digital.laboratory.platform.reagent.entity.AcceptanceRecordForm">
        <id property="acceptanceRecordFormId" column="acceptance_record_form_id"/>
        <result property="acceptanceConclusion" column="acceptance_conclusion"/>
        <result property="auditTimeOfThreeLevel" column="audit_time_of_three_level"/>
        <result property="dateOfAcceptance" column="date_of_acceptance"/>
        <result property="auditOpinionOfThreeLevel" column="audit_opinion_of_three_level"/>
        <result property="threeLevelAuditorId" column="three_level_auditor_id"/>
        <result property="followUpTreatment" column="follow_up_treatment"/>
        <result property="nonconformingItem" column="nonconforming_item"/>
        <result property="auditOpinionOfSecondary" column="audit_opinion_of_secondary"/>
        <result property="primaryAuditorId" column="primary_auditor_id"/>
        <result property="secondaryAuditorId" column="secondary_auditor_id"/>
        <result property="auditTimeOfSecondary" column="audit_time_of_secondary"/>
        <result property="reagentConsumableId" column="reagent_consumable_id"/>
        <result property="auditOpinionOfPrimary" column="audit_opinion_of_primary"/>
        <result property="auditTimeOfPrimary" column="audit_time_of_primary"/>
        <result property="signedBatchListId" column="signed_batch_list_id"/>
        <result property="auditResultOfPrimary" column="audit_result_of_primary"/>
        <result property="auditResultOfThreeLevel" column="audit_result_of_three_level"/>
        <result property="auditResultOfSecondary" column="audit_result_of_secondary"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="theSameBrandAndModel" column="the_same_brand_and_model"/>
        <result property="bam_remarks" column="bam_remarks"/>
        <result property="consistentQuantity" column="consistent_quantity"/>
        <result property="cq_remarks" column="cq_remarks"/>
        <result property="packingInGoodCondition" column="packing_in_good_condition"/>
        <result property="pgc_remarks" column="pgc_remarks"/>
        <result property="validityPeriod" column="validity_period"/>
        <result property="vp_remarks" column="vp_remarks"/>
        <result property="deliveryCycle" column="delivery_cycle"/>
        <result property="dc_remarks" column="dc_remarks"/>
        <result property="supplierId" column="supplier_id"/>
        <result property="status" column="status"/>
        <result property="warehousingContentId" column="warehousing_content_id"/>
    </resultMap>

    <resultMap id="acceptanceRecordFormVO" type="digital.laboratory.platform.reagent.vo.AcceptanceRecordFormVO"
               extends="acceptanceRecordFormMap">
        <result property="reagentConsumableName" column="reagent_consumable_name"></result>
        <result property="supplierName" column="supplier_name"></result>
        <result property="primaryAuditorName" column="primary_auditor_name"></result>
        <result property="secondaryAuditorName" column="secondary_auditor_name"></result>
        <result property="threeLevelAuditorName" column="three_level_auditor_name"></result>
    </resultMap>

    <sql id="getAcceptanceRecordFormVOSQL">
        SELECT arf.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = arf.reagent_consumable_id) as reagent_consumable_name,
               (select si.supplier_name
                from supplier_information si
                where si.supplier_information_id = arf.supplier_id)  as supplier_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=arf.primary_auditor_id
            ) AS primary_auditor_name,
            (SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=arf.secondary_auditor_id
            ) AS secondary_auditor_name,
            (SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=arf.three_level_auditor_id
            ) AS three_level_auditor_name
        FROM acceptance_record_form arf
    </sql>

    <select id="getAcceptanceRecordFormVOPage" resultMap="acceptanceRecordFormVO"
            resultType="digital.laboratory.platform.reagent.vo.AcceptanceRecordFormVO">
        <include refid="getAcceptanceRecordFormVOSQL"></include>

    </select>

    <select id="getAcceptanceRecordFormVO" resultMap="acceptanceRecordFormVO"
            resultType="digital.laboratory.platform.reagent.vo.AcceptanceRecordFormVO">
        SELECT arf.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = arf.reagent_consumable_id) as reagent_consumable_name,
               (select si.supplier_name
                from supplier_information si
                where si.supplier_id = arf.supplier_id)as supplier_name
        FROM acceptance_record_form arf
        WHERE arf.acceptance_record_form_id = #{acceptanceRecordFormId}
    </select>
</mapper>
