diff --git a/async_function_pool/README.md b/async_function_pool/README.md index 441326e97..2acdebc41 100644 --- a/async_function_pool/README.md +++ b/async_function_pool/README.md @@ -35,4 +35,13 @@ 出参 字段名称描述类型说明taskId任务idString任务唯一标识taskStatus单个任务执行状态Integer1成功,2进行中,3不存在taskResult单个任务执行返回结果StringString类型,须用户根据实际类型自行序列化。执行成功与否的标志需要逻辑在返回的序列化String中标记,获取结果后反序列化解析返回信息。 ## 异步获取结果asyncGetLogicResult -与同步获取相同,区别点在于同步是流程卡住的,等全部任务执行完成后才会返回。异步则是仅返回当前执行完成的任务。 \ No newline at end of file +与同步获取相同,区别点在于同步是流程卡住的,等全部任务执行完成后才会返回。异步则是仅返回当前执行完成的任务。 +## 异步执行任务,无返回结果asyncRunLogicNoResult +``` + /** + * 异步执行任务,无返回结果 + */ + @NaslLogic + public Boolean asyncRunLogicNoResult(Function asyncfunction, String requestStr) { + +``` \ No newline at end of file diff --git a/async_function_pool/pom.xml b/async_function_pool/pom.xml index fa5f99e6d..82aaa31cb 100644 --- a/async_function_pool/pom.xml +++ b/async_function_pool/pom.xml @@ -12,7 +12,7 @@ com.netease async_function_pool - 1.0.2 + 1.0.4 8 diff --git a/async_function_pool/src/main/java/com/netease/lib/tasks/api/FunctionManagerApi.java b/async_function_pool/src/main/java/com/netease/lib/tasks/api/FunctionManagerApi.java index a389888e2..8a5008f24 100644 --- a/async_function_pool/src/main/java/com/netease/lib/tasks/api/FunctionManagerApi.java +++ b/async_function_pool/src/main/java/com/netease/lib/tasks/api/FunctionManagerApi.java @@ -6,12 +6,15 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import java.util.concurrent.RejectedExecutionException; import java.util.function.Function; /** @@ -34,6 +37,10 @@ public class FunctionManagerApi { */ private final Map> runningTaskRegister = new ConcurrentHashMap<>(); + + @Resource(name = "libraryCommonTaskExecutor") + private Executor contextAwareExecutor; + /** * 初始化注册逻辑 * @@ -63,7 +70,7 @@ public String asyncRunLogic(String logicKey, String requestStr) { logger.error("asyncRunLogic not exist: {}", logicKey); return null; } - CompletableFuture future = CompletableFuture.supplyAsync(() -> function.apply(requestStr)); + CompletableFuture future = CompletableFuture.supplyAsync(() -> function.apply(requestStr), contextAwareExecutor); logger.info("asyncRunLogic success: {}", logicKey); String taskId = UUID.randomUUID().toString(); runningTaskRegister.put(taskId, future); @@ -130,4 +137,21 @@ public List asyncGetLogicResult(List taskIdList) { return resultDTOList; } + /** + * 异步执行任务,无返回结果 + */ + @NaslLogic + public Boolean asyncRunLogicNoResult(Function asyncfunction, String requestStr) { + try { + contextAwareExecutor.execute(() -> asyncfunction.apply(requestStr)); + return true; + } catch (RejectedExecutionException e) { + logger.error("Async task rejected for request: {}", requestStr, e); + return false; + } catch (Exception e) { + logger.error("Failed to submit async task for request: {}", requestStr, e); + return false; + } + } + } \ No newline at end of file diff --git a/async_function_pool/src/main/java/com/netease/lib/tasks/config/AsyncExecutorConfig.java b/async_function_pool/src/main/java/com/netease/lib/tasks/config/AsyncExecutorConfig.java new file mode 100644 index 000000000..25c837697 --- /dev/null +++ b/async_function_pool/src/main/java/com/netease/lib/tasks/config/AsyncExecutorConfig.java @@ -0,0 +1,53 @@ +package com.netease.lib.tasks.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +import javax.annotation.Resource; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +public class AsyncExecutorConfig { + + @Resource(name = "libraryThreadPoolConfig") + private ThreadPoolConfig threadPoolConfig; + + @Bean(name = "libraryCommonTaskExecutor") + public Executor commonTaskExecutor() { + // Spring 默认配置是核心线程数大小为1,最大线程容量大小不受限制,队列容量也不受限制。 + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + // 核心线程数 + executor.setCorePoolSize(Integer.parseInt(threadPoolConfig.getCorePoolSize())); + // 最大线程数 + executor.setMaxPoolSize(Integer.parseInt(threadPoolConfig.getMaxPoolSize())); + // 队列大小 + executor.setQueueCapacity(Integer.parseInt(threadPoolConfig.getQueueCapacity())); + //核心线程等待销毁时间 + executor.setKeepAliveSeconds(Integer.parseInt(threadPoolConfig.getKeepAliveSeconds())); + // 当最大池已满时,此策略保证不会丢失任务请求,但是可能会影响应用程序整体性能。 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); + executor.setThreadNamePrefix("common-pool"); + // 传递request + executor.setTaskDecorator(runnable -> { + RequestAttributes context = RequestContextHolder.getRequestAttributes(); + return () -> { + try { + if (context != null) { + RequestContextHolder.setRequestAttributes(context); + } + runnable.run(); + } finally { + if (context != null) { + RequestContextHolder.resetRequestAttributes(); + } + } + }; + }); + executor.initialize(); + return executor; + } +} \ No newline at end of file diff --git a/async_function_pool/src/main/java/com/netease/lib/tasks/config/ThreadPoolConfig.java b/async_function_pool/src/main/java/com/netease/lib/tasks/config/ThreadPoolConfig.java new file mode 100644 index 000000000..107fca60d --- /dev/null +++ b/async_function_pool/src/main/java/com/netease/lib/tasks/config/ThreadPoolConfig.java @@ -0,0 +1,83 @@ +package com.netease.lib.tasks.config; + +import com.netease.lowcode.core.EnvironmentType; +import com.netease.lowcode.core.annotation.Environment; +import com.netease.lowcode.core.annotation.NaslConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component("libraryThreadPoolConfig") +public class ThreadPoolConfig { + + /** + * 核心线程数 + */ + @Value("${corePoolSize:8}") + @NaslConfiguration(defaultValue = { + @Environment(type = EnvironmentType.DEV, value = "8"), + @Environment(type = EnvironmentType.ONLINE, value = "8") + }) + public String corePoolSize; + + /** + * 最大线程数 + */ + @Value("${maxPoolSize:24}") + @NaslConfiguration(defaultValue = { + @Environment(type = EnvironmentType.DEV, value = "24"), + @Environment(type = EnvironmentType.ONLINE, value = "24") + }) + public String maxPoolSize; + + /** + * 队列大小 + */ + @Value("${queueCapacity:1024}") + @NaslConfiguration(defaultValue = { + @Environment(type = EnvironmentType.DEV, value = "1024"), + @Environment(type = EnvironmentType.ONLINE, value = "1024") + }) + public String queueCapacity; + + /** + * 核心线程等待销毁时间 + */ + @Value("${keepAliveSeconds:60}") + @NaslConfiguration(defaultValue = { + @Environment(type = EnvironmentType.DEV, value = "60"), + @Environment(type = EnvironmentType.ONLINE, value = "60") + }) + public String keepAliveSeconds; + + public String getCorePoolSize() { + return corePoolSize; + } + + public void setCorePoolSize(String corePoolSize) { + this.corePoolSize = corePoolSize; + } + + public String getMaxPoolSize() { + return maxPoolSize; + } + + public void setMaxPoolSize(String maxPoolSize) { + this.maxPoolSize = maxPoolSize; + } + + public String getQueueCapacity() { + return queueCapacity; + } + + public void setQueueCapacity(String queueCapacity) { + this.queueCapacity = queueCapacity; + } + + public String getKeepAliveSeconds() { + return keepAliveSeconds; + } + + public void setKeepAliveSeconds(String keepAliveSeconds) { + this.keepAliveSeconds = keepAliveSeconds; + } +} diff --git a/excel-parser/doc/nasl-metadata.json b/excel-parser/doc/nasl-metadata.json new file mode 100644 index 000000000..e20071956 --- /dev/null +++ b/excel-parser/doc/nasl-metadata.json @@ -0,0 +1,679 @@ +{ + "name":"excel_parser", + "title":"excel解析", + "description":"excel解析工具包", + "specVersion":"1.0.0", + "ideVersion":"2.21", + "type":"module", + "subType":"extension", + "version":"1.3.0", + "editable":false, + "externalDependencyMap":{ + "maven":[ + { + "groupId":"com.netease.lowcode.extension", + "artifactId":"excel-parser", + "version":"1.3.0" + } + ] + }, + "structures":[ + { + "concept":"Structure", + "name":"ExcelParseResult", + "typeParams":null, + "compilerInfo":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel.dto", + "className":"ExcelParseResult" + } + }, + "properties":[ + { + "concept":"StructureProperty", + "name":"errors", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"List", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseError", + "typeArguments":null + } + ] + }, + "isLeaf":true, + "changedTime":1667477064094, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb" + }, + { + "concept":"StructureProperty", + "name":"data", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"List", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"typeParam", + "typeName":"T", + "typeArguments":null + } + ] + }, + "isLeaf":true, + "changedTime":1667477033992, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb" + }, + { + "concept":"StructureProperty", + "name":"unParsedData", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"List", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"Map", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + } + ] + } + ] + }, + "isLeaf":true, + "changedTime":1667477033992, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb" + }, + { + "concept":"StructureProperty", + "name":"success", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"Boolean", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667477055022, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb" + } + ], + "changedTime":1667477064095, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"excel解析结果" + }, + { + "concept":"Structure", + "name":"ExcelParseError", + "typeParams":null, + "compilerInfo":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel.dto", + "className":"ExcelParseError" + } + }, + "properties":[ + { + "concept":"StructureProperty", + "name":"cellName", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667476937855, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"错误的单元格" + }, + { + "concept":"StructureProperty", + "name":"cellValue", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667476942779, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"错误的数据" + }, + { + "concept":"StructureProperty", + "name":"errorMsg", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667476956187, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"错误信息" + }, + { + "concept":"StructureProperty", + "name":"sheetName", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667476956187, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"错误的数据页" + } + ], + "changedTime":1667476956188, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "description":"excel单元格解析失败信息" + }, + { + "concept":"Structure", + "name":"ExcelParseRect", + "typeParams":null, + "compilerInfo":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel.dto", + "className":"ExcelParseRect" + } + }, + "properties":[ + { + "concept":"StructureProperty", + "name":"startCell", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "changedTime":1667476303768, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb", + "label":"起始单元格" + }, + { + "concept":"StructureProperty", + "name":"endCell", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + }, + "isLeaf":true, + "label":"结束单元格", + "description":"指定excel读取区域" + } + ], + "changedTime":1667476348804, + "updatebyapp":"79844f17-96a5-4e64-941b-0f09d8e13beb" + } + ], + "enums":[ + + ], + "logics":[ + { + "concept":"Logic", + "name":"parseAllSheet", + "description":"解析excel文件", + "compilerInfoMap":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel", + "className":"ExcelParser" + } + }, + "typeParams":[ + { + "concept":"TypeParam", + "name":"T" + } + ], + "params":[ + { + "concept":"Param", + "name":"path", + "description":"文件路径", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + } + }, + { + "concept":"Param", + "name":"rect", + "description":"数据读取区域,可以为空", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseRect", + "typeArguments":null + } + }, + { + "required":false, + "concept":"Param", + "name":"columnFieldMap", + "description":"列和属性的对应", + "typeAnnotation":{ + "typeKind":"generic", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.collection", + "typeName":"Map", + "typeArguments":[ + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + }, + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + } + ] + } + }, + { + "description":"表头行数", + "typeAnnotation":{ + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"Long" + }, + "required":false, + "concept":"Param", + "name":"row" + } + ], + "returns":[ + { + "concept":"Return", + "name":"result", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseResult", + "typeArguments":null + } + } + ], + "variables":[ + + ], + "body":[ + { + "concept":"Start", + "name":"", + "label":"开始", + "folded":false + }, + { + "concept":"End", + "name":"", + "label":"结束", + "folded":false + } + ], + "playground":[ + + ] + }, + { + "concept":"Logic", + "name":"parseBySheetName", + "description":"解析excel文件,指定页名", + "compilerInfoMap":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel", + "className":"ExcelParser" + } + }, + "typeParams":[ + { + "concept":"TypeParam", + "name":"T" + } + ], + "params":[ + { + "concept":"Param", + "name":"path", + "description":"文件路径", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + } + }, + { + "concept":"Param", + "name":"sheetNames", + "description":"待读取页的名称列表", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"List", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + } + ] + } + }, + { + "concept":"Param", + "name":"rect", + "description":"数据读取区域,可以为空", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseRect", + "typeArguments":null + } + }, + { + "required":false, + "concept":"Param", + "name":"columnFieldMap", + "description":"列和属性的对应", + "typeAnnotation":{ + "typeKind":"generic", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.collection", + "typeName":"Map", + "typeArguments":[ + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + }, + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + } + ] + } + }, + { + "description":"表头行数", + "typeAnnotation":{ + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"Long" + }, + "required":false, + "concept":"Param", + "name":"row" + } + ], + "returns":[ + { + "concept":"Return", + "name":"result", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseResult", + "typeArguments":null + } + } + ], + "variables":[ + + ], + "body":[ + { + "concept":"Start", + "name":"", + "label":"开始", + "folded":false + }, + { + "concept":"End", + "name":"", + "label":"结束", + "folded":false + } + ], + "playground":[ + + ] + }, + { + "concept":"Logic", + "name":"parseBySheetIndex", + "description":"解析excel文件,指定页下标", + "compilerInfoMap":{ + "java":{ + "packageName":"com.netease.lowcode.extension.excel", + "className":"ExcelParser" + } + }, + "typeParams":[ + { + "concept":"TypeParam", + "name":"T" + } + ], + "params":[ + { + "concept":"Param", + "name":"path", + "description":"文件路径", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"String", + "typeArguments":null + } + }, + { + "concept":"Param", + "name":"sheetIndexes", + "description":"待读取页的下标列表", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"generic", + "typeNamespace":"nasl.collection", + "typeName":"List", + "typeArguments":[ + { + "concept":"TypeAnnotation", + "name":"", + "typeKind":"primitive", + "typeNamespace":"nasl.core", + "typeName":"Integer", + "typeArguments":null + } + ] + } + }, + { + "concept":"Param", + "name":"rect", + "description":"数据读取区域,可以为空", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseRect", + "typeArguments":null + } + }, + { + "required":false, + "concept":"Param", + "name":"columnFieldMap", + "description":"列和属性的对应", + "typeAnnotation":{ + "typeKind":"generic", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.collection", + "typeName":"Map", + "typeArguments":[ + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + }, + { + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"String" + } + ] + } + }, + { + "description":"表头行数", + "typeAnnotation":{ + "typeKind":"primitive", + "concept":"TypeAnnotation", + "typeNamespace":"nasl.core", + "typeName":"Long" + }, + "required":false, + "concept":"Param", + "name":"row" + } + ], + "returns":[ + { + "concept":"Return", + "name":"result", + "typeAnnotation":{ + "concept":"TypeAnnotation", + "name":"", + "typeKind":"reference", + "typeNamespace":"extensions.excel_parser.structures", + "typeName":"ExcelParseResult", + "typeArguments":null + } + } + ], + "variables":[ + + ], + "body":[ + { + "concept":"Start", + "name":"", + "label":"开始", + "folded":false + }, + { + "concept":"End", + "name":"", + "label":"结束", + "folded":false + } + ], + "playground":[ + + ] + } + ], + "interfaces":[ + + ], + "views":[ + + ], + "processes":[ + + ], + "viewComponents":[ + + ] +} \ No newline at end of file diff --git a/excel-parser/doc/usage.json b/excel-parser/doc/usage.json deleted file mode 100644 index 61c7749a8..000000000 --- a/excel-parser/doc/usage.json +++ /dev/null @@ -1,532 +0,0 @@ -{ - "name":"excel_parser", - "title":"excel解析", - "description":"excel解析工具包", - "specVersion":"1.0.0", - "type":"module", - "subType":"extension", - "version":"1.2.1", - "editable":false, - "externalDependencyMap": { - "maven": [ - { - "groupId": "com.netease.lowcode.extension", - "artifactId": "excel-parser", - "version": "1.2.1" - } - ] - }, - "structures": [{ - "concept": "Structure", - "name": "ExcelParseResult", - "typeParams": null, - "compilerInfo": { - "java": { - "packageName": "com.netease.lowcode.extension.excel.dto", - "className": "ExcelParseResult" - } - }, - "properties": [ - { - "concept": "StructureProperty", - "name": "errors", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "List", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseError", - "typeArguments": null - } - ] - }, - "isLeaf": true, - "changedTime": 1667477064094, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb" - }, - { - "concept": "StructureProperty", - "name": "data", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "List", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "typeParam", - "typeName": "T", - "typeArguments": null - } - ] - }, - "isLeaf": true, - "changedTime": 1667477033992, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb" - }, - { - "concept": "StructureProperty", - "name": "unParsedData", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "List", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "Map", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - } - ] - } - ] - }, - "isLeaf": true, - "changedTime": 1667477033992, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb" - }, - { - "concept": "StructureProperty", - "name": "success", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "Boolean", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667477055022, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb" - } - ], - "changedTime": 1667477064095, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "excel解析结果" - },{ - "concept": "Structure", - "name": "ExcelParseError", - "typeParams": null, - "compilerInfo": { - "java": { - "packageName": "com.netease.lowcode.extension.excel.dto", - "className": "ExcelParseError" - } - }, - "properties": [ - { - "concept": "StructureProperty", - "name": "cellName", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667476937855, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "错误的单元格" - }, - { - "concept": "StructureProperty", - "name": "cellValue", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667476942779, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "错误的数据" - }, - { - "concept": "StructureProperty", - "name": "errorMsg", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667476956187, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "错误信息" - }, - { - "concept": "StructureProperty", - "name": "sheetName", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667476956187, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "错误的数据页" - } - ], - "changedTime": 1667476956188, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "description": "excel单元格解析失败信息" - },{ - "concept": "Structure", - "name": "ExcelParseRect", - "typeParams": null, - "compilerInfo": { - "java": { - "packageName": "com.netease.lowcode.extension.excel.dto", - "className": "ExcelParseRect" - } - }, - "properties": [ - { - "concept": "StructureProperty", - "name": "startCell", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "changedTime": 1667476303768, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb", - "label": "起始单元格" - }, - { - "concept": "StructureProperty", - "name": "endCell", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - }, - "isLeaf": true, - "label": "结束单元格", - "description": "指定excel读取区域" - } - ], - "changedTime": 1667476348804, - "updatebyapp": "79844f17-96a5-4e64-941b-0f09d8e13beb" - }], - "enums": [], - "logics": [ - { - "concept": "Logic", - "name": "parseAllSheet", - "description": "解析excel文件", - "compilerInfoMap": { - "java": { - "packageName": "com.netease.lowcode.extension.excel", - "className": "ExcelParser" - } - }, - "typeParams": [ - { - "concept": "TypeParam", - "name": "T" - } - ], - "params": [ - { - "concept": "Param", - "name": "path", - "description": "文件路径", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - } - }, - { - "concept": "Param", - "name": "rect", - "description": "数据读取区域,可以为空", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseRect", - "typeArguments": null - } - } - ], - "returns": [{ - "concept": "Return", - "name": "result", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseResult", - "typeArguments": null - } - }], - "variables": [], - "body": [ - { - "concept": "Start", - "name": "", - "label": "开始", - "folded": false - }, - { - "concept": "End", - "name": "", - "label": "结束", - "folded": false - } - ], - "playground": [] - }, - { - "concept": "Logic", - "name": "parseBySheetName", - "description": "解析excel文件,指定页名", - "compilerInfoMap": { - "java": { - "packageName": "com.netease.lowcode.extension.excel", - "className": "ExcelParser" - } - }, - "typeParams": [ - { - "concept": "TypeParam", - "name": "T" - } - ], - "params": [ - { - "concept": "Param", - "name": "path", - "description": "文件路径", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - } - }, - { - "concept": "Param", - "name": "sheetNames", - "description": "待读取页的名称列表", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "List", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - } - ] - } - }, - { - "concept": "Param", - "name": "rect", - "description": "数据读取区域,可以为空", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseRect", - "typeArguments": null - } - } - ], - "returns": [{ - "concept": "Return", - "name": "result", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseResult", - "typeArguments": null - } - }], - "variables": [], - "body": [ - { - "concept": "Start", - "name": "", - "label": "开始", - "folded": false - }, - { - "concept": "End", - "name": "", - "label": "结束", - "folded": false - } - ], - "playground": [] - }, - { - "concept": "Logic", - "name": "parseBySheetIndex", - "description": "解析excel文件,指定页下标", - "compilerInfoMap": { - "java": { - "packageName": "com.netease.lowcode.extension.excel", - "className": "ExcelParser" - } - }, - "typeParams": [ - { - "concept": "TypeParam", - "name": "T" - } - ], - "params": [ - { - "concept": "Param", - "name": "path", - "description": "文件路径", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "String", - "typeArguments": null - } - }, - { - "concept": "Param", - "name": "sheetIndexes", - "description": "待读取页的下标列表", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "generic", - "typeNamespace": "nasl.collection", - "typeName": "List", - "typeArguments": [ - { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "primitive", - "typeNamespace": "nasl.core", - "typeName": "Integer", - "typeArguments": null - } - ] - } - }, - { - "concept": "Param", - "name": "rect", - "description": "数据读取区域,可以为空", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseRect", - "typeArguments": null - } - } - ], - "returns": [{ - "concept": "Return", - "name": "result", - "typeAnnotation": { - "concept": "TypeAnnotation", - "name": "", - "typeKind": "reference", - "typeNamespace": "extensions.excel_parser.structures", - "typeName": "ExcelParseResult", - "typeArguments": null - } - }], - "variables": [], - "body": [ - { - "concept": "Start", - "name": "", - "label": "开始", - "folded": false - }, - { - "concept": "End", - "name": "", - "label": "结束", - "folded": false - } - ], - "playground": [] - } - ], - "interfaces": [], - "views": [], - "processes": [], - "viewComponents": [] -} diff --git a/excel-parser/pom.xml b/excel-parser/pom.xml index 8daa865d0..44ee210df 100644 --- a/excel-parser/pom.xml +++ b/excel-parser/pom.xml @@ -4,7 +4,7 @@ com.netease.lowcode.extension excel-parser - 1.2.1 + 1.3.0 extension module archetype jar diff --git a/httpclient/pom.xml b/httpclient/pom.xml index a41fc234b..a967e650e 100644 --- a/httpclient/pom.xml +++ b/httpclient/pom.xml @@ -16,7 +16,7 @@ httpclient httpclient httpclient - 1.2.0 + 1.3.0 @@ -96,7 +96,7 @@ 1.4.3 false - true + diff --git a/httpclient/src/main/java/com/netease/http/dto/ExchangeResponseDto.java b/httpclient/src/main/java/com/netease/http/dto/ExchangeResponseDto.java new file mode 100644 index 000000000..ece3b8a1c --- /dev/null +++ b/httpclient/src/main/java/com/netease/http/dto/ExchangeResponseDto.java @@ -0,0 +1,34 @@ +package com.netease.http.dto; + +import com.netease.lowcode.core.annotation.NaslStructure; + +import java.util.Map; + +@NaslStructure +public class ExchangeResponseDto { + /** + * 响应体 + */ + public String bodyString; + /** + * 响应头 + */ + public Map responseHeaders; + + public String getBodyString() { + return bodyString; + } + + public void setBodyString(String bodyString) { + this.bodyString = bodyString; + } + + public Map getResponseHeaders() { + return responseHeaders; + } + + public void setResponseHeaders(Map responseHeaders) { + this.responseHeaders = responseHeaders; + } +} + diff --git a/httpclient/src/main/java/com/netease/http/httpclient/LCAPHttpClient.java b/httpclient/src/main/java/com/netease/http/httpclient/LCAPHttpClient.java index 080ffc0f0..3dcb5db1f 100644 --- a/httpclient/src/main/java/com/netease/http/httpclient/LCAPHttpClient.java +++ b/httpclient/src/main/java/com/netease/http/httpclient/LCAPHttpClient.java @@ -29,6 +29,7 @@ import java.net.URL; import java.nio.file.Files; import java.util.Map; +import java.util.stream.Collectors; /** * desc @@ -148,6 +149,38 @@ public String exchangeV3(@Required String url, @Required String httpMethod, @Req } } + + /** + * http/https调用(非form使用,异常时返回http错误码) + * + * @param url + * @param httpMethod + * @param header + * @param body + * @return + * @throws URISyntaxException + */ + @NaslLogic + @Retryable(value = {Exception.class}, maxAttempts = 3, backoff = @Backoff(delay = 1000L)) + public ExchangeResponseDto exchangeV4(@Required String url, @Required String httpMethod, @Required Map header, @Required String body) throws TransferCommonException { + try { + RequestParamAllBodyTypeInner requestParam = new RequestParamAllBodyTypeInner(); + requestParam.setBody(body); + //填充requestParam参数 + requestParam.setUrl(url); + requestParam.setHttpMethod(httpMethod); + requestParam.setHeader(header); + ResponseEntity exchange = httpClientService.exchangeInner(requestParam, restTemplate, String.class); + return convertToExchangeResponseDto(exchange); + } catch (HttpClientErrorException e) { + logger.error("", e); + throw new TransferCommonException(e.getStatusCode().value(), e.getResponseBodyAsString()); + } catch (Exception e) { + logger.error("", e); + throw new TransferCommonException(e.getMessage(), e); + } + } + /** * 下载文件并上传到nos(默认fileUrl是get请求,默认格式xlsx) * @@ -407,6 +440,60 @@ public String exchangeCrtForm(RequestParam requestParam) throws TransferCommonEx } } + /** + * https请求忽略证书,form表单专用body为MultiValueMap。包含返回头信息 + * + * @param requestParam + * @return + */ + @NaslLogic + @Retryable(value = {Exception.class}, maxAttempts = 3, backoff = @Backoff(delay = 1000L)) + public ExchangeResponseDto exchangeCrtFormResHeader(RequestParam requestParam) throws TransferCommonException { + try { + if (requestParam.getIsIgnoreCrt() == null) { + requestParam.setIsIgnoreCrt(false); + } + if (requestParam.getIsIgnoreCrt()) { + SSLUtil.turnOffCertificateValidation(); + } + RequestParamAllBodyTypeInner requestParamAllBodyTypeInner = DtoConvert.convertToRequestParamAllBodyTypeInner(requestParam); + if (requestParam.getBody() != null) { + MultiValueMap multiValueMap = new LinkedMultiValueMap(); + //map 转MultiValueMap + requestParam.getBody().forEach(multiValueMap::add); + requestParamAllBodyTypeInner.setBody(multiValueMap); + } + ResponseEntity exchange = httpClientService + .exchangeInner(requestParamAllBodyTypeInner, restTemplate, String.class); + return convertToExchangeResponseDto(exchange); + } catch (HttpClientErrorException e) { + logger.error("", e); + throw new TransferCommonException(e.getStatusCode().value(), e.getResponseBodyAsString()); + } catch (Exception e) { + logger.error("", e); + throw new TransferCommonException(e.getMessage(), e); + } + } + + private ExchangeResponseDto convertToExchangeResponseDto(ResponseEntity exchange) { + if (exchange.getStatusCode() == HttpStatus.OK) { + ExchangeResponseDto exchangeResponseDto = new ExchangeResponseDto(); + Map headerMap = exchange.getHeaders() + .entrySet() + .stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> String.join(", ", entry.getValue()) + )); + + exchangeResponseDto.setResponseHeaders(headerMap); + exchangeResponseDto.setBodyString(exchange.getBody()); + return exchangeResponseDto; + } else { + throw new TransferCommonException(exchange.getStatusCode().value(), JSONObject.toJSONString(exchange)); + } + } + /** * http/https调用(非form使用,url不编码) * diff --git a/ip-filter-aop/pom.xml b/ip-filter-aop/pom.xml index 07120dd1a..a05e55754 100644 --- a/ip-filter-aop/pom.xml +++ b/ip-filter-aop/pom.xml @@ -63,12 +63,6 @@ org.springframework.boot spring-boot-starter-data-redis - - com.fasterxml.jackson.core - jackson-databind - 2.10.5 - provided -