|
|
@@ -41,7 +41,7 @@ public class ShowroomService {
|
|
|
/*
|
|
|
不做盲盒
|
|
|
*/
|
|
|
- public void save(Long userId, Showroom showroom) {
|
|
|
+ public Showroom save(Long userId, Showroom showroom) {
|
|
|
Asset asset = assetRepo.findById(showroom.getAssetId()).orElseThrow(new BusinessException("资产不存在"));
|
|
|
if (!userId.equals(asset.getUserId())) {
|
|
|
throw new BusinessException("该资产不属于你");
|
|
|
@@ -96,10 +96,12 @@ public class ShowroomService {
|
|
|
showCollectionRepo.save(showCollection);
|
|
|
}
|
|
|
});
|
|
|
+ return show;
|
|
|
}
|
|
|
|
|
|
- public void update(Showroom showroom) {
|
|
|
+ public Showroom update(Long userId, Showroom showroom) {
|
|
|
Showroom recordRoom = showroomRepo.findById(showroom.getId()).orElseThrow(new BusinessException("无展厅"));
|
|
|
+ showroom.setMaxCollection(recordRoom.getMaxCollection());
|
|
|
// 上传的藏品
|
|
|
List<ShowCollection> showCollections = showroom.getCollections();
|
|
|
|
|
|
@@ -107,6 +109,9 @@ public class ShowroomService {
|
|
|
Map<Long, ShowCollection> showCollectionMap = recordShowColls.stream()
|
|
|
.collect(Collectors.toMap(ShowCollection::getId, coll -> coll));
|
|
|
|
|
|
+ Map<Long, ShowCollection> showCollectionMap1 = recordShowColls.stream()
|
|
|
+ .collect(Collectors.toMap(ShowCollection::getCollectionId, coll -> coll));
|
|
|
+
|
|
|
Set<Long> removeRecord = new HashSet<>(showCollectionMap.keySet());
|
|
|
|
|
|
if (CollUtil.isNotEmpty(showCollections)) {
|
|
|
@@ -119,10 +124,15 @@ public class ShowroomService {
|
|
|
.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));
|
|
|
|
|
|
+ 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);
|
|
|
+ });
|
|
|
|
|
|
showCollections.forEach(coll -> {
|
|
|
if (coll.getId() != null) {
|
|
|
@@ -134,12 +144,19 @@ public class ShowroomService {
|
|
|
removeRecord.remove(coll.getId());
|
|
|
}
|
|
|
} else {
|
|
|
- Collection collection = collectionMap.get(coll.getCollectionId());
|
|
|
- if (ObjectUtils.isNotEmpty(collection)) {
|
|
|
- coll.setPic(collection.getPic().get(0).getUrl());
|
|
|
- coll.setShowroomId(recordRoom.getId());
|
|
|
- coll.setAssetId(collection.getAssetId());
|
|
|
- showCollectionRepo.save(coll);
|
|
|
+ ShowCollection showCollection = showCollectionMap1.get(coll.getCollectionId());
|
|
|
+ if (ObjectUtils.isNotEmpty(showCollection)) {
|
|
|
+ ObjUtils.merge(showCollection, coll);
|
|
|
+ showCollectionRepo.save(showCollection);
|
|
|
+ removeRecord.remove(showCollection.getId());
|
|
|
+ } else {
|
|
|
+ Collection collection = collectionMap.get(coll.getCollectionId());
|
|
|
+ if (ObjectUtils.isNotEmpty(collection)) {
|
|
|
+ coll.setPic(collection.getPic().get(0).getUrl());
|
|
|
+ coll.setShowroomId(recordRoom.getId());
|
|
|
+ coll.setAssetId(collection.getAssetId());
|
|
|
+ showCollectionRepo.save(coll);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -152,7 +169,7 @@ public class ShowroomService {
|
|
|
}
|
|
|
|
|
|
ObjUtils.merge(recordRoom, showroom);
|
|
|
- showroomRepo.save(recordRoom);
|
|
|
+ return showroomRepo.save(recordRoom);
|
|
|
}
|
|
|
|
|
|
}
|