package com.mes.device.mapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.mes.device.entity.DeviceGroupRelation;
|
import com.mes.device.vo.DeviceGroupVO;
|
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Select;
|
|
import java.util.List;
|
|
/**
|
* 设备组关系Mapper接口
|
*
|
* @author mes
|
* @since 2024-10-30
|
*/
|
@Mapper
|
public interface DeviceGroupRelationMapper extends BaseMapper<DeviceGroupRelation> {
|
|
/**
|
* 批量添加设备到设备组
|
*
|
* @param groupId 设备组ID
|
* @param deviceIds 设备ID列表
|
* @param deviceRole 设备角色
|
*/
|
void batchAddDevicesToGroup(@Param("groupId") Long groupId,
|
@Param("deviceIds") List<Long> deviceIds,
|
@Param("deviceRole") String deviceRole);
|
|
/**
|
* 批量从设备组移除设备
|
*
|
* @param groupId 设备组ID
|
* @param deviceIds 设备ID列表
|
*/
|
void batchRemoveDevicesFromGroup(@Param("groupId") Long groupId,
|
@Param("deviceIds") List<Long> deviceIds);
|
|
/**
|
* 更新设备在设备组中的角色
|
*
|
* @param groupId 设备组ID
|
* @param deviceId 设备ID
|
* @param deviceRole 设备角色
|
*/
|
void updateDeviceRole(@Param("groupId") Long groupId,
|
@Param("deviceId") Long deviceId,
|
@Param("deviceRole") String deviceRole);
|
|
/**
|
* 获取设备组下的设备列表(联表查询)
|
*
|
* @param groupId 设备组ID
|
* @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 " +
|
"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")
|
List<DeviceGroupVO.DeviceInfo> getGroupDevices(@Param("groupId") Long groupId);
|
|
/**
|
* 获取设备所属的设备组列表(联表查询)
|
*
|
* @param deviceId 设备ID
|
* @return 设备组信息列表
|
*/
|
@Select("SELECT dgc.id, dgc.group_code as groupCode, dgc.group_name as groupName, " +
|
"dgc.group_type as groupType, dgc.status, dgr.created_time as createTime, "+
|
"dgc.project_id as projectId, " +
|
"(SELECT COUNT(*) FROM device_group_relation WHERE group_id = dgc.id AND is_deleted = 0) as deviceCount " +
|
"FROM device_group_config dgc " +
|
"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);
|
}
|