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

    <resultMap id="sampleInfoMap" type="digital.laboratory.platform.inspetion.api.entity.SampleInfo">
        <id property="id" column="id"/>
        <result property="sampleName" column="sample_name"></result>
        <result property="acceptNo" column="accept_no"></result>
        <result property="quality" column="quality"></result>
        <result property="unit" column="unit"></result>
        <result property="sampleQuality" column="sample_quality"></result>
        <result property="sampleQualityUnit" column="sample_quality_unit"></result>
        <result property="source" column="source"></result>
        <result property="businessId" column="business_id"></result>
        <result property="status" column="status"></result>
        <result property="form" column="form"></result>
        <result property="businessType" column="business_type"></result>
        <result property="color" column="color"></result>
        <result property="analysisOption" column="analysisOption"></result>
        <result property="orderNo" column="orderNo"></result>
        <result property="targetObject" column="target_object" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"></result>
    </resultMap>

    <resultMap id="sampleInfoVoMap" type="digital.laboratory.platform.inspection.vo.SampleInfoVo"
               extends="sampleInfoMap">
        <result property="businessTypeName" column="business_type_name"></result>
    </resultMap>

    <select id="getSampleInfoList" resultMap="sampleInfoMap">
        SELECT *
        FROM b_sampleinfo
        WHERE id in (SELECT sample_id
                     FROM b_assignmentinfo
                     WHERE business_id = (#{businessId})
                       and test_user = #{testUser})
          and `status` = 1
        order by accept_no asc
    </select>

    <select id="getFullSampleInfoList" resultMap="sampleInfoVoMap">
        SELECT *,
               CASE
                   WHEN business_type = '10001' THEN '缴获物检验'
                   WHEN business_type = '10002' THEN '生物样本案件'
                   WHEN business_type = '20001' THEN '毛发任务'
                   WHEN business_type = '20002' THEN '污水任务'
                   WHEN business_type = '30001' THEN '筛查事件'
                   ELSE ''
                   END as business_type_name
        FROM b_sampleinfo ${ew.customSqlSegment}
    </select>
</mapper>
