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

    <resultMap id="testRecordMap" type="digital.laboratory.platform.inspection.entity.TestRecordInstrumentCondition">
        <id property="id" column="id"/>
        <result property="testId" column="test_Id"/>
        <result property="conditionData" column="condition_data"
                typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
    </resultMap>

    <resultMap id="testRecordInstrumentConditionVoMap" type="digital.laboratory.platform.inspection.vo.TestRecordInstrumentConditionVo"
               extends="testRecordMap">
        <result property="testSerialNumber" column="test_serial_number"/>
        <result property="testUserName" column="test_user_name"/>
    </resultMap>

    <sql id="getTestRecordInstrumentConditionVoMapSQL">
        select ic.*, (select t.test_serial_number from b_test_record t where t.id = ic.test_id) as test_serial_number
        from b_test_record_use_condition ic
        order by create_time desc
    </sql>

    <select id="getTestRecordInstrumentConditionVoMapByTestId" resultMap="testRecordInstrumentConditionVoMap">
        select ic.*, (select t.test_serial_number from b_test_record t where t.id = ic.test_id) as test_serial_number
        from b_test_record_use_condition ic
        where ic.test_id = #{testId}
        order by create_time desc
    </select>
    <select id="getTestRecordInstrumentConditionVoMapPage" resultMap="testRecordInstrumentConditionVoMap">
        <include refid="getTestRecordInstrumentConditionVoMapSQL"></include>
        ${ew.customSqlSegment}
    </select>

    <select id="getTestRecordInstrumentConditionVoMapList" resultMap="testRecordInstrumentConditionVoMap">
        <include refid="getTestRecordInstrumentConditionVoMapSQL"></include>
        ${ew.customSqlSegment}
    </select>

</mapper>
