licailing hace 3 años
padre
commit
901b98d783

+ 3 - 1
src/main/java/com/izouma/nineth/domain/ShowCollection.java

@@ -26,9 +26,11 @@ public class ShowCollection extends BaseEntity {
 
     private Long showroomId;
 
+    private Long assetId;
+
     private Long collectionId;
 
-    private Long pic;
+    private String pic;
 
     private int sort;
 }

+ 1 - 1
src/main/java/com/izouma/nineth/domain/Showroom.java

@@ -37,7 +37,7 @@ public class Showroom extends BaseEntity {
 
     private int share;
 
-    private String status;
+    private boolean publish;
 
     @Transient
     private List<ShowCollection> collections;

+ 7 - 0
src/main/java/com/izouma/nineth/repo/ShowCollectionRepo.java

@@ -7,10 +7,17 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.util.List;
 
 public interface ShowCollectionRepo extends JpaRepository<ShowCollection, Long>, JpaSpecificationExecutor<ShowCollection> {
     @Query("update ShowCollection t set t.del = true where t.id = ?1")
     @Modifying
     @Transactional
     void softDelete(Long id);
+
+    @Query("update ShowCollection t set t.del = true where t.collectionId = ?1")
+    @Modifying
+    @Transactional
+    void softDeleteCollection(Long collectionId);
+
 }

+ 3 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -53,6 +53,7 @@ public class AssetService {
     private RocketMQTemplate   rocketMQTemplate;
     private GeneralProperties  generalProperties;
     private ShowroomRepo       showroomRepo;
+    private ShowCollectionRepo showCollectionRepo;
 
 
     public Page<Asset> all(PageQuery pageQuery) {
@@ -279,6 +280,8 @@ public class AssetService {
         Collection collection = collectionRepo.findById(asset.getPublicCollectionId())
                 .orElseThrow(new BusinessException("无展示记录"));
         collectionRepo.delete(collection);
+        // 如果展厅有此藏品
+        showCollectionRepo.softDeleteCollection(asset.getPublicCollectionId());
 
         asset.setPublicShow(false);
         asset.setPublicCollectionId(null);

+ 3 - 0
src/main/java/com/izouma/nineth/service/MintOrderService.java

@@ -76,6 +76,7 @@ public class MintOrderService {
     private RocketMQTemplate              rocketMQTemplate;
     private CollectionRepo                collectionRepo;
     private OrderRepo                     orderRepo;
+    private ShowCollectionRepo            showCollectionRepo;
 
     public Page<MintOrder> all(PageQuery pageQuery) {
         return mintOrderRepo.findAll(JpaUtils.toSpecification(pageQuery, MintOrder.class), JpaUtils.toPageRequest(pageQuery));
@@ -253,6 +254,8 @@ public class MintOrderService {
                         Collection collection = collectionRepo.findById(asset.getPublicCollectionId())
                                 .orElseThrow(new BusinessException("无展示记录"));
                         collectionRepo.delete(collection);
+                        // 如果展厅有此藏品
+                        showCollectionRepo.softDeleteCollection(asset.getPublicCollectionId());
 
                         asset.setPublicShow(false);
                         asset.setPublicCollectionId(null);

+ 3 - 1
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -79,7 +79,6 @@ public class OrderService {
     private WxPayProperties               wxPayProperties;
     private AssetService                  assetService;
     private SysConfigService              sysConfigService;
-    private BlindBoxItemRepo              blindBoxItemRepo;
     private AssetRepo                     assetRepo;
     private UserCouponRepo                userCouponRepo;
     private CollectionService             collectionService;
@@ -91,6 +90,7 @@ public class OrderService {
     private SnowflakeIdWorker             snowflakeIdWorker;
     private SmsService                    smsService;
     private ErrorOrderRepo                errorOrderRepo;
+    private ShowCollectionRepo            showCollectionRepo;
 
     public Page<Order> all(PageQuery pageQuery) {
         return orderRepo.findAll(JpaUtils.toSpecification(pageQuery, Order.class), JpaUtils.toPageRequest(pageQuery));
@@ -573,6 +573,8 @@ public class OrderService {
                         Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
                         assetService.transfer(asset, order.getPrice(), user, "转让", order.getId());
                         collectionRepo.delete(collection);
+                        // 如果展厅有此藏品
+                        showCollectionRepo.softDeleteCollection(order.getCollectionId());
 
                         // 发送短信提醒用户转让成功
                         if (asset != null && asset.getUserId() != null) {

+ 16 - 2
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -13,10 +13,13 @@ import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.ShowroomRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 @Service
@@ -34,7 +37,7 @@ public class ShowroomService {
     /*
     做盲盒? 加字段?
      */
-    public void create(Long userId, Showroom showroom) {
+    public void save(Long userId, Showroom showroom) {
         Asset asset = assetRepo.findById(showroom.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
         if (!userId.equals(asset.getUserId())) {
             throw new BusinessException("该资产不属于你");
@@ -59,13 +62,24 @@ public class ShowroomService {
                 .collect(Collectors.toList());
 
         List<Collection> collections = collectionRepo.findAllByIdIn(collectionIds);
+        Map<Long, Collection> collectionMap = new HashMap<>();
         collections.forEach(collection -> {
             if (!userId.equals(collection.getOwnerId())) {
                 throw new BusinessException("该藏品不属于你");
             }
+            collectionMap.put(collection.getId(), collection);
         });
 
-        showroomRepo.save(showroom);
+        showroom.setUserId(userId);
+        Showroom show = showroomRepo.save(showroom);
 
+        showCollections.forEach(showCollection -> {
+            Collection collection = collectionMap.get(showCollection.getCollectionId());
+            if (ObjectUtils.isNotEmpty(collection)) {
+                showCollection.setPic(collection.getPic().get(0).getUrl());
+                showCollection.setShowroomId(show.getId());
+                showCollection.setAssetId(collection.getAssetId());
+            }
+        });
     }
 }