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

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
               b.merchant_name,b.merchant_code
        FROM apps_equipment a
        LEFT JOIN shop_merchant b ON a.merchant_code = b.merchant_code
        <where>
            <if test="param.equipmentId != null">
                AND a.equipment_id = #{param.equipmentId}
            </if>
            <if test="param.equipmentName != null">
                AND a.equipment_name LIKE CONCAT('%', #{param.equipmentName}, '%')
            </if>
            <if test="param.equipmentCode != null">
                AND a.equipment_code LIKE CONCAT('%', #{param.equipmentCode}, '%')
            </if>
            <if test="param.equipmentCategory != null">
              AND a.equipment_category LIKE CONCAT('%', #{param.equipmentCategory}, '%')
            </if>
            <if test="param.equipmentAvatar != null">
                AND a.equipment_avatar LIKE CONCAT('%', #{param.equipmentAvatar}, '%')
            </if>
            <if test="param.batteryModel != null">
                AND a.battery_model LIKE CONCAT('%', #{param.batteryModel}, '%')
            </if>
            <if test="param.bms != null">
                AND a.bms LIKE CONCAT('%', #{param.bms}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.isCtive != null">
                AND a.is_ctive LIKE CONCAT('%', #{param.isCtive}, '%')
            </if>
            <if test="param.workingStatus != null">
                AND a.working_status LIKE CONCAT('%', #{param.workingStatus}, '%')
            </if>
            <if test="param.leaseStatus != null">
                AND a.lease_status LIKE CONCAT('%', #{param.leaseStatus}, '%')
            </if>
            <if test="param.batteryStatus != null">
                AND a.battery_status LIKE CONCAT('%', #{param.batteryStatus}, '%')
            </if>
            <if test="param.batteryPower != null">
                AND a.battery_power LIKE CONCAT('%', #{param.batteryPower}, '%')
            </if>
            <if test="param.isOnline != null">
                AND a.is_online LIKE CONCAT('%', #{param.isOnline}, '%')
            </if>
            <if test="param.totalVoltage != null">
                AND a.total_voltage LIKE CONCAT('%', #{param.totalVoltage}, '%')
            </if>
            <if test="param.bmsBrand != null">
                AND a.bms_brand LIKE CONCAT('%', #{param.bmsBrand}, '%')
            </if>
            <if test="param.surplusCapacity != null">
                AND a.surplus_capacity LIKE CONCAT('%', #{param.surplusCapacity}, '%')
            </if>
            <if test="param.iccid != null">
                AND a.iccid LIKE CONCAT('%', #{param.iccid}, '%')
            </if>
            <if test="param.ctiveTime != null">
                AND a.ctive_time LIKE CONCAT('%', #{param.ctiveTime}, '%')
            </if>
            <if test="param.batteryDeliveryTime != null">
                AND a.battery_delivery_time LIKE CONCAT('%', #{param.batteryDeliveryTime}, '%')
            </if>
            <if test="param.orderId != null">
              AND a.order_id = #{param.orderId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </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.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.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.Equipment">
        <include refid="selectSql"></include>
    </select>

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

</mapper>
