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

    <resultMap id="periodVerificationImplementationMap"
               type="digital.laboratory.platform.reagent.entity.PeriodVerificationImplementation">
        <id property="periodVerificationImplementationId" column="period_verification_implementation_id"/>
        <result property="auditOpinionOfTechnical" column="audit_opinion_of_technical"/>
        <result property="auditResultOfTechnical" column="audit_result_of_technical"/>
        <result property="auditTimeOfTechnical" column="audit_time_of_technical"/>
        <result property="causeOfDissatisfaction" column="cause_of_dissatisfaction"/>
        <result property="checkingTime" column="checking_time"/>
        <result property="commitStatus" column="commit_status"/>
        <result property="deviationAndUncertainty" column="deviation_and_uncertainty"/>
        <result property="implementationAndResults" column="implementation_and_results"/>
        <result property="inspectorId" column="inspector_id"/>
        <result property="number" column="number"/>
        <result property="opinionOfInspector" column="opinion_of_inspector"/>
        <result property="referenceMaterialId" column="reference_material_id"/>
        <result property="remarks" column="remarks"/>
        <result property="standardValueAndPurity" column="standard_value_and_purity"/>
        <result property="technicalDirectorId" column="technical_director_id"/>
        <result property="verificationMethod" column="verification_method"/>
        <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="referenceMaterialNumber" column="reference_material_number"/>
        <result property="periodVerificationPlanId" column="period_verification_plan_id"/>
    </resultMap>

    <resultMap id="periodVerificationImplementationVO" type="digital.laboratory.platform.reagent.vo.PeriodVerificationImplementationVO"
               extends="periodVerificationImplementationMap">
        <result property="inspectorName" column="inspector_name"></result>
        <result property="referenceMaterialName" column="reference_material_name"></result>
        <result property="technicalDirectorName" column="technical_director_name"></result>
    </resultMap>

    <sql id="getPeriodVerificationImplementationVOSQL">
        select pvi.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = pvi.reference_material_id) as reference_material_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=pvi.inspector_id ) as inspector_nam
            , (
        SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=pvi.technical_director_id ) as technical_director_name
        FROM period_verification_implementation pvi

    </sql>

    <select id="getPeriodVerificationImplementationVOPage" resultMap="periodVerificationImplementationVO" resultType="digital.laboratory.platform.reagent.vo.PeriodVerificationImplementationVO">
        <include refid="getPeriodVerificationImplementationVOSQL"></include>
    </select>

    <select id="getPeriodVerificationImplementationVO" resultMap="periodVerificationImplementationVO" resultType="digital.laboratory.platform.reagent.vo.PeriodVerificationImplementationVO">
        select pvi.*,
               (select rc.reagent_consumable_name
                from reagent_consumables rc
                where rc.reagent_consumable_id = pvi.reference_material_id) as reference_material_name,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=pvi.inspector_id ) as inspector_nam
            , (
        SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=pvi.technical_director_id ) as technical_director_name
        FROM period_verification_implementation pvi
        WHERE pvi.period_verification_implementation_id = #{periodVerificationImplementationId}
    </select>
</mapper>
