@Override
public Tree treeWithSpaceCameraAndCollect ( Long buildingId) {
List< EquipmentCollect> equipmentCollects = this . baseMapper. selectCollectByBuildingId ( buildingId) ;
Tree linkSectorParentTree;
if ( equipmentCollects. size ( ) == 0 ) {
Tree< Object> emptyTree = new Tree < > ( ) ;
linkSectorParentTree = emptyTree;
} else {
List< EquipmentCollect> linkedSector = equipmentCollects. stream ( )
. filter ( e - > ! ObjectUtils. isEmpty ( e. getFloorId ( ) ) )
. collect ( Collectors. toList ( ) ) ;
Map< Long, List< EquipmentCollect> > floorCollect = linkedSector. stream ( )
. collect ( Collectors. groupingBy ( EquipmentCollect: : getFloorId) ) ;
linkSectorParentTree = buildSpaceTree ( floorCollect) ;
}
List< EquipmentCamera> equipmentCameras = this . baseMapper. selectCameraByBuildingId ( buildingId) ;
Tree linkSectorCameraParentTree;
if ( equipmentCameras. size ( ) == 0 ) {
Tree< Object> emptyTree = new Tree < > ( ) ;
linkSectorCameraParentTree = emptyTree;
} else {
List< EquipmentCamera> linkedSectorCamera = equipmentCameras. stream ( )
. filter ( e - > ! ObjectUtils. isEmpty ( e. getFloorId ( ) ) )
. collect ( Collectors. toList ( ) ) ;
Map< Long, List< EquipmentCamera> > floorCamers = linkedSectorCamera. stream ( )
. collect ( Collectors. groupingBy ( EquipmentCamera: : getFloorId) ) ;
linkSectorCameraParentTree = buildCameraSpaceTree ( floorCamers) ;
}
List< Tree> parent = Arrays. asList ( linkSectorParentTree, linkSectorCameraParentTree) ;
Tree root = new Tree < > ( ) ;
root. setChildren ( parent) ;
root. setId ( "0" ) ;
root. setKey ( "0" ) ;
return root;
}
在这里插入代码片
private Tree buildSpaceTree ( Map< Long, List< EquipmentCollect> > floorCollect) {
List< Long> floorIds = new ArrayList < > ( floorCollect. keySet ( ) ) ;
String ids = StringUtils. join ( floorIds, "," ) ;
Collection< BuildingFloor> buidingFloor = spaceService. getFloorByIds ( ids) ;
Map< Long, Map< Long, Map< Long, List< BuildingFloor> >>> treeGroup = buidingFloor. stream ( )
. collect ( Collectors. groupingBy ( BuildingFloor: : getParkId,
Collectors. groupingBy ( BuildingFloor: : getBuildingId,
Collectors. groupingBy ( BuildingFloor: : getId) ) ) ) ;
Tree linkSectorParentTree = new Tree ( ) ;
List< Tree< Park> > linkSectorChildren = new ArrayList < > ( ) ;
linkSectorParentTree. setId ( "linkSectorParentTree" ) ;
linkSectorParentTree. setKey ( "linkSectorParentTree" ) ;
linkSectorParentTree. setParentId ( "0" ) ;
linkSectorParentTree. setLabel ( "采集设备" ) ;
linkSectorParentTree. setChildren ( linkSectorChildren) ;
treeGroup. forEach ( ( parkId, parks) - > {
Tree parkTree = new Tree ( ) ;
List< Tree< ParkBuilding> > parkChildren = new ArrayList < > ( ) ;
Park parkById = spaceService. getParkById ( parkId) ;
parkTree. setLabel ( parkById. getParkName ( ) ) ;
parkTree. setId ( "parkId-" + parkId) ;
parkTree. setKey ( "parkId-" + parkId) ;
parkTree. setParentId ( "linkSectorParentTree" ) ;
parkTree. setChildren ( parkChildren) ;
linkSectorChildren. add ( parkTree) ;
parks. forEach ( ( buildingId, builds) - > {
Tree buildTree = new Tree ( ) ;
List< Tree< BuildingFloor> > buildChildren = new ArrayList < > ( ) ;
ParkBuilding parkBuildingById = spaceService. getParkBuildingById ( buildingId) ;
buildTree. setLabel ( parkBuildingById. getBuildingName ( ) ) ;
buildTree. setId ( "buildingId-" + buildingId) ;
buildTree. setKey ( "buildingId-" + buildingId) ;
buildTree. setParentId ( "parkId-" + parkId) ;
buildTree. setChildren ( buildChildren) ;
parkChildren. add ( buildTree) ;
builds. forEach ( ( floorId, floors) - > {
Tree floorTree = new Tree ( ) ;
List< Tree< BuildingSector> > floorChildren = new ArrayList < > ( ) ;
BuildingFloor buildingFloorById = spaceService. getBuildingFloorById ( floorId) ;
floorTree. setLabel ( buildingFloorById. getFloorName ( ) ) ;
floorTree. setId ( "floorId-" + floorId) ;
floorTree. setKey ( "floorId-" + floorId) ;
floorTree. setParentId ( "buildingId-" + buildingId) ;
floorTree. setChildren ( floorChildren) ;
buildChildren. add ( floorTree) ;
List< EquipmentCollect> collects = floorCollect. get ( floorId) ;
collects. forEach ( c - > {
Tree lastNode = new Tree < > ( ) ;
lastNode. setId ( "collectId-" + c. getId ( ) ) ;
lastNode. setKey ( "collectId-" + c. getId ( ) ) ;
lastNode. setValue ( c. getCollectName ( ) ) ;
lastNode. setParentId ( "floorId-" + floorId) ;
BuildingFloor floor = spaceService. getBuildingFloorById ( floorId) ;
c. setFloorCode ( floor. getFloorCode ( ) ) ;
lastNode. setProp ( c) ;
lastNode. setLabel ( c. getCollectName ( ) ) ;
floorChildren. add ( lastNode) ;
} ) ;
} ) ;
} ) ;
} ) ;
return linkSectorParentTree;
}
在这里插入代码片
private Tree buildCameraSpaceTree ( Map< Long, List< EquipmentCamera> > floorCameras) {
List< Long> sectorIds = new ArrayList < > ( floorCameras. keySet ( ) ) ;
String ids = StringUtils. join ( sectorIds, "," ) ;
Collection< BuildingFloor> buildingFloors = spaceService. getFloorByIds ( ids) ;
Map< Long, Map< Long, Map< Long, List< BuildingFloor> >>> treeGroup = buildingFloors. stream ( )
. collect ( Collectors. groupingBy ( BuildingFloor: : getParkId,
Collectors. groupingBy ( BuildingFloor: : getBuildingId,
Collectors. groupingBy ( BuildingFloor: : getId) ) ) ) ;
Tree linkSectorCameraParentTree = new Tree ( ) ;
List< Tree< Park> > linkSectorChildren = new ArrayList < > ( ) ;
linkSectorCameraParentTree. setId ( "linkSectorCameraParentTree" ) ;
linkSectorCameraParentTree. setKey ( "linkSectorCameraParentTree" ) ;
linkSectorCameraParentTree. setParentId ( "0" ) ;
linkSectorCameraParentTree. setLabel ( "监控设备" ) ;
linkSectorCameraParentTree. setChildren ( linkSectorChildren) ;
treeGroup. forEach ( ( parkId, parks) - > {
Tree parkTree = new Tree ( ) ;
List< Tree< ParkBuilding> > parkChildren = new ArrayList < > ( ) ;
Park parkById = spaceService. getParkById ( parkId) ;
parkTree. setLabel ( parkById. getParkName ( ) ) ;
parkTree. setId ( "parkId-" + parkId) ;
parkTree. setKey ( "parkId-" + parkId) ;
parkTree. setParentId ( "linkSectorCameraParentTree" ) ;
parkTree. setChildren ( parkChildren) ;
linkSectorChildren. add ( parkTree) ;
parks. forEach ( ( buildingId, builds) - > {
Tree buildTree = new Tree ( ) ;
List< Tree< BuildingFloor> > buildChildren = new ArrayList < > ( ) ;
ParkBuilding parkBuildingById = spaceService. getParkBuildingById ( buildingId) ;
buildTree. setLabel ( parkBuildingById. getBuildingName ( ) ) ;
buildTree. setId ( "buildingId-" + buildingId) ;
buildTree. setKey ( "buildingId-" + buildingId) ;
buildTree. setParentId ( "parkId-" + parkId) ;
buildTree. setChildren ( buildChildren) ;
parkChildren. add ( buildTree) ;
builds. forEach ( ( floorId, floors) - > {
Tree floorTree = new Tree ( ) ;
List< Tree< BuildingSector> > floorChildren = new ArrayList < > ( ) ;
BuildingFloor buildingFloorById = spaceService. getBuildingFloorById ( floorId) ;
floorTree. setLabel ( buildingFloorById. getFloorName ( ) ) ;
floorTree. setId ( "floorId-" + floorId) ;
floorTree. setKey ( "floorId-" + floorId) ;
floorTree. setParentId ( "buildingId-" + buildingId) ;
floorTree. setChildren ( floorChildren) ;
buildChildren. add ( floorTree) ;
List< EquipmentCamera> cameras = floorCameras. get ( floorId) ;
cameras. forEach ( c - > {
Tree cameraTree = new Tree < > ( ) ;
cameraTree. setId ( "cameraId-" + c. getId ( ) ) ;
cameraTree. setKey ( "cameraId-" + c. getId ( ) ) ;
cameraTree. setValue ( c. getStreamUrl ( ) ) ;
cameraTree. setParentId ( "floorId-" + floorId) ;
BuildingFloor floor = spaceService. getBuildingFloorById ( floorId) ;
c. setFloorCode ( floor. getFloorCode ( ) ) ;
cameraTree. setProp ( c) ;
cameraTree. setLabel ( c. getCameraName ( ) ) ;
floorChildren. add ( cameraTree) ;
} ) ;
} ) ;
} ) ;
} ) ;
return linkSectorCameraParentTree;
}
在这里插入代码片
import com. fasterxml. jackson. annotation. JsonInclude;
import lombok. AllArgsConstructor;
import lombok. Builder;
import lombok. Data;
import lombok. NoArgsConstructor;
import java. util. ArrayList;
import java. util. Date;
import java. util. List;
import java. util. Map;
@Data
@JsonInclude ( JsonInclude. Include. NON_NULL)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Tree < T> {
public static final String[ ] pathList = new String [ ] { "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" } ;
private String id;
private String parentId;
private String label;
private String key;
private String icon;
private Map slots;
private String title;
private String value;
private String text;
private String permission;
private String description;
private String deptName;
private Long deptId;
private String userTotal;
private String userLoginTotal;
private String loginRate;
private String type;
private boolean disabled;
private String linkType;
private T prop;
private Integer order;
private String path;
private String component;
private List< Tree< T> > children;
private boolean hasParent = false ;
private boolean hasChildren = false ;
private Date createTime;
private Date modifyTime;
public void initChildren ( ) {
this . children = new ArrayList < > ( ) ;
}
在这里插入代码片