<?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.device.manage.mapper.DeviceDcTerminalMapper">

    <select id="pageByParams" resultType="com.bonus.canteen.core.device.door.dto.terminal.DcTerminalVo"
            parameterType="com.bonus.canteen.core.device.door.dto.terminal.QueryPageDcTerminalDto">
        select
        di.device_id as id,
        di.device_model as terminalType ,
        di.device_num as terminalNo ,
        di.device_name as terminalName,
        IF(di.online_state =1,1,0) as isalive,
        di.device_ip as ipAddress,
        ddt.ip_port as ipPort,
        di.device_mac as macAddress ,
        ddt.serial_no as serialNo,
        di.version_name as fwVersion,
        ddt.note ,
        ddt.device_category ,
        db.build_name as buildName
        from device_info di
        left join device_dc_terminal ddt on di.device_id = ddt.device_id
        left join dc_build db on ddt.build_id = db.id
        where di.device_type = 60
        <if test="params.terminalName != null and params.terminalName != '' ">
            and di.device_name like concat('%',#{params.terminalName},'%')
        </if>
        <if test="params.terminalNo != null and params.terminalNo != '' ">
            and di.device_num = #{params.terminalNo}
        </if>
        <if test="params.note != null and params.note != '' ">
            and ddt.note like concat('%',#{params.note},'%')
        </if>

    </select>


    <select id="getDoUpdateDevices" resultType="com.bonus.canteen.core.device.manage.model.DeviceInfo">
        SELECT di.device_id,
        di.device_mac
        FROM device_dc_terminal ddt
        LEFT JOIN device_info di on ddt.device_id = di.device_id
        WHERE di.online_state = 1
        AND ((ddt.system_date_update_date &gt; ddt.last_push_date) OR ddt.last_push_date IS NULL)
        <if test="terminalIds != null and terminalIds.size() > 0">
            AND ddt.device_id IN
            <foreach collection="terminalIds" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
    </select>
</mapper>
