diff --git a/ecology-weaver.iml b/ecology-weaver.iml index 672f9b7..9e5b286 100644 --- a/ecology-weaver.iml +++ b/ecology-weaver.iml @@ -25,11 +25,11 @@ + - @@ -43,6 +43,5 @@ - \ No newline at end of file diff --git a/pom.xml b/pom.xml index f60cb12..a185203 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ ${hutool.version} + com.drewnoakes metadata-extractor @@ -95,13 +96,13 @@ 8 8 - - - org.projectors - lombok - ${lombok.version} - - + + + + + + + diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 297f5d7..4e63802 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -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); + } + /** * 将list转化为树形list @@ -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); } + /** * 将list转化为树形list * @@ -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 list的泛型 * @param 元数据id的泛型 * @return 树形的list */ - public static List listToTree(List dataList, Function getIdFn, - Function getParentId, Function> getChildFn, - BiConsumer> setChildFn, Predicate predicate){ + public static List listToTree(List dataList, Function getIdFn, + Function getParentId, Function> getChildFn, + BiConsumer> setChildFn, Predicate 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 原对象泛型 - * @param 目标对象泛型 + * @param 原对象泛型 + * @param 目标对象泛型 * @return 复制后的目标对象 */ - public static K copyBeanBaseField(T source, K target){ - if(Objects.isNull(source)){ + public static 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 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 ff1e539..00dd1fa 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 @@ -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; /** *

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

@@ -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 mainData = mapper.selectMainData(workflowTable, apiRequestMain.getRequestId()); ParamConfigInfo paramConfigInfo = Util.copyBeanBaseField(apiRequestMain, new ParamConfigInfo()); List paramDetailList = apiRequestMain.getParamDetailList(); // 明细请求模式,单挑明细 当做请求参数进行一次请求 if (apiRequestMain.getParamRequestType() == 1) { - + List> lists = parseValueForDetail(apiRequestMain, mainData); } else { // 默认模式 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 9a6a03a..4a696e9 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 @@ -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)); } } 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 2cb8b8b..407249a 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 @@ -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)); } } 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 6ad58eb..5af20c5 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 @@ -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)); } } 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 new file mode 100644 index 0000000..c906d13 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/CustomerSqlRuleHandler.java @@ -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; + +/** + *

自定义SQL处理器

+ *

create 2022/1/26 0026 16:30

+ * + * @author EBU7-dev1-ayh + */ + + +public class CustomerSqlRuleHandler implements IParamValueRuleHandler { + private final ParamValueParseMapper mapper = Util.getMapper(ParamValueParseMapper.class); + @Override + public Object getValue(ApiRequestParamDetail 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操作!"); + } + } +} 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 d19df23..751b7b3 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 @@ -17,6 +17,6 @@ public class FixedValueRuleHandle implements IParamValueRuleHandler { @Override public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { - return null; + return paramInfo.getCustomerValue(); } } 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 new file mode 100644 index 0000000..6474b89 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/core/typehandler/paramvalue/SystemFieldValueRuleHandle.java @@ -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; + +/** + *

系统字段值处理

+ *

create 2022/1/26 0026 16:25

+ * + * @author EBU7-dev1-ayh + */ + + +public class SystemFieldValueRuleHandle implements IParamValueRuleHandler { + @Override + public Object getValue(ApiRequestParamDetail paramInfo, Map dataMap) { + Map main = (Map) dataMap.get("main"); + return main.get(paramInfo.getSystemFieldName()); + } +} diff --git a/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java b/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java new file mode 100644 index 0000000..83be7a1 --- /dev/null +++ b/src/main/java/aiyh/utils/apirequest/mapper/ParamValueParseMapper.java @@ -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; + +/** + *

参数值解析查询操作

+ *

create 2022/1/26 0026 16:32

+ * + * @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 map); +} diff --git a/src/main/java/aiyh/utils/mapper/UtilMapper.java b/src/main/java/aiyh/utils/mapper/UtilMapper.java new file mode 100644 index 0000000..6c069cc --- /dev/null +++ b/src/main/java/aiyh/utils/mapper/UtilMapper.java @@ -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; + +/** + *

工具类查询SQL

+ *

create 2022/1/27 0027 12:01

+ * + * @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); +} diff --git a/src/test/java/utilTest/UtilTest.java b/src/test/java/utilTest/UtilTest.java index 4e06fdb..eb0a96c 100644 --- a/src/test/java/utilTest/UtilTest.java +++ b/src/test/java/utilTest/UtilTest.java @@ -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()); + } }