<?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.bonus.canteen.core.bus.mapper.BusDeviceInfoMapper">
    <select id="queryPageBusDeviceInfo" resultType="com.bonus.canteen.core.bus.vo.BusDeviceInfoVO">
        SELECT t1.device_id,
        t1.device_num,
        t1.device_name,
        t1.device_sn,
        t1.device_key,
        t1.online_state,
        t1.device_ip,
        t1.device_mac,
        t1.device_addr,
        t1.device_type,
        t1.device_gateway,
        t1.online_state as commState,
        t1.version_code,
        t1.version_name,
        t2.line_id,
        t3.line_name,
        t2.use_scene,
        t2.del_flag,
        t1.crtime,
        t1.uptime
        FROM device_info t1
        left join bus_device_info t2 on t1.device_id = t2.device_id
        left join bus_line t3 on t2.line_id = t3.line_id
        <where>
            t2.del_flag = 2
            <if test="keyword != null and keyword != ''">
                and concat(t1.device_num, t1.device_name, t1.device_sn) like concat('%', #{keyword}, '%')
            </if>
        </where>
        ORDER BY t1.uptime DESC
    </select>

    <select id="queryBusDeviceInfoDetail" resultType="com.bonus.canteen.core.bus.vo.BusDeviceInfoVO">
        SELECT t1.device_id,
        t1.device_num,
        t1.device_name,
        t1.device_sn,
        t1.device_key,
        t1.online_state,
        t1.device_ip,
        t1.device_mac,
        t1.device_addr,
        t1.device_type,
        t1.device_gateway,
        t1.online_state,
        t1.version_code,
        t1.version_name,
        t2.line_id,
        t3.line_name,
        t2.use_scene,
        t2.del_flag,
        t1.crtime,
        t1.uptime
        FROM device_info t1
        left join bus_device_info t2 on t1.device_id = t2.device_id
        left join bus_line t3 on t2.line_id = t3.line_id
        <where>
            t2.del_flag = 2
            <if test="deviceId != null and deviceId != ''">
                and t1.device_id = #{deviceId}
            </if>
        </where>
    </select>

    <select id="queryMacBusSceneByTimeSize" resultType="com.bonus.canteen.core.bus.vo.MacBusSceneVO">
        SELECT t1.*,
               t2.device_num,
               t2.device_name,
               t2.device_sn,
               t2.device_key,
               t3.line_name,
               t3.line_sites,
               t4.billing_id,
               t4.billing_name,
               t4.billing_num,
               t4.billing_type,
               t4.ceiling_price,
               t4.fixed_amount,
               t4.site_price
        FROM bus_device_info t1
                 LEFT JOIN device_info t2 ON t1.device_id = t2.device_id
                 LEFT JOIN bus_line t3 ON t1.line_id = t3.line_id
                 LEFT JOIN bus_billing_rule t4 ON t3.billing_id = t4.billing_id
        WHERE t1.del_flag = 2
          AND t3.del_flag = 2
          AND t4.del_flag = 2
          AND t1.uptime > #{custAccTempQueryDto.time,jdbcType=VARCHAR}
        <if test="machineSn != null and machineSn != ''">
            and t2.device_sn = #{machineSn}
        </if>
        ORDER BY t1.uptime ASC
<!--            limit #{custAccTempQueryDto.pagesize,jdbcType=INTEGER};-->
    </select>

    <select id="queryMacBusSceneByTimeSizeBetween" resultType="com.bonus.canteen.core.bus.vo.MacBusSceneVO">
        SELECT t1.*,
               t2.device_num,
               t2.device_name,
               t2.device_sn,
               t2.device_key,
               t3.line_name,
               t4.billing_id,
               t4.billing_name,
               t4.billing_num,
               t4.billing_type,
               t4.ceiling_price,
               t4.fixed_amount,
               t4.site_price
        FROM bus_device_info t1
                 LEFT JOIN device_info t2 ON t1.device_id = t2.device_id
                 LEFT JOIN bus_line t3 ON t1.line_id = t3.line_id
                 LEFT JOIN bus_billing_rule t4 ON t3.billing_id = t4.billing_id
        WHERE t1.del_flag = 2
          AND t3.del_flag = 2
          AND t4.del_flag = 2
          AND <![CDATA[t1.uptime > #{custAccTempQueryDto.time,jdbcType=VARCHAR}
          AND t1.uptime <= #{custAccTempQueryDto.endtime,jdbcType=VARCHAR}]]>
        ORDER BY t1.uptime ASC
    </select>
</mapper>
