Merge pull request #9373 from ulleo/dev
feat(X-Pack): 数据填报Excel批量上传校验优化
This commit is contained in:
commit
4f4dead823
@ -41,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -171,7 +172,15 @@ public class DataFillDataService {
|
|||||||
List<String[]> countData = datasourceProvider.getData(datasourceRequest);
|
List<String[]> countData = datasourceProvider.getData(datasourceRequest);
|
||||||
long count = NumberUtils.toLong(countData.get(0)[0]);
|
long count = NumberUtils.toLong(countData.get(0)[0]);
|
||||||
|
|
||||||
String searchSql = extDDLProvider.searchSql(dataFillForm.getTableName(), searchFields, whereSql, searchRequest.getPageSize(), (searchRequest.getCurrentPage() - 1) * searchRequest.getPageSize());
|
long totalPage = new BigDecimal(count).divide(new BigDecimal(searchRequest.getPageSize()), 0, RoundingMode.CEILING).longValue();
|
||||||
|
|
||||||
|
long currentPage = totalPage < searchRequest.getCurrentPage() ? totalPage - 1 : searchRequest.getCurrentPage();
|
||||||
|
|
||||||
|
if (currentPage < 1) {
|
||||||
|
currentPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String searchSql = extDDLProvider.searchSql(dataFillForm.getTableName(), searchFields, whereSql, searchRequest.getPageSize(), (currentPage - 1) * searchRequest.getPageSize());
|
||||||
datasourceRequest.setQuery(searchSql);
|
datasourceRequest.setQuery(searchSql);
|
||||||
|
|
||||||
List<String[]> data2 = datasourceProvider.getData(datasourceRequest);
|
List<String[]> data2 = datasourceProvider.getData(datasourceRequest);
|
||||||
@ -241,7 +250,7 @@ public class DataFillDataService {
|
|||||||
.setFields(fields)
|
.setFields(fields)
|
||||||
.setTotal(count)
|
.setTotal(count)
|
||||||
.setPageSize(searchRequest.getPageSize())
|
.setPageSize(searchRequest.getPageSize())
|
||||||
.setCurrentPage(searchRequest.getCurrentPage());
|
.setCurrentPage(currentPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -378,7 +387,7 @@ public class DataFillDataService {
|
|||||||
uniqueMap.putIfAbsent(name, new ArrayList<>());
|
uniqueMap.putIfAbsent(name, new ArrayList<>());
|
||||||
if (uniqueMap.get(name).contains(data.get(name).toString())) {
|
if (uniqueMap.get(name).contains(data.get(name).toString())) {
|
||||||
//提前判断录入的数据有没有unique字段重复的
|
//提前判断录入的数据有没有unique字段重复的
|
||||||
DataEaseException.throwException(extTableFields.get(name).getSettings().getName() + " 值不能重复");
|
DataEaseException.throwException("[" + extTableFields.get(name).getSettings().getName() + "] 值: " + data.get(name) + " 不能重复");
|
||||||
} else {
|
} else {
|
||||||
uniqueMap.get(name).add(data.get(name).toString());
|
uniqueMap.get(name).add(data.get(name).toString());
|
||||||
}
|
}
|
||||||
@ -416,7 +425,7 @@ public class DataFillDataService {
|
|||||||
long count = NumberUtils.toLong(countData.get(0)[0]);
|
long count = NumberUtils.toLong(countData.get(0)[0]);
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
DataEaseException.throwException(extTableFields.get(uniqueField.getFiledName()).getSettings().getName() + " 值不能重复");
|
DataEaseException.throwException("[" + extTableFields.get(uniqueField.getFiledName()).getSettings().getName() + "] 值: " + data.get(name) + " 在数据库中已存在, 不能重复");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -684,14 +693,10 @@ public class DataFillDataService {
|
|||||||
if (i < excelDatum.size()) {
|
if (i < excelDatum.size()) {
|
||||||
excelRowData = excelDatum.get(i);
|
excelRowData = excelDatum.get(i);
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(excelRowData)) { //处理必填,这里如果是字符串格式的,强制改成空字符串防止报错,其他类型都直接报错
|
if (StringUtils.isBlank(excelRowData)) { //处理必填
|
||||||
|
excelRowData = null;
|
||||||
if (field.getSettings().isRequired()) {
|
if (field.getSettings().isRequired()) {
|
||||||
if (field.getSettings().getMapping().getType().equals(ExtTableField.BaseType.nvarchar) ||
|
DataEaseException.throwException("[" + field.getSettings().getName() + "] 不能为空");
|
||||||
field.getSettings().getMapping().getType().equals(ExtTableField.BaseType.text)) {
|
|
||||||
excelRowData = StringUtils.EMPTY;
|
|
||||||
} else {
|
|
||||||
DataEaseException.throwException(field.getSettings().getName() + "不能为空");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (excelRowData == null) {
|
if (excelRowData == null) {
|
||||||
@ -709,7 +714,11 @@ public class DataFillDataService {
|
|||||||
break;
|
break;
|
||||||
case datetime:
|
case datetime:
|
||||||
Date date = getDate(field, excelRowData);
|
Date date = getDate(field, excelRowData);
|
||||||
rowData.put(field.getSettings().getMapping().getColumnName(), date.getTime());
|
Long time = date == null ? null : date.getTime();
|
||||||
|
if (time != null && time < 0) {
|
||||||
|
throw new Exception("时间不能小于1970/01/01");
|
||||||
|
}
|
||||||
|
rowData.put(field.getSettings().getMapping().getColumnName(), time);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (StringUtils.equalsIgnoreCase(field.getType(), "checkbox") ||
|
if (StringUtils.equalsIgnoreCase(field.getType(), "checkbox") ||
|
||||||
@ -723,11 +732,23 @@ public class DataFillDataService {
|
|||||||
}
|
}
|
||||||
if (field.getSettings().isRequired()) {
|
if (field.getSettings().isRequired()) {
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
DataEaseException.throwException(field.getSettings().getName() + "不能为空");
|
DataEaseException.throwException("[" + field.getSettings().getName() + "] 不能为空");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rowData.put(field.getSettings().getMapping().getColumnName(), gson.toJson(list));
|
rowData.put(field.getSettings().getMapping().getColumnName(), gson.toJson(list));
|
||||||
} else {
|
} else {
|
||||||
|
//校验手机号,校验邮箱格式
|
||||||
|
if (StringUtils.equalsAnyIgnoreCase(field.getSettings().getInputType(), "tel")) {
|
||||||
|
if (!excelRowData.matches("^1[3|4|5|7|8][0-9]{9}$")) {
|
||||||
|
throw new Exception(Translator.get("i18n_wrong_tel"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.equalsAnyIgnoreCase(field.getSettings().getInputType(), "email")) {
|
||||||
|
if (!excelRowData.matches("^[a-zA-Z0-9_._-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$")) {
|
||||||
|
throw new Exception(Translator.get("i18n_wrong_email"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rowData.put(field.getSettings().getMapping().getColumnName(), excelRowData);
|
rowData.put(field.getSettings().getMapping().getColumnName(), excelRowData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -735,7 +756,7 @@ public class DataFillDataService {
|
|||||||
} catch (DataEaseException e) {
|
} catch (DataEaseException e) {
|
||||||
DataEaseException.throwException(e.getMessage());
|
DataEaseException.throwException(e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
DataEaseException.throwException(field.getSettings().getName() + "格式错误");
|
DataEaseException.throwException("[" + field.getSettings().getName() + "] 值: " + excelRowData + " 格式解析错误: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,6 +776,9 @@ public class DataFillDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Date getDate(ExtTableField field, String excelRowData) throws ParseException {
|
private static Date getDate(ExtTableField field, String excelRowData) throws ParseException {
|
||||||
|
if (StringUtils.isBlank(excelRowData)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //默认会拿到这种格式的
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //默认会拿到这种格式的
|
||||||
if (field.getSettings().isEnableTime()) {
|
if (field.getSettings().isEnableTime()) {
|
||||||
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|||||||
@ -387,7 +387,7 @@ public class DataFillService {
|
|||||||
break;
|
break;
|
||||||
case text:
|
case text:
|
||||||
case nvarchar:
|
case nvarchar:
|
||||||
if (StringUtils.equalsIgnoreCase("select", formField.getType()) || StringUtils.equalsIgnoreCase("checkbox", formField.getType())) {
|
if (StringUtils.equalsIgnoreCase("select", formField.getType()) && formField.getSettings().isMultiple() || StringUtils.equalsIgnoreCase("checkbox", formField.getType())) {
|
||||||
example = "\n(多个值使用分号\";\"分割)";
|
example = "\n(多个值使用分号\";\"分割)";
|
||||||
} else if (StringUtils.equalsIgnoreCase("email", formField.getSettings().getInputType())) {
|
} else if (StringUtils.equalsIgnoreCase("email", formField.getSettings().getInputType())) {
|
||||||
example = "\n(邮箱格式)";
|
example = "\n(邮箱格式)";
|
||||||
|
|||||||
@ -77,7 +77,12 @@ export default {
|
|||||||
name: this.$t('data_fill.form.email'),
|
name: this.$t('data_fill.form.email'),
|
||||||
rules: [{ pattern: EMAIL_REGEX, message: this.$t('user.email_format_is_incorrect'), trigger: ['blur', 'change'] }]
|
rules: [{ pattern: EMAIL_REGEX, message: this.$t('user.email_format_is_incorrect'), trigger: ['blur', 'change'] }]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
pickerOptions: {
|
||||||
|
disabledDate: (time) => {
|
||||||
|
return time.getTime() < new Date(0).getTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {},
|
watch: {},
|
||||||
@ -343,6 +348,7 @@ export default {
|
|||||||
:placeholder="item.settings.placeholder"
|
:placeholder="item.settings.placeholder"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
size="small"
|
size="small"
|
||||||
|
:picker-options="pickerOptions"
|
||||||
/>
|
/>
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-else-if="item.type === 'date' && item.settings.enableTime"
|
v-else-if="item.type === 'date' && item.settings.enableTime"
|
||||||
@ -353,6 +359,7 @@ export default {
|
|||||||
:placeholder="item.settings.placeholder"
|
:placeholder="item.settings.placeholder"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
size="small"
|
size="small"
|
||||||
|
:picker-options="pickerOptions"
|
||||||
/>
|
/>
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-else-if="item.type === 'dateRange' && !item.settings.enableTime"
|
v-else-if="item.type === 'dateRange' && !item.settings.enableTime"
|
||||||
@ -365,6 +372,7 @@ export default {
|
|||||||
:end-placeholder="item.settings.endPlaceholder"
|
:end-placeholder="item.settings.endPlaceholder"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
size="small"
|
size="small"
|
||||||
|
:picker-options="pickerOptions"
|
||||||
/>
|
/>
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-else-if="item.type === 'dateRange' && item.settings.enableTime"
|
v-else-if="item.type === 'dateRange' && item.settings.enableTime"
|
||||||
@ -377,6 +385,7 @@ export default {
|
|||||||
:end-placeholder="item.settings.endPlaceholder"
|
:end-placeholder="item.settings.endPlaceholder"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
size="small"
|
size="small"
|
||||||
|
:picker-options="pickerOptions"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|||||||
@ -136,7 +136,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div style="flex: 1">
|
<div style="flex: 1">
|
||||||
<grid-table
|
<grid-table
|
||||||
v-if="columns.length > 0"
|
v-if="columns.length > 0 && dataTableShow"
|
||||||
|
ref="dataTable"
|
||||||
v-loading="$store.getters.loadingMap[$store.getters.currentPath]"
|
v-loading="$store.getters.loadingMap[$store.getters.currentPath]"
|
||||||
style="width: 100%; height: 100%"
|
style="width: 100%; height: 100%"
|
||||||
border
|
border
|
||||||
@ -547,6 +548,7 @@ export default {
|
|||||||
Authorization: token,
|
Authorization: token,
|
||||||
'Accept-Language': i18n.locale.replace('_', '-')
|
'Accept-Language': i18n.locale.replace('_', '-')
|
||||||
},
|
},
|
||||||
|
dataTableShow: true,
|
||||||
fileList: [],
|
fileList: [],
|
||||||
uploading: false,
|
uploading: false,
|
||||||
operateName: '',
|
operateName: '',
|
||||||
@ -642,6 +644,10 @@ export default {
|
|||||||
this.data = []
|
this.data = []
|
||||||
this.records = []
|
this.records = []
|
||||||
this.tasks = []
|
this.tasks = []
|
||||||
|
this.dataTableShow = false
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.dataTableShow = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
this.initTable(this.param.id)
|
this.initTable(this.param.id)
|
||||||
},
|
},
|
||||||
@ -731,6 +737,7 @@ export default {
|
|||||||
if (res.data) {
|
if (res.data) {
|
||||||
this.paginationConfig.key = res.data.key
|
this.paginationConfig.key = res.data.key
|
||||||
this.paginationConfig.total = res.data.total
|
this.paginationConfig.total = res.data.total
|
||||||
|
this.paginationConfig.currentPage = res.data.currentPage
|
||||||
const _data = []
|
const _data = []
|
||||||
forEach(res.data.data, d => {
|
forEach(res.data.data, d => {
|
||||||
const obj = {}
|
const obj = {}
|
||||||
@ -911,7 +918,7 @@ export default {
|
|||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.style.display = 'none'
|
link.style.display = 'none'
|
||||||
link.href = URL.createObjectURL(blob)
|
link.href = URL.createObjectURL(blob)
|
||||||
link.download = 'test.xlsx' // 下载的文件名
|
link.download = this.param.name + '.xlsx' // 下载的文件名
|
||||||
document.body.appendChild(link)
|
document.body.appendChild(link)
|
||||||
link.click()
|
link.click()
|
||||||
document.body.removeChild(link)
|
document.body.removeChild(link)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user