1
1
package org .lowcoder .api .application ;
2
2
3
- import static org .lowcoder .api .util .ViewBuilder .multiBuild ;
4
-
5
- import java .time .Instant ;
6
- import java .util .List ;
7
- import java .util .Map ;
8
- import java .util .stream .Collectors ;
9
-
3
+ import com .google .common .collect .ImmutableMap ;
4
+ import lombok .RequiredArgsConstructor ;
10
5
import org .lowcoder .api .application .view .HistorySnapshotDslView ;
11
6
import org .lowcoder .api .framework .view .ResponseView ;
12
7
import org .lowcoder .api .home .SessionUserService ;
13
8
import org .lowcoder .api .util .Pagination ;
14
9
import org .lowcoder .domain .application .model .Application ;
10
+ import org .lowcoder .domain .application .model .ApplicationHistorySnapshot ;
15
11
import org .lowcoder .domain .application .model .ApplicationHistorySnapshotTS ;
16
12
import org .lowcoder .domain .application .service .ApplicationHistorySnapshotService ;
17
13
import org .lowcoder .domain .application .service .ApplicationService ;
22
18
import org .springframework .web .bind .annotation .RequestBody ;
23
19
import org .springframework .web .bind .annotation .RequestParam ;
24
20
import org .springframework .web .bind .annotation .RestController ;
21
+ import reactor .core .publisher .Mono ;
25
22
26
- import com .google .common .collect .ImmutableMap ;
23
+ import java .time .Instant ;
24
+ import java .util .List ;
25
+ import java .util .Map ;
26
+ import java .util .stream .Collectors ;
27
27
28
- import lombok .RequiredArgsConstructor ;
29
- import reactor .core .publisher .Mono ;
28
+ import static org .lowcoder .api .util .ViewBuilder .multiBuild ;
30
29
31
30
@ RequiredArgsConstructor
32
31
@ RestController
@@ -90,6 +89,43 @@ public Mono<ResponseView<Map<String, Object>>> listAllHistorySnapshotBriefInfo(@
90
89
.map (ResponseView ::success );
91
90
}
92
91
92
+ @ Override
93
+ public Mono <ResponseView <Map <String , Object >>> listAllHistorySnapshotBriefInfoArchived (@ PathVariable String applicationId ,
94
+ @ RequestParam (defaultValue = "0" ) int page ,
95
+ @ RequestParam (defaultValue = "10" ) int size ,
96
+ @ RequestParam String compName ,
97
+ @ RequestParam String theme ,
98
+ @ RequestParam Instant from ,
99
+ @ RequestParam Instant to ) {
100
+
101
+ Pagination pagination = Pagination .of (page , size ).check ();
102
+
103
+ return sessionUserService .getVisitorId ()
104
+ .delayUntil (visitor -> resourcePermissionService .checkResourcePermissionWithError (visitor , applicationId ,
105
+ ResourceAction .EDIT_APPLICATIONS ))
106
+ .flatMap (__ -> applicationHistorySnapshotService .listAllHistorySnapshotBriefInfoArchived (applicationId , compName , theme , from , to , pagination .toPageRequest ()))
107
+ .flatMap (snapshotList -> {
108
+ Mono <List <ApplicationHistorySnapshotBriefInfo >> snapshotBriefInfoList = multiBuild (snapshotList ,
109
+ ApplicationHistorySnapshot ::getCreatedBy ,
110
+ userService ::getByIds ,
111
+ (applicationHistorySnapshot , user ) -> new ApplicationHistorySnapshotBriefInfo (
112
+ applicationHistorySnapshot .getId (),
113
+ applicationHistorySnapshot .getContext (),
114
+ applicationHistorySnapshot .getCreatedBy (),
115
+ user .getName (),
116
+ user .getAvatarUrl (),
117
+ applicationHistorySnapshot .getCreatedAt ().toEpochMilli ()
118
+ )
119
+ );
120
+
121
+ Mono <Long > applicationHistorySnapshotCount = applicationHistorySnapshotService .countByApplicationId (applicationId );
122
+
123
+ return Mono .zip (snapshotBriefInfoList , applicationHistorySnapshotCount )
124
+ .map (tuple -> ImmutableMap .of ("list" , tuple .getT1 (), "count" , tuple .getT2 ()));
125
+ })
126
+ .map (ResponseView ::success );
127
+ }
128
+
93
129
@ Override
94
130
public Mono <ResponseView <HistorySnapshotDslView >> getHistorySnapshotDsl (@ PathVariable String applicationId ,
95
131
@ PathVariable String snapshotId ) {
@@ -98,7 +134,29 @@ public Mono<ResponseView<HistorySnapshotDslView>> getHistorySnapshotDsl(@PathVar
98
134
ResourceAction .EDIT_APPLICATIONS ))
99
135
.flatMap (__ -> applicationHistorySnapshotService .getHistorySnapshotDetail (snapshotId ))
100
136
.map (ApplicationHistorySnapshotTS ::getDsl )
101
- .zipWhen (dsl -> applicationService .getAllDependentModulesFromDsl (dsl ))
137
+ .zipWhen (applicationService ::getAllDependentModulesFromDsl )
138
+ .map (tuple -> {
139
+ Map <String , Object > applicationDsl = tuple .getT1 ();
140
+ List <Application > dependentModules = tuple .getT2 ();
141
+ Map <String , Map <String , Object >> dependentModuleDsl = dependentModules .stream ()
142
+ .collect (Collectors .toMap (Application ::getId , Application ::getLiveApplicationDsl , (a , b ) -> b ));
143
+ return HistorySnapshotDslView .builder ()
144
+ .applicationsDsl (applicationDsl )
145
+ .moduleDSL (dependentModuleDsl )
146
+ .build ();
147
+ })
148
+ .map (ResponseView ::success );
149
+ }
150
+
151
+ @ Override
152
+ public Mono <ResponseView <HistorySnapshotDslView >> getHistorySnapshotDslArchived (@ PathVariable String applicationId ,
153
+ @ PathVariable String snapshotId ) {
154
+ return sessionUserService .getVisitorId ()
155
+ .delayUntil (visitor -> resourcePermissionService .checkResourcePermissionWithError (visitor , applicationId ,
156
+ ResourceAction .EDIT_APPLICATIONS ))
157
+ .flatMap (__ -> applicationHistorySnapshotService .getHistorySnapshotDetailArchived (snapshotId ))
158
+ .map (ApplicationHistorySnapshot ::getDsl )
159
+ .zipWhen (applicationService ::getAllDependentModulesFromDsl )
102
160
.map (tuple -> {
103
161
Map <String , Object > applicationDsl = tuple .getT1 ();
104
162
List <Application > dependentModules = tuple .getT2 ();
0 commit comments