|
8 | 8 | import org.lowcoder.api.framework.view.ResponseView; |
9 | 9 | import org.lowcoder.api.home.SessionUserService; |
10 | 10 | import org.lowcoder.api.home.UserHomeApiService; |
| 11 | +import org.lowcoder.api.home.UserHomepageView; |
11 | 12 | import org.lowcoder.api.usermanagement.view.OrgView; |
12 | 13 | import org.lowcoder.api.usermanagement.view.UpdateUserRequest; |
13 | 14 | import org.lowcoder.api.usermanagement.view.UserProfileView; |
14 | 15 | import org.lowcoder.domain.organization.model.MemberRole; |
15 | 16 | import org.lowcoder.domain.organization.model.OrgMember; |
| 17 | +import org.lowcoder.domain.organization.model.Organization; |
16 | 18 | import org.lowcoder.domain.organization.service.OrgMemberService; |
17 | 19 | import org.lowcoder.domain.organization.service.OrganizationService; |
18 | 20 | import org.lowcoder.domain.user.constant.UserStatusType; |
|
34 | 36 | import reactor.core.publisher.Flux; |
35 | 37 | import reactor.core.publisher.Mono; |
36 | 38 |
|
| 39 | +import java.util.HashMap; |
37 | 40 | import java.util.List; |
| 41 | +import java.util.Map; |
| 42 | +import java.util.stream.Collectors; |
38 | 43 |
|
39 | 44 | import static org.lowcoder.sdk.exception.BizError.INVALID_USER_STATUS; |
40 | 45 | import static org.lowcoder.sdk.util.ExceptionUtils.ofError; |
@@ -83,13 +88,31 @@ public Mono<ResponseView<?>> getUserOrgs(ServerWebExchange exchange, |
83 | 88 | .flatMap(user -> { |
84 | 89 | Pageable pageable = PageRequest.of(pageNum - 1, pageSize, Sort.by(Sort.Direction.DESC, "updatedAt")); |
85 | 90 | String filter = orgName == null ? "" : orgName; |
| 91 | + Mono<String> currentOrgIdMono = sessionUserService.getVisitorOrgMemberCache() |
| 92 | + .map(OrgMember::getOrgId); |
86 | 93 | return organizationService.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 | + long total = tuple.getT1().getT2(); |
| 101 | + String currentOrgId = 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 = new HashMap<>(); |
| 107 | + map.put("orgView", orgView); |
| 108 | + map.put("isCurrentOrg", orgView.getOrgId().equals(currentOrgId)); |
| 109 | + return map; |
| 110 | + }) |
| 111 | + .sorted((a, b) -> Boolean.compare((Boolean) b.get("isCurrentOrg"), (Boolean) a.get("isCurrentOrg"))) |
| 112 | + .collect(Collectors.toList()); |
| 113 | + |
| 114 | + return PageResponseView.success(resultList, pageNum, pageSize, (int) total); |
| 115 | + }); |
93 | 116 | }) |
94 | 117 | .map(ResponseView::success); |
95 | 118 | } |
|
0 commit comments