3
3
import static org .lowcoder .sdk .util .JsonUtils .fromJsonMap ;
4
4
import static org .lowcoder .sdk .util .JsonUtils .toJson ;
5
5
6
- import java .util .Collection ;
7
- import java .util .HashSet ;
8
- import java .util .Set ;
6
+ import java .util .*;
9
7
import java .util .function .Function ;
10
8
11
9
import org .apache .commons .collections4 .CollectionUtils ;
18
16
import org .lowcoder .domain .plugin .client .DatasourcePluginClient ;
19
17
import org .lowcoder .domain .plugin .service .DatasourceMetaInfoService ;
20
18
import org .lowcoder .infra .mongo .MongoUpsertHelper ;
19
+ import org .lowcoder .sdk .constants .FieldName ;
21
20
import org .lowcoder .sdk .models .DatasourceConnectionConfig ;
22
21
import org .lowcoder .sdk .models .HasIdAndAuditing ;
23
22
import org .lowcoder .sdk .models .JsDatasourceConnectionConfig ;
@@ -56,6 +55,9 @@ public class DatasourceRepository {
56
55
private JsDatasourceHelper jsDatasourceHelper ;
57
56
58
57
public Mono <Datasource > findById (String datasourceId ) {
58
+ if (FieldName .isGID (datasourceId ))
59
+ return Mono .from (repository .findByGid (datasourceId ))
60
+ .flatMap (this ::convertToDomainObjectAndDecrypt );
59
61
return repository .findById (datasourceId )
60
62
.flatMap (this ::convertToDomainObjectAndDecrypt );
61
63
}
@@ -67,8 +69,24 @@ public Mono<Datasource> findWorkspacePredefinedDatasourceByOrgIdAndType(String o
67
69
}
68
70
69
71
public Flux <Datasource > findAllById (Iterable <String > ids ) {
70
- return repository .findAllById (ids )
72
+ List <String > idList = new ArrayList <>();
73
+ List <String > gidList = new ArrayList <>();
74
+
75
+ for (String id : ids ) {
76
+ if (FieldName .isGID (id )) {
77
+ gidList .add (id );
78
+ } else {
79
+ idList .add (id );
80
+ }
81
+ }
82
+
83
+ Flux <Datasource > idFlux = idList .isEmpty () ? Flux .empty () : repository .findAllById (idList )
71
84
.flatMap (this ::convertToDomainObjectAndDecrypt );
85
+
86
+ Flux <Datasource > gidFlux = gidList .isEmpty () ? Flux .empty () : repository .findAllByGidIn (gidList )
87
+ .flatMap (this ::convertToDomainObjectAndDecrypt );
88
+
89
+ return Flux .merge (idFlux , gidFlux );
72
90
}
73
91
74
92
public Flux <Datasource > findAllByOrganizationId (String orgId ) {
@@ -92,8 +110,12 @@ public Flux<String> retainNoneExistAndNonCurrentOrgDatasourceIds(Collection<Stri
92
110
if (CollectionUtils .isEmpty (datasourceIds )) {
93
111
return Flux .empty ();
94
112
}
95
- return repository .findAllById (new HashSet <>(datasourceIds ))
96
- .collectList ()
113
+ Flux <DatasourceDO > mixedMono ;
114
+ if (FieldName .isGID (datasourceIds .stream ().findFirst ().orElseThrow ()))
115
+ mixedMono = repository .findAllByGidIn (new HashSet <>(datasourceIds ));
116
+ else
117
+ mixedMono = repository .findAllById (new HashSet <>(datasourceIds ));
118
+ return mixedMono .collectList ()
97
119
.map (existDatasources -> {
98
120
Set <String > result = new HashSet <>(datasourceIds );
99
121
existDatasources .stream ()
@@ -114,6 +136,7 @@ private Mono<Datasource> convertToDomainObjectAndDecrypt(DatasourceDO datasource
114
136
115
137
Mono <Datasource > datasourceMono = Mono .fromSupplier (() -> {
116
138
Datasource result = new Datasource ();
139
+ result .setGid (datasourceDO .getGid ());
117
140
result .setName (datasourceDO .getName ());
118
141
result .setType (datasourceDO .getType ());
119
142
result .setOrganizationId (datasourceDO .getOrganizationId ());
@@ -156,6 +179,7 @@ private Mono<DatasourceDO> encryptDataAndConvertToDataObject(Datasource datasour
156
179
157
180
return Mono .fromSupplier (() -> {
158
181
DatasourceDO result = new DatasourceDO ();
182
+ result .setGid (datasource .getGid ());
159
183
result .setName (datasource .getName ());
160
184
result .setType (datasource .getType ());
161
185
result .setOrganizationId (datasource .getOrganizationId ());
0 commit comments