forked from github/dataease
Merge pull request #9820 from ulleo/dev
feat(X-Pack): 数据填报>编辑表单>删除表单组建时,对应变更表内字段名称,且在创建索引时过滤掉该字段
This commit is contained in:
commit
6488dd37a5
@ -49,10 +49,11 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addTableColumnSql(String table, List<ExtTableField> formFields) {
|
public String addTableColumnSql(String table, List<ExtTableField> formFieldsToCreate, List<ExtTableField> formFieldsToModify) {
|
||||||
String modifyTableSql = "ALTER TABLE `$TABLE_NAME$` $Column_Fields$ ;";
|
String modifyTableSql = "ALTER TABLE `$TABLE_NAME$` $Column_Fields$ ;";
|
||||||
List<ExtTableField.TableField> fields = convertTableFields(false, formFields);
|
List<ExtTableField.TableField> fields = convertTableFields(false, formFieldsToCreate);
|
||||||
String fieldSql = convertTableFieldsString(table, fields, true);
|
List<ExtTableField.TableField> fieldsToModify = convertTableFields(false, formFieldsToModify);
|
||||||
|
String fieldSql = convertTableFieldsString(table, fields, true, fieldsToModify);
|
||||||
return modifyTableSql.replace("$TABLE_NAME$", table).replace("$Column_Fields$", fieldSql);
|
return modifyTableSql.replace("$TABLE_NAME$", table).replace("$Column_Fields$", fieldSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,18 +145,21 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
for (ExtTableField formField : formFields) {
|
for (ExtTableField formField : formFields) {
|
||||||
ExtTableField.TableField.TableFieldBuilder fieldBuilder = ExtTableField.TableField.builder()
|
ExtTableField.TableField.TableFieldBuilder fieldBuilder = ExtTableField.TableField.builder()
|
||||||
.columnName(formField.getSettings().getMapping().getColumnName())
|
.columnName(formField.getSettings().getMapping().getColumnName())
|
||||||
|
.oldColumnName(formField.getSettings().getMapping().getOldColumnName())
|
||||||
.type(formField.getSettings().getMapping().getType())
|
.type(formField.getSettings().getMapping().getType())
|
||||||
.comment(formField.getSettings().getName())
|
.comment(formField.getSettings().getName())
|
||||||
.required(formField.getSettings().isRequired());
|
.required(formField.getSettings().isRequired());
|
||||||
if (StringUtils.equalsIgnoreCase(formField.getType(), "dateRange")) {
|
if (StringUtils.equalsIgnoreCase(formField.getType(), "dateRange")) {
|
||||||
ExtTableField.TableField f1 = fieldBuilder
|
ExtTableField.TableField f1 = fieldBuilder
|
||||||
.columnName(formField.getSettings().getMapping().getColumnName1())
|
.columnName(formField.getSettings().getMapping().getColumnName1())
|
||||||
|
.oldColumnName(formField.getSettings().getMapping().getOldColumnName1())
|
||||||
.comment(formField.getSettings().getName() + " start")
|
.comment(formField.getSettings().getName() + " start")
|
||||||
.build();
|
.build();
|
||||||
list.add(f1);
|
list.add(f1);
|
||||||
|
|
||||||
ExtTableField.TableField f2 = BeanUtils.copyBean(new ExtTableField.TableField(), f1);
|
ExtTableField.TableField f2 = BeanUtils.copyBean(new ExtTableField.TableField(), f1);
|
||||||
f2.setColumnName(formField.getSettings().getMapping().getColumnName2());
|
f2.setColumnName(formField.getSettings().getMapping().getColumnName2());
|
||||||
|
f2.setOldColumnName(formField.getSettings().getMapping().getOldColumnName2());
|
||||||
f2.setComment(formField.getSettings().getName() + " end");
|
f2.setComment(formField.getSettings().getName() + " end");
|
||||||
list.add(f2);
|
list.add(f2);
|
||||||
} else {
|
} else {
|
||||||
@ -265,13 +269,42 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
return convertTableFieldsString(table, fields, false);
|
return convertTableFieldsString(table, fields, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String convertTableFieldsString(String table, List<ExtTableField.TableField> fields, boolean addColumn) {
|
private String convertTableFieldsString(String table, List<ExtTableField.TableField> fields, boolean notCreateTable) {
|
||||||
|
return convertTableFieldsString(table, fields, notCreateTable, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String convertTableFieldsString(String table, List<ExtTableField.TableField> fields, boolean notCreateTable, List<ExtTableField.TableField> fieldsToModify) {
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
if (addColumn) {
|
if (notCreateTable) {
|
||||||
str.append("\n");
|
str.append("\n");
|
||||||
} else {
|
} else {
|
||||||
str.append("(\n");
|
str.append("(\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notCreateTable && CollectionUtils.isNotEmpty(fieldsToModify)) {
|
||||||
|
for (int i = 0; i < fieldsToModify.size(); i++) {
|
||||||
|
ExtTableField.TableField field = fieldsToModify.get(i);
|
||||||
|
|
||||||
|
str.append("change ");
|
||||||
|
|
||||||
|
//column name
|
||||||
|
str.append("`").append(field.getOldColumnName()).append("` ");
|
||||||
|
str.append("`").append(field.getColumnName()).append("` ");
|
||||||
|
|
||||||
|
appendTypes(str, field);
|
||||||
|
|
||||||
|
//换行
|
||||||
|
if (i < fieldsToModify.size() - 1) {
|
||||||
|
str.append(",\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(fields)) {
|
||||||
|
str.append(",\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ExtTableField.TableField primaryKeyField = null;
|
ExtTableField.TableField primaryKeyField = null;
|
||||||
for (int i = 0; i < fields.size(); i++) {
|
for (int i = 0; i < fields.size(); i++) {
|
||||||
ExtTableField.TableField field = fields.get(i);
|
ExtTableField.TableField field = fields.get(i);
|
||||||
@ -283,62 +316,14 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
/*if (checkSqlInjection(field.getColumnName())) {
|
/*if (checkSqlInjection(field.getColumnName())) {
|
||||||
throw new RuntimeException("包含SQL注入的参数,请检查参数!");
|
throw new RuntimeException("包含SQL注入的参数,请检查参数!");
|
||||||
}*/
|
}*/
|
||||||
if (addColumn) {
|
if (notCreateTable) {
|
||||||
str.append("add ");
|
str.append("add ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//column name
|
//column name
|
||||||
str.append("`").append(field.getColumnName()).append("` ");
|
str.append("`").append(field.getColumnName()).append("` ");
|
||||||
//type
|
|
||||||
switch (field.getType()) {
|
|
||||||
case nvarchar:
|
|
||||||
str.append("NVARCHAR(");
|
|
||||||
if (field.getSize() != null && field.getSize() > 0) {
|
|
||||||
str.append(field.getSize());
|
|
||||||
} else {
|
|
||||||
str.append(256);
|
|
||||||
}
|
|
||||||
str.append(") ");
|
|
||||||
break;
|
|
||||||
case number:
|
|
||||||
str.append("BIGINT(");
|
|
||||||
if (field.getSize() != null && field.getSize() > 0) {
|
|
||||||
str.append(field.getSize());
|
|
||||||
} else {
|
|
||||||
str.append(20);
|
|
||||||
}
|
|
||||||
str.append(") ");
|
|
||||||
break;
|
|
||||||
case decimal:
|
|
||||||
str.append("DECIMAL(");
|
|
||||||
if (field.getSize() != null && field.getSize() > 0) {
|
|
||||||
str.append(field.getSize());
|
|
||||||
} else {
|
|
||||||
str.append(20);
|
|
||||||
}
|
|
||||||
str.append(",");
|
|
||||||
if (field.getAccuracy() != null && field.getAccuracy() >= 0) {
|
|
||||||
str.append(field.getAccuracy());
|
|
||||||
} else {
|
|
||||||
str.append(8);
|
|
||||||
}
|
|
||||||
str.append(") ");
|
|
||||||
break;
|
|
||||||
case datetime:
|
|
||||||
str.append("DATETIME ");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
str.append("LONGTEXT ");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//必填 考虑到表单编辑的情况,调整为代码判断
|
appendTypes(str, field);
|
||||||
/*if (field.isRequired()) {
|
|
||||||
str.append("NOT NULL ");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//comment
|
|
||||||
str.append("COMMENT '").append(field.getComment()).append("' ");
|
|
||||||
|
|
||||||
//换行
|
//换行
|
||||||
if (i < fields.size() - 1) {
|
if (i < fields.size() - 1) {
|
||||||
@ -351,7 +336,7 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (primaryKeyField != null) {
|
if (!notCreateTable && primaryKeyField != null) {
|
||||||
str.append("constraint `")
|
str.append("constraint `")
|
||||||
.append(table)
|
.append(table)
|
||||||
.append("_pk` ")
|
.append("_pk` ")
|
||||||
@ -361,12 +346,65 @@ public class MysqlExtDDLProvider extends DefaultExtDDLProvider {
|
|||||||
.append("`)");
|
.append("`)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!addColumn) {
|
if (!notCreateTable) {
|
||||||
str.append("\n)\n");
|
str.append("\n)\n");
|
||||||
}
|
}
|
||||||
return str.toString();
|
return str.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void appendTypes(StringBuilder str, ExtTableField.TableField field) {
|
||||||
|
//type
|
||||||
|
switch (field.getType()) {
|
||||||
|
case nvarchar:
|
||||||
|
str.append("NVARCHAR(");
|
||||||
|
if (field.getSize() != null && field.getSize() > 0) {
|
||||||
|
str.append(field.getSize());
|
||||||
|
} else {
|
||||||
|
str.append(256);
|
||||||
|
}
|
||||||
|
str.append(") ");
|
||||||
|
break;
|
||||||
|
case number:
|
||||||
|
str.append("BIGINT(");
|
||||||
|
if (field.getSize() != null && field.getSize() > 0) {
|
||||||
|
str.append(field.getSize());
|
||||||
|
} else {
|
||||||
|
str.append(20);
|
||||||
|
}
|
||||||
|
str.append(") ");
|
||||||
|
break;
|
||||||
|
case decimal:
|
||||||
|
str.append("DECIMAL(");
|
||||||
|
if (field.getSize() != null && field.getSize() > 0) {
|
||||||
|
str.append(field.getSize());
|
||||||
|
} else {
|
||||||
|
str.append(20);
|
||||||
|
}
|
||||||
|
str.append(",");
|
||||||
|
if (field.getAccuracy() != null && field.getAccuracy() >= 0) {
|
||||||
|
str.append(field.getAccuracy());
|
||||||
|
} else {
|
||||||
|
str.append(8);
|
||||||
|
}
|
||||||
|
str.append(") ");
|
||||||
|
break;
|
||||||
|
case datetime:
|
||||||
|
str.append("DATETIME ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
str.append("LONGTEXT ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//必填 考虑到表单编辑的情况,调整为代码判断
|
||||||
|
/*if (field.isRequired()) {
|
||||||
|
str.append("NOT NULL ");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//comment
|
||||||
|
str.append("COMMENT '").append(field.getComment()).append("' ");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> createTableIndexSql(String table, List<ExtIndexField> indexFields) {
|
public List<String> createTableIndexSql(String table, List<ExtIndexField> indexFields) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
|
@ -83,10 +83,30 @@ public class DataFillService {
|
|||||||
List<ExtTableField> fields = gson.fromJson(dataFillForm.getForms(), new TypeToken<List<ExtTableField>>() {
|
List<ExtTableField> fields = gson.fromJson(dataFillForm.getForms(), new TypeToken<List<ExtTableField>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
|
|
||||||
List<ExtIndexField> indexes = new ArrayList<>();
|
List<ExtIndexField> indexesToCreate = new ArrayList<>();
|
||||||
if (dataFillForm.getCreateIndex()) {
|
if (dataFillForm.getCreateIndex()) {
|
||||||
indexes = gson.fromJson(dataFillForm.getTableIndexes(), new TypeToken<List<ExtIndexField>>() {
|
List<ExtIndexField> indexes = gson.fromJson(dataFillForm.getTableIndexes(), new TypeToken<List<ExtIndexField>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
|
|
||||||
|
Map<String, String> indexColumnItems = new HashMap<>();
|
||||||
|
fields.forEach(f -> {
|
||||||
|
if (StringUtils.equalsIgnoreCase(f.getType(), "dateRange")) {
|
||||||
|
indexColumnItems.put(f.getId() + "_1", f.getSettings().getMapping().getColumnName1());
|
||||||
|
indexColumnItems.put(f.getId() + "_2", f.getSettings().getMapping().getColumnName2());
|
||||||
|
} else {
|
||||||
|
indexColumnItems.put(f.getId(), f.getSettings().getMapping().getColumnName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
indexes.forEach(f -> {
|
||||||
|
ExtIndexField index = gson.fromJson(gson.toJson(f), ExtIndexField.class);
|
||||||
|
index.getColumns().forEach(c -> {
|
||||||
|
//根据id获取实际的column名
|
||||||
|
c.setColumn(indexColumnItems.get(c.getColumn()));
|
||||||
|
});
|
||||||
|
indexesToCreate.add(index);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Datasource ds = dataFillDataService.getDataSource(dataFillForm.getDatasource(), true);
|
Datasource ds = dataFillDataService.getDataSource(dataFillForm.getDatasource(), true);
|
||||||
@ -107,7 +127,7 @@ public class DataFillService {
|
|||||||
|
|
||||||
if (dataFillForm.getCreateIndex()) {
|
if (dataFillForm.getCreateIndex()) {
|
||||||
try {
|
try {
|
||||||
List<String> sqls = extDDLProvider.createTableIndexSql(dataFillForm.getTableName(), indexes);
|
List<String> sqls = extDDLProvider.createTableIndexSql(dataFillForm.getTableName(), indexesToCreate);
|
||||||
|
|
||||||
for (String indexSql : sqls) {
|
for (String indexSql : sqls) {
|
||||||
datasourceRequest.setQuery(indexSql);
|
datasourceRequest.setQuery(indexSql);
|
||||||
@ -202,9 +222,46 @@ public class DataFillService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<ExtTableField> fieldsToCreate = fields.stream().filter(f -> !oldFieldIds.contains(f.getId())).collect(Collectors.toList());
|
List<ExtTableField> fieldsToCreate = fields.stream().filter(f -> !oldFieldIds.contains(f.getId())).collect(Collectors.toList());
|
||||||
List<ExtIndexField> indexesToCreate = indexes.stream().filter(f -> !oldIndexNames.contains(f.getName())).collect(Collectors.toList());
|
//这里是表单中被删除的字段
|
||||||
|
List<String> fieldsIds = fields.stream().map(ExtTableField::getId).collect(Collectors.toList());
|
||||||
|
List<ExtTableField> removedFields = oldFields.stream().filter(f -> !fieldsIds.contains(f.getId()) && !f.isRemoved()).collect(Collectors.toList());
|
||||||
|
List<ExtTableField> alreadyRemovedFields = oldFields.stream().filter(ExtTableField::isRemoved).collect(Collectors.toList());
|
||||||
|
//需要修改列名的字段
|
||||||
|
List<ExtTableField> fieldsToModify = removedFields.stream().filter(f -> !f.isRemoved()).collect(Collectors.toList());
|
||||||
|
fieldsToModify.forEach(f -> {
|
||||||
|
f.setRemoved(true);
|
||||||
|
if (StringUtils.equalsIgnoreCase(f.getType(), "dateRange")) {
|
||||||
|
f.getSettings().getMapping().setOldColumnName1(f.getSettings().getMapping().getColumnName1());
|
||||||
|
f.getSettings().getMapping().setOldColumnName2(f.getSettings().getMapping().getColumnName2());
|
||||||
|
f.getSettings().getMapping().setColumnName1(f.getId() + "_1");
|
||||||
|
f.getSettings().getMapping().setColumnName2(f.getId() + "_2");
|
||||||
|
} else {
|
||||||
|
f.getSettings().getMapping().setOldColumnName(f.getSettings().getMapping().getColumnName());
|
||||||
|
f.getSettings().getMapping().setColumnName(f.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Map<String, String> indexColumnItems = new HashMap<>();
|
||||||
|
fields.forEach(f -> {
|
||||||
|
if (StringUtils.equalsIgnoreCase(f.getType(), "dateRange")) {
|
||||||
|
indexColumnItems.put(f.getId() + "_1", f.getSettings().getMapping().getColumnName1());
|
||||||
|
indexColumnItems.put(f.getId() + "_2", f.getSettings().getMapping().getColumnName2());
|
||||||
|
} else {
|
||||||
|
indexColumnItems.put(f.getId(), f.getSettings().getMapping().getColumnName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
List<ExtIndexField> indexesToCreate = new ArrayList<>();
|
||||||
|
indexes.stream()
|
||||||
|
.filter(f -> !oldIndexNames.contains(f.getName())).collect(Collectors.toList())
|
||||||
|
.forEach(f -> {
|
||||||
|
ExtIndexField index = gson.fromJson(gson.toJson(f), ExtIndexField.class);
|
||||||
|
index.getColumns().forEach(c -> {
|
||||||
|
//根据id获取实际的column名
|
||||||
|
c.setColumn(indexColumnItems.get(c.getColumn()));
|
||||||
|
});
|
||||||
|
indexesToCreate.add(index);
|
||||||
|
});
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(fieldsToCreate) || CollectionUtils.isNotEmpty(indexesToCreate)) {
|
if (CollectionUtils.isNotEmpty(fieldsToCreate) || CollectionUtils.isNotEmpty(indexesToCreate) || CollectionUtils.isNotEmpty(fieldsToModify)) {
|
||||||
|
|
||||||
Datasource ds = dataFillDataService.getDataSource(dataFillForm.getDatasource());
|
Datasource ds = dataFillDataService.getDataSource(dataFillForm.getDatasource());
|
||||||
|
|
||||||
@ -218,8 +275,8 @@ public class DataFillService {
|
|||||||
//拼sql
|
//拼sql
|
||||||
ExtDDLProvider extDDLProvider = ProviderFactory.gerExtDDLProvider(ds.getType());
|
ExtDDLProvider extDDLProvider = ProviderFactory.gerExtDDLProvider(ds.getType());
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(fieldsToCreate)) {
|
if (CollectionUtils.isNotEmpty(fieldsToCreate) || CollectionUtils.isNotEmpty(fieldsToModify)) {
|
||||||
String sql = extDDLProvider.addTableColumnSql(dataFillForm.getTableName(), fieldsToCreate);
|
String sql = extDDLProvider.addTableColumnSql(dataFillForm.getTableName(), fieldsToCreate, fieldsToModify);
|
||||||
//创建
|
//创建
|
||||||
datasourceRequest.setQuery(sql);
|
datasourceRequest.setQuery(sql);
|
||||||
jdbcProvider.exec(datasourceRequest);
|
jdbcProvider.exec(datasourceRequest);
|
||||||
@ -263,12 +320,10 @@ public class DataFillService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//处理被删除的form
|
//处理被删除的form
|
||||||
List<String> fieldsIds = fields.stream().map(ExtTableField::getId).collect(Collectors.toList());
|
if (CollectionUtils.isNotEmpty(fieldsToModify) || CollectionUtils.isNotEmpty(alreadyRemovedFields)) {
|
||||||
List<ExtTableField> removedFields = oldFields.stream().filter(f -> !fieldsIds.contains(f.getId())).collect(Collectors.toList());
|
|
||||||
removedFields.forEach(f -> f.setRemoved(true));
|
|
||||||
if (CollectionUtils.isNotEmpty(removedFields)) {
|
|
||||||
List<ExtTableField> finalFields = new ArrayList<>(fields);
|
List<ExtTableField> finalFields = new ArrayList<>(fields);
|
||||||
finalFields.addAll(removedFields);
|
finalFields.addAll(fieldsToModify);
|
||||||
|
finalFields.addAll(alreadyRemovedFields);
|
||||||
dataFillForm.setForms(new Gson().toJson(finalFields));
|
dataFillForm.setForms(new Gson().toJson(finalFields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,13 +268,21 @@ export default {
|
|||||||
this.formSettings.forms = filter(JSON.parse(res.data.forms), f => !f.removed)
|
this.formSettings.forms = filter(JSON.parse(res.data.forms), f => !f.removed)
|
||||||
forEach(this.formSettings.forms, f => {
|
forEach(this.formSettings.forms, f => {
|
||||||
f.old = true
|
f.old = true
|
||||||
|
if (f.type === 'checkbox' || f.type === 'select' && f.settings.multiple) {
|
||||||
|
f.value = []
|
||||||
|
}
|
||||||
})
|
})
|
||||||
this.formSettings.oldForms = JSON.parse(res.data.forms)
|
this.formSettings.oldForms = JSON.parse(res.data.forms)
|
||||||
this.formSettings.tableIndexes = JSON.parse(res.data.tableIndexes)
|
this.formSettings.tableIndexes = JSON.parse(res.data.tableIndexes)
|
||||||
forEach(this.formSettings.tableIndexes, f => {
|
|
||||||
f.old = true
|
if (res.data.createIndex) {
|
||||||
})
|
forEach(this.formSettings.tableIndexes, f => {
|
||||||
this.formSettings.oldTableIndexes = JSON.parse(res.data.tableIndexes)
|
f.old = true
|
||||||
|
})
|
||||||
|
this.formSettings.oldTableIndexes = JSON.parse(res.data.tableIndexes)
|
||||||
|
} else {
|
||||||
|
this.formSettings.oldTableIndexes = []
|
||||||
|
}
|
||||||
|
|
||||||
this.disableCreateIndex = res.data.createIndex
|
this.disableCreateIndex = res.data.createIndex
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { filter, forEach, find, split, get, groupBy, keys, includes } from 'lodash-es'
|
import { filter, forEach, find, split, get, groupBy, keys, includes, cloneDeep } from 'lodash-es'
|
||||||
import { listDatasource } from '@/api/system/datasource'
|
import { listDatasource } from '@/api/system/datasource'
|
||||||
import { listForm, saveForm, updateForm } from '@/views/dataFilling/form/dataFilling'
|
import { listForm, saveForm, updateForm } from '@/views/dataFilling/form/dataFilling'
|
||||||
import { hasDataPermission } from '@/utils/permission'
|
import { hasDataPermission } from '@/utils/permission'
|
||||||
@ -31,17 +31,21 @@ export default {
|
|||||||
}
|
}
|
||||||
let count = 0
|
let count = 0
|
||||||
forEach(this.computedFormList, f => {
|
forEach(this.computedFormList, f => {
|
||||||
if (f.type === 'dateRange') {
|
if (!f.deleted) {
|
||||||
if (f.settings.mapping.columnName1 === value) {
|
if (f.type === 'dateRange') {
|
||||||
count++
|
if (f.settings.mapping.columnName1 === value) {
|
||||||
}
|
count++
|
||||||
if (f.settings.mapping.columnName2 === value) {
|
}
|
||||||
count++
|
if (f.settings.mapping.columnName2 === value) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (f.settings.mapping.columnName === value) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (f.settings.mapping.columnName === value) {
|
// 后台会讲删除的字段名处理成uuid,正常不会有重复的
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
@ -65,13 +69,19 @@ export default {
|
|||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
const checkInvalidColumnValidator = (rule, value, callback) => {
|
const checkInvalidColumnValidator = (rule, value, callback) => {
|
||||||
|
const f = split(rule.field, '.')[0]
|
||||||
|
const _index = get(this.formData, f)
|
||||||
|
if (_index.old) {
|
||||||
|
// 旧的 index 跳过校验
|
||||||
|
callback()
|
||||||
|
}
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error(this.$t('commons.component.required')))
|
return callback(new Error(this.$t('commons.component.required')))
|
||||||
}
|
}
|
||||||
if (this.columnsList.length === 0) {
|
if (this.columnsList.length === 0) {
|
||||||
return callback(new Error(this.$t('data_fill.form.value_not_exists')))
|
return callback(new Error(this.$t('data_fill.form.value_not_exists')))
|
||||||
}
|
}
|
||||||
if (find(this.columnsList, c => c === value) === undefined) {
|
if (find(this.columnsList, c => c.value === value) === undefined) {
|
||||||
callback(new Error(this.$t('data_fill.form.value_not_exists')))
|
callback(new Error(this.$t('data_fill.form.value_not_exists')))
|
||||||
}
|
}
|
||||||
callback()
|
callback()
|
||||||
@ -142,15 +152,16 @@ export default {
|
|||||||
const _list = []
|
const _list = []
|
||||||
const columnIds = []
|
const columnIds = []
|
||||||
for (let i = 0; i < this.formData.forms.length; i++) {
|
for (let i = 0; i < this.formData.forms.length; i++) {
|
||||||
const row = this.formData.forms[i]
|
const row = cloneDeep(this.formData.forms[i])
|
||||||
columnIds.push(row.id)
|
columnIds.push(row.id)
|
||||||
_list.push(row)
|
_list.push(row)
|
||||||
}
|
}
|
||||||
for (let i = 0; i < this.formData.oldForms.length; i++) {
|
for (let i = 0; i < this.formData.oldForms.length; i++) {
|
||||||
const row = this.formData.oldForms[i]
|
const row = cloneDeep(this.formData.oldForms[i])
|
||||||
if (includes(columnIds, row.id)) {
|
if (includes(columnIds, row.id)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
row.deleted = true
|
||||||
_list.push(row)
|
_list.push(row)
|
||||||
}
|
}
|
||||||
return _list
|
return _list
|
||||||
@ -180,25 +191,40 @@ export default {
|
|||||||
return this.formData.tableIndexes
|
return this.formData.tableIndexes
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
columnsList() {
|
allColumnsList() {
|
||||||
const _list = []
|
const _list = []
|
||||||
for (let i = 0; i < this.computedFormList.length; i++) {
|
for (let i = 0; i < this.computedFormList.length; i++) {
|
||||||
const row = this.computedFormList[i]
|
const row = this.computedFormList[i]
|
||||||
if (row.type === 'dateRange') {
|
if (row.type === 'dateRange') {
|
||||||
if (row.settings.mapping.columnName1 !== undefined && row.settings.mapping.columnName1 !== '') {
|
if (row.settings.mapping.columnName1 !== undefined && row.settings.mapping.columnName1 !== '') {
|
||||||
_list.push(row.settings.mapping.columnName1)
|
_list.push({
|
||||||
|
name: !row.deleted ? row.settings.mapping.columnName1 : row.id + '_1',
|
||||||
|
value: row.id + '_1',
|
||||||
|
deleted: !!row.deleted
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (row.settings.mapping.columnName2 !== undefined && row.settings.mapping.columnName2 !== '') {
|
if (row.settings.mapping.columnName2 !== undefined && row.settings.mapping.columnName2 !== '') {
|
||||||
_list.push(row.settings.mapping.columnName2)
|
_list.push({
|
||||||
|
name: !row.deleted ? row.settings.mapping.columnName2 : row.id + '_2',
|
||||||
|
value: row.id + '_2',
|
||||||
|
deleted: !!row.deleted
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (row.settings.mapping.columnName !== undefined && row.settings.mapping.columnName !== '' && row.settings.mapping.type !== 'text') {
|
if (row.settings.mapping.columnName !== undefined && row.settings.mapping.columnName !== '' && row.settings.mapping.type !== 'text') {
|
||||||
_list.push(row.settings.mapping.columnName)
|
_list.push({
|
||||||
|
name: !row.deleted ? row.settings.mapping.columnName : row.id,
|
||||||
|
value: row.id,
|
||||||
|
deleted: !!row.deleted
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _list
|
return _list
|
||||||
|
},
|
||||||
|
columnsList() {
|
||||||
|
return filter(this.allColumnsList, c => !c.deleted)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -756,12 +782,11 @@ export default {
|
|||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(x, $index) in columnsList"
|
v-for="(x, $index) in (isEdit && scope.row.old ? allColumnsList : columnsList)"
|
||||||
:key="$index"
|
:key="$index"
|
||||||
:value="x"
|
:value="x.value"
|
||||||
:label="x"
|
:label="x.name"
|
||||||
>{{ x }}
|
/>
|
||||||
</el-option>
|
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
@ -81,6 +81,10 @@ public class ExtTableField implements Serializable {
|
|||||||
private String columnName1;
|
private String columnName1;
|
||||||
private String columnName2;
|
private String columnName2;
|
||||||
|
|
||||||
|
private String oldColumnName;
|
||||||
|
private String oldColumnName1;
|
||||||
|
private String oldColumnName2;
|
||||||
|
|
||||||
private BaseType type;
|
private BaseType type;
|
||||||
|
|
||||||
//长度
|
//长度
|
||||||
@ -107,6 +111,8 @@ public class ExtTableField implements Serializable {
|
|||||||
|
|
||||||
private String columnName;
|
private String columnName;
|
||||||
|
|
||||||
|
private String oldColumnName;
|
||||||
|
|
||||||
private BaseType type;
|
private BaseType type;
|
||||||
|
|
||||||
private boolean required;
|
private boolean required;
|
||||||
|
@ -23,7 +23,7 @@ public class DefaultExtDDLProvider extends ExtDDLProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addTableColumnSql(String table, List<ExtTableField> formFields) {
|
public String addTableColumnSql(String table, List<ExtTableField> formFieldsToCreate, List<ExtTableField> formFieldsToModify) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ public abstract class ExtDDLProvider {
|
|||||||
|
|
||||||
public abstract String createTableSql(String table, List<ExtTableField> formFields);
|
public abstract String createTableSql(String table, List<ExtTableField> formFields);
|
||||||
|
|
||||||
public abstract String addTableColumnSql(String table, List<ExtTableField> formFields);
|
public abstract String addTableColumnSql(String table, List<ExtTableField> formFieldsToCreate, List<ExtTableField> formFieldsToModify);
|
||||||
|
|
||||||
public abstract String dropTableColumnSql(String table, List<ExtTableField> formFields);
|
public abstract String dropTableColumnSql(String table, List<ExtTableField> formFields);
|
||||||
|
|
||||||
public abstract String searchSql(String table, List<TableField> formFields, String whereSql, long limit, long offset);
|
public abstract String searchSql(String table, List<TableField> formFields, String whereSql, long limit, long offset);
|
||||||
@ -25,6 +26,7 @@ public abstract class ExtDDLProvider {
|
|||||||
public abstract String dropTableSql(String table);
|
public abstract String dropTableSql(String table);
|
||||||
|
|
||||||
public abstract List<String> createTableIndexSql(String table, List<ExtIndexField> indexFields);
|
public abstract List<String> createTableIndexSql(String table, List<ExtIndexField> indexFields);
|
||||||
|
|
||||||
public abstract List<String> dropTableIndexSql(String table, List<ExtIndexField> indexFields);
|
public abstract List<String> dropTableIndexSql(String table, List<ExtIndexField> indexFields);
|
||||||
|
|
||||||
public abstract String deleteDataByIdsSql(String table, List<DatasourceRequest.TableFieldWithValue> pks);
|
public abstract String deleteDataByIdsSql(String table, List<DatasourceRequest.TableFieldWithValue> pks);
|
||||||
|
Loading…
Reference in New Issue
Block a user