forked from github/dataease
fix(数据集): 增加自定义数据集字段校验
This commit is contained in:
parent
1bd0242588
commit
7cf90a2654
@ -1,7 +1,6 @@
|
|||||||
package io.dataease.service.dataset;
|
package io.dataease.service.dataset;
|
||||||
|
|
||||||
|
|
||||||
import com.fit2cloud.quartz.anno.QuartzScheduled;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import io.dataease.base.domain.*;
|
import io.dataease.base.domain.*;
|
||||||
import io.dataease.base.mapper.*;
|
import io.dataease.base.mapper.*;
|
||||||
@ -115,9 +114,9 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveExcel(DataSetTableRequest datasetTable)throws Exception {
|
public void saveExcel(DataSetTableRequest datasetTable) throws Exception {
|
||||||
if (StringUtils.isEmpty(datasetTable.getId())) {
|
if (StringUtils.isEmpty(datasetTable.getId())) {
|
||||||
if(datasetTable.isMergeSheet()){
|
if (datasetTable.isMergeSheet()) {
|
||||||
Map<String, List<ExcelSheetData>> map = datasetTable.getSheets().stream().collect(Collectors.groupingBy(ExcelSheetData::getFieldsMd5));
|
Map<String, List<ExcelSheetData>> map = datasetTable.getSheets().stream().collect(Collectors.groupingBy(ExcelSheetData::getFieldsMd5));
|
||||||
for (String s : map.keySet()) {
|
for (String s : map.keySet()) {
|
||||||
DataSetTableRequest sheetTable = new DataSetTableRequest();
|
DataSetTableRequest sheetTable = new DataSetTableRequest();
|
||||||
@ -147,7 +146,7 @@ public class DataSetTableService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
for (ExcelSheetData sheet : datasetTable.getSheets()) {
|
for (ExcelSheetData sheet : datasetTable.getSheets()) {
|
||||||
String[] fieldArray = sheet.getFields().stream().map(TableFiled::getFieldName).toArray(String[]::new);
|
String[] fieldArray = sheet.getFields().stream().map(TableFiled::getFieldName).toArray(String[]::new);
|
||||||
if (checkIsRepeat(fieldArray)) {
|
if (checkIsRepeat(fieldArray)) {
|
||||||
@ -183,7 +182,7 @@ public class DataSetTableService {
|
|||||||
List<String> oldFields = datasetTable.getSheets().get(0).getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList());
|
List<String> oldFields = datasetTable.getSheets().get(0).getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList());
|
||||||
for (ExcelSheetData sheet : datasetTable.getSheets()) {
|
for (ExcelSheetData sheet : datasetTable.getSheets()) {
|
||||||
//替换时,
|
//替换时,
|
||||||
if(datasetTable.getEditType() == 0){
|
if (datasetTable.getEditType() == 0) {
|
||||||
List<String> newFields = sheet.getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList());
|
List<String> newFields = sheet.getFields().stream().map(TableFiled::getRemarks).collect(Collectors.toList());
|
||||||
if (!oldFields.equals(newFields)) {
|
if (!oldFields.equals(newFields)) {
|
||||||
DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
|
DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
|
||||||
@ -240,7 +239,7 @@ public class DataSetTableService {
|
|||||||
if (datasetTable.getIsRename() == null || !datasetTable.getIsRename()) {
|
if (datasetTable.getIsRename() == null || !datasetTable.getIsRename()) {
|
||||||
// 更新数据和字段
|
// 更新数据和字段
|
||||||
if (update == 1) {
|
if (update == 1) {
|
||||||
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom") ) {
|
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
||||||
// 删除所有字段,重新抽象
|
// 删除所有字段,重新抽象
|
||||||
dataSetTableFieldsService.deleteByTableId(datasetTable.getId());
|
dataSetTableFieldsService.deleteByTableId(datasetTable.getId());
|
||||||
saveTableField(datasetTable);
|
saveTableField(datasetTable);
|
||||||
@ -251,7 +250,7 @@ public class DataSetTableService {
|
|||||||
return datasetTable;
|
return datasetTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alter(DataSetTableRequest request)throws Exception {
|
public void alter(DataSetTableRequest request) throws Exception {
|
||||||
checkName(request);
|
checkName(request);
|
||||||
datasetTableMapper.updateByPrimaryKeySelective(request);
|
datasetTableMapper.updateByPrimaryKeySelective(request);
|
||||||
}
|
}
|
||||||
@ -804,6 +803,9 @@ public class DataSetTableService {
|
|||||||
if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) {
|
if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) {
|
||||||
DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId());
|
DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId());
|
||||||
DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId());
|
DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId());
|
||||||
|
if (ObjectUtils.isEmpty(sourceField) || ObjectUtils.isEmpty(targetField)) {
|
||||||
|
DEException.throwException(Translator.get("i18n_dataset_field_delete"));
|
||||||
|
}
|
||||||
join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation()))
|
join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation()))
|
||||||
.append(DorisTableUtils.dorisName(dto.getTargetTableId()))
|
.append(DorisTableUtils.dorisName(dto.getTargetTableId()))
|
||||||
.append(" ON ")
|
.append(" ON ")
|
||||||
@ -861,6 +863,9 @@ public class DataSetTableService {
|
|||||||
if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) {
|
if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) {
|
||||||
DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId());
|
DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId());
|
||||||
DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId());
|
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());
|
DatasetTable sourceTable = datasetTableMapper.selectByPrimaryKey(dto.getSourceTableId());
|
||||||
String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable();
|
String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable();
|
||||||
DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId());
|
DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId());
|
||||||
@ -901,7 +906,7 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DatasetTableField> saveExcelTableField(String datasetTableId, List<TableFiled> fields, boolean insert){
|
public List<DatasetTableField> saveExcelTableField(String datasetTableId, List<TableFiled> fields, boolean insert) {
|
||||||
List<DatasetTableField> datasetTableFields = new ArrayList<>();
|
List<DatasetTableField> datasetTableFields = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(fields)) {
|
if (CollectionUtils.isNotEmpty(fields)) {
|
||||||
for (int i = 0; i < fields.size(); i++) {
|
for (int i = 0; i < fields.size(); i++) {
|
||||||
@ -920,7 +925,7 @@ public class DataSetTableService {
|
|||||||
datasetTableField.setLastSyncTime(System.currentTimeMillis());
|
datasetTableField.setLastSyncTime(System.currentTimeMillis());
|
||||||
datasetTableField.setExtField(0);
|
datasetTableField.setExtField(0);
|
||||||
datasetTableField.setGroupType(datasetTableField.getDeType() < 2 ? "d" : "q");
|
datasetTableField.setGroupType(datasetTableField.getDeType() < 2 ? "d" : "q");
|
||||||
if(insert){
|
if (insert) {
|
||||||
dataSetTableFieldsService.save(datasetTableField);
|
dataSetTableFieldsService.save(datasetTableField);
|
||||||
}
|
}
|
||||||
datasetTableFields.add(datasetTableField);
|
datasetTableFields.add(datasetTableField);
|
||||||
@ -1120,11 +1125,11 @@ public class DataSetTableService {
|
|||||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
||||||
datasourceRequest.setQuery(qp.wrapSql(sql));
|
datasourceRequest.setQuery(qp.wrapSql(sql));
|
||||||
List<String> sqlFileds = new ArrayList<>();
|
List<String> sqlFileds = new ArrayList<>();
|
||||||
try{
|
try {
|
||||||
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
|
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
|
||||||
sqlFileds.add(filed);
|
sqlFileds.add(filed);
|
||||||
});
|
});
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
|
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1137,11 +1142,11 @@ public class DataSetTableService {
|
|||||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
||||||
datasourceRequest.setQuery(qp.wrapSql(sql));
|
datasourceRequest.setQuery(qp.wrapSql(sql));
|
||||||
List<String> sqlFileds = new ArrayList<>();
|
List<String> sqlFileds = new ArrayList<>();
|
||||||
try{
|
try {
|
||||||
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
|
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
|
||||||
sqlFileds.add(filed);
|
sqlFileds.add(filed);
|
||||||
});
|
});
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
|
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1186,7 +1191,7 @@ public class DataSetTableService {
|
|||||||
List<ExcelSheetData> excelSheetDataList = parseExcel2(filename, file.getInputStream(), true);
|
List<ExcelSheetData> excelSheetDataList = parseExcel2(filename, file.getInputStream(), true);
|
||||||
List<ExcelSheetData> retrunSheetDataList = new ArrayList<>();
|
List<ExcelSheetData> retrunSheetDataList = new ArrayList<>();
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(tableId) && editType == 1 ) {
|
if (StringUtils.isNotEmpty(tableId) && editType == 1) {
|
||||||
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId);
|
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId);
|
||||||
datasetTableFields.stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).collect(Collectors.toList());
|
datasetTableFields.stream().filter(datasetTableField -> datasetTableField.getExtField() == 0).collect(Collectors.toList());
|
||||||
datasetTableFields.sort((o1, o2) -> {
|
datasetTableFields.sort((o1, o2) -> {
|
||||||
@ -1210,7 +1215,7 @@ public class DataSetTableService {
|
|||||||
if (retrunSheetDataList.size() == 0) {
|
if (retrunSheetDataList.size() == 0) {
|
||||||
DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
|
DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
retrunSheetDataList = excelSheetDataList;
|
retrunSheetDataList = excelSheetDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1223,12 +1228,12 @@ public class DataSetTableService {
|
|||||||
excelFileData.setPath(filePath);
|
excelFileData.setPath(filePath);
|
||||||
|
|
||||||
filename = filename.substring(0, filename.lastIndexOf('.'));
|
filename = filename.substring(0, filename.lastIndexOf('.'));
|
||||||
if(retrunSheetDataList.size() == 1){
|
if (retrunSheetDataList.size() == 1) {
|
||||||
retrunSheetDataList.get(0).setDatasetName(filename);
|
retrunSheetDataList.get(0).setDatasetName(filename);
|
||||||
retrunSheetDataList.get(0).setSheetExcelId(excelId);
|
retrunSheetDataList.get(0).setSheetExcelId(excelId);
|
||||||
retrunSheetDataList.get(0).setId(UUID.randomUUID().toString());
|
retrunSheetDataList.get(0).setId(UUID.randomUUID().toString());
|
||||||
retrunSheetDataList.get(0).setPath(filePath);
|
retrunSheetDataList.get(0).setPath(filePath);
|
||||||
}else {
|
} else {
|
||||||
for (ExcelSheetData excelSheetData : retrunSheetDataList) {
|
for (ExcelSheetData excelSheetData : retrunSheetDataList) {
|
||||||
excelSheetData.setDatasetName(filename + "-" + excelSheetData.getExcelLable());
|
excelSheetData.setDatasetName(filename + "-" + excelSheetData.getExcelLable());
|
||||||
excelSheetData.setSheetExcelId(excelId);
|
excelSheetData.setSheetExcelId(excelId);
|
||||||
|
@ -283,3 +283,4 @@ i18n_change_task_status_error=Suspension is not allowed. The task status is:
|
|||||||
i18n_Stopped=END
|
i18n_Stopped=END
|
||||||
i18n_Exec=Running
|
i18n_Exec=Running
|
||||||
i18n_no_trigger=The current setting does not trigger task generation.
|
i18n_no_trigger=The current setting does not trigger task generation.
|
||||||
|
i18n_dataset_field_delete=Union field deleted,please set again and redo.
|
||||||
|
@ -282,4 +282,5 @@ i18n_change_task_status_error=不允许暂停,任务状态为:
|
|||||||
i18n_Stopped=执行结束
|
i18n_Stopped=执行结束
|
||||||
i18n_Exec=运行中
|
i18n_Exec=运行中
|
||||||
i18n_no_trigger=当前设置没有触发任务生成
|
i18n_no_trigger=当前设置没有触发任务生成
|
||||||
|
i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集
|
||||||
|
|
||||||
|
@ -285,3 +285,4 @@ i18n_change_task_status_error=不允許暫停,任務狀態為:
|
|||||||
i18n_Stopped=執行結束
|
i18n_Stopped=執行結束
|
||||||
i18n_Exec=運行中
|
i18n_Exec=運行中
|
||||||
i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成.
|
i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成.
|
||||||
|
i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集
|
||||||
|
Loading…
Reference in New Issue
Block a user