licailing il y a 4 ans
Parent
commit
5192cb52f1

+ 5 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -99,8 +99,13 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Query("select c.id from Collection c where c.assetId in ?1")
     List<Long> findAllByDelFalseAndAssetIdIn(java.util.Collection<Long> assetId);
 
+    @Query("select c.id from Collection c where c.assetId = ?1 and c.source = 'TRANSFER'")
+    List<Long> findAllByAssetId(Long assetId);
+
     @Query("update Collection t set t.del = true where t.id in ?1")
     @Modifying
     @Transactional
     void softDeleteByIdIn(java.util.Collection<Long> id);
+
+    void deleteAllByIdIn(java.util.Collection<Long> id);
 }

+ 9 - 2
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -34,6 +34,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.net.URLCodec;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.event.EventListener;
@@ -399,8 +400,14 @@ public class OrderService {
                 if (collection.getSource() == CollectionSource.TRANSFER) {
                     Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
                     assetService.transfer(asset, order.getPrice(), user, "转让", order.getId());
-                    log.info("删除collection {}", collection.getId());
-                    collectionRepo.delete(collection);
+                    List<Long> collectionIds = collectionRepo.findAllByAssetId(collection.getAssetId());
+                    log.info("删除collection {}", collectionIds);
+                    if (CollectionUtils.isNotEmpty(collectionIds)) {
+                        collectionRepo.deleteAllByIdIn(collectionIds);
+                    } else {
+                        collectionRepo.delete(collection);
+                    }
+
                 } else {
                     orderRepo.save(order);
                     assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",