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

  <resultMap id="complianceCheckMap" type="digital.laboratory.platform.reagent.entity.ComplianceCheck">
    <id property="complianceCheckId" column="compliance_check_id"/>
    <result property="auditOpinionOfPrimary" column="audit_opinion_of_primary"/>
    <result property="auditOpinionOfSecondary" column="audit_opinion_of_secondary"/>
    <result property="auditResultOfPrimary" column="audit_result_of_primary"/>
    <result property="auditResultOfSecondary" column="audit_result_of_secondary"/>
    <result property="auditTimeOfPrimary" column="audit_time_of_primary"/>
    <result property="auditTimeOfSecondary" column="audit_time_of_secondary"/>
    <result property="dateOfInspection" column="date_of_inspection"/>
    <result property="examinationConclusion" column="examination_conclusion"/>
    <result property="primaryAuditorId" column="primary_auditor_id"/>
    <result property="inspectionScheme" column="inspection_scheme"/>
    <result property="status" column="status"/>
    <result property="secondaryAuditorId" column="secondary_auditor_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"/>
    <result property="number" column="number"/>
    <result property="brand" column="brand"/>
    <result property="reagentConsumableId" column="reagent_consumable_id"/>
    <result property="specificationAndModel" column="specification_and_model"/>
    <result property="nonconformingItem" column="nonconforming_item"/>
    <result property="reagentConsumableNumber" column="reagent_consumable_number"/>
  </resultMap>

  <resultMap id="complianceCheckVO" type="digital.laboratory.platform.reagent.vo.ComplianceCheckVO" extends="complianceCheckMap">
    <result property="executorName" column="executor_name"></result>
    <result property="primaryAuditorName" column="primary_auditor_name"></result>
    <result property="secondaryAuditorId" column="secondary_auditor_name"></result>
  </resultMap>
  <sql id="getComplianceCheckVOSQL">
    SELECT cc.*,
           (SELECT user.name
            FROM dlp_base.sys_user user
    WHERE user.user_id =cc.executor_id) AS executor_name,
        (SELECT user.name
    FROM dlp_base.sys_user user
    WHERE user.user_id =cc.primary_auditor_id) AS primary_auditor_name ,
        (SELECT user.name
    FROM dlp_base.sys_user user
    WHERE user.user_id =cc.secondary_auditor_id) AS secondary_auditor_name
    FROM compliance_check cc
  </sql>

  <select id="getComplianceCheckVOPage" resultMap="complianceCheckVO" resultType="digital.laboratory.platform.reagent.vo.ComplianceCheckVO">
    <include refid="getComplianceCheckVOSQL"></include>
    ${ew.customSqlSegment}
  </select>

  <select id="getComplianceCheckVOList" resultMap="complianceCheckVO" resultType="digital.laboratory.platform.reagent.vo.ComplianceCheckVO">
    <include refid="getComplianceCheckVOSQL"></include>
    ${ew.customSqlSegment}
  </select>

  <select id="getComplianceCheckVO" resultMap="complianceCheckVO" resultType="digital.laboratory.platform.reagent.vo.ComplianceCheckVO">
    SELECT cc.*,
           (SELECT user.name
            FROM dlp_base.sys_user user
    WHERE user.user_id =cc.executor_id) AS executor_name ,
        (SELECT user.name
    FROM dlp_base.sys_user user
    WHERE user.user_id =cc.primary_auditor_id) AS primary_auditor_name ,
        (SELECT user.name
    FROM dlp_base.sys_user user
    WHERE user.user_id =cc.secondary_auditor_id) AS secondary_auditor_name
    FROM compliance_check cc
    WHERE cc.compliance_check_id = #{complianceCheckId}
  </select>
</mapper>
