| | |
| | | package com.mes.device.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.mes.device.entity.DeviceConfig; |
| | | import com.mes.device.entity.DeviceGroupRelation; |
| | | import com.mes.device.vo.DeviceGroupVO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | |
| | | * @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); |
| | | |
| | | /** |
| | |
| | | "INNER JOIN device_group_relation dgr ON dgc.id = dgr.group_id " + |
| | | "WHERE dgr.device_id = #{deviceId} AND dgr.is_deleted = 0 AND dgc.is_deleted = 0") |
| | | List<DeviceGroupVO.GroupInfo> getDeviceGroups(@Param("deviceId") Long deviceId); |
| | | |
| | | /** |
| | | * 获取按连接顺序排序的设备配置列表 |
| | | * |
| | | * @param groupId 设备组ID |
| | | * @return 设备配置集合 |
| | | */ |
| | | @Select("SELECT d.* " + |
| | | "FROM device_group_relation dgr " + |
| | | "INNER JOIN device_config d ON dgr.device_id = d.id " + |
| | | "WHERE dgr.group_id = #{groupId} " + |
| | | " AND dgr.is_deleted = 0 " + |
| | | " 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); |
| | | } |