1515import com .easywecom .wecom .domain .dto .UserBehaviorDataDTO ;
1616import com .easywecom .wecom .domain .query .UserBehaviorDataQuery ;
1717import com .easywecom .wecom .service .WeCorpAccountService ;
18+ import com .easywecom .wecom .service .WeDepartmentService ;
1819import com .easywecom .wecom .service .WeUserBehaviorDataService ;
1920import lombok .extern .slf4j .Slf4j ;
21+ import org .apache .commons .collections4 .CollectionUtils ;
2022import org .apache .commons .lang3 .StringUtils ;
2123import org .apache .commons .lang3 .exception .ExceptionUtils ;
2224import org .springframework .beans .factory .annotation .Autowired ;
@@ -42,13 +44,15 @@ public class UserBehaviorDataTak {
4244 private final WeUserClient weUserClient ;
4345
4446 private final WeCorpAccountService weCorpAccountService ;
47+ private final WeDepartmentService weDepartmentService ;
4548
4649 @ Autowired
47- public UserBehaviorDataTak (WeCustomerClient weCustomerClient , WeUserBehaviorDataService weUserBehaviorDataService , WeUserClient weUserClient , WeCorpAccountService weCorpAccountService ) {
50+ public UserBehaviorDataTak (WeCustomerClient weCustomerClient , WeUserBehaviorDataService weUserBehaviorDataService , WeUserClient weUserClient , WeCorpAccountService weCorpAccountService , WeDepartmentService weDepartmentService ) {
4851 this .weCustomerClient = weCustomerClient ;
4952 this .weUserBehaviorDataService = weUserBehaviorDataService ;
5053 this .weUserClient = weUserClient ;
5154 this .weCorpAccountService = weCorpAccountService ;
55+ this .weDepartmentService = weDepartmentService ;
5256 }
5357
5458 public void getUserBehaviorData () {
@@ -68,7 +72,19 @@ void getUserBehaviorDataByCorpId(String corpId) {
6872 log .error ("corpId不允许为空。" );
6973 return ;
7074 }
71- List <WeUser > weUsers = weUserClient .simpleList (WeConstans .WE_ROOT_DEPARMENT_ID , WeConstans .DEPARTMENT_SUB_WEUSER , corpId ).getWeUsers ();
75+ // 获取根部门
76+ List <Long > visibleRoots = weDepartmentService .getVisibleRootDepartment (corpId );
77+ if (CollectionUtils .isEmpty (visibleRoots )) {
78+ log .error ("同步成员,找不到根部门,停止同步,corpID:{}" ,corpId );
79+ return ;
80+ }
81+ List <WeUser > weUsers = new ArrayList <>();
82+ for (Long department : visibleRoots ) {
83+ List <WeUser > tempList = weUserClient .simpleList (department , WeConstans .DEPARTMENT_SUB_WEUSER , corpId ).getWeUsers ();
84+ if (CollectionUtils .isNotEmpty (tempList ) ) {
85+ weUsers .addAll (tempList );
86+ }
87+ }
7288 //删除存在的数据
7389 if (CollUtil .isNotEmpty (weUsers )) {
7490 Long startTime = MyDateUtil .strToDate (-1 , 0 );
0 commit comments