Skip to content

Commit

Permalink
fix: 增加excel字段重复错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaJunjie2020 committed Jun 30, 2021
1 parent 81e7d61 commit f30b86a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,12 @@ private Map<String, Object> parseExcel(String filename, InputStream inputStream,
}

String[] fieldArray = fields.stream().map(TableFiled::getFieldName).toArray(String[]::new);

// 校验excel字段是否重名
if (checkIsRepeat(fieldArray)) {
DataEaseException.throwException(Translator.get("i18n_excel_field_repeat"));
}

if (CollectionUtils.isNotEmpty(data)) {
jsonArray = data.stream().map(ele -> {
Map<String, Object> map = new HashMap<>();
Expand Down Expand Up @@ -1087,4 +1093,19 @@ public void updateDatasetTableStatus() {

}
}

/*
* 判断数组中是否有重复的值
*/
public static boolean checkIsRepeat(String[] array) {
HashSet<String> hashSet = new HashSet<String>();
for (int i = 0; i < array.length; i++) {
hashSet.add(array[i]);
}
if (hashSet.size() == array.length) {
return false;
} else {
return true;
}
}
}
8 changes: 8 additions & 0 deletions frontend/src/views/dataset/add/AddExcel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export default {
this.uploading = true
},
uploadFail(response, file, fileList) {
this.path = ''
this.fields = []
this.sheets = []
this.data = []
const datas = this.data
this.$refs.plxTable.reloadData(datas)
this.name = ''
this.fileList = []
this.uploading = false
this.$message({
type: 'error',
Expand Down

0 comments on commit f30b86a

Please sign in to comment.