一些工具的开发

dev
IT-xiaoXiong 2022-01-27 15:22:43 +08:00
parent 3e4971c2d4
commit d161236561
13 changed files with 195 additions and 34 deletions

View File

@ -25,11 +25,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="classbean" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.22" 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" />
@ -43,6 +43,5 @@
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:3.8" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.3.0" level="project" />
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
<orderEntry type="library" name="classbean" level="project" />
</component>
</module>

15
pom.xml
View File

@ -50,6 +50,7 @@
<version>${hutool.version}</version>
</dependency>
<!-- 图片efi信息识别ps贵酒-->
<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
@ -95,13 +96,13 @@
<configuration>
<source>8</source>
<target>8</target>
<annotationProcessors>
<annotationProcessor>
<groupId>org.projectors</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</annotationProcessor>
</annotationProcessors>
<!-- <annotationProcessors>-->
<!-- <annotationProcessor>-->
<!-- <groupId>org.projectors</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- <version>${lombok.version}</version>-->
<!-- </annotationProcessor>-->
<!-- </annotationProcessors>-->
</configuration>
</plugin>
<plugin>

View File

@ -6,6 +6,7 @@ import aiyh.utils.fileUtil.ProperUtil;
import aiyh.utils.logger.LoggerUtil;
import aiyh.utils.mapUtil.UtilHashMap;
import aiyh.utils.mapUtil.UtilLinkedHashMap;
import aiyh.utils.mapper.UtilMapper;
import aiyh.utils.recordset.RecordsetUtil;
import aiyh.utils.service.UtilService;
import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl;
@ -16,7 +17,7 @@ import aiyh.utils.zwl.common.ToolUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ibm.icu.text.SimpleDateFormat;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.*;
import org.h2.util.StringUtils;
import weaver.common.util.string.StringUtil;
import weaver.conn.RecordSet;
@ -64,10 +65,10 @@ public class Util extends weaver.general.Util {
private static final String LOGGER_NAME = "cusAYH";
static ToolUtil toolUtil = new ToolUtil();
private static RecordsetUtil recordsetUtil = new RecordsetUtil();
private static final UtilMapper mapper = getMapper(UtilMapper.class);
private static LoggerUtil loggerUtil = new LoggerUtil();
private static volatile Logger log = null;
/**
*
*
@ -1888,17 +1889,47 @@ public class Util extends weaver.general.Util {
loggerUtil.error(message, exception);
}
/**
*
*
* @return
*/
public static Logger getLogger() {
if (log == null) {
synchronized (Util.class) {
if (log == null) {
log = org.apache.log4j.Logger.getLogger(LOGGER_NAME);
// log = org.apache.log4j.Logger.getLogger(LOGGER_NAME);
DailyRollingFileAppender appender = new DailyRollingFileAppender();
log = Logger.getLogger("aiyh_cus");
appender.setName("aiyh_cus");
appender.setEncoding("UTF-8");
appender.setDatePattern("'_'yyyyMMdd'.log'");
appender.setFile(weaver.general.GCONST.getLogPath() + "cus" + File.separator + "util_cus" + File.separator + "cus.log");
appender.setThreshold(Priority.DEBUG);
appender.setLayout(new PatternLayout("[%-5p] [%d{yyyy-MM-dd HH:mm:ss,SSS}] [%r] [Thread:%t][%F.%M:%L] ==> : %m %x %n"));
appender.setAppend(true);
appender.activateOptions();
log.addAppender(appender);
Boolean enableDebug = mapper.selectLogLevel();
if (!enableDebug) {
log.setLevel(Level.INFO);
}
}
}
}
return log;
}
/**
*
*
* @param onlyMark
* @return
*/
public static String getCusConfigValue(String onlyMark) {
return mapper.selectCusConfigParam(onlyMark);
}
/**
* listlist
@ -1920,6 +1951,7 @@ public class Util extends weaver.general.Util {
return buildTree(dataList, new HashMap<>(dataList.size()), new HashMap<>(dataList.size()), 0,
getIdFn, getParentId, setChildFn, predicate);
}
/**
* listlist
*
@ -1927,20 +1959,20 @@ public class Util extends weaver.general.Util {
* @param getIdFn id
* @param getParentId id
* @param setChildFn
* @param getChildFn
* @param getChildFn
* @param predicate
* @param <T> list
* @param <K> id
* @return list
*/
public static <T,K> List<T> listToTree(List<T> dataList, Function<T, K> getIdFn,
Function<T, K> getParentId, Function<T, List<T>> getChildFn,
BiConsumer<T, List<T>> setChildFn, Predicate<K> predicate){
public static <T, K> List<T> listToTree(List<T> dataList, Function<T, K> getIdFn,
Function<T, K> getParentId, Function<T, List<T>> getChildFn,
BiConsumer<T, List<T>> setChildFn, Predicate<K> predicate) {
if (dataList == null || dataList.isEmpty() || dataList.size() == 1) {
return dataList;
}
return buildTree(dataList,new HashMap<>(dataList.size()),new HashMap<>(dataList.size()),
0,getIdFn,getParentId,getChildFn,setChildFn,predicate);
return buildTree(dataList, new HashMap<>(dataList.size()), new HashMap<>(dataList.size()),
0, getIdFn, getParentId, getChildFn, setChildFn, predicate);
}
/**
@ -2085,26 +2117,27 @@ public class Util extends weaver.general.Util {
/**
* java bean
*
* @param source
* @param target
* @param <T>
* @param <K>
* @param <T>
* @param <K>
* @return
*/
public static <T,K> K copyBeanBaseField(T source, K target){
if(Objects.isNull(source)){
public static <T, K> K copyBeanBaseField(T source, K target) {
if (Objects.isNull(source)) {
return target;
}
if(Objects.isNull(target)){
if (Objects.isNull(target)) {
throw new RuntimeException("target is null, You cannot pass a null bean");
}
BeanInfo beanInfo = null;
try {
beanInfo = Introspector.getBeanInfo(target.getClass());
beanInfo = Introspector.getBeanInfo(target.getClass());
} catch (IntrospectionException e) {
e.printStackTrace();
}
if(Objects.isNull(beanInfo)){
if (Objects.isNull(beanInfo)) {
throw new RuntimeException("无法获取对象信息can not get bean info");
}
Class<?> sourceClass = source.getClass();
@ -2116,14 +2149,14 @@ public class Util extends weaver.general.Util {
Field sourceClassField = sourceClass.getDeclaredField(name);
Class<?> propertyType = propertyDescriptor.getPropertyType();
Class<?> classFieldType = sourceClassField.getType();
if(propertyType.equals(classFieldType)){
if (propertyType.equals(classFieldType)) {
Method getMethod = sourceClass.getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
Object invoke = getMethod.invoke(source);
writeMethod.invoke(target,invoke);
writeMethod.invoke(target, invoke);
}
} catch (NoSuchFieldException | IllegalAccessException | InvocationTargetException ignored) {
} catch (NoSuchMethodException e) {
throw new RuntimeException("invoke method err, cant not invoke method set" + name.substring(0,1).toUpperCase() + name.substring(1));
throw new RuntimeException("invoke method err, cant not invoke method set" + name.substring(0, 1).toUpperCase() + name.substring(1));
}
}
// TODO 复制bean

View File

@ -17,6 +17,7 @@ import weaver.workflow.workflow.WorkflowVersion;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* <p></p>
@ -36,12 +37,15 @@ public class WorkflowDataHandler implements IDataSourceHandler {
String workflowId = apiRequestMain.getWorkflowType();
String workflowVersionIds = WorkflowVersion.getVersionStringByWfid(workflowId);
String workflowTable = mapper.selectWorkflowTableById(workflowVersionIds.split(","));
if("".equals(apiRequestMain.getRequestId()) || Objects.isNull(apiRequestMain.getRequestId())){
throw new RuntimeException("数据来源为流程时流程的requestId为必要参数");
}
Map<String, Object> mainData = mapper.selectMainData(workflowTable, apiRequestMain.getRequestId());
ParamConfigInfo paramConfigInfo = Util.copyBeanBaseField(apiRequestMain, new ParamConfigInfo());
List<ApiRequestParamDetail> paramDetailList = apiRequestMain.getParamDetailList();
// 明细请求模式,单挑明细 当做请求参数进行一次请求
if (apiRequestMain.getParamRequestType() == 1) {
List<List<ParamInfo>> lists = parseValueForDetail(apiRequestMain, mainData);
} else {
// 默认模式

View File

@ -13,6 +13,6 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler;
public class BooleanTypeHandler implements IParamTypeHandler {
@Override
public Boolean getValue(Object value) {
return Boolean.valueOf(String.valueOf(value));
return Boolean.parseBoolean(String.valueOf(value));
}
}

View File

@ -13,6 +13,6 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler;
public class DoubleTypeHandler implements IParamTypeHandler {
@Override
public Double getValue(Object value) {
return Double.valueOf(String.valueOf(value));
return Double.parseDouble(String.valueOf(value));
}
}

View File

@ -13,6 +13,6 @@ import aiyh.utils.apirequest.core.typehandler.IParamTypeHandler;
public class LongTypeHandler implements IParamTypeHandler {
@Override
public Long getValue(Object value) {
return Long.valueOf(String.valueOf(value));
return Long.parseLong(String.valueOf(value));
}
}

View File

@ -0,0 +1,29 @@
package aiyh.utils.apirequest.core.typehandler.paramvalue;
import aiyh.utils.Util;
import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler;
import aiyh.utils.apirequest.mapper.ParamValueParseMapper;
import aiyh.utils.apirequest.pojo.ApiRequestParamDetail;
import java.util.Map;
/**
* <p>SQL</p>
* <p>create 2022/1/26 0026 16:30</p>
*
* @author EBU7-dev1-ayh
*/
public class CustomerSqlRuleHandler implements IParamValueRuleHandler {
private final ParamValueParseMapper mapper = Util.getMapper(ParamValueParseMapper.class);
@Override
public Object getValue(ApiRequestParamDetail paramInfo, Map<String, Object> 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操作!");
}
}
}

View File

@ -17,6 +17,6 @@ public class FixedValueRuleHandle implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamDetail paramInfo, Map<String, Object> dataMap) {
return null;
return paramInfo.getCustomerValue();
}
}

View File

@ -0,0 +1,22 @@
package aiyh.utils.apirequest.core.typehandler.paramvalue;
import aiyh.utils.apirequest.core.typehandler.IParamValueRuleHandler;
import aiyh.utils.apirequest.pojo.ApiRequestParamDetail;
import java.util.Map;
/**
* <p></p>
* <p>create 2022/1/26 0026 16:25</p>
*
* @author EBU7-dev1-ayh
*/
public class SystemFieldValueRuleHandle implements IParamValueRuleHandler {
@Override
public Object getValue(ApiRequestParamDetail paramInfo, Map<String, Object> dataMap) {
Map<String,Object> main = (Map<String, Object>) dataMap.get("main");
return main.get(paramInfo.getSystemFieldName());
}
}

View File

@ -0,0 +1,29 @@
package aiyh.utils.apirequest.mapper;
import aiyh.utils.annotation.recordset.CaseConversion;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import aiyh.utils.annotation.recordset.SqlString;
import java.util.Map;
/**
* <p></p>
* <p>create 2022/1/26 0026 16:32</p>
*
* @author EBU7-dev1-ayh
*/
@SqlMapper
public interface ParamValueParseMapper {
/**
* SQL
* @param sql SQL
* @param map
* @return
*/
@Select(custom = true)
@CaseConversion(false)
public String selectCustomerSql(@SqlString String sql, Map<String,Object> map);
}

View File

@ -0,0 +1,32 @@
package aiyh.utils.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
/**
* <p>SQL</p>
* <p>create 2022/1/27 0027 12:01</p>
*
* @author EBU7-dev1-ayh
*/
@SqlMapper
public interface UtilMapper {
/**
* Debug
* @return Debug
*/
@Select("select param_value from uf_cus_dev_config where only_mark = 'enableDebugLog'")
public Boolean selectLogLevel();
/**
*
* @param onlyMark
* @return
*/
@Select("select param_value from uf_cus_dev_config where only_mark = #{onlyMark} and enable_param = 1")
public String selectCusConfigParam(@ParamMapper("onlyMark") String onlyMark);
}

View File

@ -16,9 +16,12 @@ 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;
@ -493,8 +496,17 @@ public class UtilTest {
apiRequestMain.setParamRequestType(2);
apiRequestMain.setOnlyMark("onlyMark");
ParamConfigInfo paramConfigInfo = new ParamConfigInfo();
paramConfigInfo = Util.copyBeanBaseField(apiRequestMain, paramConfigInfo);
Util.copyBeanBaseField(apiRequestMain, paramConfigInfo);
System.out.println(paramConfigInfo);
}
@Test
public void testLog(){
Logger log= Util.getLogger();
log.info("我是info --------------------->");
log.debug("我是debug---------------------------------->");
log.error("我是错误---------------->");
log.warn("我是警告-------------->");
System.out.println(log.getEffectiveLevel());
}
}