工具类修改

dev
IT-xiaoXiong 2022-02-09 16:46:39 +08:00
parent d161236561
commit df192939ce
39 changed files with 804 additions and 96 deletions

View File

@ -9,6 +9,7 @@
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
<root url="file://$MODULE_DIR$/src/main/resources" />
<root url="file://$MODULE_DIR$/target/generated-sources/annotations" />
</sourceRoots>
</configuration>
</facet>
@ -20,16 +21,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" generated="true" />
<excludeFolder url="file://$MODULE_DIR$/log" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="classbean" level="project" />
<orderEntry type="library" exported="" name="classbean" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.22" level="project" />
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct-jdk8:1.4.2.Final" level="project" />
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.4.2.Final" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.7.12" level="project" />
<orderEntry type="library" name="Maven: com.drewnoakes:metadata-extractor:2.16.0" level="project" />
<orderEntry type="library" name="Maven: com.adobe.xmp:xmpcore:6.1.11" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-excelant:3.12" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi:3.12" level="project" />

View File

@ -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)
}
})
}

35
pom.xml
View File

@ -32,6 +32,7 @@
<lombok.version>1.18.22</lombok.version>
<hutool.version>5.7.12</hutool.version>
<metadata-extractor.version>2.16.0</metadata-extractor.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
</properties>
@ -43,6 +44,17 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<!-- 糊涂工具包,法大大验签指定版本-->
<dependency>
<groupId>cn.hutool</groupId>
@ -92,17 +104,24 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<!-- <annotationProcessors>-->
<!-- <annotationProcessor>-->
<!-- <groupId>org.projectors</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- <version>${lombok.version}</version>-->
<!-- </annotationProcessor>-->
<!-- </annotationProcessors>-->
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -1,5 +1,9 @@
package aiyh.utils.apirequest.core.typehandler;
import aiyh.utils.apirequest.entity.ApiRequestParamData;
import java.util.Map;
/**
* <p></p>
* <p>create 2022/1/22 0022 20:21</p>
@ -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<String, Object> dataMap);
}

View File

@ -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<String,Object> dataMap);
public Object getValue(ApiRequestParamData paramInfo, Map<String,Object> dataMap);
}

View File

@ -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;
}
}

View File

@ -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;
/**
* <p></p>
@ -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<String, Object> mainData = mapper.selectMainData(workflowTable, apiRequestMain.getRequestId());
ParamConfigInfo paramConfigInfo = Util.copyBeanBaseField(apiRequestMain, new ParamConfigInfo());
List<ApiRequestParamDetail> paramDetailList = apiRequestMain.getParamDetailList();
Map<String, Object> mainData = mapper.selectMainData(workflowTable, apiBaseInfo.getRequestId());
// 明细请求模式,单挑明细 当做请求参数进行一次请求
if (apiRequestMain.getParamRequestType() == 1) {
List<List<ParamInfo>> lists = parseValueForDetail(apiRequestMain, mainData);
if (apiRequestData.getParamRequestType() == 1) {
List<List<ParamInfo>> lists = parseValueForDetail(apiRequestData, mainData);
} else {
// 默认模式
}
return paramConfigInfo;
return null;
}
public List<List<ParamInfo>> parseValueForDetail(ApiRequestMain apiRequestMain, Map<String, Object> mainData) {
String requestDetailTableName = apiRequestMain.getRequestDetailTableName();
/**
*
* @param apiRequestData api
* @param mainData
* @return api
*/
public List<List<ParamInfo>> parseValueForDetail(ApiRequestData apiRequestData, Map<String, Object> mainData) {
String requestDetailTableName = apiRequestData.getRequestDetailTableName();
List<Map<String, Object>> detailList = mapper.selectDetailData(requestDetailTableName, String.valueOf(mainData.get("id")));
List<ApiRequestParamDetail> paramDetailList = apiRequestMain.getParamDetailList();
// 获取api请求配置明细表配置信息
List<ApiRequestParamData> paramDetailList = apiRequestData.getParamDetailList();
// 创建参数处理对象
ParamValueRuleHandlerFactory paramHandlerFactory = factory.createParamHandlerFactory(ParamValueRuleHandlerFactory.class);
for (Map<String, Object> detail : detailList) {
ParamTypeHandlerFactory paramTypeHandlerFactory = factory.createParamHandlerFactory(ParamTypeHandlerFactory.class);
List<List<ParamInfo>> result = new ArrayList<>();
Map<String, Object> 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<String, Object> detail : detailList) {
dataMap.put("detail", detail);
for (ApiRequestParamDetail paramDetail : paramDetailList) {
List<ParamInfo> 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<ParamInfo> parseValueForDefault() {

View File

@ -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;
/**
* <p>boolean</p>
@ -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<String, Object> dataMap) {
Object value = paramValueRuleHandler.getValue(paramData, dataMap);
return Boolean.parseBoolean(String.valueOf(value));
}
}

View File

@ -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;
/**
* <p></p>
@ -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<String, Object> dataMap) {
Object value = paramValueRuleHandler.getValue(paramData, dataMap);
return Double.parseDouble(String.valueOf(value));
}
}

View File

@ -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;
/**
* <p></p>
@ -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<String, Object> dataMap) {
return null;
}
}

View File

@ -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;
/**
* <p></p>
@ -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<String, Object> dataMap) {
Object value = paramValueRuleHandler.getValue(paramData, dataMap);
return Long.parseLong(String.valueOf(value));
}
}

View File

@ -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;
/**
* <p>Object</p>
@ -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<String, Object> dataMap) {
return null;
}
}

View File

@ -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;
/**
* <p></p>
@ -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<String, Object> dataMap) {
Object value = paramValueRuleHandler.getValue(paramData, dataMap);
return String.valueOf(value);
}
}

View File

@ -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;
/**
* <p></p>
* <p>create 2022/1/27 0027 15:51</p>
*
* @author EBU7-dev1-ayh
*/
public class CurrentDataTimeRuleHandler implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(paramInfo.getCustomerValue());
return simpleDateFormat.format(new Date());
}
}

View File

@ -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;
/**
* <p>SQL</p>
@ -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<String, Object> dataMap) {
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
String customerSql = paramInfo.getCustomerValue();
if(customerSql.toLowerCase().trim().startsWith("select ".toLowerCase())){
return mapper.selectCustomerSql(customerSql, dataMap);
String pattern = "^(\\$:)(?<name>\\w*)\\{(?<sql>[\\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<Map<String, Object>> maps = mapper.selectListByCustomerSql(sqlStr, dataMap);
dataMap.put(name, maps);
}
// 如果是Object类型则需要查询Map类型的数据并将数据保存在dataMap中
if (paramTypeEnum == ParamTypeEnum.OBJECT_TYPE) {
Map<String, Object> dataResult = mapper.selectMapByCustomerSql(sqlStr, dataMap);
dataMap.put(name, dataResult);
return null;
}
}
} else {
throw new RuntimeException("违规SQL自定义SQL只支持查询SQL不支持其他SQL操作!");
}
}
return null;
}
}

View File

@ -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<String, Object> dataMap) {
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return paramInfo.getCustomerValue();
}
}

View File

@ -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<String, Object> dataMap) {
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return null;
}
}

View File

@ -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;
/**
* <p></p>
* <p>create 2022/1/27 0027 17:28</p>
*
* @author EBU7-dev1-ayh
*/
public class RandomValueRuleHandle implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
String customerValue = paramInfo.getCustomerValue();
String pattern = "\\$\\{number:(?<length>(\\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:(?<length>(\\\\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:(?<length>(\\\\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);
}
}

