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

    <resultMap id="periodVerificationPlanMap" type="digital.laboratory.platform.reagent.entity.PeriodVerificationPlan">
        <id property="periodVerificationPlanId" column="period_verification_plan_id"/>
        <result property="dateOfNextCheck" column="date_of_next_check"/>
        <result property="deviationAndUncertainty" column="deviation_and_uncertainty"/>
        <result property="inspectorId" column="inspector_id"/>
        <result property="referenceMaterialId" column="reference_material_id"/>
        <result property="instructionBookId" column="instruction_book_id"/>
        <result property="plannedVerificationCycle" column="planned_verification_cycle"/>
        <result property="scheduledVerificationDate" column="scheduled_verification_date"/>
        <result property="standardValueAndPurity" column="standard_value_and_purity"/>
        <result property="verificationBasis" column="verification_basis"/>
        <result property="implementationDate" column="implementation_date"/>
        <result property="verificationResult" column="verification_result"/>
        <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="checkScheduleId" column="check_schedule_id"/>

    </resultMap>
    <resultMap id="periodVerificationPlanVO" type="digital.laboratory.platform.reagent.vo.PeriodVerificationPlanVO"
               extends="periodVerificationPlanMap">
        <result property="referenceMaterialName" column="reference_material_name"></result>
        <result property="inspectorName" column="inspector_name"></result>
    </resultMap>

    <sql id="getPeriodVerificationPlanVOSQL">
        select pvp.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = pvp.reference_material_id) as reference_material_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=pvp.inspector_id ) as inspector_name
        from period_verification_plan pvp
        where pvp.check_schedule_id = #{checkScheduleId}
    </sql>

    <select id="getPeriodVerificationPlanVOList" resultMap="periodVerificationPlanVO" resultType="digital.laboratory.platform.reagent.vo.PeriodVerificationPlanVO">
        <include refid="getPeriodVerificationPlanVOSQL"></include>
    </select>
</mapper>
