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

    <resultMap id="standardMaterialApplicationMap"
               type="digital.laboratory.platform.reagent.entity.StandardMaterialApplication">
        <id property="standardMaterialApplicationId" column="standard_material_application_id"/>
        <result property="administratorId" column="administrator_id"/>
        <result property="dateOfClaim" column="date_of_claim"/>
        <result property="dateOfReturn" column="date_of_return"/>
        <result property="purposeAndQuantity" column="purpose_and_quantity"/>
        <result property="recipientId" column="recipient_id"/>
        <result property="referenceMaterialNumber" column="reference_material_number"/>
        <result property="referenceSubstanceId" column="reference_substance_id"/>
        <result property="requisitionedQuantity" column="requisitioned_quantity"/>
        <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="serialNumber" column="serial_number"/>
        <result property="specification" column="specification"/>
        <result property="deliveryRegistrationFormId" column="delivery_registration_form_id"/>
        <result property="requisitionRecordId" column="requisition_record_id"/>
        <result property="storageRegistrationFormId" column="storage_registration_form_id"/>
        <result property="claimCode" column="claim_code"/>
        <result property="purpose" column="purpose"/>
        <result property="number" column="number"/>
        <result property="status" column="status"/>
        <result property="applicationForUseId" column="application_for_use_id"/>
    </resultMap>

    <resultMap id="standardMaterialApplicationVO"
               type="digital.laboratory.platform.reagent.vo.StandardMaterialApplicationVO"
               extends="standardMaterialApplicationMap">
        <result property="referenceSubstanceName" column="reference_substance_name"></result>
        <result property="recipientName" column="recipient_name"></result>
    </resultMap>

    <sql id="getStandardMaterialApplicationVOSQL">
        select sma.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = sma.reference_substance_id) as reference_substance_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=sma.recipient_id
            ) AS recipient_name
        from standard_material_application sma
    </sql>

    <select id="getStandardMaterialApplicationVOPage" resultMap="standardMaterialApplicationVO"
            resultType="digital.laboratory.platform.reagent.vo.StandardMaterialApplicationVO">
    <include refid="getStandardMaterialApplicationVOSQL"></include>
    </select>

    <select id="getStandardMaterialApplicationVOList" resultMap="standardMaterialApplicationVO"
            resultType="digital.laboratory.platform.reagent.vo.StandardMaterialApplicationVO">
        select sma.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = sma.reference_substance_id) as reference_substance_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=sma.recipient_id
            ) AS recipient_name
        from standard_material_application sma
        where sma.status = 1
    </select>
</mapper>