View File

@ -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;
/**
* <p>id</p>
* <p>create 2022/1/27 0027 15:53</p>
*
* @author EBU7-dev1-ayh
*/
public class RequestIdRuleHandler implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return dataMap.get("requestId");
}
}

View File

@ -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;
/**
* <p>SQL</p>
* <p>create 2022/2/8 0008 11:40</p>
*
* @author EBU7-dev1-ayh
*/
public class SqlFieldRuleHandler implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return null;
}
}

View File

@ -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<String, Object> dataMap) {
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
if (paramInfo.getFieldTableName() != null && mainTableName.equalsIgnoreCase(paramInfo.getFieldTableName())) {
Map<String, Object> main = (Map<String, Object>) dataMap.get("main");
return main.get(paramInfo.getSystemFieldName());
} else {
Map<String, Object> detail = (Map<String, Object>) dataMap.get("detail");
return detail.get(paramInfo.getSystemFieldName());
}
}
}

View File

@ -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;
/**
* <p></p>
* <p>create 2022/2/8 0008 11:38</p>
*
* @author EBU7-dev1-ayh
*/
public class TimeStampRuleHandler implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return System.currentTimeMillis();
}
}

View File

@ -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;
/**
* <p></p>
* <p>create 2022/1/27 0027 17:27</p>
*
* @author EBU7-dev1-ayh
*/
public class WorkflowIdRuleHandle implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamData paramInfo, Map<String, Object> dataMap) {
return dataMap.get("workflowId");
}
}

View File

@ -0,0 +1,32 @@
package aiyh.utils.apirequest.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import weaver.hrm.User;
/**
* <p>api</p>
* <p>create 2022/1/28 0028 9:16</p>
*
* @author EBU7-dev1-ayh
*/
@Setter
@Getter
@ToString
public class ApiBaseInfo {
/**
* requestId
*/
private String requestId;
/**
* id
*/
private String workflowId;
/**
*
*/
private User user;
}

