|
@@ -13,10 +13,13 @@ import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.ShowroomRepo;
|
|
import com.izouma.nineth.repo.ShowroomRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -34,7 +37,7 @@ public class ShowroomService {
|
|
|
/*
|
|
/*
|
|
|
做盲盒? 加字段?
|
|
做盲盒? 加字段?
|
|
|
*/
|
|
*/
|
|
|
- public void create(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("资产不存在"));
|
|
|
if (!userId.equals(asset.getUserId())) {
|
|
if (!userId.equals(asset.getUserId())) {
|
|
|
throw new BusinessException("该资产不属于你");
|
|
throw new BusinessException("该资产不属于你");
|
|
@@ -59,13 +62,24 @@ public class ShowroomService {
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
List<Collection> collections = collectionRepo.findAllByIdIn(collectionIds);
|
|
List<Collection> collections = collectionRepo.findAllByIdIn(collectionIds);
|
|
|
|
|
+ Map<Long, Collection> collectionMap = new HashMap<>();
|
|
|
collections.forEach(collection -> {
|
|
collections.forEach(collection -> {
|
|
|
if (!userId.equals(collection.getOwnerId())) {
|
|
if (!userId.equals(collection.getOwnerId())) {
|
|
|
throw new BusinessException("该藏品不属于你");
|
|
throw new BusinessException("该藏品不属于你");
|
|
|
}
|
|
}
|
|
|
|
|
+ collectionMap.put(collection.getId(), collection);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- showroomRepo.save(showroom);
|
|
|
|
|
|
|
+ showroom.setUserId(userId);
|
|
|
|
|
+ Showroom show = showroomRepo.save(showroom);
|
|
|
|
|
|
|
|
|
|
+ showCollections.forEach(showCollection -> {
|
|
|
|
|
+ Collection collection = collectionMap.get(showCollection.getCollectionId());
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(collection)) {
|
|
|
|
|
+ showCollection.setPic(collection.getPic().get(0).getUrl());
|
|
|
|
|
+ showCollection.setShowroomId(show.getId());
|
|
|
|
|
+ showCollection.setAssetId(collection.getAssetId());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|