|
|
@@ -1,68 +0,0 @@
|
|
1
|
|
-package com.tdba.cxb.ares.api.user;
|
|
2
|
|
-
|
|
3
|
|
-import com.tdba.cxb.ares.api.util.TDBAException;
|
|
4
|
|
-import org.junit.jupiter.api.Test;
|
|
5
|
|
-import org.slf4j.Logger;
|
|
6
|
|
-import org.slf4j.LoggerFactory;
|
|
7
|
|
-import org.springframework.util.CollectionUtils;
|
|
8
|
|
-
|
|
9
|
|
-import java.util.List;
|
|
10
|
|
-
|
|
11
|
|
-/**
|
|
12
|
|
- * @program: admin-web
|
|
13
|
|
- * @description:
|
|
14
|
|
- * @author: libo
|
|
15
|
|
- * @create: 2022-06-06 15:17:42
|
|
16
|
|
- */
|
|
17
|
|
-public class UserTest {
|
|
18
|
|
-
|
|
19
|
|
- private static Logger logger = LoggerFactory.getLogger(UserTest.class);
|
|
20
|
|
-
|
|
21
|
|
- @Test
|
|
22
|
|
- public void test(){
|
|
23
|
|
-
|
|
24
|
|
- List<UserDto> list = List.of(UserDto.UserDtoBuilder.anUserDto()
|
|
25
|
|
- .withUid(2)
|
|
26
|
|
- .withSpread_uid(1)
|
|
27
|
|
- .build(),
|
|
28
|
|
- UserDto.UserDtoBuilder.anUserDto()
|
|
29
|
|
- .withUid(3)
|
|
30
|
|
- .withSpread_uid(2)
|
|
31
|
|
- .build(),
|
|
32
|
|
- UserDto.UserDtoBuilder.anUserDto()
|
|
33
|
|
- .withUid(1)
|
|
34
|
|
- .withSpread_uid(0)
|
|
35
|
|
- .build(),
|
|
36
|
|
- UserDto.UserDtoBuilder.anUserDto()
|
|
37
|
|
- .withUid(4)
|
|
38
|
|
- .withSpread_uid(0)
|
|
39
|
|
- .build());
|
|
40
|
|
-
|
|
41
|
|
- list.stream().forEach(row -> {
|
|
42
|
|
- logger.info("uid = {}, count = {}", row.getUid(), countOfChildren(row, list));
|
|
43
|
|
- });
|
|
44
|
|
-
|
|
45
|
|
- }
|
|
46
|
|
-
|
|
47
|
|
- public static Integer countOfChildren(UserDto userDto, List<UserDto> list){
|
|
48
|
|
-
|
|
49
|
|
- if(userDto == null || CollectionUtils.isEmpty(list)){
|
|
50
|
|
- return 0;
|
|
51
|
|
- }
|
|
52
|
|
-
|
|
53
|
|
- Integer result = 0;
|
|
54
|
|
- for(UserDto row : list){
|
|
55
|
|
- if(userDto.getUid() == row.getUid()){
|
|
56
|
|
- continue;
|
|
57
|
|
- }
|
|
58
|
|
- if(row.getSpread_uid() == userDto.getUid()){
|
|
59
|
|
- if(row.getUid() == userDto.getSpread_uid()){
|
|
60
|
|
- logger.error("循环嵌套 row.getSpread_uid() = {}, userDto.getUid() = {}", row.getSpread_uid(), userDto.getSpread_uid());
|
|
61
|
|
- throw new TDBAException("循环嵌套");
|
|
62
|
|
- }
|
|
63
|
|
- result = 1 + countOfChildren(row, list);
|
|
64
|
|
- }
|
|
65
|
|
- }
|
|
66
|
|
- return result;
|
|
67
|
|
- }
|
|
68
|
|
-}
|