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

    <resultMap id="procurementContentMap" type="digital.laboratory.platform.reagent.entity.ProcurementContent">
        <id property="procurementContentId" column="procurement_content_id"/>
        <result property="purchasingPlanId" column="purchasing_plan_id"/>
        <result property="quantityPurchased" column="quantity_purchased"/>
        <result property="reagentConsumableId" column="reagent_consumable_id"/>
        <result property="subtotal" column="subtotal"/>
        <result property="unitPrice" column="unit_price"/>
        <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="detailsOfCentralizedId" column="details_of_centralized_id"/>
        <result property="replacementReagentConsumableId" column="replacement_reagent_consumable_id"/>
        <result property="replacementQuantity" column="replacement_quantity"/>
        <result property="replacementPrice" column="replacement_price"/>
        <result property="numberOfApplications" column="number_of_applications"/>

    </resultMap>

    <resultMap id="procurementContentVO" type="digital.laboratory.platform.reagent.vo.ProcurementContentVO"
               extends="procurementContentMap">
        <result property="reagentConsumableName" column="reagent_consumable_name"></result>
        <result property="replacementReagentConsumableName" column="replacement_reagent_consumable_name"></result>
    </resultMap>

    <select id="getProcurementContentVOList" resultMap="procurementContentVO"
            resultType="digital.laboratory.platform.reagent.vo.ProcurementContentVO">
        SELECT pc.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = pc.reagent_consumable_id)             as reagent_consumable_name,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = pc.replacement_reagent_consumable_id) as replacement_reagent_consumable_name
        FROM procurement_content pc
        WHERE pc.purchasing_plan_id = #{purchasingPlanId}
    </select>
</mapper>
