diff --git a/server/src/main/java/io/edurt/datacap/server/body/FunctionsImportBody.java b/server/src/main/java/io/edurt/datacap/server/body/FunctionsImportBody.java new file mode 100644 index 00000000..f887d4a3 --- /dev/null +++ b/server/src/main/java/io/edurt/datacap/server/body/FunctionsImportBody.java @@ -0,0 +1,28 @@ +package io.edurt.datacap.server.body; + +import io.edurt.datacap.server.common.FunctionType; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import java.util.List; + +@Data +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class FunctionsImportBody +{ + @NotBlank + private String content; + + @NotNull + @Size(min = 1) + private List plugin; + private FunctionType type = FunctionType.KEYWORD; +} diff --git a/server/src/main/java/io/edurt/datacap/server/controller/admin/FunctionsController.java b/server/src/main/java/io/edurt/datacap/server/controller/admin/FunctionsController.java index dde32742..418f8b11 100644 --- a/server/src/main/java/io/edurt/datacap/server/controller/admin/FunctionsController.java +++ b/server/src/main/java/io/edurt/datacap/server/controller/admin/FunctionsController.java @@ -1,6 +1,7 @@ package io.edurt.datacap.server.controller.admin; import io.edurt.datacap.server.body.FilterBody; +import io.edurt.datacap.server.body.FunctionsImportBody; import io.edurt.datacap.server.common.Response; import io.edurt.datacap.server.entity.FunctionsEntity; import io.edurt.datacap.server.entity.PageEntity; @@ -50,4 +51,10 @@ public class FunctionsController { return this.functionsService.getById(id); } + + @PutMapping(value = "import") + public Response batchImport(@RequestBody @Validated FunctionsImportBody configure) + { + return this.functionsService.batchImport(configure); + } } diff --git a/server/src/main/java/io/edurt/datacap/server/service/FunctionsService.java b/server/src/main/java/io/edurt/datacap/server/service/FunctionsService.java index 7345b8cd..1ed17525 100644 --- a/server/src/main/java/io/edurt/datacap/server/service/FunctionsService.java +++ b/server/src/main/java/io/edurt/datacap/server/service/FunctionsService.java @@ -1,6 +1,7 @@ package io.edurt.datacap.server.service; import io.edurt.datacap.server.body.FilterBody; +import io.edurt.datacap.server.body.FunctionsImportBody; import io.edurt.datacap.server.common.Response; import io.edurt.datacap.server.entity.FunctionsEntity; import io.edurt.datacap.server.entity.PageEntity; @@ -12,4 +13,6 @@ public interface FunctionsService Response> getAllByFilter(FilterBody filter); Response getById(Long id); + + Response batchImport(FunctionsImportBody configure); } diff --git a/server/src/main/java/io/edurt/datacap/server/service/impl/FunctionsServiceImpl.java b/server/src/main/java/io/edurt/datacap/server/service/impl/FunctionsServiceImpl.java index 365093da..48f024c3 100644 --- a/server/src/main/java/io/edurt/datacap/server/service/impl/FunctionsServiceImpl.java +++ b/server/src/main/java/io/edurt/datacap/server/service/impl/FunctionsServiceImpl.java @@ -2,6 +2,7 @@ package io.edurt.datacap.server.service.impl; import io.edurt.datacap.server.adapter.PageRequestAdapter; import io.edurt.datacap.server.body.FilterBody; +import io.edurt.datacap.server.body.FunctionsImportBody; import io.edurt.datacap.server.common.Response; import io.edurt.datacap.server.entity.FunctionsEntity; import io.edurt.datacap.server.entity.PageEntity; @@ -10,6 +11,10 @@ import io.edurt.datacap.server.service.FunctionsService; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @Service public class FunctionsServiceImpl implements FunctionsService @@ -39,4 +44,21 @@ public class FunctionsServiceImpl { return Response.success(this.functionsRepository.findById(id)); } + + @Override + public Response batchImport(FunctionsImportBody configure) + { + List functions = new ArrayList<>(); + Arrays.stream(configure.getContent().split("\n")).forEach(value -> { + FunctionsEntity function = new FunctionsEntity(); + function.setContent(value); + function.setName(value); + function.setExample(value); + function.setPlugin(configure.getPlugin()); + function.setDescription(value); + function.setType(configure.getType()); + functions.add(function); + }); + return Response.success(this.functionsRepository.saveAll(functions)); + } } diff --git a/web/console-fe/src/i18n/langs/en/common.ts b/web/console-fe/src/i18n/langs/en/common.ts index 007b5552..1ab00cf4 100644 --- a/web/console-fe/src/i18n/langs/en/common.ts +++ b/web/console-fe/src/i18n/langs/en/common.ts @@ -62,5 +62,8 @@ export default { type: 'Type', keyword: 'KeyWord', operator: 'Operator', - example: 'Example' + example: 'Example', + more: 'More', + batch: 'Batch', + import: 'import' } diff --git a/web/console-fe/src/i18n/langs/en/tooltip.ts b/web/console-fe/src/i18n/langs/en/tooltip.ts index 0692839a..8a622dfe 100644 --- a/web/console-fe/src/i18n/langs/en/tooltip.ts +++ b/web/console-fe/src/i18n/langs/en/tooltip.ts @@ -1,4 +1,5 @@ export default { elapsedMillisecond: 'The value is expressed in milliseconds', - pageShow: 'Open / Close the page' + pageShow: 'Open / Close the page', + multipleLines: 'One for each line. Multiple lines are represented by newline characters' } diff --git a/web/console-fe/src/i18n/langs/zhCn/common.ts b/web/console-fe/src/i18n/langs/zhCn/common.ts index 75bdd64c..4fcb1ab7 100644 --- a/web/console-fe/src/i18n/langs/zhCn/common.ts +++ b/web/console-fe/src/i18n/langs/zhCn/common.ts @@ -62,5 +62,8 @@ export default { type: '类型', keyword: '关键字', operator: '操作符', - example: '示例' + example: '示例', + more: '更多', + batch: '批量', + import: '导入' } diff --git a/web/console-fe/src/i18n/langs/zhCn/tooltip.ts b/web/console-fe/src/i18n/langs/zhCn/tooltip.ts index 0bd5302b..e8f6284a 100644 --- a/web/console-fe/src/i18n/langs/zhCn/tooltip.ts +++ b/web/console-fe/src/i18n/langs/zhCn/tooltip.ts @@ -1,4 +1,5 @@ export default { elapsedMillisecond: '单位为毫秒', - pageShow: '开启/关闭分页' + pageShow: '开启/关闭分页', + multipleLines: '每行一个,多个使用换行符表示' } diff --git a/web/console-fe/src/model/settings/function/FunctionImport.ts b/web/console-fe/src/model/settings/function/FunctionImport.ts new file mode 100644 index 00000000..1e8e7bd1 --- /dev/null +++ b/web/console-fe/src/model/settings/function/FunctionImport.ts @@ -0,0 +1,6 @@ +export interface FunctionImport +{ + content: string; + plugin: string; + type: string; +} diff --git a/web/console-fe/src/services/settings/function/FunctionService.ts b/web/console-fe/src/services/settings/function/FunctionService.ts index cf1a23a2..891ffb8f 100644 --- a/web/console-fe/src/services/settings/function/FunctionService.ts +++ b/web/console-fe/src/services/settings/function/FunctionService.ts @@ -2,6 +2,7 @@ import {HttpCommon} from "@/common/HttpCommon"; import {ResponseModel} from "@/model/ResponseModel"; import {Filter} from "@/model/Filter"; import {Function} from "@/model/settings/function/Function"; +import {FunctionImport} from "@/model/settings/function/FunctionImport"; const baseUrl = "/api/v1/admin/function"; @@ -26,6 +27,11 @@ class FunctionService { return new HttpCommon().get(baseUrl + "/" + id); } + + import(configure: FunctionImport): Promise + { + return new HttpCommon().put(baseUrl + "/import", configure); + } } export default new FunctionService(); diff --git a/web/console-fe/src/views/pages/admin/settings/function/FunctionAdmin.vue b/web/console-fe/src/views/pages/admin/settings/function/FunctionAdmin.vue index 33b0de08..8a2c0f96 100644 --- a/web/console-fe/src/views/pages/admin/settings/function/FunctionAdmin.vue +++ b/web/console-fe/src/views/pages/admin/settings/function/FunctionAdmin.vue @@ -7,6 +7,17 @@