diff --git a/blade-core-log/src/main/java/org/springblade/core/log/model/LogApi.java b/blade-core-log/src/main/java/org/springblade/core/log/model/LogApi.java index e385e07..762da12 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/model/LogApi.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/model/LogApi.java @@ -100,10 +100,6 @@ public class LogApi implements Serializable { * 执行时间 */ private String time; - /** - * 异常信息 - */ - private String exception; /** * 创建人 diff --git a/blade-core-log/src/main/java/org/springblade/core/log/model/LogApiVo.java b/blade-core-log/src/main/java/org/springblade/core/log/model/LogApiVo.java new file mode 100644 index 0000000..5262426 --- /dev/null +++ b/blade-core-log/src/main/java/org/springblade/core/log/model/LogApiVo.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.log.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * LogApi视图实体类 + * + * @author smallchill + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class LogApiVo extends LogApi { + private static final long serialVersionUID = 1L; + + private String strId; + +} diff --git a/blade-core-log/src/main/java/org/springblade/core/log/model/LogErrorVo.java b/blade-core-log/src/main/java/org/springblade/core/log/model/LogErrorVo.java new file mode 100644 index 0000000..437ffd2 --- /dev/null +++ b/blade-core-log/src/main/java/org/springblade/core/log/model/LogErrorVo.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.log.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * LogError视图实体类 + * + * @author smallchill + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class LogErrorVo extends LogError { + private static final long serialVersionUID = 1L; + + private String strId; + +} diff --git a/blade-core-log/src/main/java/org/springblade/core/log/model/LogUsualVo.java b/blade-core-log/src/main/java/org/springblade/core/log/model/LogUsualVo.java new file mode 100644 index 0000000..a908997 --- /dev/null +++ b/blade-core-log/src/main/java/org/springblade/core/log/model/LogUsualVo.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.log.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * LogUsual视图实体类 + * + * @author smallchill + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class LogUsualVo extends LogUsual { + private static final long serialVersionUID = 1L; + + private String strId; + +} diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/support/BladeBeanCopier.java b/blade-core-tool/src/main/java/org/springblade/core/tool/support/BladeBeanCopier.java new file mode 100644 index 0000000..7b389a5 --- /dev/null +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/support/BladeBeanCopier.java @@ -0,0 +1,184 @@ +package org.springblade.core.tool.support; + +import org.springblade.core.tool.utils.BeanUtil; +import org.springframework.asm.ClassVisitor; +import org.springframework.asm.Type; +import org.springframework.cglib.core.*; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.Modifier; +import java.security.ProtectionDomain; +import java.util.HashMap; +import java.util.Map; + +/** + * spring cglib 魔改 + * + *
+ * 1. 支持链式 bean + * 2. 自定义的 BeanCopier 解决 spring boot 和 cglib ClassLoader classLoader 不一致的问题 + *
+ * + * @author L.cm + */ +public abstract class BladeBeanCopier { + private static final BeanCopierKey KEY_FACTORY = (BeanCopierKey) KeyFactory.create(BeanCopierKey.class); + private static final Type CONVERTER = TypeUtils.parseType("org.springframework.cglib.core.Converter"); + private static final Type BEAN_COPIER = TypeUtils.parseType(BladeBeanCopier.class.getName()); + private static final Signature COPY = new Signature("copy", Type.VOID_TYPE, new Type[]{Constants.TYPE_OBJECT, Constants.TYPE_OBJECT, CONVERTER}); + private static final Signature CONVERT = TypeUtils.parseSignature("Object convert(Object, Class, Object)"); + + interface BeanCopierKey { + Object newInstance(String source, String target, boolean useConverter); + } + + public static BladeBeanCopier create(Class source, Class target, boolean useConverter) { + return BladeBeanCopier.create(source, target, null, useConverter); + } + + public static BladeBeanCopier create(Class source, Class target, ClassLoader classLoader, boolean useConverter) { + Generator gen; + if (classLoader == null) { + gen = new Generator(); + } else { + gen = new Generator(classLoader); + } + gen.setSource(source); + gen.setTarget(target); + gen.setUseConverter(useConverter); + return gen.create(); + } + + abstract public void copy(Object from, Object to, Converter converter); + + public static class Generator extends AbstractClassGenerator { + private static final Source SOURCE = new Source(BladeBeanCopier.class.getName()); + private final ClassLoader classLoader; + private Class source; + private Class target; + private boolean useConverter; + + Generator() { + super(SOURCE); + this.classLoader = null; + } + + Generator(ClassLoader classLoader) { + super(SOURCE); + this.classLoader = classLoader; + } + + public void setSource(Class source) { + if (!Modifier.isPublic(source.getModifiers())) { + setNamePrefix(source.getName()); + } + this.source = source; + } + + public void setTarget(Class target) { + if (!Modifier.isPublic(target.getModifiers())) { + setNamePrefix(target.getName()); + } + + this.target = target; + } + + public void setUseConverter(boolean useConverter) { + this.useConverter = useConverter; + } + + @Override + protected ClassLoader getDefaultClassLoader() { + return target.getClassLoader(); + } + + @Override + protected ProtectionDomain getProtectionDomain() { + return ReflectUtils.getProtectionDomain(source); + } + + public BladeBeanCopier create() { + Object key = KEY_FACTORY.newInstance(source.getName(), target.getName(), useConverter); + return (BladeBeanCopier) super.create(key); + } + + @Override + public void generateClass(ClassVisitor v) { + Type sourceType = Type.getType(source); + Type targetType = Type.getType(target); + ClassEmitter ce = new ClassEmitter(v); + ce.begin_class(Constants.V1_2, + Constants.ACC_PUBLIC, + getClassName(), + BEAN_COPIER, + null, + Constants.SOURCE_FILE); + + EmitUtils.null_constructor(ce); + CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, COPY, null); + + // 2018.12.27 by L.cm 支持链式 bean + PropertyDescriptor[] getters = BeanUtil.getBeanGetters(source); + PropertyDescriptor[] setters = BeanUtil.getBeanSetters(target); + Map