licailing 4 years ago
parent
commit
d3397dd5b7

+ 3 - 0
src/main/java/com/izouma/nineth/domain/Asset.java

@@ -164,6 +164,9 @@ public class Asset extends BaseEntity {
     @ApiModelProperty("持有几天")
     private Integer holdDays;
 
+    @ApiModelProperty("展厅背景")
+    private String showroomBg;
+
     @ApiModelProperty("最多可放藏品数量")
     private Integer maxCollection;
 

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

@@ -1,6 +1,7 @@
 package com.izouma.nineth.domain;
 
 import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -29,6 +30,7 @@ public class Showroom extends BaseEntity {
 
     private Long assetId;
 
+    @ApiModelProperty("头像")
     private String pic;
 
     private String introduction;
@@ -39,6 +41,12 @@ public class Showroom extends BaseEntity {
 
     private boolean publish;
 
+    @ApiModelProperty("最多可放藏品数量")
+    private int maxCollection;
+
+    @ApiModelProperty("展厅背景")
+    private String showroomBg;
+
     @Transient
     private List<ShowCollection> collections;
 }

+ 24 - 5
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -40,7 +40,7 @@ public class ShowroomService {
     }
 
     /*
-    做盲盒? 加字段?
+    做盲盒
      */
     public void save(Long userId, Showroom showroom) {
         Asset asset = assetRepo.findById(showroom.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
@@ -62,6 +62,9 @@ public class ShowroomService {
         }
 
         List<ShowCollection> showCollections = showroom.getCollections();
+
+//        Collection showColl = collectionRepo.findById(asset.getCollectionId())
+//                .orElseThrow(new BusinessException("无藏品"));
         if (asset.getMaxCollection() < showCollections.size()) {
             throw new BusinessException("选择的藏品数量大于最多可放置数量");
         }
@@ -80,6 +83,8 @@ public class ShowroomService {
         });
 
         showroom.setUserId(userId);
+        showroom.setShowroomBg(asset.getShowroomBg());
+        showroom.setMaxCollection(asset.getMaxCollection());
         Showroom show = showroomRepo.save(showroom);
 
         showCollections.forEach(showCollection -> {
@@ -100,6 +105,17 @@ public class ShowroomService {
             Map<Long, ShowCollection> showCollectionMap = collections.stream()
                     .collect(Collectors.toMap(ShowCollection::getId, coll -> coll));
 
+            if (room.getMaxCollection() < collections.size()) {
+                throw new BusinessException("选择的藏品数量大于最多可放置数量");
+            }
+            List<Long> collectionIds = room.getCollections()
+                    .stream()
+                    .filter(show -> ObjectUtils.isEmpty(show.getId()))
+                    .map(ShowCollection::getCollectionId)
+                    .collect(Collectors.toList());
+            Map<Long, Collection> collectionMap = collectionRepo.findAllByIdIn(collectionIds)
+                    .stream()
+                    .collect(Collectors.toMap(Collection::getId, coll -> coll));
 
             room.getCollections().forEach(coll -> {
                 if (coll.getId() != null) {
@@ -107,10 +123,13 @@ public class ShowroomService {
                     ObjUtils.merge(showCollection, coll);
                     showCollectionRepo.save(showCollection);
                 } else {
-//                    coll.setPic(collection.getPic().get(0).getUrl());
-//                    coll.setShowroomId(room.getId());
-//                    coll.setAssetId(collection.getAssetId());
-//                    showCollectionRepo.save(showCollection);
+                    Collection collection = collectionMap.get(coll.getCollectionId());
+                    if (ObjectUtils.isNotEmpty(collection)){
+                        coll.setPic(collection.getPic().get(0).getUrl());
+                        coll.setShowroomId(room.getId());
+                        coll.setAssetId(collection.getAssetId());
+                        showCollectionRepo.save(coll);
+                    }
                 }
             });
         }