2
2
3
3
import java .util .List ;
4
4
5
+ import org .lowcoder .api .datasource .UpsertDatasourceRequest ;
5
6
import org .lowcoder .api .framework .view .PageResponseView ;
6
7
import org .lowcoder .api .framework .view .ResponseView ;
7
8
import org .lowcoder .api .query .view .LibraryQueryAggregateView ;
11
12
import org .lowcoder .api .query .view .UpsertLibraryQueryRequest ;
12
13
import org .lowcoder .api .util .BusinessEventPublisher ;
13
14
import org .lowcoder .api .util .GidService ;
15
+ import org .lowcoder .domain .datasource .model .Datasource ;
14
16
import org .lowcoder .domain .query .model .LibraryQuery ;
17
+ import org .lowcoder .domain .query .model .LibraryQueryRecord ;
18
+ import org .lowcoder .domain .query .service .LibraryQueryRecordService ;
15
19
import org .lowcoder .domain .query .service .LibraryQueryService ;
16
20
import org .lowcoder .plugin .api .event .LowcoderEvent .EventType ;
17
21
import org .springframework .beans .factory .annotation .Autowired ;
22
26
23
27
import reactor .core .publisher .Flux ;
24
28
import reactor .core .publisher .Mono ;
29
+ import reactor .util .function .Tuple2 ;
25
30
26
31
import static org .lowcoder .api .util .Pagination .fluxToPageResponseView ;
32
+ import static org .lowcoder .plugin .api .event .LowcoderEvent .EventType .DATA_SOURCE_UPDATE ;
27
33
28
34
@ RestController
29
35
public class LibraryQueryController implements LibraryQueryEndpoints
@@ -37,6 +43,8 @@ public class LibraryQueryController implements LibraryQueryEndpoints
37
43
private BusinessEventPublisher businessEventPublisher ;
38
44
@ Autowired
39
45
private GidService gidService ;
46
+ @ Autowired
47
+ private LibraryQueryRecordService libraryQueryRecordService ;
40
48
41
49
@ Override
42
50
public Mono <ResponseView <List <LibraryQueryAggregateView >>> dropDownList (@ RequestParam (required = false , defaultValue = "" ) String name ) {
@@ -64,16 +72,20 @@ public Mono<ResponseView<LibraryQueryView>> create(@RequestBody LibraryQuery lib
64
72
return libraryQueryApiService .create (libraryQuery )
65
73
.delayUntil (libraryQueryView ->
66
74
businessEventPublisher .publishLibraryQueryEvent (libraryQueryView .id (), libraryQueryView .name (),
67
- EventType .LIBRARY_QUERY_CREATE ))
75
+ EventType .LIBRARY_QUERY_CREATE , null ))
68
76
.map (ResponseView ::success );
69
77
}
70
78
71
79
@ Override
72
80
public Mono <ResponseView <Boolean >> update (@ PathVariable String libraryQueryId ,
73
- @ RequestBody UpsertLibraryQueryRequest upsertLibraryQueryRequest ) {
81
+ @ RequestBody UpsertLibraryQueryRequest request ) {
74
82
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 )));
77
89
}
78
90
79
91
@ Override
@@ -82,18 +94,19 @@ public Mono<ResponseView<Boolean>> delete(@PathVariable String libraryQueryId) {
82
94
libraryQueryService .getById (objectId )
83
95
.delayUntil (__ -> libraryQueryApiService .delete (objectId ))
84
96
.delayUntil (libraryQuery -> businessEventPublisher .publishLibraryQueryEvent (libraryQuery .getId (), libraryQuery .getName (),
85
- EventType .LIBRARY_QUERY_DELETE ))
97
+ EventType .LIBRARY_QUERY_DELETE , libraryQuery . getName () ))
86
98
.thenReturn (ResponseView .success (true )));
87
99
}
88
100
89
101
@ Override
90
102
public Mono <ResponseView <LibraryQueryRecordMetaView >> publish (@ PathVariable String libraryQueryId ,
91
103
@ RequestBody LibraryQueryPublishRequest libraryQueryPublishRequest ) {
92
104
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 )));
97
110
}
98
111
99
112
}
0 commit comments