<?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.inspection.mapper.TestTemplateMapper">

    <resultMap id="testTemplateMap" type="digital.laboratory.platform.inspection.entity.TestTemplate">
        <id property="id" column="id"/>
        <result property="nature" column="nature"/>
        <result property="status" column="status"/>
        <result property="author" column="author"/>
        <result property="useCount" column="use_count"/>
        <result property="createDate" column="create_date"/>
        <result property="publishDate" column="publish_date"/>
        <result property="introduce" column="introduce"/>
        <result property="deviceIdList" column="device_id_list" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
        <result property="reagentConsumables" column="reagent_consumables" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
        <result property="testMethods" column="test_methods" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
        <result property="deviceUseCondition" column="device_use_condition" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
    </resultMap>

    <resultMap id="testTemplateMapVo" type="digital.laboratory.platform.inspection.vo.TestTemplateVo"
               extends="testTemplateMap">
        <result property="authorName" column="author_name"></result>
    </resultMap>

    <select id="getTestTemplateMapById" resultMap="testTemplateMapVo">
        select t.*,
               (select u.name from dlp_base.sys_user u where u.user_id = t.author) as author_name
        from b_test_template t
        where t.id = #{id}
    </select>

    <sql id="getTestTemplateMapSQL">
        select t.*,
               (select u.name from dlp_base.sys_user u where u.user_id = t.author) as author_name
        from b_test_template t
    </sql>

    <select id="getTestTemplateMapPage" resultMap="testTemplateMapVo">
        <include refid="getTestTemplateMapSQL"></include>
        ${ew.customSqlSegment}
    </select>

    <select id="getTestTemplateMapList" resultMap="testTemplateMapVo">
        <include refid="getTestTemplateMapSQL"></include>
        ${ew.customSqlSegment}
    </select>
</mapper>
