diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java deleted file mode 100644 index 52ad492..0000000 --- a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/common/utils/BeanCopyUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.digiwin.athena.app.infra.common.utils; - -import com.digiwin.app.container.exceptions.DWRuntimeException; -import net.sf.cglib.beans.BeanCopier; -import net.sf.cglib.beans.BeanMap; -import org.springframework.objenesis.ObjenesisStd; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public final class BeanCopyUtil { - private BeanCopyUtil() { - } - - private static ThreadLocal objenesisStdThreadLocal = ThreadLocal.withInitial(ObjenesisStd::new); - private static ConcurrentHashMap, ConcurrentHashMap, BeanCopier>> cache = new ConcurrentHashMap<>(); - - - public static T copy(Object source, Class target) { - return copy(source, objenesisStdThreadLocal.get().newInstance(target)); - } - - public static T copy(Object source, T target) { - BeanCopier beanCopier = getCacheBeanCopier(source.getClass(), target.getClass()); - beanCopier.copy(source, target, null); - return target; - } - - public static List copyList(List sources, Class target) { - if (sources.isEmpty()) { - return Collections.emptyList(); - } - - ArrayList list = new ArrayList<>(sources.size()); - ObjenesisStd objenesisStd = objenesisStdThreadLocal.get(); - for (Object source : sources) { - if (source == null) { - throw new DWRuntimeException("转换异常"); - } - T newInstance = objenesisStd.newInstance(target); - BeanCopier beanCopier = getCacheBeanCopier(source.getClass(), target); - beanCopier.copy(source, newInstance, null); - list.add(newInstance); - } - return list; - } - - public static T mapToBean(Map source, Class target) { - T bean = objenesisStdThreadLocal.get().newInstance(target); - BeanMap beanMap = BeanMap.create(bean); - beanMap.putAll(source); - return bean; - } - - public static Map beanToMap(T source) { - return BeanMap.create(source); - } - - private static BeanCopier getCacheBeanCopier(Class source, Class target) { - ConcurrentHashMap, BeanCopier> copierConcurrentHashMap = cache.computeIfAbsent(source, aClass -> new ConcurrentHashMap<>(16)); - return copierConcurrentHashMap.computeIfAbsent(target, aClass -> BeanCopier.create(source, target, false)); - } -} diff --git a/demo-athenaopt_backend/pom.xml b/demo-athenaopt_backend/pom.xml index 256f35c..486bf64 100644 --- a/demo-athenaopt_backend/pom.xml +++ b/demo-athenaopt_backend/pom.xml @@ -32,9 +32,10 @@ https://repo.digiwincloud.com.cn/maven 1.1.0.0 5.0.5.RELEASE - 5.2.0.1029 + 5.2.0.1085 2.8.6 1.05 + 4.1.67.Final