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

    <resultMap id="sampleStorageMap" type="digital.laboratory.platform.imr.entity.SampleStorage">
        <id property="id" column="id"/>
        <result property="sampleId" column="sample_id"/>
        <result property="storageLocation" column="storage_location"/>
        <result property="status" column="status"/>
        <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="storageDate" column="storage_date"/>
        <result property="depositorId" column="depositor_id"/>
        <result property="recipientId" column="recipient_id"/>
        <result property="inRepositoryDate" column="in_repository_date"/>
        <result property="outRepositoryDate" column="out_repository_date"/>
        <result property="earlyWarning" column="early_warning"/>
        <result property="storageCellId" column="storage_cell_id"/>
        <result property="quality" column="quality"/>
        <result property="unit" column="unit"/>
        <result property="name" column="name"/>
        <result property="sampleType" column="sample_type"/>
        <result property="isReturn" column="is_return"/>
        <result property="returnTime" column="return_time"/>
        <result property="purpose" column="purpose"/>
        <result property="buildingLv" column="building_lv"/>
        <result property="roomNo" column="room_no"/>
        <result property="cabinetName" column="cabinet_name"/>
        <result property="boxId" column="box_id"/>
    </resultMap>



    <resultMap id="outSampleVo" type="digital.laboratory.platform.imr.vo.OutSampleVO">
        <id property="id" column="id"/>
        <result property="sampleId" column="sample_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="sampleType" column="sample_type"/>
        <result property="form" column="form"/>
        <result property="holder" column="holder"/>
        <result property="holderName" column="holder_name"/>
        <result property="sampleStatus" column="status"/>
        <result property="existingQuality" column="existing_quality"/>
        <result property="eventName" column="event_name"/>
        <result property="source" column="source"/>
        <result property="roomNo" column="room_no"/>
    </resultMap>


    <!--String getUserName(String userId);-->
    <select id="getUserName" resultType="String">
        select u.name
        from dlp_base.sys_user u
        where u.user_id = #{userId}
    </select>



    <resultMap id="baseSampleVo" type="digital.laboratory.platform.imr.vo.BaseSampleVO">
        <result property="sampleId" column="id"/>
        <result property="sampleNo" column="sample_no"/>
        <result property="name" column="name"/>
        <result property="storageMethod" column="storage_method"/>
        <result property="storageLocation" column="storage_location"/>
        <result property="category" column="category"/>
        <result property="sampleType" column="sample_type"/>
        <result property="form" column="form"/>
        <result property="status" column="status"/>
        <result property="id" column="storage_id"/>
    </resultMap>


    <!--OutSampleVO getSampleByNo(String sampleNo);-->
    <select id="getSampleByNo" resultMap="outSampleVo">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               im.type as category,
               s.holder,
               s.status,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=s.holder
               ) AS holder_name,
            s.existing_quality
        from dlp_identification_material_transfer.b_sample s
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
        where s.sample_no = #{sampleNo}
        order by s.sample_no
    </select>



