优化国标树型展示
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package com.genersoft.iot.vmp.vmanager.bean;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public class BaseTree<T> implements Comparable<BaseTree>{
|
||||
private String id;
|
||||
|
||||
private String deviceId;
|
||||
private String pid;
|
||||
private String name;
|
||||
private boolean parent;
|
||||
|
||||
private T basicData;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public T getBasicData() {
|
||||
return basicData;
|
||||
}
|
||||
|
||||
public void setBasicData(T basicData) {
|
||||
this.basicData = basicData;
|
||||
}
|
||||
|
||||
public boolean isParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(boolean parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull BaseTree treeNode) {
|
||||
if (this.parent || treeNode.isParent()) {
|
||||
if (!this.parent && !treeNode.isParent()) {
|
||||
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
|
||||
return cmp.compare(treeNode.getName(), this.getName());
|
||||
}else {
|
||||
if (this.isParent()) {
|
||||
return 1;
|
||||
}else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
|
||||
return cmp.compare(treeNode.getName(), this.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -479,4 +480,99 @@ public class DeviceQuery {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询国标树
|
||||
* @param deviceId 设备ID
|
||||
* @param parentId 父ID
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @return 国标设备
|
||||
*/
|
||||
@ApiOperation("查询国标树")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "parentId", value = "父ID", required = false, dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "onlyCatalog", value = "只获取目录", required = false, dataTypeClass = Boolean.class),
|
||||
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class),
|
||||
@ApiImplicitParam(name="count", value = "每页条数", required = true, dataTypeClass = Integer.class),
|
||||
})
|
||||
@GetMapping("/tree/{deviceId}")
|
||||
public ResponseEntity<PageInfo> getTree(@PathVariable String deviceId, @RequestParam(required = false) String parentId, @RequestParam(required = false) Boolean onlyCatalog, int page, int count){
|
||||
|
||||
|
||||
if (page <= 0) {
|
||||
page = 1;
|
||||
}
|
||||
if (onlyCatalog == null) {
|
||||
onlyCatalog = false;
|
||||
}
|
||||
|
||||
List<BaseTree<DeviceChannel>> treeData = deviceService.queryVideoDeviceTree(deviceId, parentId, onlyCatalog);
|
||||
if (treeData == null || (page - 1) * count > treeData.size()) {
|
||||
PageInfo<BaseTree<DeviceChannel>> pageInfo = new PageInfo<>();
|
||||
pageInfo.setPageNum(page);
|
||||
pageInfo.setTotal(treeData == null? 0 : treeData.size());
|
||||
pageInfo.setSize(0);
|
||||
pageInfo.setList(new ArrayList<>());
|
||||
return new ResponseEntity<>(pageInfo,HttpStatus.OK);
|
||||
}
|
||||
|
||||
int toIndex = Math.min(page * count, treeData.size());
|
||||
// 处理分页
|
||||
List<BaseTree<DeviceChannel>> trees = treeData.subList((page - 1) * count, toIndex);
|
||||
PageInfo<BaseTree<DeviceChannel>> pageInfo = new PageInfo<>();
|
||||
pageInfo.setPageNum(page);
|
||||
pageInfo.setTotal(treeData.size());
|
||||
pageInfo.setSize(trees.size());
|
||||
pageInfo.setList(trees);
|
||||
|
||||
return new ResponseEntity<>(pageInfo,HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询国标树下的通道
|
||||
* @param deviceId 设备ID
|
||||
* @param parentId 父ID
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @return 国标设备
|
||||
*/
|
||||
@ApiOperation("查询国标树下的通道")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "parentId", value = "父ID", required = false, dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class),
|
||||
@ApiImplicitParam(name="count", value = "每页条数", required = true, dataTypeClass = Integer.class),
|
||||
})
|
||||
@GetMapping("/tree/channel/{deviceId}")
|
||||
public ResponseEntity<PageInfo> getChannelInTreeNode(@PathVariable String deviceId, @RequestParam(required = false) String parentId, int page, int count){
|
||||
|
||||
|
||||
if (page <= 0) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
List<DeviceChannel> treeData = deviceService.queryVideoDeviceInTreeNode(deviceId, parentId);
|
||||
if (treeData == null || (page - 1) * count > treeData.size()) {
|
||||
PageInfo<BaseTree<DeviceChannel>> pageInfo = new PageInfo<>();
|
||||
pageInfo.setPageNum(page);
|
||||
pageInfo.setTotal(treeData == null? 0 : treeData.size());
|
||||
pageInfo.setSize(0);
|
||||
pageInfo.setList(new ArrayList<>());
|
||||
return new ResponseEntity<>(pageInfo,HttpStatus.OK);
|
||||
}
|
||||
|
||||
int toIndex = Math.min(page * count, treeData.size());
|
||||
// 处理分页
|
||||
List<DeviceChannel> trees = treeData.subList((page - 1) * count, toIndex);
|
||||
PageInfo<DeviceChannel> pageInfo = new PageInfo<>();
|
||||
pageInfo.setPageNum(page);
|
||||
pageInfo.setTotal(treeData.size());
|
||||
pageInfo.setSize(trees.size());
|
||||
pageInfo.setList(trees);
|
||||
|
||||
return new ResponseEntity<>(pageInfo,HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user