<?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.imr.mapper.SampleInboundRecordMapper">

    <resultMap id="sampleInboundRecordMap" type="digital.laboratory.platform.imr.entity.SampleInboundRecord">
        <id property="id" column="id"/>
        <result property="warehousingDate" column="warehousing_date"/>
        <result property="imAdministrators" column="im_administrators"/>
        <result property="sampleId" column="sample_id"/>
        <result property="warehousingPersonId" column="warehousing_person_id"/>
        <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="remarks" column="remarks"/>
        <result property="name" column="name"/>
    </resultMap>



    <resultMap id="repositorySampleMap" type="digital.laboratory.platform.imr.vo.InboundRecordVO" extends="sampleInboundRecordMap">
        <result property="sampleNo" column="sample_no"/>
        <result property="storageMethod" column="storage_method"/>
        <result property="category" column="category"/>
        <result property="form" column="form"/>
        <result property="source" column="source"/>
        <result property="depositorName" column="depositor_name"/>
        <result property="imAdministratorsName" column="im_administrators_name"/>
    </resultMap>

    <!--inboundRecord-->
    <sql id="inboundRecordMap">
        select inbound.*,
               sample.sample_no,
               sample.storage_method,
               sample.sample_type,
               sample.source,
               im.form,
               im.type as category,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=inbound.warehousing_person_id
               ) AS depositor_name,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=inbound.im_administrators
               ) AS im_administrators_name
        from dlp_identification_material_repository.sample_inbound_record inbound
        join dlp_identification_material_transfer.b_sample sample
        on sample.id = inbound.sample_id
        join dlp_identification_material_transfer.identification_material im
        on im.id = sample.identification_material_id
    </sql>

    <select id="inboundRecord" resultMap="repositorySampleMap">
        <include refid="inboundRecordMap"/>
        ${ew.customSqlSegment}
    </select>


</mapper>
