<?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="com.gxwebsoft.clinic.mapper.PrescriptionOrderItemMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM clinic_prescription_order_item a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.prescriptionId != null">
                AND a.prescription_id = #{param.prescriptionId}
            </if>
            <if test="param.prescriptionNo != null">
                AND a.prescription_no LIKE CONCAT('%', #{param.prescriptionNo}, '%')
            </if>
            <if test="param.medicineId != null">
                AND a.medicine_id = #{param.medicineId}
            </if>
            <if test="param.dosage != null">
                AND a.dosage LIKE CONCAT('%', #{param.dosage}, '%')
            </if>
            <if test="param.usageFrequency != null">
                AND a.usage_frequency LIKE CONCAT('%', #{param.usageFrequency}, '%')
            </if>
            <if test="param.days != null">
                AND a.days = #{param.days}
            </if>
            <if test="param.amount != null">
                AND a.amount = #{param.amount}
            </if>
            <if test="param.unitPrice != null">
                AND a.unit_price = #{param.unitPrice}
            </if>
            <if test="param.quantity != null">
                AND a.quantity = #{param.quantity}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.clinic.entity.PrescriptionOrderItem">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.clinic.entity.PrescriptionOrderItem">
        <include refid="selectSql"></include>
    </select>

</mapper>
