VideoServiceImpl.java
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.bsth.service.impl.videoimpl;
import com.bsth.entity.Business;
import com.bsth.entity.Line;
import com.bsth.entity.video.VideoTree;
import com.bsth.service.BusinessService;
import com.bsth.service.LineService;
import com.bsth.service.video.VideoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author liujun
* @date 2024年07月01日 12:57
*/
@Service
public class VideoServiceImpl implements VideoService {
@Autowired
private BusinessService businessService;
@Autowired
private LineService lineService;
@Override
public List<VideoTree> combinationTree() {
List<VideoTree> returnList = new ArrayList<>();
List<VideoTree> bussessTree = queryBusiness();
if (CollectionUtils.isNotEmpty(bussessTree)) {
returnList.addAll(bussessTree);
}
// List<VideoTree> lineTree = queryLine();
// if (CollectionUtils.isNotEmpty(lineTree)) {
// returnList.addAll(lineTree);
// }
return returnList;
}
/***
*查询公交公司的数据。
* @author liujun
* @date 2024/6/27 11:29
* @return java.util.List<com.bsth.entity.video.VideoTree>
*/
private List<VideoTree> queryBusiness() {
Iterable<Business> businessIterable = businessService.list(new HashMap<>());
if (Objects.isNull(businessIterable)) {
return Collections.emptyList();
}
List<VideoTree> trees = new ArrayList<>();
Iterator<Business> iterator = businessIterable.iterator();
while (iterator.hasNext()) {
Business business = iterator.next();
VideoTree videoTree = combinationVideoTree(business.getBusinessCode(), business.getBusinessName(), business.getUpCode(), business.getId(), 1, null);
trees.add(videoTree);
}
List<VideoTree> groupTree = new ArrayList<>();
for (VideoTree tree : trees) {
if (Objects.equals(tree.getParentId(), "0")) {
VideoTree target = new VideoTree();
BeanUtils.copyProperties(tree,target);
target.setParentId("#");
groupTree.add(target);
}
}
if (CollectionUtils.isNotEmpty(groupTree)) {
for (VideoTree tree : groupTree) {
groupTree(trees, tree);
}
}
return groupTree;
}
private List<VideoTree> queryLine() {
Iterable<Line> lines = lineService.list(new HashMap<>());
if (Objects.isNull(lines)) {
return Collections.emptyList();
}
List<VideoTree> trees = new ArrayList<>();
Iterator<Line> iterator = lines.iterator();
while (iterator.hasNext()) {
Line line = iterator.next();
VideoTree videoTree = combinationVideoTree(line.getId(), line.getName(), line.getCompany(), line.getId(), 2, null);
trees.add(videoTree);
}
return trees;
}
private List<VideoTree> queryCars() {
return null;
}
/***
* 组合树
* @author liujun
* @date 2024/6/27 13:12
* @param id id
* @param text 显示的文本
* @param sourceId 数据的ID
* @param parent 数据的父节点
* @param type 类型
* @param icon 图标
* @return com.bsth.entity.video.VideoTree
*/
private VideoTree combinationVideoTree(Object id, String text, String parent, Integer sourceId, Integer type, String icon) {
VideoTree videoTree = new VideoTree();
videoTree.setId(id);
videoTree.setText(text);
videoTree.setSourceId(sourceId);
videoTree.setParentId(parent);
videoTree.setType(type);
videoTree.setIcon(icon);
return videoTree;
}
private void groupTree(List<VideoTree> trees, VideoTree tree) {
if (Objects.isNull(trees) || CollectionUtils.isEmpty(trees)) {
return;
}
for (VideoTree videoTree : trees) {
if (Objects.equals(videoTree.getParentId(), tree.getId())) {
if (Objects.isNull(tree.getChildren())) {
tree.setChildren(new ArrayList<>());
}
tree.getChildren().add(videoTree);
groupTree(trees, videoTree);
}
}
}
}