View File

@ -0,0 +1,85 @@
package aiyh.utils.apirequest.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
/**
* <p></p>
* <p>create 2022/1/27 0027 16:07</p>
*
* @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<ApiRequestParamData> paramDetailList;
/**
*
*/
private List<ApiRequestHeardData> heardDetailList;
/**
* api
*/
private ApiBaseInfo apiBaseInfo;
}

View File

@ -0,0 +1,14 @@
package aiyh.utils.apirequest.entity;
import aiyh.utils.apirequest.pojo.ApiRequestHeardDetail;
/**
* <p>api </p>
* <p>create 2022/2/8 0008 11:15</p>
*
* @author EBU7-dev1-ayh
*/
public class ApiRequestHeardData extends ApiRequestHeardDetail {
}

View File

@ -0,0 +1,14 @@
package aiyh.utils.apirequest.entity;
import aiyh.utils.apirequest.pojo.ApiRequestParamDetail;
/**
* <p>Api </p>
* <p>create 2022/1/28 0028 12:09</p>
*
* @author EBU7-dev1-ayh
*/
public class ApiRequestParamData extends ApiRequestParamDetail {
}

View File

@ -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;
/**
*
*/

View File

@ -1,5 +1,9 @@
package aiyh.utils.apirequest.enumtype;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* <p></p>
* <p>create 2022/1/25 0025 10:36</p>
@ -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<Integer, ParamTypeEnum> 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;
}
}

View File

@ -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<String,Object> map);
/**
* SQL
* @param sqlStr SQL
* @param dataMap
* @return
*/
@Select(custom = true)
@CaseConversion(false)
public Map<String, Object> selectMapByCustomerSql(@SqlString String sqlStr, Map<String, Object> dataMap);
/**
* SQL
* @param sql SQL
* @param dataMap
* @return
*/
@Select(custom = true)
@CaseConversion(false)
public List<Map<String,Object>> selectListByCustomerSql(@SqlString String sql, Map<String,Object> dataMap);
}

View File

@ -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;
/**
* <p></p>
* <p>create 2022/1/28 0028 9:34</p>
*
* @author EBU7-dev1-ayh
*/
/*
maven
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<!-- mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
*/
@Mapper
public interface BeanMapper {
static final BeanMapper INSTANCE = Mappers.getMapper(BeanMapper.class);
/**
* ApiRequestMainAPIRequestData
*
* @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<ApiRequestParamData> apiRequestDetailList2Data(List<ApiRequestParamDetail> list);
/**
* ApiRequestHeardDetailAPIRequestHeardData
*
* @param heardDetail
* @return
*/
public ApiRequestHeardData apiRequestHeard2Data(ApiRequestHeardDetail heardDetail);
/**
*
*
* @param list
* @return
*/
public List<ApiRequestHeardData> apiRequestHeardList2Data(List<ApiRequestHeardDetail> 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);
}

View File

@ -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<ApiRequestHeardDetail> heardDetailList;
}

View File

@ -2,8 +2,6 @@ package aiyh.utils.apirequest.pojo;
import lombok.Data;
import java.util.List;
/**
* <p></p>
* <p>create 2022/1/23 0023 18:04</p>
@ -59,4 +57,9 @@ public class ApiRequestParamDetail {
private Integer enableParam;
/**
*
*/
private String fieldTableName;
}

View File

@ -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> paramConfigInfo = new AtomicReference<>(paramHandler.parseDataSource(apiRequestMain));
ApiRequestData apiRequestData = BeanMapper.INSTANCE.apiRequestMain2Data(apiRequestMain);
apiRequestData.setApiBaseInfo(this.apiBaseInfo);
AtomicReference<ParamConfigInfo> paramConfigInfo = new AtomicReference<>(paramHandler.parseDataSource(apiRequestData));
// TODO 解析配置表中的参数
Optional.ofNullable(interceptor).map(interceptor -> {
Optional.ofNullable(interceptor.parseAfter(paramConfigInfo.get())).map(v -> {
@ -126,12 +129,4 @@ public class ApiRequestService {
return null;
}
public String getRequestId() {
return requestId;
}
public void setRequestId(String requestId) {
this.requestId = requestId;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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<A> 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<? extends String> list = new ArrayList<>();
public List<Map<String,ApiRequestMain>> list1 = new ArrayList<>();
}
@Test
public void testRandom(){
String pattern = "\\$\\{number:(?<length>(\\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 = "^(\\$:)(?<name>\\w*)\\{(?<sql>[\\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"));
}
}
}