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

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM clinic_prescription_order a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.clinicId != null">
                AND a.clinic_id = #{param.clinicId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.doctorId != null">
                AND a.doctor_id = #{param.doctorId}
            </if>
            <if test="param.orderId != null">
                AND a.order_id = #{param.orderId}
            </if>
            <if test="param.orderNo != null">
                AND a.order_no LIKE CONCAT('%', #{param.orderNo}, '%')
            </if>
            <if test="param.visitRecordId != null">
                AND a.visit_record_id = #{param.visitRecordId}
            </if>
            <if test="param.prescriptionType != null">
                AND a.prescription_type = #{param.prescriptionType}
            </if>
            <if test="param.diagnosis != null">
                AND a.diagnosis LIKE CONCAT('%', #{param.diagnosis}, '%')
            </if>
            <if test="param.treatmentPlan != null">
                AND a.treatment_plan LIKE CONCAT('%', #{param.treatmentPlan}, '%')
            </if>
            <if test="param.decoctionInstructions != null">
                AND a.decoction_instructions LIKE CONCAT('%', #{param.decoctionInstructions}, '%')
            </if>
            <if test="param.image != null">
                AND a.image LIKE CONCAT('%', #{param.image}, '%')
            </if>
            <if test="param.orderPrice != null">
                AND a.order_price = #{param.orderPrice}
            </if>
            <if test="param.price != null">
                AND a.price = #{param.price}
            </if>
            <if test="param.payPrice != null">
                AND a.pay_price = #{param.payPrice}
            </if>
            <if test="param.isInvalid != null">
                AND a.is_invalid = #{param.isInvalid}
            </if>
            <if test="param.isSettled != null">
                AND a.is_settled = #{param.isSettled}
            </if>
            <if test="param.settleTime != null">
                AND a.settle_time LIKE CONCAT('%', #{param.settleTime}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </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.PrescriptionOrder">
        <include refid="selectSql"></include>
    </select>

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

</mapper>
