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