|
|
@@ -22,9 +22,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.persistence.Id;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -51,7 +49,7 @@ public class ShowroomService {
|
|
|
if (!CollectionType.SHOWROOM.equals(asset.getType())) {
|
|
|
throw new BusinessException("不是展厅藏品");
|
|
|
}
|
|
|
- if (AssetStatus.NORMAL.equals(asset.getStatus())) {
|
|
|
+ if (!AssetStatus.NORMAL.equals(asset.getStatus())) {
|
|
|
throw new BusinessException("该状态不可创建展厅");
|
|
|
}
|
|
|
if (asset.isConsignment()) {
|
|
|
@@ -72,6 +70,7 @@ public class ShowroomService {
|
|
|
|
|
|
List<Long> collectionIds = showCollections.stream()
|
|
|
.map(ShowCollection::getCollectionId)
|
|
|
+ .distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
List<Collection> collections = collectionRepo.findAllByIdIn(collectionIds);
|
|
|
@@ -100,16 +99,22 @@ public class ShowroomService {
|
|
|
}
|
|
|
|
|
|
public void update(Showroom showroom) {
|
|
|
- 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));
|
|
|
+ Showroom recordRoom = showroomRepo.findById(showroom.getId()).orElseThrow(new BusinessException("无展厅"));
|
|
|
+ // 上传的藏品
|
|
|
+ List<ShowCollection> showCollections = showroom.getCollections();
|
|
|
+
|
|
|
+ List<ShowCollection> recordShowColls = showCollectionRepo.findAllByShowroomId(showroom.getId());
|
|
|
+ Map<Long, ShowCollection> showCollectionMap = recordShowColls.stream()
|
|
|
+ .collect(Collectors.toMap(ShowCollection::getId, coll -> coll));
|
|
|
+
|
|
|
+ Set<Long> removeRecord = new HashSet<>(showCollectionMap.keySet());
|
|
|
|
|
|
- if (room.getMaxCollection() < collections.size()) {
|
|
|
+ if (CollUtil.isNotEmpty(showCollections)) {
|
|
|
+
|
|
|
+ if (recordRoom.getMaxCollection() < showCollections.size()) {
|
|
|
throw new BusinessException("选择的藏品数量大于最多可放置数量");
|
|
|
}
|
|
|
- List<Long> collectionIds = room.getCollections()
|
|
|
+ List<Long> collectionIds = showCollections
|
|
|
.stream()
|
|
|
.filter(show -> ObjectUtils.isEmpty(show.getId()))
|
|
|
.map(ShowCollection::getCollectionId)
|
|
|
@@ -119,27 +124,33 @@ public class ShowroomService {
|
|
|
.collect(Collectors.toMap(Collection::getId, coll -> coll));
|
|
|
|
|
|
|
|
|
- room.getCollections().forEach(coll -> {
|
|
|
+ showCollections.forEach(coll -> {
|
|
|
if (coll.getId() != null) {
|
|
|
ShowCollection showCollection = showCollectionMap.get(coll.getId());
|
|
|
ObjUtils.merge(showCollection, coll);
|
|
|
showCollectionRepo.save(showCollection);
|
|
|
+ // 移除掉
|
|
|
+ removeRecord.remove(coll.getId());
|
|
|
} else {
|
|
|
Collection collection = collectionMap.get(coll.getCollectionId());
|
|
|
if (ObjectUtils.isNotEmpty(collection)) {
|
|
|
coll.setPic(collection.getPic().get(0).getUrl());
|
|
|
- coll.setShowroomId(room.getId());
|
|
|
+ coll.setShowroomId(recordRoom.getId());
|
|
|
coll.setAssetId(collection.getAssetId());
|
|
|
showCollectionRepo.save(coll);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- showCollectionRepo.softDeleteByRoom(room.getId());
|
|
|
+ // 删掉本次没有的
|
|
|
+ showCollectionRepo.softDeleteByRoom(recordRoom.getId());
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(removeRecord)) {
|
|
|
+ showCollectionRepo.softDeleteByIdIn(removeRecord);
|
|
|
}
|
|
|
|
|
|
- ObjUtils.merge(room, showroom);
|
|
|
- showroomRepo.save(room);
|
|
|
+ ObjUtils.merge(recordRoom, showroom);
|
|
|
+ showroomRepo.save(recordRoom);
|
|
|
}
|
|
|
|
|
|
}
|