<?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.apps.mapper.EquipmentRecordMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
               b.merchant_name,b.merchant_code,
               c.nickname,c.user_id
        FROM apps_equipment_record a
        LEFT JOIN shop_merchant b ON a.merchant_code = b.merchant_code
        LEFT JOIN sys_user c ON a.user_id = c.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.equipmentCode != null">
                AND a.equipment_code LIKE CONCAT('%', #{param.equipmentCode}, '%')
            </if>
            <if test="param.eventType != null">
                AND a.event_type LIKE CONCAT('%', #{param.eventType}, '%')
            </if>
            <if test="param.params != null">
                AND a.params LIKE CONCAT('%', #{param.params}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </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.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </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.createTimeEnd != null">
            AND a.create_time &lt;= #{param.createTimeEnd}
          </if>
          <if test="param.orderId != null">
            AND a.order_id = #{param.orderId}
          </if>
          <if test="param.merchantName != null">
            AND b.merchant_name LIKE CONCAT('%', #{param.merchantName}, '%')
          </if>
          <if test="param.merchantCode != null">
            AND b.merchant_code = #{param.merchantCode}
          </if>
        </where>
    </sql>

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

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

</mapper>
