<?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.sunwin.robot2ips.dao.UploadMapper">
    <insert id="insertBindLink">
        insert into ips_sw_point_link (monitoring_point,point_id,device_code)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.monitoringPoint},
            #{item.pointId},
            #{item.deviceCode})
        </foreach>
        ON DUPLICATE key update
        point_id = values(point_id),
        device_code = values(device_code)
    </insert>


    <select id="queryDataByDate" resultType="com.sunwin.robot2ips.beans.vo.RecordTaskPoint">
        select
        c.id result_id,
        c.point_name remark,
        c.result result_value,
        1 data_source,
        ips.monitoring_point point_code,
        c.time update_time,
        c.robot_id
        from
        ips_sw_point_link ips
        LEFT JOIN  check_data c ON ips.point_id = c.point_id
        where
            c.time BETWEEN #{startDate} and #{endDate}
    </select>
    <select id="selectRobots" resultType="com.sunwin.robot2ips.beans.dto.RobotDTO">
        select * from robot
    </select>
    <select id="queryDataAfterId" resultType="com.sunwin.robot2ips.beans.vo.RecordTaskPoint">
        SELECT
        c.id result_id,
        c.point_name remark,
        c.result result_value,
        1 data_source,
        ips.device_code,
        ips.monitoring_point point_code,
        c.time update_time,
        d.start_time record_start_date,
        concat( t.id, "-", c.run_times ) task_id,
        CASE
        p.save_type
        WHEN 2 THEN
        c.infrared ELSE c.image
        END AS image,
        c.robot_id
        FROM
        ips_sw_point_link ips
        LEFT JOIN  check_data c ON ips.point_id = c.point_id
        LEFT JOIN check_task t ON t.id = c.task_id
        left join task_data d on c.task_id=d.task_id and c.run_times=d.run_times
        LEFT JOIN check_point p ON p.id = c.point_id AND c.robot_id = p.robot_id
        where
        c.id <![CDATA[ > ]]> #{lastDataId}
        order by c.id asc
        limit #{count}
    </select>
    <select id="selectMaxId" resultType="java.lang.Long">
        select max(id) from check_data
    </select>
</mapper>