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

    <resultMap id="applicationForUseMap" type="digital.laboratory.platform.reagent.entity.ApplicationForUse">
        <id property="applicationForUseId" column="application_for_use_id"/>
        <result property="dateOfCollection" column="date_of_collection"/>
        <result property="recipientId" column="recipient_id"/>
        <result property="status" column="status"/>
        <result property="deliveryRegistrationFormId" column="delivery_registration_form_id"/>
        <result property="requisitionRecordId" column="requisition_record_id"/>
        <result property="claimCode" column="claim_code"/>
        <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="applicationForUseVO" type="digital.laboratory.platform.reagent.vo.ApplicationForUseVO"
               extends="applicationForUseMap">
        <result property="recipientName" column="recipient_name"></result>
    </resultMap>

    <sql id="getApplicationForUseVOSQL">
        SELECT afu.*,
               (select user.name
                from dlp_base.sys_user user
        where user.user_id =afu.recipient_id) AS recipient_name
        FROM application_for_use afu
    </sql>

    <select id="getApplicationForUseVOList" resultMap="applicationForUseVO"
            resultType="digital.laboratory.platform.reagent.vo.ApplicationForUseVO">
        <include refid="getApplicationForUseVOSQL"></include>

    </select>

    <select id="getApplicationForUseVOPage" resultMap="applicationForUseVO"
            resultType="digital.laboratory.platform.reagent.vo.ApplicationForUseVO">
        <include refid="getApplicationForUseVOSQL"></include>

    </select>

    <select id="getApplicationForUseVO" resultMap="applicationForUseVO"
            resultType="digital.laboratory.platform.reagent.vo.ApplicationForUseVO">
        SELECT afu.*,
               (select user.name
                from dlp_base.sys_user user
        where user.user_id =afu.recipient_id) AS recipient_name
        FROM application_for_use afu
        WHERE afu.application_for_use_id = #{applicationForUseId}
    </select>

</mapper>
