Browse Source

新增获取摄像头列表功能

main
sjh 10 months ago
parent
commit
7b87bb4e07
  1. 6
      src/main/java/com/biutag/supervision/pojo/entity/WvpDeviceChannel.java
  2. 37
      src/main/java/com/biutag/supervision/service/WvpDeviceChannelService.java

6
src/main/java/com/biutag/supervision/pojo/entity/WvpDeviceChannel.java

@ -6,6 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
@Setter @Setter
@Getter @Getter
public class WvpDeviceChannel { public class WvpDeviceChannel {
@ -330,4 +333,7 @@ public class WvpDeviceChannel {
@TableField("data_device_id") @TableField("data_device_id")
private Integer dataDeviceId; private Integer dataDeviceId;
// 存储子设备的列表
@TableField(exist = false)
private List<WvpDeviceChannel> childList = new ArrayList<>();
} }

37
src/main/java/com/biutag/supervision/service/WvpDeviceChannelService.java

@ -1,11 +1,46 @@
package com.biutag.supervision.service; package com.biutag.supervision.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.supervision.pojo.entity.WvpDeviceChannel;
import com.biutag.supervision.mapper.WvpDeviceChannelMapper; import com.biutag.supervision.mapper.WvpDeviceChannelMapper;
import com.biutag.supervision.pojo.entity.WvpDeviceChannel;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service @Service
public class WvpDeviceChannelService extends ServiceImpl<WvpDeviceChannelMapper, WvpDeviceChannel> { public class WvpDeviceChannelService extends ServiceImpl<WvpDeviceChannelMapper, WvpDeviceChannel> {
public List<WvpDeviceChannel> getDeviceList() {
List<WvpDeviceChannel> allDevices = list();
Map<String, WvpDeviceChannel> deviceMap = allDevices.stream()
.collect(Collectors.toMap(WvpDeviceChannel::getDeviceId, device -> device));
List<WvpDeviceChannel> hierarchy = new ArrayList<>();
Queue<WvpDeviceChannel> queue = new LinkedList<>();
for (WvpDeviceChannel device : allDevices) {
if (device.getParentId() == null) {
hierarchy.add(device);
queue.offer(device);
}
}
while (!queue.isEmpty()) {
WvpDeviceChannel parentDevice = queue.poll();
List<WvpDeviceChannel> children = deviceMap.values().stream()
.filter(device -> parentDevice.getDeviceId().equals(getParentDeviceId(device.getParentId())))
.collect(Collectors.toList());
if (!children.isEmpty()) {
parentDevice.setChildList(children);
queue.addAll(children);
}
}
return hierarchy;
}
private String getParentDeviceId(String parentId) {
if (parentId != null && parentId.contains("/")) {
return parentId.substring(parentId.lastIndexOf("/") + 1);
}
return parentId;
}
} }
Loading…
Cancel
Save