<?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.imr.mapper.DrugCaseInfoMapper">

    <resultMap id="BaseResultMap" type="digital.laboratory.platform.imr.entity.DrugCaseInfo">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="caseName" column="case_name" jdbcType="VARCHAR"/>
            <result property="caseNo" column="case_no" jdbcType="VARCHAR"/>
            <result property="handingOverOrg" column="handing_over_org" jdbcType="VARCHAR"/>
            <result property="handingOverDate" column="handing_over_date" jdbcType="TIMESTAMP"/>
            <result property="frontOrgIds" column="front_org_ids" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,case_name,case_no,
        handing_over_org,handing_over_date,front_org_ids,create_time,
        update_time,create_by,update_by
    </sql>

    <sql id="queryDrugCaseInfoVOSql">
        SELECT
               <include refid="Base_Column_List"/>, handingOverCount
        FROM b_drug_case_info
        LEFT JOIN (
            SELECT COUNT(*) AS handingOverCount , case_id
        FROM b_drug_material_info GROUP BY case_id
        ) AS t
        ON b_drug_case_info.id = t.case_id
    </sql>

    <select id="queryDrugCaseInfoVOPage"
            resultType="digital.laboratory.platform.imr.vo.DrugCaseInfoVO">
        <include refid="queryDrugCaseInfoVOSql"/>
        ${ew.customSqlSegment}
    </select>
</mapper>
