|
|
@@ -0,0 +1,150 @@
|
|
|
+package com.izouma.nineth.service;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.izouma.nineth.config.Constants;
|
|
|
+import com.izouma.nineth.domain.Asset;
|
|
|
+import com.izouma.nineth.domain.MetaItem;
|
|
|
+import com.izouma.nineth.domain.MetaShowRoomAsset;
|
|
|
+import com.izouma.nineth.dto.MetaRestResult;
|
|
|
+import com.izouma.nineth.dto.MetaServiceResult;
|
|
|
+import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.MetaItemEnum;
|
|
|
+import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.AssetRepo;
|
|
|
+import com.izouma.nineth.repo.MetaItemRepo;
|
|
|
+import com.izouma.nineth.repo.MetaShowRoomAssetRepo;
|
|
|
+import com.izouma.nineth.utils.JpaUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class MetaShowRoomAssetService {
|
|
|
+
|
|
|
+ private MetaShowRoomAssetRepo metaShowRoomAssetRepo;
|
|
|
+
|
|
|
+ private AssetRepo assetRepo;
|
|
|
+
|
|
|
+ private MetaItemRepo metaItemRepo;
|
|
|
+
|
|
|
+ public Page<MetaShowRoomAsset> all(PageQuery pageQuery) {
|
|
|
+ return metaShowRoomAssetRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaShowRoomAsset.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ public MetaRestResult<Boolean> putOn(MetaShowRoomAsset metaShowRoomAsset) {
|
|
|
+ MetaServiceResult result = checkParams(metaShowRoomAsset);
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ return MetaRestResult.returnError(result.getMessage(), Boolean.FALSE);
|
|
|
+ }
|
|
|
+ Asset asset = assetRepo.findById(metaShowRoomAsset.getAssetId()).orElse(null);
|
|
|
+ if (Objects.isNull(asset)) {
|
|
|
+ return MetaRestResult.returnError("不存在该资产", Boolean.FALSE);
|
|
|
+ }
|
|
|
+ if (!asset.getUserId().equals(metaShowRoomAsset.getUserId())) {
|
|
|
+ return MetaRestResult.returnError("该资产不属于你");
|
|
|
+ }
|
|
|
+ if (Constants.META_INOPERABLE_STATUS.contains(asset.getStatus())) {
|
|
|
+ return MetaRestResult.returnError(String.format("该资产目前状态为[%S],不可上架。请刷新藏品室数据", asset.getStatus().getDescription()), Boolean.FALSE);
|
|
|
+ }
|
|
|
+ metaShowRoomAssetRepo.save(metaShowRoomAsset);
|
|
|
+ return MetaRestResult.returnSuccess("上架成功", Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ public MetaRestResult<Boolean> putOff(MetaShowRoomAsset metaShowRoomAsset) {
|
|
|
+ MetaServiceResult result = checkParams(metaShowRoomAsset);
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ return MetaRestResult.returnError(result.getMessage(), Boolean.FALSE);
|
|
|
+ }
|
|
|
+ metaShowRoomAssetRepo.deleteByShowRoomIdAndAssetId(metaShowRoomAsset.getShowRoomId(), metaShowRoomAsset.getAssetId());
|
|
|
+ return MetaRestResult.returnSuccess("下架成功", Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ public MetaRestResult<Boolean> putOffAll(Long showRoomId) {
|
|
|
+ metaShowRoomAssetRepo.deleteByShowRoomId(showRoomId);
|
|
|
+ return MetaRestResult.returnSuccess("一键下架成功", Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ public MetaRestResult<List<MetaShowRoomAsset>> findShowRoomAsset(Long showRoomId) {
|
|
|
+ List<MetaShowRoomAsset> metaShowRoomAssets = metaShowRoomAssetRepo.findAllByShowRoomId(showRoomId);
|
|
|
+ List<MetaShowRoomAsset> newMetaShowRoomAsset = new ArrayList<>();
|
|
|
+ metaShowRoomAssets.forEach(metaShowRoomAsset -> {
|
|
|
+ Asset asset = assetRepo.findById(metaShowRoomAsset.getAssetId()).orElseThrow(new BusinessException(String.format("assetId[%S]的资产不存在", metaShowRoomAsset.getAssetId())));
|
|
|
+ if (Constants.META_INOPERABLE_STATUS.contains(asset.getStatus())) {
|
|
|
+ metaShowRoomAssetRepo.deleteByAssetId(asset.getId());
|
|
|
+ } else {
|
|
|
+ metaShowRoomAsset.setAsset(asset);
|
|
|
+ newMetaShowRoomAsset.add(metaShowRoomAsset);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return MetaRestResult.returnSuccess(newMetaShowRoomAsset);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public MetaRestResult<List<Asset>> noShowRoomAndBlindBox(Long userId) {
|
|
|
+ // 查询已上架藏品
|
|
|
+ List<Long> assetIds = metaShowRoomAssetRepo.findAssetIdAllByUserId(userId);
|
|
|
+ List<MetaItem> metaItems = metaItemRepo.findAllByType(MetaItemEnum.META_SHOW_ROOM);
|
|
|
+ // 查询展厅数据
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ metaItems.forEach(metaItem -> {
|
|
|
+ List<Asset> metaItemAssets = assetRepo.findAllByUserIdAndStatusInAndNameLike(userId, Constants.META_NORMAL_STATUS, "%" + metaItem.getName() + "%");
|
|
|
+ if (CollectionUtil.isNotEmpty(metaItemAssets)) {
|
|
|
+ metaItemAssets.forEach(metaItemAsset -> {
|
|
|
+ ids.add(metaItemAsset.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Asset> assets;
|
|
|
+ if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
+ assets = assetRepo.findAllByIdNotInAndUserIdAndStatusInAndOpened(ids, userId, Constants.META_NORMAL_STATUS, true);
|
|
|
+ } else {
|
|
|
+ assets = assetRepo.findAllByUserIdAndStatusInAndOpened(userId, Constants.META_NORMAL_STATUS, true);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(assets) || CollectionUtils.isEmpty(assetIds)) {
|
|
|
+ return MetaRestResult.returnSuccess(assets);
|
|
|
+ }
|
|
|
+ // 查询用户拥有的非展厅非未开启盲盒藏品
|
|
|
+ assets.forEach(asset -> {
|
|
|
+ asset.setMetaPutOn(assetIds.contains(asset.getId()));
|
|
|
+ });
|
|
|
+ return MetaRestResult.returnSuccess(assets);
|
|
|
+ }
|
|
|
+
|
|
|
+ public MetaRestResult<List<Asset>> noBlindBox(Long userId) {
|
|
|
+ List<Long> assetIds = metaShowRoomAssetRepo.findAssetIdAllByUserId(userId);
|
|
|
+ // 查询玩家拥有的非未开启藏品
|
|
|
+ List<Asset> assets = assetRepo.findAllByUserIdAndStatusInAndOpened(userId, Constants.META_NORMAL_STATUS, true);
|
|
|
+ if (CollectionUtils.isEmpty(assets) || CollectionUtils.isEmpty(assetIds)) {
|
|
|
+ return MetaRestResult.returnSuccess(assets);
|
|
|
+ }
|
|
|
+ assets.forEach(asset -> {
|
|
|
+ asset.setMetaPutOn(assetIds.contains(asset.getId()));
|
|
|
+ });
|
|
|
+ return MetaRestResult.returnSuccess(assets);
|
|
|
+ }
|
|
|
+
|
|
|
+ private MetaServiceResult checkParams(MetaShowRoomAsset metaShowRoomAsset) {
|
|
|
+ if (Objects.isNull(metaShowRoomAsset)) {
|
|
|
+ return MetaServiceResult.returnError("Illegal parameter : parameter can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaShowRoomAsset.getShowRoomId())) {
|
|
|
+ return MetaServiceResult.returnError("Illegal parameter : showRoomId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaShowRoomAsset.getUserId())) {
|
|
|
+ return MetaServiceResult.returnError("Illegal parameter : userId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaShowRoomAsset.getAssetId())) {
|
|
|
+ return MetaServiceResult.returnError("Illegal parameter : assetId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaShowRoomAsset.getCoordinate())) {
|
|
|
+ return MetaServiceResult.returnError("Illegal parameter : coordinate can not be null");
|
|
|
+ }
|
|
|
+ return MetaServiceResult.returnSuccess();
|
|
|
+ }
|
|
|
+}
|