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

    <resultMap id="BaseResultMap" type="digital.laboratory.platform.imr.entity.DrugUsageRecord">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="drugId" column="drug_id" jdbcType="VARCHAR"/>
            <result property="applicant" column="applicant" jdbcType="VARCHAR"/>
            <result property="applicantName" column="applicant_name" jdbcType="VARCHAR"/>
            <result property="usageDate" column="usage_date" jdbcType="TIMESTAMP"/>
            <result property="usageName" column="usage_name" jdbcType="TIMESTAMP"/>
            <result property="usagePurpose" column="usage_purpose" 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,drug_id,applicant,applicant_name,
        usage_date,usage_purpose,
        create_time,update_time,
        create_by,update_by
    </sql>

    <select id="queryUsageRecordVOPage">
        SELECT
               <include refid="Base_Column_List"/>
        FROM b_drug_usage_record du
        <where>
            <if test="query.keywords != null and query.keywords != ''">
                OR du.applicant_name = #{query.keywords}
            </if>
            <if test="query.startDate != null">
                AND du.usage_date &gt;= #{query.startDate}
            </if>
            <if test="query.endDate != null">
                AND du.usage_date &lt;= #{query.endDate}
            </if>
        </where>
        ORDER BY du.usage_date DESC
    </select>
</mapper>