<!--    List<OutSampleVO> getSampleListByNo(String sampleNo);-->

    <select id="getSampleListByNo" resultMap="outSampleVo">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               s.existing_quality,
               im.form,
               im.type as category,
               s.holder,
               s.status,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=s.holder
               ) AS holder_name
        from dlp_identification_material_transfer.b_sample s
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
        where s.sample_no like concat ('%',#{sampleNo},'%' )  or im.inspection_materials_no = #{sampleNo}
              or s.box_id = #{sampleNo}
        order by s.sample_no asc
    </select>




    <!--OutSampleVO getSampleById(String sampleId);-->
    <select id="getSampleById" resultMap="outSampleVo">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               im.type as category,
               s.holder,
               s.status,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=s.holder
               ) AS holder_name,
               s.existing_quality
        from dlp_identification_material_transfer.b_sample s
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
        where s.id = #{id}
    </select>


    <resultMap id="repositorySampleMap" type="digital.laboratory.platform.imr.vo.RepositorySampleVO" extends="sampleStorageMap">
        <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="sourceName" column="source_name"/>
        <result property="depositorName" column="depositor_name"/>
        <result property="recipientName" column="recipient_name"/>
    </resultMap>




    <!--
        待存放样本列表
    List<RepositorySampleVO> getToBeStoredSample(String name);-->

    <sql id="toBeStoredMap">
        select storage.*,
               sample.sample_no,
               sample.storage_method,
               im.type as category,
               im.form,
               sample.source
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on im.id = sample.identification_material_id
    </sql>

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




    <sql id="repositorySampleMap">
        select storage.*,
               sample.sample_no,
               sample.storage_method,
               sample.source,
               im.form,
               im.type as category,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.depositor_id
               ) AS depositor_name,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.recipient_id
               ) AS recipient_name
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
    </sql>


    <!--getSampleVOList-->
    <select id="getSampleVOList" resultMap="repositorySampleMap">
        <include refid="repositorySampleMap"></include>
        ${ew.customSqlSegment}
    </select>


    <resultMap id="detailSampleMap" type="digital.laboratory.platform.imr.vo.RepositorySampleVO" extends="repositorySampleMap">
        <result property="source" column="source"/>
        <result property="imNo" column="im_no"/>
        <result property="orgName" column="org_name"/>
    </resultMap>



    <!--
        详细样本信息
    RepositorySampleVO getSampleDetailed(String id);-->

    <select id="getSampleDetailed" resultMap="detailSampleMap" >
        select storage.*,
               im.inspection_materials_no as im_no,
               sample.sample_no,
               sample.storage_method,
               sample.source,
               (select d.dictionary_describe
                from dlp_identification_material_transfer.sample_dictionary d
                where d.business_status = sample.source
                )as source_name,
               im.form,
               im.type as category,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.depositor_id
               ) AS depositor_name,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.recipient_id
               ) AS recipient_name,
               (
                   select org.name
                   from dlp_base.sys_org org
                   where sample.org_id = org.org_id
               )AS org_name
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        where storage.id = #{id}
    </select>



    <!--
        创建领用申请查询仓库样本
        getSampleInfo-->

    <sql id="outSampleMap">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               s.source,
               im.type as category,
               s.holder,
               storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample s
        on storage.sample_id = s.id
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
    </sql>

    <select id="getSampleInfo" resultMap="outSampleVo">
        <include refid="outSampleMap"/>
        ${ew.customSqlSegment}
    </select>

    <select id="getSampleInfoList" resultMap="outSampleVo">
        <include refid="outSampleMap"/>
        ${ew.customSqlSegment}
    </select>

    <sql id="toBeReturnSampleMap">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               im.type as category,
               s.holder,
               storage.storage_location,
               storage.id as storage_id
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample s
        on storage.sample_id = s.id
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
    </sql>

    <select id="getSampleInfoTwo" resultMap="baseSampleVo">
        <include refid="toBeReturnSampleMap"/>
        ${ew.customSqlSegment}
    </select>


    <resultMap id="toBeReturnedMap" type="digital.laboratory.platform.imr.vo.ToBeReturnVO">
        <id column="id" property="id"/>
        <result property="sampleId" column="sample_id"/>
        <result property="name" column="name"/>
        <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="recipientName" column="recipient_name"/>
        <result property="outRepositoryDate" column="out_repository_date"/>
        <result property="sampleType" column="sample_type"/>
        <result property="returnTime" column="return_time"/>
    </resultMap>

    <resultMap id="recipientMap" type="digital.laboratory.platform.imr.vo.RecipientDTO" extends="toBeReturnedMap">
        <result property="department" column="department"/>
        <result property="purpose" column="purpose"/>
        <result property="recipientId" column="recipient_Id"/>
    </resultMap>

    <sql id="toBeReturn">
        select storage.return_time,
               storage.name,
               storage.out_repository_date,
               storage.sample_id,
               storage.id,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.recipient_id
               ) AS recipient_name,
               sample.sample_type,
               sample.sample_no,
               im.form ,
               sample.source,
               im.type as category,
               sample.storage_method
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
    </sql>

    <select id="toBeReturned" resultMap="toBeReturnedMap">
        <include refid="toBeReturn"/>
        ${ew.customSqlSegment}
    </select>

    <select id="toBeReturnedDetail" resultMap="recipientMap">
        select storage.return_time,
               storage.name,
               storage.out_repository_date,
               storage.sample_id,
               storage.id,
               storage.purpose,
               storage.recipient_id,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.recipient_id
               ) AS recipient_name,
               (
                   SELECT user.department
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=storage.recipient_id
               ) as department,
               sample.sample_type,
               sample.sample_no,
               im.form ,
               im.type as category,
               sample.storage_method
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        where storage.sample_id = #{id}
    </select>




    <sql id="holderMap">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               im.type as category,
               s.holder
        from dlp_identification_material_transfer.b_sample s
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
    </sql>


    <select id="getSampleInfoByHolder" resultMap="baseSampleVo">
        <include refid="holderMap"/>
        ${ew.customSqlSegment}
    </select>


    <select id="getDestructionSample" resultMap="baseSampleVo">
        <include refid="toBeReturnSampleMap"/>
        ${ew.customSqlSegment}
    </select>


    <resultMap id="baseSampleInventory" type="digital.laboratory.platform.imr.entity.InventorySample">
        <result property="sampleNo" column="sample_no"/>
        <result property="name" column="name"/>
        <result property="storageLocation" column="storage_location"/>
        <result property="sampleType" column="sample_type"/>
    </resultMap>


    <sql id="inventoryMap">
        select storage.storage_location,
               sample.sample_no,
               sample.sample_type,
               sample.name
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on sample.id = storage.sample_id
    </sql>

    <select id="getSampleInventory" resultMap="baseSampleInventory">
        <include refid="inventoryMap"/>
        ${ew.customSqlSegment}
    </select>




    <resultMap id="sampleDetailMap" type="digital.laboratory.platform.imr.vo.BaseSampleDetail">
        <id column="id" property="id"/>
        <result property="name" column="name"/>
        <result property="sampleNo" column="sample_no"/>
        <result property="storageMethod" column="storage_method"/>
        <result property="category" column="category"/>
        <result property="form" column="form"/>
        <result property="sampleType" column="sample_type"/>
        <result property="source" column="source"/>
        <result property="sourceName" column="source_name"/>
        <result property="quantity" column="quantity"/>
        <result property="drawWay" column="draw_way"/>
        <result property="unit" column="unit"/>
        <result property="orgName" column="org_name"/>
        <result property="acceptedBy" column="accepted_by"/>
        <result property="existingQuality" column="existing_quality"/>
    </resultMap>

