| | |
| | | * @return 设备信息列表 |
| | | */ |
| | | @Select("SELECT d.id, d.device_name as deviceName, d.device_code as deviceCode, " + |
| | | "d.device_type as deviceType, dgr.role, d.status, " + |
| | | "d.last_heartbeat as lastHeartbeat, d.is_online as isOnline " + |
| | | "d.device_type as deviceType, d.plc_ip as plcIp, dgr.role, d.status, " + |
| | | "ds.last_heartbeat as lastHeartbeat, " + |
| | | "CASE WHEN ds.status = 'ONLINE' THEN TRUE ELSE FALSE END as isOnline " + |
| | | "FROM device_config d " + |
| | | "INNER JOIN device_group_relation dgr ON d.id = dgr.device_id " + |
| | | "WHERE dgr.group_id = #{groupId} AND dgr.is_deleted = 0 AND d.is_deleted = 0") |
| | | "LEFT JOIN device_status ds ON d.device_id = ds.device_id " + |
| | | " AND ds.id = (SELECT MAX(id) FROM device_status WHERE device_id = d.device_id) " + |
| | | "WHERE dgr.group_id = #{groupId} AND dgr.is_deleted = 0 AND d.is_deleted = 0 " + |
| | | "ORDER BY dgr.connection_order ASC") |
| | | List<DeviceGroupVO.DeviceInfo> getGroupDevices(@Param("groupId") Long groupId); |
| | | |
| | | /** |
| | |
| | | " AND d.is_deleted = 0 " + |
| | | "ORDER BY IFNULL(dgr.connection_order, 0) ASC, dgr.id ASC") |
| | | List<DeviceConfig> getOrderedDeviceConfigs(@Param("groupId") Long groupId); |
| | | |
| | | /** |
| | | * 获取设备组下的在线设备数量 |
| | | * |
| | | * @param groupId 设备组ID |
| | | * @return 在线设备数量 |
| | | */ |
| | | @Select("SELECT COUNT(DISTINCT d.id) " + |
| | | "FROM device_config d " + |
| | | "INNER JOIN device_group_relation dgr ON d.id = dgr.device_id " + |
| | | "LEFT JOIN device_status ds ON d.device_id = ds.device_id " + |
| | | " AND ds.id = (SELECT MAX(id) FROM device_status WHERE device_id = d.device_id) " + |
| | | "WHERE dgr.group_id = #{groupId} " + |
| | | " AND dgr.is_deleted = 0 " + |
| | | " AND d.is_deleted = 0 " + |
| | | " AND ds.status = 'ONLINE'") |
| | | Integer getOnlineDeviceCountByGroupId(@Param("groupId") Long groupId); |
| | | } |