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

    <resultMap id="storageRegistrationFormMap"
               type="digital.laboratory.platform.reagent.entity.StorageRegistrationForm">
        <id property="storageRegistrationFormId" column="storage_registration_form_id"/>
        <result property="dateOfArrival" column="date_of_arrival"/>
        <result property="depositorId" column="depositor_id"/>
        <result property="quantity" column="quantity"/>
        <result property="reagentConsumableId" column="reagent_consumable_id"/>
        <result property="reagentConsumableNumber" column="reagent_consumable_number"/>
        <result property="reagentConsumableType" column="reagent_consumable_type"/>
        <result property="remarks" column="remarks"/>
        <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="storageLife" column="storage_life"/>
        <result property="latticeId" column="lattice_id"/>
    </resultMap>

    <resultMap id="storageRegistrationFormVO" type="digital.laboratory.platform.reagent.vo.StorageRegistrationFormVO"
               extends="storageRegistrationFormMap">
        <result property="depositorName" column="depositor_name"></result>
        <result property="reagentConsumableName" column="reagent_consumable_name"></result>
        <result property="location" column="location"></result>
        <result property="storageRoomName" column="storage_room_name"></result>
        <result property="cabinetName" column="cabinet_name"></result>
        <result property="latticeNumber" column="lattice_number"></result>
    </resultMap>

    <select id="getStorageRegistrationFormVOList" resultMap="storageRegistrationFormVO"
            resultType="digital.laboratory.platform.reagent.vo.StorageRegistrationFormVO">
        SELECT srf.*,
               (select user.name
                from dlp_base.sys_user user
        where user.user_id = srf.depositor_id) as depositor_name
            , (
        select rc.name
        from reagent_consumables rc
        where rc.reagent_consumable_id = srf.reagent_consumable_id) as reagent_consumable_name,
            FROM storage_registration_form srf

    </select>

    <select id="getStorageRegistrationFormVO" resultMap="storageRegistrationFormVO"
            resultType="digital.laboratory.platform.reagent.vo.StorageRegistrationFormVO">
        SELECT srf.*,
               (select user.name
                from dlp_base.sys_user user
        where user.user_id = srf.depositor_id) as depositor_name
            , (
        select rc.name
        from reagent_consumables rc
        where rc.reagent_consumable_id = srf.reagent_consumable_id) as reagent_consumable_name,
        FROM storage_registration_form srf
        WHERE srf.storage_registration_form_id = #{storageRegistrationFormId}

    </select>
</mapper>
