From df192939cea3a64fcae7a8d0c01b04a707c49f2e Mon Sep 17 00:00:00 2001 From: IT-xiaoXiong <774495953@qq.com> Date: Wed, 9 Feb 2022 16:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecology-weaver.iml | 7 +- html/aiyh_pcn/流程代码块/index.js | 8 +- pom.xml | 39 +++++-- src/main/java/aiyh/utils/Util.java | 32 +++++- .../core/typehandler/IDataSourceHandler.java | 5 +- .../core/typehandler/IParamTypeHandler.java | 10 +- .../typehandler/IParamValueRuleHandler.java | 3 +- .../datasource/ModelDataHandler.java | 3 +- .../datasource/WorkflowDataHandler.java | 66 +++++++---- .../paramtype/BooleanTypeHandler.java | 9 +- .../paramtype/DoubleTypeHandler.java | 9 +- .../paramtype/ListTypeHandler.java | 7 +- .../paramtype/LongTypeHandler.java | 7 +- .../paramtype/ObjectTypeHandler.java | 7 +- .../paramtype/StringTypeHandler.java | 9 +- .../CurrentDataTimeRuleHandler.java | 25 +++++ .../paramvalue/CustomerSqlRuleHandler.java | 43 ++++++- .../paramvalue/FixedValueRuleHandle.java | 3 +- .../paramvalue/NullValueRuleHandler.java | 3 +- .../paramvalue/RandomValueRuleHandle.java | 47 ++++++++ .../paramvalue/RequestIdRuleHandler.java | 22 ++++ .../paramvalue/SqlFieldRuleHandler.java | 21 ++++ .../SystemFieldValueRuleHandle.java | 14 ++- .../paramvalue/TimeStampRuleHandler.java | 21 ++++ .../paramvalue/WorkflowIdRuleHandle.java | 22 ++++ .../utils/apirequest/entity/ApiBaseInfo.java | 32 ++++++ .../apirequest/entity/ApiRequestData.java | 85 ++++++++++++++ .../entity/ApiRequestHeardData.java | 14 +++ .../entity/ApiRequestParamData.java | 14 +++ .../apirequest/entity/ParamConfigInfo.java | 15 +-- .../apirequest/enumtype/ParamTypeEnum.java | 55 +++++++++ .../mapper/ParamValueParseMapper.java | 23 ++++ .../apirequest/mapsturct/BeanMapper.java | 106 ++++++++++++++++++ .../utils/apirequest/pojo/ApiRequestMain.java | 6 +- .../pojo/ApiRequestParamDetail.java | 7 +- .../apirequest/service/ApiRequestService.java | 29 ++--- .../apirequest/service/ParseParamValue.java | 3 +- .../async_organization/ExportExcel.java | 2 +- src/test/java/utilTest/UtilTest.java | 67 ++++++++++- 39 files changed, 804 insertions(+), 96 deletions(-) create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CurrentDataTimeRuleHandler.java create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RandomValueRuleHandle.java create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RequestIdRuleHandler.java create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SqlFieldRuleHandler.java create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/TimeStampRuleHandler.java create mode 100644 src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/WorkflowIdRuleHandle.java create mode 100644 src/main/java/aiyh/utils/apirequest/entity/ApiBaseInfo.java create mode 100644 src/main/java/aiyh/utils/apirequest/entity/ApiRequestData.java create mode 100644 src/main/java/aiyh/utils/apirequest/entity/ApiRequestHeardData.java create mode 100644 src/main/java/aiyh/utils/apirequest/entity/ApiRequestParamData.java create mode 100644 src/main/java/aiyh/utils/apirequest/mapsturct/BeanMapper.java diff --git a/ecology-weaver.iml b/ecology-weaver.iml index 9e5b286..6c52021 100644 --- a/ecology-weaver.iml +++ b/ecology-weaver.iml @@ -9,6 +9,7 @@ + @@ -20,16 +21,20 @@ + - + + + + diff --git a/html/aiyh_pcn/流程代码块/index.js b/html/aiyh_pcn/流程代码块/index.js index 4eca779..09e0952 100644 --- a/html/aiyh_pcn/流程代码块/index.js +++ b/html/aiyh_pcn/流程代码块/index.js @@ -337,7 +337,13 @@ function bindEvent(configObj) { let colorMapper = item.colorMapper for (let v in colorMapper) { WfForm.proxyFieldContentComp(convertField2Id(v, item.simpleTableName, false), changeColor(colorMapper[v])); - WfForm.forceRenderField(convertField2Id(v, item.simpleTableName)); + setTimeout(()=>{ + let rowArr = (WfForm.getDetailAllRowIndexStr(item.simpleTableName) ?? '').split(","); + rowArr.forEach(value=>{ + console.log(convertField2Id(v, item.simpleTableName)+"_"+value) + WfForm.forceRenderField(convertField2Id(v, item.simpleTableName)+"_"+value); + }) + },100) } }) } diff --git a/pom.xml b/pom.xml index a185203..ed6e7ae 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ 1.18.22 5.7.12 2.16.0 + 1.4.2.Final @@ -43,6 +44,17 @@ ${lombok.version} provided + + + org.mapstruct + mapstruct-jdk8 + ${org.mapstruct.version} + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + cn.hutool @@ -62,7 +74,7 @@ junit 4.12 - + org.apache.poi poi-excelant @@ -83,7 +95,7 @@ poi-ooxml-schemas 3.8 - + @@ -92,17 +104,24 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.8.1 8 8 - - - - - - - + + + org.projectlombok + lombok + ${lombok.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 4e63802..80a054e 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -64,9 +64,9 @@ public class Util extends weaver.general.Util { private static final RecordSet rs = new RecordSet(); private static final String LOGGER_NAME = "cusAYH"; static ToolUtil toolUtil = new ToolUtil(); - private static RecordsetUtil recordsetUtil = new RecordsetUtil(); + private static final RecordsetUtil recordsetUtil = new RecordsetUtil(); private static final UtilMapper mapper = getMapper(UtilMapper.class); - private static LoggerUtil loggerUtil = new LoggerUtil(); + private static final LoggerUtil loggerUtil = new LoggerUtil(); private static volatile Logger log = null; /** @@ -2145,6 +2145,9 @@ public class Util extends weaver.general.Util { for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Method writeMethod = propertyDescriptor.getWriteMethod(); String name = propertyDescriptor.getName(); + if (writeMethod == null) { + continue; + } try { Field sourceClassField = sourceClass.getDeclaredField(name); Class propertyType = propertyDescriptor.getPropertyType(); @@ -2162,4 +2165,29 @@ public class Util extends weaver.general.Util { // TODO 复制bean return target; } + + public static String randomNumber(int length) { + return creatRandom("0123456789", length); + } + + public static String randomString(int length) { + return creatRandom("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", length); + } + + public static String randomLetter(int length) { + return creatRandom("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", length); + } + + + public static String creatRandom(String randomStr, int length) { + StringBuffer sb = new StringBuffer(); + Random random = new Random(); + for (int i = 0; i < length; i++) { + int rand = random.nextInt(randomStr.length()); + sb.append(randomStr.charAt(rand)); + } + return sb.toString(); + } + + } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/IDataSourceHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/IDataSourceHandler.java index c3d66d9..7fe064e 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/IDataSourceHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/IDataSourceHandler.java @@ -1,5 +1,6 @@ package aiyh.utils.apirequest.core.typehandler; +import aiyh.utils.apirequest.entity.ApiRequestData; import aiyh.utils.apirequest.entity.ParamConfigInfo; import aiyh.utils.apirequest.pojo.ApiRequestMain; @@ -15,8 +16,8 @@ public interface IDataSourceHandler { /** * 数据来源处理方法 - * @param apiRequestMain 请求配置信息 + * @param apiRequestData 请求配置信息 * @return 解析后 */ - public ParamConfigInfo parseDataSource(ApiRequestMain apiRequestMain); + public ParamConfigInfo parseDataSource(ApiRequestData apiRequestData); } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamTypeHandler.java index ae3c593..ba1e36b 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamTypeHandler.java @@ -1,5 +1,9 @@ package aiyh.utils.apirequest.core.typehandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; + /** *

请求参数类型处理器接口

*

create 2022/1/22 0022 20:21

@@ -11,8 +15,10 @@ package aiyh.utils.apirequest.core.typehandler; public interface IParamTypeHandler { /** * 参数值类型的转换 - * @param value 为转换前参数值 + * + * @param paramData 为转换前参数信息 + * @param paramValueRuleHandler 参数转换处理器 * @return 转换后的参数 */ - public Object getValue(Object value); + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap); } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamValueRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamValueRuleHandler.java index 8e9b5ff..d8f3c13 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamValueRuleHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/IParamValueRuleHandler.java @@ -1,5 +1,6 @@ package aiyh.utils.apirequest.core.typehandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; import java.util.Map; @@ -19,5 +20,5 @@ public interface IParamValueRuleHandler { * @param dataMap 流程数据或建模表数据 * @return 参数对应 的值 */ - public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap); + public Object getValue(ApiRequestParamData paramInfo, Map dataMap); } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/ModelDataHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/ModelDataHandler.java index 89d2c6f..8ee61f8 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/ModelDataHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/ModelDataHandler.java @@ -1,6 +1,7 @@ package aiyh.utils.apirequest.core.typehandler.datasource; import aiyh.utils.apirequest.core.typehandler.IDataSourceHandler; +import aiyh.utils.apirequest.entity.ApiRequestData; import aiyh.utils.apirequest.entity.ParamConfigInfo; import aiyh.utils.apirequest.pojo.ApiRequestMain; @@ -14,7 +15,7 @@ import aiyh.utils.apirequest.pojo.ApiRequestMain; public class ModelDataHandler implements IDataSourceHandler { @Override - public ParamConfigInfo parseDataSource(ApiRequestMain apiRequestMain) { + public ParamConfigInfo parseDataSource(ApiRequestData apiRequestData) { return null; } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/WorkflowDataHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/WorkflowDataHandler.java index 00dd1fa..9737ec8 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/WorkflowDataHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/datasource/WorkflowDataHandler.java @@ -3,21 +3,22 @@ package aiyh.utils.apirequest.core.typehandler.datasource; import aiyh.utils.Util; import aiyh.utils.apirequest.core.factory.AbstractFactory; import aiyh.utils.apirequest.core.factory.AbstractFactoryImpl; +import aiyh.utils.apirequest.core.factory.ParamTypeHandlerFactory; import aiyh.utils.apirequest.core.factory.ParamValueRuleHandlerFactory; import aiyh.utils.apirequest.core.typehandler.IDataSourceHandler; +import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; -import aiyh.utils.apirequest.entity.ParamConfigInfo; -import aiyh.utils.apirequest.entity.ParamInfo; +import aiyh.utils.apirequest.entity.*; +import aiyh.utils.apirequest.enumtype.ParamTypeEnum; import aiyh.utils.apirequest.enumtype.ParamValueRuleEnum; import aiyh.utils.apirequest.mapper.DataSourceMapper; -import aiyh.utils.apirequest.pojo.ApiRequestMain; -import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; +import aiyh.utils.apirequest.mapsturct.BeanMapper; import weaver.workflow.workflow.WorkflowVersion; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; /** *

数据来源为流程的处理方法实现

@@ -33,43 +34,62 @@ public class WorkflowDataHandler implements IDataSourceHandler { private final AbstractFactory factory = new AbstractFactoryImpl(); @Override - public ParamConfigInfo parseDataSource(ApiRequestMain apiRequestMain) { - String workflowId = apiRequestMain.getWorkflowType(); + public ParamConfigInfo parseDataSource(ApiRequestData apiRequestData) { + String workflowId = apiRequestData.getWorkflowType(); String workflowVersionIds = WorkflowVersion.getVersionStringByWfid(workflowId); String workflowTable = mapper.selectWorkflowTableById(workflowVersionIds.split(",")); - if("".equals(apiRequestMain.getRequestId()) || Objects.isNull(apiRequestMain.getRequestId())){ - throw new RuntimeException("数据来源为流程时,流程的requestId为必要参数!"); + ApiBaseInfo apiBaseInfo = apiRequestData.getApiBaseInfo(); + if (apiBaseInfo == null) { + throw new RuntimeException("The mandatory parameter is ApiBaseInfo empty"); } - Map mainData = mapper.selectMainData(workflowTable, apiRequestMain.getRequestId()); - ParamConfigInfo paramConfigInfo = Util.copyBeanBaseField(apiRequestMain, new ParamConfigInfo()); - List paramDetailList = apiRequestMain.getParamDetailList(); + Map mainData = mapper.selectMainData(workflowTable, apiBaseInfo.getRequestId()); // 明细请求模式,单挑明细 当做请求参数进行一次请求 - if (apiRequestMain.getParamRequestType() == 1) { - List> lists = parseValueForDetail(apiRequestMain, mainData); + if (apiRequestData.getParamRequestType() == 1) { + List> lists = parseValueForDetail(apiRequestData, mainData); } else { // 默认模式 } - return paramConfigInfo; + return null; } - public List> parseValueForDetail(ApiRequestMain apiRequestMain, Map mainData) { - String requestDetailTableName = apiRequestMain.getRequestDetailTableName(); + /** + * 查询流程明细表数据,并通过明细表数据解析请求参数 + * @param apiRequestData api请求配置参数对象 + * @param mainData 流程主表数据信息 + * @return api请求参数信息 + */ + public List> parseValueForDetail(ApiRequestData apiRequestData, Map mainData) { + String requestDetailTableName = apiRequestData.getRequestDetailTableName(); List> detailList = mapper.selectDetailData(requestDetailTableName, String.valueOf(mainData.get("id"))); - List paramDetailList = apiRequestMain.getParamDetailList(); +// 获取api请求配置明细表配置信息 + List paramDetailList = apiRequestData.getParamDetailList(); +// 创建参数处理对象 ParamValueRuleHandlerFactory paramHandlerFactory = factory.createParamHandlerFactory(ParamValueRuleHandlerFactory.class); + ParamTypeHandlerFactory paramTypeHandlerFactory = factory.createParamHandlerFactory(ParamTypeHandlerFactory.class); + List> result = new ArrayList<>(); + Map dataMap = new HashMap<>(8); + dataMap.put("main", mainData); + dataMap.put("requestId", apiRequestData.getApiBaseInfo().getRequestId()); + dataMap.put("workflowId", apiRequestData.getApiBaseInfo().getWorkflowId()); + dataMap.put("user", apiRequestData.getApiBaseInfo().getUser()); for (Map detail : detailList) { - Map dataMap = new HashMap<>(8); - dataMap.put("main", mainData); dataMap.put("detail", detail); - for (ApiRequestParamDetail paramDetail : paramDetailList) { + List paramInfoList = new ArrayList<>(); + for (ApiRequestParamData paramDetail : paramDetailList) { ParamValueRuleEnum paramValueRuleEnum = ParamValueRuleEnum.get(paramDetail.getValueRule()); + ParamTypeEnum paramTypeEnum = ParamTypeEnum.get(paramDetail.getParamType()); IParamValueRuleHandler paramHandler = paramHandlerFactory.createParamHandler(paramValueRuleEnum); - Object value = paramHandler.getValue(paramDetail, dataMap); + IParamTypeHandler paramTypeHandler = paramTypeHandlerFactory.createParamHandler(paramTypeEnum); + Object value = paramTypeHandler.getValue(paramDetail, paramHandler,dataMap); + ParamInfo paramInfo = BeanMapper.INSTANCE.apiRequestData2ParamInfo(paramDetail); + paramInfo.setParamValue(value); + paramInfoList.add(paramInfo); } + result.add(paramInfoList); } - return null; + return result; } public List parseValueForDefault() { diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/BooleanTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/BooleanTypeHandler.java index 4a696e9..b792b04 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/BooleanTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/BooleanTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

boolean参数类型处理器

@@ -11,8 +15,11 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class BooleanTypeHandler implements IParamTypeHandler { + + @Override - public Boolean getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { + Object value = paramValueRuleHandler.getValue(paramData, dataMap); return Boolean.parseBoolean(String.valueOf(value)); } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/DoubleTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/DoubleTypeHandler.java index 407249a..f4c9651 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/DoubleTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/DoubleTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

浮点数类型处理器

@@ -11,8 +15,11 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class DoubleTypeHandler implements IParamTypeHandler { + + @Override - public Double getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { + Object value = paramValueRuleHandler.getValue(paramData, dataMap); return Double.parseDouble(String.valueOf(value)); } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ListTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ListTypeHandler.java index 64d7ddb..43a2e7e 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ListTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ListTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

数组参数类型处理器

@@ -11,8 +15,9 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class ListTypeHandler implements IParamTypeHandler { + @Override - public Object getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { return null; } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/LongTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/LongTypeHandler.java index 5af20c5..30cf639 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/LongTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/LongTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

长整型数据类型处理器

@@ -12,7 +16,8 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class LongTypeHandler implements IParamTypeHandler { @Override - public Long getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { + Object value = paramValueRuleHandler.getValue(paramData, dataMap); return Long.parseLong(String.valueOf(value)); } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ObjectTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ObjectTypeHandler.java index 4a50981..4dc4db6 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ObjectTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/ObjectTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

Object参数类型处理器

@@ -11,8 +15,9 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class ObjectTypeHandler implements IParamTypeHandler { + @Override - public Object getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { return null; } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/StringTypeHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/StringTypeHandler.java index 12c8f36..d53df9e 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/StringTypeHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramtype/StringTypeHandler.java @@ -1,6 +1,10 @@ package aiyh.utils.apirequest.core.typehandler.paramtype; import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; /** *

字符串类型处理器

@@ -11,8 +15,11 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler; public class StringTypeHandler implements IParamTypeHandler { + + @Override - public String getValue(Object value) { + public Object getValue(ApiRequestParamData paramData, IParamValueRuleHandler paramValueRuleHandler, Map dataMap) { + Object value = paramValueRuleHandler.getValue(paramData, dataMap); return String.valueOf(value); } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CurrentDataTimeRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CurrentDataTimeRuleHandler.java new file mode 100644 index 0000000..2123cc7 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CurrentDataTimeRuleHandler.java @@ -0,0 +1,25 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +/** + *

当前日期时间处理

+ *

create 2022/1/27 0027 15:51

+ * + * @author EBU7-dev1-ayh + */ + + +public class CurrentDataTimeRuleHandler implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(paramInfo.getCustomerValue()); + return simpleDateFormat.format(new Date()); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CustomerSqlRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CustomerSqlRuleHandler.java index c906d13..c3743ed 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CustomerSqlRuleHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CustomerSqlRuleHandler.java @@ -2,10 +2,15 @@ package aiyh.utils.apirequest.core.typehandler.paramvalue; import aiyh.utils.Util; import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.enumtype.ParamTypeEnum; import aiyh.utils.apirequest.mapper.ParamValueParseMapper; -import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; +import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** *

自定义SQL处理器

@@ -16,14 +21,40 @@ import java.util.Map; public class CustomerSqlRuleHandler implements IParamValueRuleHandler { + public static final String SELECT = "select "; private final ParamValueParseMapper mapper = Util.getMapper(ParamValueParseMapper.class); + @Override - public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { String customerSql = paramInfo.getCustomerValue(); - if(customerSql.toLowerCase().trim().startsWith("select ".toLowerCase())){ - return mapper.selectCustomerSql(customerSql, dataMap); - }else { - throw new RuntimeException("违规SQL,自定义SQL只支持查询SQL,不支持其他SQL操作!"); + String pattern = "^(\\$:)(?\\w*)\\{(?[\\S\\s]+)}"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(customerSql.trim()); + if (matcher.find()) { + String sqlStr = matcher.group("sql"); + String name = matcher.group("name"); + if (sqlStr.toLowerCase().trim().startsWith(SELECT.toLowerCase())) { + if (Objects.isNull(name) || "".equals(name)) { + return mapper.selectCustomerSql(sqlStr, dataMap); + } else { +// 起名字的SQL需要做特殊处理 + ParamTypeEnum paramTypeEnum = ParamTypeEnum.get(paramInfo.getParamType()); +// 如果参数类型是List类型,则需要查询list类型出来,并且将list数据存储在dataMap中 + if (paramTypeEnum == ParamTypeEnum.LIST_TYPE) { + List> maps = mapper.selectListByCustomerSql(sqlStr, dataMap); + dataMap.put(name, maps); + } +// 如果是Object类型,则需要查询Map类型的数据,并将数据保存在dataMap中 + if (paramTypeEnum == ParamTypeEnum.OBJECT_TYPE) { + Map dataResult = mapper.selectMapByCustomerSql(sqlStr, dataMap); + dataMap.put(name, dataResult); + return null; + } + } + } else { + throw new RuntimeException("违规SQL,自定义SQL只支持查询SQL,不支持其他SQL操作!"); + } } + return null; } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/FixedValueRuleHandle.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/FixedValueRuleHandle.java index 751b7b3..6025ba2 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/FixedValueRuleHandle.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/FixedValueRuleHandle.java @@ -1,6 +1,7 @@ package aiyh.utils.apirequest.core.typehandler.paramvalue; import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; import java.util.Map; @@ -16,7 +17,7 @@ import java.util.Map; public class FixedValueRuleHandle implements IParamValueRuleHandler { @Override - public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { return paramInfo.getCustomerValue(); } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/NullValueRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/NullValueRuleHandler.java index d4ef605..5a0a876 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/NullValueRuleHandler.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/NullValueRuleHandler.java @@ -1,6 +1,7 @@ package aiyh.utils.apirequest.core.typehandler.paramvalue; import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; import java.util.Map; @@ -16,7 +17,7 @@ import java.util.Map; public class NullValueRuleHandler implements IParamValueRuleHandler { @Override - public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { return null; } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RandomValueRuleHandle.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RandomValueRuleHandle.java new file mode 100644 index 0000000..a3dee4c --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RandomValueRuleHandle.java @@ -0,0 +1,47 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.Util; +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + *

随机值处理器

+ *

create 2022/1/27 0027 17:28

+ * + * @author EBU7-dev1-ayh + */ + + +public class RandomValueRuleHandle implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + String customerValue = paramInfo.getCustomerValue(); + String pattern = "\\$\\{number:(?(\\d)+)}"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(customerValue.trim()); + if (matcher.find()) { + int length = Integer.parseInt(matcher.group("length")); + return Util.randomNumber(length); + } + pattern = "\\$\\{string:(?(\\\\d)+)}"; + compile = Pattern.compile(pattern); + matcher = compile.matcher(customerValue.trim()); + if (matcher.find()) { + int length = Integer.parseInt(matcher.group("length")); + return Util.randomString(length); + } + pattern = "\\$\\{letter:(?(\\\\d)+)}"; + compile = Pattern.compile(pattern); + matcher = compile.matcher(customerValue.trim()); + if (matcher.find()) { + int length = Integer.parseInt(matcher.group("length")); + return Util.randomLetter(length); + } + return Util.randomNumber(6); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RequestIdRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RequestIdRuleHandler.java new file mode 100644 index 0000000..f823dad --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/RequestIdRuleHandler.java @@ -0,0 +1,22 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; + +import java.util.Map; + +/** + *

流程请求id值处理

+ *

create 2022/1/27 0027 15:53

+ * + * @author EBU7-dev1-ayh + */ + + +public class RequestIdRuleHandler implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + return dataMap.get("requestId"); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SqlFieldRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SqlFieldRuleHandler.java new file mode 100644 index 0000000..3aede2d --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SqlFieldRuleHandler.java @@ -0,0 +1,21 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; + +/** + *

SQL字段值处理

+ *

create 2022/2/8 0008 11:40

+ * + * @author EBU7-dev1-ayh + */ + + +public class SqlFieldRuleHandler implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + return null; + } +} diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SystemFieldValueRuleHandle.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SystemFieldValueRuleHandle.java index 6474b89..144ca67 100644 --- a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SystemFieldValueRuleHandle.java +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SystemFieldValueRuleHandle.java @@ -1,6 +1,7 @@ package aiyh.utils.apirequest.core.typehandler.paramvalue; import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; import java.util.Map; @@ -14,9 +15,16 @@ import java.util.Map; public class SystemFieldValueRuleHandle implements IParamValueRuleHandler { + private String mainTableName = "workflow main table"; + @Override - public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { - Map main = (Map) dataMap.get("main"); - return main.get(paramInfo.getSystemFieldName()); + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + if (paramInfo.getFieldTableName() != null && mainTableName.equalsIgnoreCase(paramInfo.getFieldTableName())) { + Map main = (Map) dataMap.get("main"); + return main.get(paramInfo.getSystemFieldName()); + } else { + Map detail = (Map) dataMap.get("detail"); + return detail.get(paramInfo.getSystemFieldName()); + } } } diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/TimeStampRuleHandler.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/TimeStampRuleHandler.java new file mode 100644 index 0000000..ec55336 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/TimeStampRuleHandler.java @@ -0,0 +1,21 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; + +import java.util.Map; + +/** + *

当前时间戳处理

+ *

create 2022/2/8 0008 11:38

+ * + * @author EBU7-dev1-ayh + */ + + +public class TimeStampRuleHandler implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + return System.currentTimeMillis(); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/WorkflowIdRuleHandle.java b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/WorkflowIdRuleHandle.java new file mode 100644 index 0000000..8d44e1c --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/WorkflowIdRuleHandle.java @@ -0,0 +1,22 @@ +package aiyh.utils.apirequest.core.typehandler.paramvalue; + +import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; + +import java.util.Map; + +/** + *

流程类型值处理规则类

+ *

create 2022/1/27 0027 17:27

+ * + * @author EBU7-dev1-ayh + */ + + +public class WorkflowIdRuleHandle implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamData paramInfo, Map dataMap) { + return dataMap.get("workflowId"); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/entity/ApiBaseInfo.java b/src/main/java/aiyh/utils/apirequest/entity/ApiBaseInfo.java new file mode 100644 index 0000000..38cfb30 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/entity/ApiBaseInfo.java @@ -0,0 +1,32 @@ +package aiyh.utils.apirequest.entity; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import weaver.hrm.User; + +/** + *

api请求参数所需的基本参数

+ *

create 2022/1/28 0028 9:16

+ * + * @author EBU7-dev1-ayh + */ + + +@Setter +@Getter +@ToString +public class ApiBaseInfo { + /** + * 流程requestId + */ + private String requestId; + /** + * 流程id + */ + private String workflowId; + /** + * 当前请求用户 + */ + private User user; +} diff --git a/src/main/java/aiyh/utils/apirequest/entity/ApiRequestData.java b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestData.java new file mode 100644 index 0000000..1a8c05e --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestData.java @@ -0,0 +1,85 @@ +package aiyh.utils.apirequest.entity; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +/** + *

请求参数必要类

+ *

create 2022/1/27 0027 16:07

+ * + * @author EBU7-dev1-ayh + */ + +@Getter +@Setter +@ToString +public class ApiRequestData { + + /** + * 主表id + */ + private Integer id; + /** + * api地址 + */ + private String apiUrl; + /** + * 测试环境api地址 + */ + private String testApiUrl; + /** + * 请求方式 + */ + private Integer requestType; + /** + * api启用类型 + */ + private Integer apiType; + /** + * 数据来源 + */ + private Integer dataSource; + /** + * api接口描述 + */ + private String apiDesc; + /** + * 流程类型 + */ + private String workflowType; + /** + * 建模表表名 + */ + private String modelTableName; + /** + * 参数请求方式 + */ + private Integer paramRequestType; + /** + * 请求参数的数据来源,适用于参数请求方式为明细表模式 + */ + private String requestDetailTableName; + + /** + * 唯一标识 + */ + private String onlyMark; + /** + * 请求参数信息 + */ + private List paramDetailList; + /** + * 请求头信息 + */ + private List heardDetailList; + + /** + * api请求基本信息 + */ + private ApiBaseInfo apiBaseInfo; + + +} diff --git a/src/main/java/aiyh/utils/apirequest/entity/ApiRequestHeardData.java b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestHeardData.java new file mode 100644 index 0000000..f73369a --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestHeardData.java @@ -0,0 +1,14 @@ +package aiyh.utils.apirequest.entity; + +import aiyh.utils.apirequest.pojo.ApiRequestHeardDetail; + +/** + *

api 请求头参数业务处理对象

+ *

create 2022/2/8 0008 11:15

+ * + * @author EBU7-dev1-ayh + */ + + +public class ApiRequestHeardData extends ApiRequestHeardDetail { +} diff --git a/src/main/java/aiyh/utils/apirequest/entity/ApiRequestParamData.java b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestParamData.java new file mode 100644 index 0000000..2374c0b --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/entity/ApiRequestParamData.java @@ -0,0 +1,14 @@ +package aiyh.utils.apirequest.entity; + +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; + +/** + *

Api 请求参数配置业务对象

+ *

create 2022/1/28 0028 12:09

+ * + * @author EBU7-dev1-ayh + */ + + +public class ApiRequestParamData extends ApiRequestParamDetail { +} diff --git a/src/main/java/aiyh/utils/apirequest/entity/ParamConfigInfo.java b/src/main/java/aiyh/utils/apirequest/entity/ParamConfigInfo.java index 1fcfb86..d2abbb7 100644 --- a/src/main/java/aiyh/utils/apirequest/entity/ParamConfigInfo.java +++ b/src/main/java/aiyh/utils/apirequest/entity/ParamConfigInfo.java @@ -13,8 +13,11 @@ import java.util.List; @Data public class ParamConfigInfo { - private String requestId; + + /** + * 配置主表id + */ private Integer id; /** * api地址 @@ -28,10 +31,7 @@ public class ParamConfigInfo { * 请求方式 */ private Integer requestType; - /** - * api启用类型 - */ - private Integer apiType; + /** * 数据来源 */ @@ -57,10 +57,7 @@ public class ParamConfigInfo { */ private String requestDetailTableName; - /** - * 唯一标识 - */ - private String onlyMark; + /** * 参数信息 */ diff --git a/src/main/java/aiyh/utils/apirequest/enumtype/ParamTypeEnum.java b/src/main/java/aiyh/utils/apirequest/enumtype/ParamTypeEnum.java index afb684a..708436b 100644 --- a/src/main/java/aiyh/utils/apirequest/enumtype/ParamTypeEnum.java +++ b/src/main/java/aiyh/utils/apirequest/enumtype/ParamTypeEnum.java @@ -1,5 +1,9 @@ package aiyh.utils.apirequest.enumtype; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + /** *

参数类型枚举

*

create 2022/1/25 0025 10:36

@@ -9,4 +13,55 @@ package aiyh.utils.apirequest.enumtype; public enum ParamTypeEnum { + + + /** + * string 类型 + */ + STRING_TYPE(0), + /** + * long 类型 + */ + LONG_TYPE(1), + /** + * boolean类型 + */ + BOOLEAN_TYPE(2), + /** + * object 类型 + */ + OBJECT_TYPE(3), + /** + * list类型 + */ + LIST_TYPE(4), + /** + * double 类型 + */ + DOUBLE_TYPE(5); + + + private static final Map LOOKUP; + + static { + LOOKUP = new HashMap<>(); + for (ParamTypeEnum enumType : EnumSet.allOf(ParamTypeEnum.class)) { + LOOKUP.put(enumType.getValue(), enumType); + } + } + + private final int value; + + ParamTypeEnum(int value) { + this.value = value; + } + + public static ParamTypeEnum get(int value) { + return LOOKUP.get(value); + } + + public int getValue() { + return this.value; + } + } diff --git a/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java b/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java index 83be7a1..443c971 100644 --- a/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java +++ b/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java @@ -5,6 +5,7 @@ import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; import aiyh.utils.annotation.recordset.SqlString; +import java.util.List; import java.util.Map; /** @@ -26,4 +27,26 @@ public interface ParamValueParseMapper { @Select(custom = true) @CaseConversion(false) public String selectCustomerSql(@SqlString String sql, Map map); + + + /** + * 自定义查询SQL对象 + * @param sqlStr 自定义SQL字符串 + * @param dataMap 参数 + * @return 查询到的数据 + */ + @Select(custom = true) + @CaseConversion(false) + public Map selectMapByCustomerSql(@SqlString String sqlStr, Map dataMap); + + + /** + * 自定义查询SQL集合 + * @param sql 自定义SQL字符串 + * @param dataMap 参数 + * @return 查询到的数据 + */ + @Select(custom = true) + @CaseConversion(false) + public List> selectListByCustomerSql(@SqlString String sql, Map dataMap); } diff --git a/src/main/java/aiyh/utils/apirequest/mapsturct/BeanMapper.java b/src/main/java/aiyh/utils/apirequest/mapsturct/BeanMapper.java new file mode 100644 index 0000000..4d4ab57 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/mapsturct/BeanMapper.java @@ -0,0 +1,106 @@ +package aiyh.utils.apirequest.mapsturct; + +import aiyh.utils.apirequest.entity.ApiRequestData; +import aiyh.utils.apirequest.entity.ApiRequestHeardData; +import aiyh.utils.apirequest.entity.ApiRequestParamData; +import aiyh.utils.apirequest.entity.ParamInfo; +import aiyh.utils.apirequest.pojo.ApiRequestHeardDetail; +import aiyh.utils.apirequest.pojo.ApiRequestMain; +import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + *

实体类映射

+ *

create 2022/1/28 0028 9:34

+ * + * @author EBU7-dev1-ayh + */ + +/* + 引入maven坐标 + + 1.4.2.Final + + + org.mapstruct + mapstruct-jdk8 + ${org.mapstruct.version} + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + */ + +@Mapper +public interface BeanMapper { + static final BeanMapper INSTANCE = Mappers.getMapper(BeanMapper.class); + + + /** + * 将ApiRequestMain对象转化为APIRequestData对象 + * + * @param requestMain 原对象 + * @return 复制转化后的对象 + */ + + @Mapping(target = "apiBaseInfo", ignore = true) + @Mapping(target = "paramDetailList", source = "paramDetailList") + @Mapping(target = "heardDetailList", source = "heardDetailList") + public ApiRequestData apiRequestMain2Data(ApiRequestMain requestMain); + + /** + * 将ApiRequestParamDetail 对象转换为ApiRequestParamData对象 + * + * @param paramDetail 原对象 + * @return 目标对象 + */ + public ApiRequestParamData apiRequestDetail2Data(ApiRequestParamDetail paramDetail); + + /** + * 批量转换 + * + * @param list 批量原对象 + * @return 目标对象集合 + */ + public List apiRequestDetailList2Data(List list); + + /** + * 将ApiRequestHeardDetail对象转换为APIRequestHeardData对象 + * + * @param heardDetail 原对象 + * @return 目标对象 + */ + public ApiRequestHeardData apiRequestHeard2Data(ApiRequestHeardDetail heardDetail); + + /** + * 批量转换 + * + * @param list 原对象集合 + * @return 目标对象集合 + */ + public List apiRequestHeardList2Data(List list); + + + /** + * apiRequestParamData 对象转为paramInfo对象 + * + * @param paramData 原对象 + * @return 转换后的对象 + */ + @Mappings({ + @Mapping(target = "lineNum", source = "lineNum"), + @Mapping(target = "paramName", source = "paramName"), + @Mapping(target = "parentLine", source = "parentLine"), + @Mapping(target = "paramValue", ignore = true), + @Mapping(target = "childList", ignore = true) + }) + public ParamInfo apiRequestData2ParamInfo(ApiRequestParamData paramData); +} diff --git a/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestMain.java b/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestMain.java index 91b3796..27cb857 100644 --- a/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestMain.java +++ b/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestMain.java @@ -14,10 +14,7 @@ import java.util.List; @Data public class ApiRequestMain { - /** - * 流程请求id - */ - private String requestId; + /** * 主表id */ @@ -75,4 +72,5 @@ public class ApiRequestMain { * 请求头信息 */ private List heardDetailList; + } diff --git a/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestParamDetail.java b/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestParamDetail.java index 1f51cda..9fc786e 100644 --- a/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestParamDetail.java +++ b/src/main/java/aiyh/utils/apirequest/pojo/ApiRequestParamDetail.java @@ -2,8 +2,6 @@ package aiyh.utils.apirequest.pojo; import lombok.Data; -import java.util.List; - /** *

*

create 2022/1/23 0023 18:04

@@ -59,4 +57,9 @@ public class ApiRequestParamDetail { private Integer enableParam; + /** + * 字段所在表 + */ + private String fieldTableName; + } diff --git a/src/main/java/aiyh/utils/apirequest/service/ApiRequestService.java b/src/main/java/aiyh/utils/apirequest/service/ApiRequestService.java index 0288f86..c67c420 100644 --- a/src/main/java/aiyh/utils/apirequest/service/ApiRequestService.java +++ b/src/main/java/aiyh/utils/apirequest/service/ApiRequestService.java @@ -5,15 +5,16 @@ import aiyh.utils.apirequest.core.factory.AbstractFactory; import aiyh.utils.apirequest.core.factory.AbstractFactoryImpl; import aiyh.utils.apirequest.core.factory.DataSourceHandlerFactory; import aiyh.utils.apirequest.core.typehandler.IDataSourceHandler; -import aiyh.utils.apirequest.entity.ParamConfigInfo; -import aiyh.utils.apirequest.entity.ParamInfo; -import aiyh.utils.apirequest.entity.ParseAfterData; +import aiyh.utils.apirequest.entity.*; import aiyh.utils.apirequest.enumtype.DataSourceRuleEnum; import aiyh.utils.apirequest.interceptor.ApiRequestInterceptor; import aiyh.utils.apirequest.mapper.ApiRequestMapper; +import aiyh.utils.apirequest.mapsturct.BeanMapper; import aiyh.utils.apirequest.pojo.ApiRequestHeardDetail; import aiyh.utils.apirequest.pojo.ApiRequestMain; import aiyh.utils.apirequest.pojo.ApiRequestParamDetail; +import lombok.Data; +import lombok.Setter; import java.util.List; import java.util.Objects; @@ -27,7 +28,8 @@ import java.util.concurrent.atomic.AtomicReference; * @author EBU7-dev1-ayh */ - +@Setter +@Data public class ApiRequestService { /** @@ -39,8 +41,8 @@ public class ApiRequestService { * 查询数据库数据 */ private final ApiRequestMapper mapper; + private ApiBaseInfo apiBaseInfo; - private String requestId; /** * @param interceptor 拦截器 @@ -86,8 +88,9 @@ public class ApiRequestService { DataSourceHandlerFactory dataSourceHandlerFactory = abstractFactory.createParamHandlerFactory(DataSourceHandlerFactory.class); DataSourceRuleEnum dataSourceRuleEnum = DataSourceRuleEnum.get(apiRequestMain.getDataSource()); IDataSourceHandler paramHandler = dataSourceHandlerFactory.createParamHandler(dataSourceRuleEnum); - apiRequestMain.setRequestId(this.requestId); - AtomicReference paramConfigInfo = new AtomicReference<>(paramHandler.parseDataSource(apiRequestMain)); + ApiRequestData apiRequestData = BeanMapper.INSTANCE.apiRequestMain2Data(apiRequestMain); + apiRequestData.setApiBaseInfo(this.apiBaseInfo); + AtomicReference paramConfigInfo = new AtomicReference<>(paramHandler.parseDataSource(apiRequestData)); // TODO 解析配置表中的参数 Optional.ofNullable(interceptor).map(interceptor -> { Optional.ofNullable(interceptor.parseAfter(paramConfigInfo.get())).map(v -> { @@ -116,8 +119,8 @@ public class ApiRequestService { parentId -> Objects.isNull(parentId) || parentId == -1 || parentId == 0); parseParamConfig.get().setParamInfoList(treeParamList); // TODO 将树形结构组合为最终的请求参数结构 - Optional.ofNullable(interceptor).map(interceptor->{ - Optional.ofNullable(interceptor.parseTreeAfter(parseParamConfig.get())).map(v->{ + Optional.ofNullable(interceptor).map(interceptor -> { + Optional.ofNullable(interceptor.parseTreeAfter(parseParamConfig.get())).map(v -> { parseParamConfig.set(v); return v; }); @@ -126,12 +129,4 @@ public class ApiRequestService { return null; } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } } diff --git a/src/main/java/aiyh/utils/apirequest/service/ParseParamValue.java b/src/main/java/aiyh/utils/apirequest/service/ParseParamValue.java index 5a01154..e199595 100644 --- a/src/main/java/aiyh/utils/apirequest/service/ParseParamValue.java +++ b/src/main/java/aiyh/utils/apirequest/service/ParseParamValue.java @@ -24,6 +24,7 @@ public class ParseParamValue { DataSourceHandlerFactory dataSourceHandlerFactory = abstractFactory.createParamHandlerFactory(DataSourceHandlerFactory.class); DataSourceRuleEnum dataSourceRuleEnum = DataSourceRuleEnum.get(apiRequestMain.getDataSource()); IDataSourceHandler paramHandler = dataSourceHandlerFactory.createParamHandler(dataSourceRuleEnum); - return paramHandler.parseDataSource(apiRequestMain); +// return paramHandler.parseDataSource(apiRequestMain); + return null; } } diff --git a/src/main/java/com/api/aiyh_pcn/async_organization/ExportExcel.java b/src/main/java/com/api/aiyh_pcn/async_organization/ExportExcel.java index abcd3a5..b462c59 100644 --- a/src/main/java/com/api/aiyh_pcn/async_organization/ExportExcel.java +++ b/src/main/java/com/api/aiyh_pcn/async_organization/ExportExcel.java @@ -1,7 +1,6 @@ package com.api.aiyh_pcn.async_organization; import aiyh.utils.zwl.common.ToolUtil; -import com.ibm.icu.text.SimpleDateFormat; import km.org.apache.poi.hssf.usermodel.HSSFCellStyle; import km.org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.*; @@ -22,6 +21,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; diff --git a/src/test/java/utilTest/UtilTest.java b/src/test/java/utilTest/UtilTest.java index eb0a96c..b5e9421 100644 --- a/src/test/java/utilTest/UtilTest.java +++ b/src/test/java/utilTest/UtilTest.java @@ -16,12 +16,10 @@ import com.drew.metadata.Directory; import com.drew.metadata.Metadata; import com.drew.metadata.Tag; import com.engine.doc.cmd.secCategoryList.DocSecCategoryAddCmd; -import com.weaver.general.GCONST; import entity.ImageInfo; import mybatisTest.mapper.IMapperTest; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.*; -import org.apache.log4j.spi.Configurator; import org.junit.Before; import org.junit.Test; import utilTest.entity.TestTreeEntity; @@ -29,11 +27,17 @@ import weaver.conn.RecordSet; import weaver.hrm.User; import weaver.hrm.moduledetach.ManageDetachComInfo; +import javax.xml.transform.Source; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.io.*; import java.lang.reflect.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; /** * @author EBU7-dev1-ayh @@ -509,4 +513,63 @@ public class UtilTest { log.warn("我是警告-------------->"); System.out.println(log.getEffectiveLevel()); } + + @Test + public void testClass() throws IntrospectionException, NoSuchFieldException { + ApiRequestMain apiRequestMain = new ApiRequestMain(); + + BeanInfo beanInfo = Introspector.getBeanInfo(ApiRequestMain.class,Object.class); + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { + System.out.println(propertyDescriptor.getName()); + System.out.println(apiRequestMain.getClass().getDeclaredField(propertyDescriptor.getName())); + ; + System.out.println("====================================="); + } + } + + @Test + public void testClassM() throws NoSuchFieldException { + Class clazz = A.class; + Field field = clazz.getField("list"); + ParameterizedType type = (ParameterizedType) field.getGenericType(); + Stream.of(type.getActualTypeArguments()).forEach(System.out::println); + + field = clazz.getField("list1"); + type = (ParameterizedType) field.getGenericType(); + Stream.of(type.getActualTypeArguments()).forEach(v->{ + ParameterizedType v1 = (ParameterizedType)v; + for (Type actualTypeArgument : v1.getActualTypeArguments()) { + System.out.println(actualTypeArgument); + } + }); + } + + class A { + public List list = new ArrayList<>(); + + public List> list1 = new ArrayList<>(); + } + @Test + public void testRandom(){ + String pattern = "\\$\\{number:(?(\\d)+)}"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(" ${number:10}".trim()); + if(matcher.find()){ + System.out.println(matcher.group("length")); + System.out.println(Util.randomNumber(Integer.parseInt(matcher.group("length")))); + } + } + + @Test + public void testReg(){ + String str = "$:{select * from #{alal} and ${sjls}}"; + String pattern = "^(\\$:)(?\\w*)\\{(?[\\S\\s]+)}"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(str.trim()); + if(matcher.find()){ + System.out.println(matcher.group("name")); + System.out.println(matcher.group("sql")); + } + } }