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

  <resultMap id="outWarehouseDetailedMap" type="digital.laboratory.platform.imr.entity.OutWarehouseDetailed">
    <id property="id" column="id"/>
    <result property="applyId" column="apply_id"/>
    <result property="sampleId" column="sample_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"/>
  </resultMap>

  <resultMap id="outSampleVo" type="digital.laboratory.platform.imr.vo.OutSampleVO">
    <id property="sampleId" column="id"/>
    <result property="sampleNo" column="sample_no"/>
    <result property="name" column="name"/>
    <result property="storageMethod" column="storage_method"/>
    <result property="category" column="category"/>
    <result property="form" column="form"/>
    <result property="sampleType" column="sample_type"/>
    <result property="cellId" column="cell_id"/>
    <result property="storageLocation" column="storage_location"/>
  </resultMap>

  <!--List<OutSampleVO> getOutWarehouseApplyDetailed(String id);-->
  <select id="getOutWarehouseApplyDetailed" resultMap="outSampleVo">
    select s.sample_type,
           s.id,
           s.storage_method,
           im.type category,
           s.name,
           s.sample_no,
           im.form,
           storage.storage_location,
           storage.storage_cell_id as cell_id
      from dlp_identification_material_repository.out_warehouse_detailed od
      join dlp_identification_material_repository.b_sample_storage storage
      on storage.sample_id = od.sample_id
      join dlp_identification_material_transfer.b_sample s
      on storage.sample_id = s.id
      join dlp_identification_material_transfer.identification_material im
      on im.id = s.identification_material_id
     where od.apply_id = #{id}
  </select>
</mapper>
