4
4
import com .baomidou .mybatisplus .core .metadata .IPage ;
5
5
import com .fasterxml .jackson .core .type .TypeReference ;
6
6
import io .dataease .api .dataset .union .DatasetGroupInfoDTO ;
7
+ import io .dataease .api .dataset .union .DatasetTableInfoDTO ;
7
8
import io .dataease .api .dataset .union .UnionDTO ;
8
9
import io .dataease .api .template .dto .TemplateManageFileDTO ;
9
10
import io .dataease .api .template .dto .VisualizationTemplateExtendDataDTO ;
38
39
import io .dataease .datasource .provider .ExcelUtils ;
39
40
import io .dataease .datasource .server .DatasourceServer ;
40
41
import io .dataease .exception .DEException ;
42
+ import io .dataease .extensions .datasource .dto .DatasetTableDTO ;
41
43
import io .dataease .extensions .datasource .vo .DatasourceConfiguration ;
42
44
import io .dataease .extensions .view .dto .ChartViewDTO ;
43
45
import io .dataease .i18n .Translator ;
@@ -257,11 +259,12 @@ public String saveCanvas(DataVisualizationBaseRequest request) throws Exception
257
259
Map <Long , Long > datasourceIdMap = new HashMap <>();
258
260
Map <Long , Map <String , String >> dsTableNamesMap = new HashMap <>();
259
261
List <Long > newDatasourceId = new ArrayList <>();
262
+ List <Long > excelDatasourceId = new ArrayList <>();
263
+ Map <String , String > excelTableNamesMap = new HashMap <>();
260
264
if (appData != null ) {
261
265
isAppSave = true ;
262
266
try {
263
267
List <AppCoreDatasourceVO > appCoreDatasourceVO = appData .getDatasourceInfo ();
264
-
265
268
// app 数据源 excel 表名映射
266
269
appCoreDatasourceVO .forEach (datasourceOld -> {
267
270
newDatasourceId .add (datasourceOld .getSystemDatasourceId ());
@@ -283,6 +286,7 @@ public String saveCanvas(DataVisualizationBaseRequest request) throws Exception
283
286
if (StringUtils .isNotEmpty (datasourceNew .getConfiguration ())) {
284
287
if (datasourceNew .getType ().equals (DatasourceConfiguration .DatasourceType .Excel .name ())) {
285
288
dsTableNamesMap .put (datasourceNew .getId (), ExcelUtils .getTableNamesMap (datasourceNew .getType (), datasourceNew .getConfiguration ()));
289
+ excelDatasourceId .add (datasourceNew .getId ());
286
290
} else if (datasourceNew .getType ().contains (DatasourceConfiguration .DatasourceType .API .name ())) {
287
291
dsTableNamesMap .put (datasourceNew .getId (), (Map <String , String >) datasourceServer .invokeMethod (datasourceNew .getType (), "getTableNamesMap" , String .class , datasourceNew .getConfiguration ()));
288
292
}
@@ -375,6 +379,7 @@ public String saveCanvas(DataVisualizationBaseRequest request) throws Exception
375
379
appDsTableNamesMap .forEach ((keyName , valueName ) -> {
376
380
if (MapUtils .isNotEmpty (systemDsTableNamesMap ) && StringUtils .isNotEmpty (systemDsTableNamesMap .get (keyName ))) {
377
381
dsGroup .setInfo (dsGroup .getInfo ().replaceAll (valueName , systemDsTableNamesMap .get (keyName )));
382
+ excelTableNamesMap .put (valueName , systemDsTableNamesMap .get (keyName ));
378
383
} else {
379
384
dsGroup .setInfo (dsGroup .getInfo ().replaceAll (valueName , "excel_can_not_find" ));
380
385
}
@@ -393,6 +398,7 @@ public String saveCanvas(DataVisualizationBaseRequest request) throws Exception
393
398
}
394
399
datasetSQLManage .mergeDatasetCrossDefault (dsGroup );
395
400
}
401
+ excelAdaptor (dsGroup ,excelTableNamesMap ,excelDatasourceId );
396
402
datasetGroupManage .innerSave (dsGroup );
397
403
});
398
404
@@ -481,6 +487,26 @@ public String saveCanvas(DataVisualizationBaseRequest request) throws Exception
481
487
return newDvId .toString ();
482
488
}
483
489
490
+ private void excelAdaptor (DatasetGroupInfoDTO dsInfo ,Map <String , String > excelTableNamesMap ,List <Long > excelDsId ) {
491
+ List <UnionDTO > unionDTOList = JsonUtil .parseList (dsInfo .getInfo (), new TypeReference <>() {
492
+ });
493
+ if (CollectionUtils .isNotEmpty (excelDsId ) && MapUtils .isNotEmpty (excelTableNamesMap )){
494
+ for (UnionDTO unionDTO : unionDTOList ) {
495
+ DatasetTableDTO tableDTO =unionDTO .getCurrentDs ();
496
+ if (excelDsId .contains (tableDTO .getDatasourceId ())){
497
+ DatasetTableInfoDTO infoDTO = JsonUtil .parseObject (tableDTO .getInfo (), DatasetTableInfoDTO .class );
498
+ String s = new String (Base64 .getDecoder ().decode (infoDTO .getSql ()));
499
+ excelTableNamesMap .forEach ((key , value ) -> {
500
+ infoDTO .setSql (Base64 .getEncoder ().encodeToString (s .replaceAll (key , value ).getBytes ()));
501
+ });
502
+ tableDTO .setInfo ((String )JsonUtil .toJSONString (infoDTO ));
503
+ }
504
+
505
+ }
506
+ }
507
+ dsInfo .setInfo ((String )JsonUtil .toJSONString (unionDTOList ));
508
+ }
509
+
484
510
@ Override
485
511
public String appCanvasNameCheck (DataVisualizationBaseRequest request ) throws Exception {
486
512
Long datasetFolderPid = request .getDatasetFolderPid ();
0 commit comments