|
@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
|
11
|
11
|
|
12
|
12
|
import java.util.ArrayList;
|
13
|
13
|
import java.util.List;
|
|
14
|
+import java.util.Objects;
|
|
15
|
+import java.util.stream.Collectors;
|
14
|
16
|
|
15
|
17
|
/**
|
16
|
18
|
* @ClassName DirectorService
|
|
@@ -24,13 +26,14 @@ public class DirectorService {
|
24
|
26
|
private DirectorMapper directorMapper;
|
25
|
27
|
|
26
|
28
|
/**
|
27
|
|
- *功能描述 新增
|
|
29
|
+ * 功能描述 新增
|
|
30
|
+ *
|
|
31
|
+ * @param * @param director
|
|
32
|
+ * @return java.lang.Integer
|
28
|
33
|
* @author WN
|
29
|
34
|
* @date 2020/6/3
|
30
|
|
- * @param * @param director
|
31
|
|
- * @return java.lang.Integer
|
32
|
35
|
*/
|
33
|
|
- public Integer addDirector(TDirector director){
|
|
36
|
+ public Integer addDirector(TDirector director) {
|
34
|
37
|
String id = StudyUtil.getId();
|
35
|
38
|
director.setDirectorid(id);
|
36
|
39
|
if ("".equals(director.getDirectorpid())) {
|
|
@@ -42,12 +45,13 @@ public class DirectorService {
|
42
|
45
|
|
43
|
46
|
/**
|
44
|
47
|
* 添加并返回主键
|
|
48
|
+ *
|
|
49
|
+ * @return java.lang.Integer
|
45
|
50
|
* @Param [director]
|
46
|
51
|
* @Author ywx
|
47
|
52
|
* @Date 2020/7/6 15:00
|
48
|
|
- * @return java.lang.Integer
|
49
|
53
|
**/
|
50
|
|
- public String addAndReturnKey(TDirector director){
|
|
54
|
+ public String addAndReturnKey(TDirector director) {
|
51
|
55
|
String id = StudyUtil.getId();
|
52
|
56
|
director.setDirectorid(id);
|
53
|
57
|
director.setCreatetime(N_Utils.getSecondTimestamp());
|
|
@@ -56,42 +60,45 @@ public class DirectorService {
|
56
|
60
|
}
|
57
|
61
|
|
58
|
62
|
/**
|
59
|
|
- *功能描述 修改
|
|
63
|
+ * 功能描述 修改
|
|
64
|
+ *
|
|
65
|
+ * @param * @param director
|
|
66
|
+ * @return java.lang.Integer
|
60
|
67
|
* @author WN
|
61
|
68
|
* @date 2020/6/3
|
62
|
|
- * @param * @param director
|
63
|
|
- * @return java.lang.Integer
|
64
|
69
|
*/
|
65
|
|
- public Integer updateDirector(TDirector director){
|
|
70
|
+ public Integer updateDirector(TDirector director) {
|
66
|
71
|
director.setCreatetime(N_Utils.getSecondTimestamp());
|
67
|
72
|
return directorMapper.updateByPrimaryKeySelective(director);
|
68
|
73
|
}
|
69
|
74
|
|
70
|
75
|
/**
|
71
|
|
- *功能描述 删除
|
|
76
|
+ * 功能描述 删除
|
|
77
|
+ *
|
|
78
|
+ * @param * @param director
|
|
79
|
+ * @return java.lang.Integer
|
72
|
80
|
* @author WN
|
73
|
81
|
* @date 2020/6/3
|
74
|
|
- * @param * @param director
|
75
|
|
- * @return java.lang.Integer
|
76
|
82
|
*/
|
77
|
|
- public Integer delDirector(TDirector director){
|
|
83
|
+ public Integer delDirector(TDirector director) {
|
78
|
84
|
return directorMapper.deleteByPrimaryKey(director.getDirectorid());
|
79
|
85
|
}
|
80
|
86
|
|
81
|
87
|
/**
|
82
|
|
- *功能描述 章节树形结构
|
|
88
|
+ * 功能描述 章节树形结构
|
|
89
|
+ *
|
|
90
|
+ * @param * @param director
|
|
91
|
+ * @return java.util.List<com.xhkjedu.model.subjectbook.TDirector>
|
83
|
92
|
* @author WN
|
84
|
93
|
* @date 2020/6/3
|
85
|
|
- * @param * @param director
|
86
|
|
- * @return java.util.List<com.xhkjedu.model.subjectbook.TDirector>
|
87
|
94
|
*/
|
88
|
|
- public List<TDirector> lisTDirectors(TDirector director){
|
|
95
|
+ public List<TDirector> lisTDirectors(TDirector director) {
|
89
|
96
|
List<TDirector> lst = directorMapper.listDirectors(director);
|
90
|
97
|
|
91
|
98
|
List<TDirector> directors = new ArrayList<>();
|
92
|
|
- for (TDirector d:lst){
|
93
|
|
- if(d.getDirectorpid() == null){
|
94
|
|
- List<TDirector> childDirectors = listChildedirector(d,lst);
|
|
99
|
+ for (TDirector d : lst) {
|
|
100
|
+ if (d.getDirectorpid() == null) {
|
|
101
|
+ List<TDirector> childDirectors = listChildedirector(d, lst);
|
95
|
102
|
d.setChildren(childDirectors);
|
96
|
103
|
directors.add(d);
|
97
|
104
|
}
|
|
@@ -101,11 +108,11 @@ public class DirectorService {
|
101
|
108
|
}
|
102
|
109
|
|
103
|
110
|
//获取子章节
|
104
|
|
- private List<TDirector> listChildedirector(TDirector director,List<TDirector> directors){
|
|
111
|
+ private List<TDirector> listChildedirector(TDirector director, List<TDirector> directors) {
|
105
|
112
|
List<TDirector> rtndirectors = new ArrayList<>();
|
106
|
|
- for(TDirector d : directors){
|
107
|
|
- if(director.getDirectorid().equals(d.getDirectorpid())){
|
108
|
|
- List<TDirector> childDirectors = listChildedirector(d,directors);
|
|
113
|
+ for (TDirector d : directors) {
|
|
114
|
+ if (director.getDirectorid().equals(d.getDirectorpid())) {
|
|
115
|
+ List<TDirector> childDirectors = listChildedirector(d, directors);
|
109
|
116
|
d.setChildren(childDirectors);
|
110
|
117
|
rtndirectors.add(d);
|
111
|
118
|
}
|
|
@@ -113,12 +120,39 @@ public class DirectorService {
|
113
|
120
|
return rtndirectors;
|
114
|
121
|
}
|
115
|
122
|
|
|
123
|
+ //2022-03-16使用stream递归
|
|
124
|
+ public List<TDirector> lisTDirectors2(TDirector director) {
|
|
125
|
+ List<TDirector> lst = directorMapper.listDirectors(director);
|
|
126
|
+
|
|
127
|
+ List<TDirector> collect = lst.stream().filter(d -> d.getDirectorpid() == null).map(
|
|
128
|
+ (d) -> {
|
|
129
|
+ d.setChildren(getChildrens(d, lst));
|
|
130
|
+ return d;
|
|
131
|
+ }
|
|
132
|
+ ).collect(Collectors.toList());
|
|
133
|
+ return collect;
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ //递归查询子节点
|
|
137
|
+ private List<TDirector> getChildrens(TDirector root, List<TDirector> all) {
|
|
138
|
+ List<TDirector> children = all.stream().filter(d -> {
|
|
139
|
+ return Objects.equals(d.getDirectorpid(), root.getDirectorid());
|
|
140
|
+ }).map(
|
|
141
|
+ (d) -> {
|
|
142
|
+ d.setChildren(getChildrens(d, all));
|
|
143
|
+ return d;
|
|
144
|
+ }
|
|
145
|
+ ).collect(Collectors.toList());
|
|
146
|
+ return children;
|
|
147
|
+ }
|
|
148
|
+
|
116
|
149
|
/**
|
117
|
150
|
* 教师收藏教材下的章节数量
|
|
151
|
+ *
|
|
152
|
+ * @return java.lang.Integer
|
118
|
153
|
* @Param [teacherid, lsbid]
|
119
|
154
|
* @Author ywx
|
120
|
155
|
* @Date 2020/7/8 14:49
|
121
|
|
- * @return java.lang.Integer
|
122
|
156
|
**/
|
123
|
157
|
public Integer countByTeacherIdLsbId(Integer teacherid, String lsbid) {
|
124
|
158
|
return directorMapper.countByTeacherIdLsbId(teacherid, lsbid);
|
|
@@ -135,10 +169,11 @@ public class DirectorService {
|
135
|
169
|
|
136
|
170
|
/**
|
137
|
171
|
* 修改层级章节
|
|
172
|
+ *
|
|
173
|
+ * @return void
|
138
|
174
|
* @Param [directorid, directorname]
|
139
|
175
|
* @Author ywx
|
140
|
176
|
* @Date 2022/3/14 15:14
|
141
|
|
- * @return void
|
142
|
177
|
**/
|
143
|
178
|
public void updateDirectorAll(String directorid) {
|
144
|
179
|
DirectorVo vo = directorMapper.getNameAndLevelById(directorid);
|