From b8be0e474741453eea3f9de9314b236ab2c35f13 Mon Sep 17 00:00:00 2001 From: junjie Date: Wed, 15 Sep 2021 17:44:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=A4=E4=B8=AA=E8=A1=A8=E5=A4=9A?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=85=B3=E8=81=94=E5=90=8E=EF=BC=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=87=AA=E5=AE=9A=E4=B9=89=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 61bf948994..ce1fab51d7 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -805,21 +805,35 @@ public class DataSetTableService { String f = field.substring(0, field.length() - 1); StringBuilder join = new StringBuilder(); + List unions = new ArrayList<>(); for (DataTableInfoCustomUnion dataTableInfoCustomUnion : dataTableInfoDTO.getList()) { for (DataSetTableUnionDTO dto : list) { // 被关联表和自助数据集的表相等 if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) { - DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); - DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); - if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { - DEException.throwException(Translator.get("i18n_dataset_field_delete")); - } + unions.add(dto); + } + } + } + if (CollectionUtils.isNotEmpty(unions)) { + for (int i = 0; i < unions.size(); i++) { + DataSetTableUnionDTO dto = unions.get(i); + DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); + DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); + if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { + DEException.throwException(Translator.get("i18n_dataset_field_delete")); + } + if (i == 0) { join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation())) .append(DorisTableUtils.dorisName(dto.getTargetTableId())) .append(" ON ") .append(DorisTableUtils.dorisName(dto.getSourceTableId())).append(".").append(sourceField.getDataeaseName()) .append(" = ") .append(DorisTableUtils.dorisName(dto.getTargetTableId())).append(".").append(targetField.getDataeaseName()); + } else { + join.append(" AND ") + .append(DorisTableUtils.dorisName(dto.getSourceTableId())).append(".").append(sourceField.getDataeaseName()) + .append(" = ") + .append(DorisTableUtils.dorisName(dto.getTargetTableId())).append(".").append(targetField.getDataeaseName()); } } } @@ -865,25 +879,39 @@ public class DataSetTableService { String f = field.substring(0, field.length() - 1); StringBuilder join = new StringBuilder(); + List unions = new ArrayList<>(); for (DataTableInfoCustomUnion dataTableInfoCustomUnion : dataTableInfoDTO.getList()) { for (DataSetTableUnionDTO dto : list) { // 被关联表和自助数据集的表相等 if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) { - DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); - DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); - if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { - DEException.throwException(Translator.get("i18n_dataset_field_delete")); - } - DatasetTable sourceTable = datasetTableMapper.selectByPrimaryKey(dto.getSourceTableId()); - String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable(); - DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId()); - String targetTableName = new Gson().fromJson(targetTable.getInfo(), DataTableInfoDTO.class).getTable(); + unions.add(dto); + } + } + } + if (CollectionUtils.isNotEmpty(unions)) { + for (int i = 0; i < unions.size(); i++) { + DataSetTableUnionDTO dto = unions.get(i); + DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId()); + DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId()); + if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) { + DEException.throwException(Translator.get("i18n_dataset_field_delete")); + } + DatasetTable sourceTable = datasetTableMapper.selectByPrimaryKey(dto.getSourceTableId()); + String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable(); + DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId()); + String targetTableName = new Gson().fromJson(targetTable.getInfo(), DataTableInfoDTO.class).getTable(); + if (i == 0) { join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation())) .append(String.format(keyword, targetTableName)) .append(" ON ") .append(String.format(keyword, sourceTableName)).append(".").append(String.format(keyword, sourceField.getOriginName())) .append(" = ") .append(String.format(keyword, targetTableName)).append(".").append(String.format(keyword, targetField.getOriginName())); + } else { + join.append(" AND ") + .append(String.format(keyword, sourceTableName)).append(".").append(String.format(keyword, sourceField.getOriginName())) + .append(" = ") + .append(String.format(keyword, targetTableName)).append(".").append(String.format(keyword, targetField.getOriginName())); } } }