<!--    BaseSampleDetail getSampleDetailInfo(String id);-->

    <select id="getSampleDetailInfo" resultMap="sampleDetailMap">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               im.form,
               im.type as category,
               s.draw_way,
               (
                   select b1.weight
                   from dlp_base.b_balance_r_material b1
                   where b1.create_time =
                         (select max(b2.create_time)
                          from dlp_base.b_balance_r_material b2
                          where b2.identification_material_id = s.id
               )
               )as quantity,
               s.unit,
               s.source,
               (select d.dictionary_describe
                from dlp_identification_material_transfer.sample_dictionary d
                where d.business_status = s.source
               )as source_name,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=s.create_by
               ) AS accepted_by,
               (
                   select org.name
                   from dlp_base.sys_org org
                   where s.org_id = org.org_id
               )AS org_name,
                s.existing_quality
            from dlp_identification_material_transfer.b_sample s
            join dlp_identification_material_transfer.identification_material im
            on s.identification_material_id = im.id
            where s.id = #{id}
    </select>



    <!--  String getEntrustmentName(@Param("id")String entrustmentId);-->
    <select id="getEntrustmentName" resultType="String">
        select event.case_name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_entrustment.b_entrustment entrustment
        on sample.entrustment_id = entrustment.id
        join dlp_entrustment.b_case_event event
        on entrustment.case_id = event.id
        where sample.id = #{id}
    </select>

    <!--  String getHairJobName(@Param("id")String hairJobId);-->

    <select id="getHairJobName" resultType="String">
        select hairJob.task_name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_hair_job.b_hair_job hairJob
        on sample.hair_job_id = hairJob.id
        where sample.id = #{id}
    </select>

    <!--  String getSewageJobName(@Param("id")String sewageJobId);-->

    <select id="getSewageJobName" resultType="String">
        select sewageJob.name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_sewage_job.b_sewage_job sewageJob
        on sample.sewage_job_id = sewageJob.id
        where sample.id = #{id}
    </select>


    <!--String getEventName(@Param("id")String sampleId);-->
    <select id="getEventName" resultType="String">
        select event.event_name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_im_acceptance.b_event event
        on sample.event_id = event.id
        where sample.id = #{id}
    </select>

    <select id="getFeatureName" resultType="String">
        select feature.name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_feature_analysis.b_feature_analysis_job feature
        on sample.feature_analysis_job_id = feature.id
        where sample.id = #{id}
    </select>


    <!--String returnOutboundQuery(String sampleId);-->


    <select id="returnOutboundQuery" resultType="String">
        select org.name
        from dlp_identification_material_transfer.b_sample sample
        join dlp_base.sys_org org
        on sample.org_id = org.org_id
        where sample.id = #{id}
    </select>



    <!--List<OutSampleVO> getWTSample(@Param("dto")CombinationOut combinationOut);-->
    <select id="getWTSample" resultMap="outSampleVo">
        select sample.id as sample_id,
        sample.sample_no,
        sample.storage_method,
        sample.sample_type,
        sample.name,
        im.form,
        im.type as category,
        sample.holder,
        sample.source,
        event.case_name as event_name,
        storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        join dlp_entrustment.b_entrustment en
        on sample.entrustment_id = en.id
        join dlp_entrustment.b_case_event event
        on en.case_id = event.id
        <where>
            and storage.status = 2
            and sample.status = 2
            and sample.source = 'entrustment'
            and sample.entrustment_id is not null
            <if test="dto.name!=null and ''!=dto.name">
                and event.case_name like concat('%',#{dto.name},'%')
                or storage.room_no like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.sampleIds!=null">
                and sample.id not in
                <foreach collection="dto.sampleIds" open="(" close=")" item="ids" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>
        order by storage.room_no asc
    </select>






<!--    List<OutSampleVO> getWSSample(@Param("dto")CombinationOut combinationOut);-->
    <select id="getWSSample" resultMap="outSampleVo">
        select sample.id as sample_id,
        sample.sample_no,
        sample.storage_method,
        sample.sample_type,
        sample.name,
        im.form,
        im.type as category,
        sample.holder,
        sample.source,
        sewageJob.name as event_name,
        storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        join dlp_sewage_job.b_sewage_job sewageJob
        on sample.sewage_job_id = sewageJob.id
        <where>
            and storage.status = 2
            and sample.status = 2
            and sample.source = 'sewageJob'
            and sample.sewage_job_id is not null
            <if test="dto.name!=null and ''!=dto.name">
                and sewageJob.name like concat('%',#{dto.name},'%')
                or storage.room_no like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.sampleIds!=null">
                and sample.id not in
                <foreach collection="dto.sampleIds" open="(" close=")" item="ids" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>

    </select>

<!--    List<OutSampleVO> getMFSample(@Param("dto")CombinationOut combinationOut);-->
    <select id="getMFSample" resultMap="outSampleVo">
        select sample.id as sample_id,
        sample.sample_no,
        sample.storage_method,
        sample.sample_type,
        sample.name,
        im.form,
        im.type as category,
        sample.holder,
        sample.source,
        hairJob.task_name as event_name,
        storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        join dlp_hair_job.b_hair_job hairJob
        on sample.hair_job_id = hairJob.id
        <where>
            and storage.status = 2
            and sample.status = 2
            and sample.source = 'hairJob'
            and sample.hair_job_id is not  null
            <if test="dto.name!=null and ''!=dto.name">
                and hairJob.task_name like concat('%',#{dto.name},'%')
                or storage.room_no like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.sampleIds!=null">
                and sample.id not in
                <foreach collection="dto.sampleIds" open="(" close=")" item="ids" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>

    </select>
<!--    List<OutSampleVO> getSJSample(@Param("dto")CombinationOut combinationOut);-->
    <select id="getSJSample" resultMap="outSampleVo">
        select sample.id as sample_id,
        sample.sample_no,
        sample.storage_method,
        sample.sample_type,
        sample.name,
        im.form,
        im.type as category,
        sample.holder,
        sample.source,
        event.event_name,
        storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        join dlp_im_acceptance.b_event event
        on event.id = sample.event_id
        <where>
            and storage.status = 2
            and sample.status = 2
            and sample.source like concat('Event','%')
            <if test="dto.name!=null and ''!=dto.name">
                and event.event_name like concat('%',#{dto.name},'%')
                or storage.room_no like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.sampleIds!=null">
                and sample.id not in
                <foreach collection="dto.sampleIds" open="(" close=")" item="ids" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>

    </select>

    <!--
    getTZSample 特征分析-->
    <select id="getTZSample" resultMap="outSampleVo">
        select sample.id as sample_id,
        sample.sample_no,
        sample.storage_method,
        sample.sample_type,
        sample.name,
        im.form,
        im.type as category,
        sample.holder,
        sample.source,
        feature.name event_name,
        storage.room_no
        from dlp_identification_material_repository.b_sample_storage storage
        join dlp_identification_material_transfer.b_sample sample
        on storage.sample_id = sample.id
        join dlp_identification_material_transfer.identification_material im
        on sample.identification_material_id = im.id
        join dlp_feature_analysis.b_feature_analysis_job feature
        on feature.id = sample.feature_analysis_job_id
        <where>
            and storage.status = 2
            and sample.status = 2
            and sample.feature_analysis_job_id is not null
            <if test="dto.name!=null and ''!=dto.name">
                and feature.name like concat('%',#{dto.name},'%')
                or storage.room_no like concat('%',#{dto.name},'%')
            </if>
            <if test="dto.sampleIds!=null">
                and sample.id not in
                <foreach collection="dto.sampleIds" open="(" close=")" item="ids" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>

    </select>









<!--    Long getTransferCount(String id);-->

    <select id="getTransferCount" resultType="Long">
        select count(*)
        from dlp_identification_material_transfer.sample_transfer transfer
        where transfer.transfer_status = 0 and transfer.recipient_id = #{id}
    </select>

<!--    Long getWitnessCount(String id);-->
    <select id="getWitnessCount" resultType="Long">
        select count(*)
        from dlp_identification_material_transfer.sample_transfer transfer
        where transfer.transfer_status = 4 and transfer.witness_id = #{id}
    </select>



    <!--int queryTransfer(@Param("userId")String userId);-->
    <select id="queryTransfer" resultType="int">
        select count(*)
        from dlp_identification_material_transfer.sample_transfer t
        where (t.recipient_id = #{userId} and t.transfer_status = 0)
                or
            (t.witness_id = #{userId} and t.transfer_status = 4)
    </select>




    <!--List<OutSampleVO> choseSampleList();-->

    <select id="choseSampleList" resultMap="outSampleVo">
        select s.id,
               s.sample_no,
               s.storage_method,
               s.sample_type,
               s.name,
               s.existing_quality,
               im.form,
               im.type as category,
               s.holder,
               s.status,
               (
                   SELECT user.name
                   FROM dlp_base.sys_user user
                   WHERE user.user_id=s.holder
               ) AS holder_name
        from dlp_identification_material_transfer.b_sample s
        join dlp_identification_material_transfer.identification_material im
        on s.identification_material_id = im.id
        where (s.status = 1 or s.status = 14) and s.sample_no is not null and s.sample_no != ''
        order by sample_no desc
    </select>




    <!--double getQuality(String sampleId);-->
    <select id="getQuality" resultType="double">
        select sample.existing_quality
        from dlp_identification_material_transfer.b_sample sample
        where sample.id = #{id}
    </select>



</mapper>