licailing 3 years ago
parent
commit
5cdbc162f5

+ 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 Integer maxCollection;
+
     @Transient
     private boolean opened = true;
 

+ 17 - 1
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -14,6 +14,7 @@ import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.ShowCollectionRepo;
 import com.izouma.nineth.repo.ShowroomRepo;
 import com.izouma.nineth.utils.JpaUtils;
+import com.izouma.nineth.utils.ObjUtils;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.data.domain.Page;
@@ -61,6 +62,10 @@ public class ShowroomService {
         }
 
         List<ShowCollection> showCollections = showroom.getCollections();
+        if (asset.getMaxCollection() < showCollections.size()) {
+            throw new BusinessException("选择的藏品数量大于最多可放置数量");
+        }
+
         List<Long> collectionIds = showCollections.stream()
                 .map(ShowCollection::getCollectionId)
                 .collect(Collectors.toList());
@@ -92,9 +97,20 @@ public class ShowroomService {
         Showroom room = showroomRepo.findById(showroom.getId()).orElseThrow(new BusinessException("无展厅"));
         if (CollUtil.isNotEmpty(room.getCollections())) {
             List<ShowCollection> collections = showCollectionRepo.findAllByShowroomId(showroom.getId());
+            Map<Long, ShowCollection> showCollectionMap = collections.stream()
+                    .collect(Collectors.toMap(ShowCollection::getId, coll -> coll));
+
+
             room.getCollections().forEach(coll -> {
                 if (coll.getId() != null) {
-
+                    ShowCollection showCollection = showCollectionMap.get(coll.getId());
+                    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);
                 }
             });
         }