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

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM clinic_medicine a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.clinicId != null">
                AND a.clinic_id = #{param.clinicId}
            </if>
            <if test="param.pinyin != null">
                AND a.pinyin LIKE CONCAT('%', #{param.pinyin}, '%')
            </if>
            <if test="param.category != null">
                AND a.category LIKE CONCAT('%', #{param.category}, '%')
            </if>
            <if test="param.specification != null">
                AND a.specification LIKE CONCAT('%', #{param.specification}, '%')
            </if>
            <if test="param.unit != null">
                AND a.unit LIKE CONCAT('%', #{param.unit}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.pricePerUnit != null">
                AND a.price_per_unit = #{param.pricePerUnit}
            </if>
            <if test="param.isActive != null">
                AND a.is_active = #{param.isActive}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </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.ClinicMedicine">
        <include refid="selectSql"></include>
    </select>

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

</mapper>
