Ver código fonte

fix:深拷贝bug

lhm 3 anos atrás
pai
commit
b915b07130

+ 20 - 1
kmall-admin/src/main/java/com/kmall/admin/haikong/utils/DeepCopyUtils.java

@@ -2,6 +2,7 @@ package com.kmall.admin.haikong.utils;
 
 import java.io.*;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 
 /**
@@ -11,7 +12,25 @@ import java.util.List;
  */
 public class DeepCopyUtils {
 
-    public static <T> Collection<T> depCopy(Collection<T> srcList) {
+    public static <T> Collection<T> depCopyHashSet(Collection<T> srcList) {
+        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+        try {
+            ObjectOutputStream out = new ObjectOutputStream(byteOut);
+            out.writeObject(srcList);
+
+            ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
+            ObjectInputStream inStream = new ObjectInputStream(byteIn);
+            HashSet<T> destList = (HashSet<T>) inStream.readObject();
+            return destList;
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static <T> Collection<T> depCopyList(Collection<T> srcList) {
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
         try {
             ObjectOutputStream out = new ObjectOutputStream(byteOut);

+ 2 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -2635,7 +2635,8 @@ public class OrderServiceImpl implements OrderService {
 
                     }
                     if (pointsType.equals(Constants.MemberScoreRulesEnum.ONE.getCode())) {
-                        Collection<GoodsEntity> entityCollection = DeepCopyUtils.depCopy(goodsDataMap.values());
+                        Collection<GoodsEntity> values = goodsDataMap.values();
+                        Collection<GoodsEntity> entityCollection = DeepCopyUtils.depCopyHashSet(new HashSet<>(values));
                         entityCollection.forEach(goodsEntity -> {
                             // 商品类别
                             Integer categoryId = goodsEntity.getCategoryId();