<?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="org.dromara.mapper.SenMonitorTaskMapper">

    <select id="selectVoPageWrapper" resultType="org.dromara.domain.vo.SenMonitorTaskVo">
        SELECT
        sac.*,
        (SELECT b.point_name from sen_monitor_point b where sac.point_id=b.point_id) AS point_name ,(SELECT c.file_name
        from sen_monitor_point_media c WHERE sac.media_id=c.id) AS file_name,
        GROUP_CONCAT(sa.algorithm_name ORDER BY sa.algorithm_name SEPARATOR ',') AS event_types
        FROM
        sen_monitor_task sac
        LEFT JOIN
        sen_monitor_task_algorithms d ON sac.id = d.task_id
        LEFT JOIN
        sen_algorithm_config sa ON d.algorithm_id = sa.id
        ${ew.customSqlSegment}
        GROUP BY
        sac.id
    </select>
    <select id="selectScheduledTask" resultType="org.dromara.domain.SenEvents">
        SELECT
        DISTINCT(map.event_type),
        map.event_category,
        (SELECT dict.dict_label from sys_dict_data dict where dict.dict_type='event_type' AND dict_value = map.event_type) AS event_name,
        b.point_id,
        b.point_name,
        b.area_id,
        c.area_name,
        '交通' AS event_obj,
        0 AS deal_status,
        CASE
        WHEN RAND() &lt; 0.25 THEN '电子警察'
        WHEN RAND() &lt; 0.50 THEN '普通卡口'
        WHEN RAND() &lt; 0.75 THEN '不文明驾驶'
        ELSE '其他'
        END AS datasource,
        1 AS create_by,
        SYSDATE() AS create_time
        FROM
        sen_monitor_task sac
        LEFT JOIN
        sen_monitor_task_algorithms d ON sac.id = d.task_id
        LEFT JOIN
        sen_algorithm_config sa ON d.algorithm_id = sa.id
        LEFT JOIN
        sen_monitor_point b ON b.point_id = sac.point_id
        LEFT JOIN
        sys_area c ON c.area_id  = b.area_id
        LEFT JOIN
        sen_map_tmp map ON map.algorithm_category = sa.algorithm_category
        WHERE sac.`status`='2'
        ORDER BY RAND()
        LIMIT 60
    </select>
    <select id="selectFlowTask" resultType="org.dromara.domain.SenFlowDetail">
        SELECT
        sac.id AS task_id,
        b.point_id,
        b.point_name,
        CAST(FLOOR(1 + RAND() * 3) AS CHAR) AS lane_number,
        CAST(FLOOR(1 + RAND() * 50) AS CHAR) AS vehicle_count,
        CAST(FLOOR(1 + RAND() * 50) AS CHAR) AS average_speed,
        CAST(FLOOR(1 + RAND() * 50) AS CHAR) AS queue_time,
        CAST(FLOOR(1 + RAND() * 100) AS CHAR) AS time_rate,
        CAST(FLOOR(1 + RAND() * 100) AS CHAR) AS space_rate,
        CAST(FLOOR(1 + RAND() * 20) AS CHAR) AS headway_time,
        CAST(FLOOR(1 + RAND() * 40) AS CHAR) AS headway_distance,
        CAST(FLOOR(1 + RAND() * 100) AS CHAR) AS vehicle_remark,
        1 AS create_by,
        SYSDATE() AS create_time
        FROM
        sen_monitor_task sac
        LEFT JOIN
        sen_monitor_point b ON b.point_id = sac.point_id
        LEFT JOIN
        sys_area c ON c.area_id = b.area_id
    </select>
</mapper>
