From 9ff9bf4c9e3e3577ad8a0f62925eb9d5c8292986 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Sat, 2 Dec 2023 10:11:25 +0800 Subject: [PATCH] [Core] [Metadata] Support clone row (close #477) --- .../service/impl/TableServiceImpl.java | 28 +++++++++++++--- core/datacap-web/src/fontawesome.ts | 2 ++ .../src/views/admin/source/AdminSource.vue | 2 +- .../admin/source/components/TableData.vue | 32 +++++++++++++++---- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/core/datacap-service/src/main/java/io/edurt/datacap/service/service/impl/TableServiceImpl.java b/core/datacap-service/src/main/java/io/edurt/datacap/service/service/impl/TableServiceImpl.java index 892c617f..5bc9e523 100644 --- a/core/datacap-service/src/main/java/io/edurt/datacap/service/service/impl/TableServiceImpl.java +++ b/core/datacap-service/src/main/java/io/edurt/datacap/service/service/impl/TableServiceImpl.java @@ -23,6 +23,7 @@ import io.edurt.datacap.spi.Plugin; import io.edurt.datacap.spi.model.Configure; import io.edurt.datacap.spi.model.Pagination; import io.edurt.datacap.spi.model.Response; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; @@ -208,12 +209,31 @@ public class TableServiceImpl updateConfigure.setFormat(FormatType.NONE); plugin.connect(updateConfigure); List allSql = Lists.newArrayList(); + // Gets the auto-increment column for the current row + List autoIncrementColumns = table.getColumns() + .stream() + .filter(v -> v.getExtra().toLowerCase().contains("auto_increment")) + .map(v -> v.getName()) + .collect(Collectors.toList()); configure.getNewColumns().forEach(v -> { List columns = Lists.newArrayList(); - v.entrySet().forEach(entry -> columns.add(SqlColumn.builder() - .column(String.format("`%s`", entry.getKey())) - .value(entry.getValue()) - .build())); + v.entrySet().forEach(entry -> { + SqlColumn column = SqlColumn.builder() + .column(String.format("`%s`", entry.getKey())) + .build(); + if (entry.getValue() == null) { + column.setValue(null); + } + else { + if (autoIncrementColumns.contains(entry.getKey())) { + column.setValue(null); + } + else { + column.setValue(String.format("'%s'", StringEscapeUtils.escapeSql(entry.getValue()))); + } + } + columns.add(column); + }); SqlBody body = SqlBody.builder() .type(SqlType.INSERT) .database(table.getDatabase().getName()) diff --git a/core/datacap-web/src/fontawesome.ts b/core/datacap-web/src/fontawesome.ts index 38ec7416..173d064b 100644 --- a/core/datacap-web/src/fontawesome.ts +++ b/core/datacap-web/src/fontawesome.ts @@ -12,6 +12,7 @@ import { faCircle, faCircleInfo, faClock, + faClone, faColumns, faDatabase, faDroplet, @@ -40,6 +41,7 @@ import { */ const createIcons = (app: any) => { library.add(faArrowRight, + faClone, faPlus, faTablet, faMinus, diff --git a/core/datacap-web/src/views/admin/source/AdminSource.vue b/core/datacap-web/src/views/admin/source/AdminSource.vue index cceaca21..66ff6f2d 100644 --- a/core/datacap-web/src/views/admin/source/AdminSource.vue +++ b/core/datacap-web/src/views/admin/source/AdminSource.vue @@ -67,7 +67,7 @@ + + +