11package org .lowcoder .api .application ;
22
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 ;
105import org .lowcoder .api .application .view .HistorySnapshotDslView ;
116import org .lowcoder .api .framework .view .ResponseView ;
127import org .lowcoder .api .home .SessionUserService ;
138import org .lowcoder .api .util .Pagination ;
149import org .lowcoder .domain .application .model .Application ;
10+ import org .lowcoder .domain .application .model .ApplicationHistorySnapshot ;
1511import org .lowcoder .domain .application .model .ApplicationHistorySnapshotTS ;
1612import org .lowcoder .domain .application .service .ApplicationHistorySnapshotService ;
1713import org .lowcoder .domain .application .service .ApplicationService ;
2218import org .springframework .web .bind .annotation .RequestBody ;
2319import org .springframework .web .bind .annotation .RequestParam ;
2420import org .springframework .web .bind .annotation .RestController ;
21+ import reactor .core .publisher .Mono ;
2522
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 ;
2727
28- import lombok .RequiredArgsConstructor ;
29- import reactor .core .publisher .Mono ;
28+ import static org .lowcoder .api .util .ViewBuilder .multiBuild ;
3029
3130@ RequiredArgsConstructor
3231@ RestController
@@ -90,6 +89,43 @@ public Mono<ResponseView<Map<String, Object>>> listAllHistorySnapshotBriefInfo(@
9089 .map (ResponseView ::success );
9190 }
9291
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+
93129 @ Override
94130 public Mono <ResponseView <HistorySnapshotDslView >> getHistorySnapshotDsl (@ PathVariable String applicationId ,
95131 @ PathVariable String snapshotId ) {
@@ -98,7 +134,29 @@ public Mono<ResponseView<HistorySnapshotDslView>> getHistorySnapshotDsl(@PathVar
98134 ResourceAction .EDIT_APPLICATIONS ))
99135 .flatMap (__ -> applicationHistorySnapshotService .getHistorySnapshotDetail (snapshotId ))
100136 .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 )
102160 .map (tuple -> {
103161 Map <String , Object > applicationDsl = tuple .getT1 ();
104162 List <Application > dependentModules = tuple .getT2 ();
0 commit comments