|
8 | 8 | importorg.lowcoder.api.framework.view.ResponseView;
|
9 | 9 | importorg.lowcoder.api.home.SessionUserService;
|
10 | 10 | importorg.lowcoder.api.home.UserHomeApiService;
|
| 11 | +importorg.lowcoder.api.home.UserHomepageView; |
11 | 12 | importorg.lowcoder.api.usermanagement.view.OrgView;
|
12 | 13 | importorg.lowcoder.api.usermanagement.view.UpdateUserRequest;
|
13 | 14 | importorg.lowcoder.api.usermanagement.view.UserProfileView;
|
14 | 15 | importorg.lowcoder.domain.organization.model.MemberRole;
|
15 | 16 | importorg.lowcoder.domain.organization.model.OrgMember;
|
| 17 | +importorg.lowcoder.domain.organization.model.Organization; |
16 | 18 | importorg.lowcoder.domain.organization.service.OrgMemberService;
|
17 | 19 | importorg.lowcoder.domain.organization.service.OrganizationService;
|
18 | 20 | importorg.lowcoder.domain.user.constant.UserStatusType;
|
|
34 | 36 | importreactor.core.publisher.Flux;
|
35 | 37 | importreactor.core.publisher.Mono;
|
36 | 38 |
|
| 39 | +importjava.util.HashMap; |
37 | 40 | importjava.util.List;
|
| 41 | +importjava.util.Map; |
| 42 | +importjava.util.stream.Collectors; |
38 | 43 |
|
39 | 44 | importstaticorg.lowcoder.sdk.exception.BizError.INVALID_USER_STATUS;
|
40 | 45 | importstaticorg.lowcoder.sdk.util.ExceptionUtils.ofError;
|
@@ -83,13 +88,31 @@ public Mono<ResponseView<?>> getUserOrgs(ServerWebExchange exchange,
|
83 | 88 | .flatMap(user -> {
|
84 | 89 | Pageablepageable =PageRequest.of(pageNum -1,pageSize,Sort.by(Sort.Direction.DESC,"updatedAt"));
|
85 | 90 | Stringfilter =orgName ==null ?"" :orgName;
|
| 91 | +Mono<String>currentOrgIdMono =sessionUserService.getVisitorOrgMemberCache() |
| 92 | + .map(OrgMember::getOrgId); |
86 | 93 | returnorganizationService.findUserOrgs(user.getId(),filter,pageable)
|
87 | 94 | .map(OrgView::new)
|
88 | 95 | .collectList()
|
89 | 96 | .zipWith(organizationService.countUserOrgs(user.getId(),filter))
|
90 |
| - .map(tuple ->PageResponseView.success( |
91 |
| -tuple.getT1(),pageNum,pageSize,tuple.getT2().intValue() |
92 |
| - )); |
| 97 | + .zipWith(currentOrgIdMono) |
| 98 | + .map(tuple -> { |
| 99 | +List<OrgView>orgViews =tuple.getT1().getT1(); |
| 100 | +longtotal =tuple.getT1().getT2(); |
| 101 | +StringcurrentOrgId =tuple.getT2(); |
| 102 | + |
| 103 | +// Create a list of maps each containing orgView and isCurrentOrg |
| 104 | +List<Map<String,Object>>resultList =orgViews.stream() |
| 105 | + .map(orgView -> { |
| 106 | +Map<String,Object>map =newHashMap<>(); |
| 107 | +map.put("orgView",orgView); |
| 108 | +map.put("isCurrentOrg",orgView.getOrgId().equals(currentOrgId)); |
| 109 | +returnmap; |
| 110 | + }) |
| 111 | + .sorted((a,b) ->Boolean.compare((Boolean)b.get("isCurrentOrg"), (Boolean)a.get("isCurrentOrg"))) |
| 112 | + .collect(Collectors.toList()); |
| 113 | + |
| 114 | +returnPageResponseView.success(resultList,pageNum,pageSize, (int)total); |
| 115 | + }); |
93 | 116 | })
|
94 | 117 | .map(ResponseView::success);
|
95 | 118 | }
|
|