22
33import java .util .List ;
44
5+ import org .lowcoder .api .datasource .UpsertDatasourceRequest ;
56import org .lowcoder .api .framework .view .PageResponseView ;
67import org .lowcoder .api .framework .view .ResponseView ;
78import org .lowcoder .api .query .view .LibraryQueryAggregateView ;
1112import org .lowcoder .api .query .view .UpsertLibraryQueryRequest ;
1213import org .lowcoder .api .util .BusinessEventPublisher ;
1314import org .lowcoder .api .util .GidService ;
15+ import org .lowcoder .domain .datasource .model .Datasource ;
1416import org .lowcoder .domain .query .model .LibraryQuery ;
17+ import org .lowcoder .domain .query .model .LibraryQueryRecord ;
18+ import org .lowcoder .domain .query .service .LibraryQueryRecordService ;
1519import org .lowcoder .domain .query .service .LibraryQueryService ;
1620import org .lowcoder .plugin .api .event .LowcoderEvent .EventType ;
1721import org .springframework .beans .factory .annotation .Autowired ;
2226
2327import reactor .core .publisher .Flux ;
2428import reactor .core .publisher .Mono ;
29+ import reactor .util .function .Tuple2 ;
2530
2631import static org .lowcoder .api .util .Pagination .fluxToPageResponseView ;
32+ import static org .lowcoder .plugin .api .event .LowcoderEvent .EventType .DATA_SOURCE_UPDATE ;
2733
2834@ RestController
2935public class LibraryQueryController implements LibraryQueryEndpoints
@@ -37,6 +43,8 @@ public class LibraryQueryController implements LibraryQueryEndpoints
3743 private BusinessEventPublisher businessEventPublisher ;
3844 @ Autowired
3945 private GidService gidService ;
46+ @ Autowired
47+ private LibraryQueryRecordService libraryQueryRecordService ;
4048
4149 @ Override
4250 public Mono <ResponseView <List <LibraryQueryAggregateView >>> dropDownList (@ RequestParam (required = false , defaultValue = "" ) String name ) {
@@ -64,16 +72,20 @@ public Mono<ResponseView<LibraryQueryView>> create(@RequestBody LibraryQuery lib
6472 return libraryQueryApiService .create (libraryQuery )
6573 .delayUntil (libraryQueryView ->
6674 businessEventPublisher .publishLibraryQueryEvent (libraryQueryView .id (), libraryQueryView .name (),
67- EventType .LIBRARY_QUERY_CREATE ))
75+ EventType .LIBRARY_QUERY_CREATE , null ))
6876 .map (ResponseView ::success );
6977 }
7078
7179 @ Override
7280 public Mono <ResponseView <Boolean >> update (@ PathVariable String libraryQueryId ,
73- @ RequestBody UpsertLibraryQueryRequest upsertLibraryQueryRequest ) {
81+ @ RequestBody UpsertLibraryQueryRequest request ) {
7482 return gidService .convertLibraryQueryIdToObjectId (libraryQueryId ).flatMap (objectId ->
75- libraryQueryApiService .update (objectId , upsertLibraryQueryRequest )
76- .map (ResponseView ::success ));
83+ libraryQueryService .getById (objectId ).flatMap (orgLibraryQuery ->
84+ libraryQueryApiService .update (objectId , request )
85+ .zipWith ( libraryQueryService .getById (objectId ))
86+ .delayUntil (tuple -> businessEventPublisher .publishLibraryQueryEvent (tuple .getT2 ().getId (), tuple .getT2 ().getName (), EventType .LIBRARY_QUERY_UPDATE , orgLibraryQuery .getName ()))
87+ .map (Tuple2 ::getT1 )
88+ .map (ResponseView ::success )));
7789 }
7890
7991 @ Override
@@ -82,18 +94,19 @@ public Mono<ResponseView<Boolean>> delete(@PathVariable String libraryQueryId) {
8294 libraryQueryService .getById (objectId )
8395 .delayUntil (__ -> libraryQueryApiService .delete (objectId ))
8496 .delayUntil (libraryQuery -> businessEventPublisher .publishLibraryQueryEvent (libraryQuery .getId (), libraryQuery .getName (),
85- EventType .LIBRARY_QUERY_DELETE ))
97+ EventType .LIBRARY_QUERY_DELETE , libraryQuery . getName () ))
8698 .thenReturn (ResponseView .success (true )));
8799 }
88100
89101 @ Override
90102 public Mono <ResponseView <LibraryQueryRecordMetaView >> publish (@ PathVariable String libraryQueryId ,
91103 @ RequestBody LibraryQueryPublishRequest libraryQueryPublishRequest ) {
92104 return gidService .convertLibraryQueryIdToObjectId (libraryQueryId ).flatMap (objectId ->
93- libraryQueryApiService .publish (objectId , libraryQueryPublishRequest )
94- .delayUntil (__ -> libraryQueryService .getById (objectId )
95- .flatMap (libraryQuery -> businessEventPublisher .publishLibraryQuery (libraryQuery , EventType .LIBRARY_QUERY_PUBLISH )))
96- .map (ResponseView ::success ));
105+ libraryQueryRecordService .getLatestRecordByLibraryQueryId (objectId ).map (LibraryQueryRecord ::getTag ).defaultIfEmpty ("" ).flatMap (oldVersion ->
106+ libraryQueryApiService .publish (objectId , libraryQueryPublishRequest )
107+ .delayUntil (__ -> libraryQueryService .getById (objectId )
108+ .flatMap (libraryQuery -> businessEventPublisher .publishLibraryQueryPublishEvent (libraryQueryId , oldVersion .isEmpty ()?null :oldVersion , libraryQueryPublishRequest .tag (), EventType .LIBRARY_QUERY_PUBLISH )))
109+ .map (ResponseView ::success )));
97110 }
98111
99112}
0 commit comments