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

    <resultMap id="checkScheduleMap" type="digital.laboratory.platform.reagent.entity.CheckSchedule">
        <id property="checkScheduleId" column="check_schedule_id"/>
        <result property="auditTimeOfTechnical" column="audit_time_of_technical"/>
        <result property="auditResultOfTechnical" column="audit_result_of_technical"/>
        <result property="auditOpinionOfTechnical" column="audit_opinion_of_technical"/>
        <result property="managerId" column="manager_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="technicalDirectorId" column="technical_director_id"/>
        <result property="number" column="number"/>
        <result property="status" column="status"/>
    </resultMap>

    <resultMap id="checkScheduleVO" type="digital.laboratory.platform.reagent.vo.CheckScheduleVO"
               extends="checkScheduleMap">
        <result property="technicalDirectorName" column="technical_director_name"></result>
        <result property="managerName" column="manager_mame"></result>
    </resultMap>

    <sql id="getCheckScheduleVOSQL">
        SELECT cs.*,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=cs.technical_director_id ) as technical_director_name
            , (
        SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=cs.manager_id ) as manager_mame
        FROM check_schedule cs

    </sql>

    <select id="getCheckScheduleVOPage" resultMap="checkScheduleVO" resultType="digital.laboratory.platform.reagent.vo.CheckScheduleVO">
        <include refid="getCheckScheduleVOSQL"></include>
    </select>

    <select id="getCheckScheduleVO"  resultMap="checkScheduleVO" resultType="digital.laboratory.platform.reagent.vo.CheckScheduleVO" >
        SELECT cs.*,
               (SELECT user.name
                FROM dlp_base.sys_user user
        WHERE user.user_id=cs.technical_director_id ) as technical_director_name
            , (
        SELECT user.name
        FROM dlp_base.sys_user user
        WHERE user.user_id=cs.manager_id ) as manager_mame
        FROM check_schedule cs
        WHERE cs.check_schedule_id = #{checkScheduleId}
    </select>
</mapper>
