|
|
@@ -4,6 +4,8 @@ import com.izouma.nineth.domain.Asset;
|
|
|
import com.izouma.nineth.domain.AssetSuperimposition;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.AssetOperationType;
|
|
|
+import com.izouma.nineth.enums.AssetShowStatus;
|
|
|
+import com.izouma.nineth.enums.CollectionType;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.AssetSuperimpositionRepo;
|
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
|
@@ -39,6 +41,15 @@ public class AssetSuperimpositionService {
|
|
|
* @param toUserId 相关用户id(买入人,被赠送人)
|
|
|
*/
|
|
|
public void adjustNum(Asset asset, AssetOperationType type, Long toUserId) {
|
|
|
+ AssetSuperimposition assetSuperimposition;
|
|
|
+ if (asset.getType().equals(CollectionType.BLIND_BOX) && !asset.isOpened()) {
|
|
|
+ assetSuperimposition = assetSuperimpositionRepo.findByBlindBoxAssetId(asset.getId()).orElse(null);
|
|
|
+ if (Objects.isNull(assetSuperimposition) && !AssetOperationType.BUY.equals(type)) {
|
|
|
+ throw new BusinessException("资产叠加表中没有该盲盒信息");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ assetSuperimposition = assetSuperimpositionRepo.findByUserIdAndPrefixName(asset.getUserId(), asset.getPrefixName()).orElse(null);
|
|
|
+ }
|
|
|
if (Objects.isNull(type)) {
|
|
|
throw new BusinessException("操作类型不能为空");
|
|
|
}
|
|
|
@@ -48,11 +59,25 @@ public class AssetSuperimpositionService {
|
|
|
if (Objects.isNull(asset.getUserId())) {
|
|
|
throw new BusinessException("用户id不能为空");
|
|
|
}
|
|
|
- AssetSuperimposition assetSuperimposition = assetSuperimpositionRepo.findByUserIdAndPrefixName(asset.getUserId(), asset.getPrefixName()).orElse(null);
|
|
|
if (Objects.isNull(assetSuperimposition)) {
|
|
|
assetSuperimposition = new AssetSuperimposition(asset, asset.getUserId());
|
|
|
}
|
|
|
switch (type) {
|
|
|
+ case OPEN_BLIND_BOX:
|
|
|
+ log.info("调整{}数量 -> 开盲盒", asset.getId());
|
|
|
+ AssetSuperimposition openBlindBox = assetSuperimpositionRepo.findByUserIdAndPrefixName(assetSuperimposition.getUserId(), assetSuperimposition.getPrefixName()).orElse(null);
|
|
|
+ if (Objects.isNull(openBlindBox)) {
|
|
|
+ openBlindBox = new AssetSuperimposition(asset, asset.getUserId());
|
|
|
+ }
|
|
|
+ openBlindBox.setAuctioningNum(openBlindBox.getAuctionedNum() + assetSuperimposition.getAuctionedNum());
|
|
|
+ openBlindBox.setConsignmentNum(openBlindBox.getConsignmentNum() + assetSuperimposition.getConsignmentNum());
|
|
|
+ openBlindBox.setNum(openBlindBox.getNum() + assetSuperimposition.getNum());
|
|
|
+ openBlindBox.setCloseShowNum(openBlindBox.getCloseShowNum() + assetSuperimposition.getCloseShowNum());
|
|
|
+ openBlindBox.setOpenShowNum(openBlindBox.getOpenShowNum() + assetSuperimposition.getOpenShowNum());
|
|
|
+ setAssetStatus(openBlindBox);
|
|
|
+ assetSuperimpositionRepo.save(openBlindBox);
|
|
|
+ assetSuperimpositionRepo.deleteById(assetSuperimposition.getId());
|
|
|
+ break;
|
|
|
case OPEN:
|
|
|
log.info("调整{}数量 -> 公开展示", asset.getId());
|
|
|
if (!asset.isConsignment()) {
|
|
|
@@ -115,9 +140,32 @@ public class AssetSuperimpositionService {
|
|
|
assetSuperimposition.setCloseShowNum(assetSuperimposition.getCloseShowNum() - NUM);
|
|
|
break;
|
|
|
}
|
|
|
+ setAssetStatus(assetSuperimposition);
|
|
|
assetSuperimpositionRepo.save(assetSuperimposition);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 当该分类下的资产数量为1的时候,添加相关状态
|
|
|
+ *
|
|
|
+ * @param assetSuperimposition
|
|
|
+ */
|
|
|
+ private void setAssetStatus(AssetSuperimposition assetSuperimposition) {
|
|
|
+ if (assetSuperimposition.getNum() != 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (assetSuperimposition.getAuctioningNum() == 1) {
|
|
|
+ assetSuperimposition.setAssetStatus(AssetShowStatus.AUCTIONING);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (assetSuperimposition.getConsignmentNum() == 1) {
|
|
|
+ assetSuperimposition.setAssetStatus(AssetShowStatus.CONSIGNMENT);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (assetSuperimposition.getOpenShowNum() == 1) {
|
|
|
+ assetSuperimposition.setAssetStatus(AssetShowStatus.OPEN_SHOW);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据藏品是否展示判断仅展示或未展示对应数量减去一
|
|
|
*
|
|
|
@@ -156,10 +204,22 @@ public class AssetSuperimpositionService {
|
|
|
* @param asset 资产信息
|
|
|
*/
|
|
|
private void relatedUserAdjustNum(Long toUserId, String prefixName, Asset asset) {
|
|
|
+ AssetSuperimposition assetSuperimposition;
|
|
|
if (Objects.isNull(toUserId)) {
|
|
|
throw new BusinessException("涉及相关用户id为空");
|
|
|
}
|
|
|
- AssetSuperimposition assetSuperimposition = assetSuperimpositionRepo.findByUserIdAndPrefixName(toUserId, prefixName).orElse(null);
|
|
|
+ if (asset.getType().equals(CollectionType.BLIND_BOX) && !asset.isOpened()) {
|
|
|
+ AssetSuperimposition blindBoxAsset = assetSuperimpositionRepo.findByBlindBoxAssetId(asset.getId()).orElseThrow(new BusinessException("盲盒信息为空"));
|
|
|
+ blindBoxAsset.setUserId(toUserId);
|
|
|
+ blindBoxAsset.setCloseShowNum(NUM);
|
|
|
+ blindBoxAsset.setNum(NUM);
|
|
|
+ blindBoxAsset.setAuctioningNum(0);
|
|
|
+ blindBoxAsset.setConsignmentNum(0);
|
|
|
+ blindBoxAsset.setOpenShowNum(0);
|
|
|
+ assetSuperimpositionRepo.save(blindBoxAsset);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ assetSuperimposition = assetSuperimpositionRepo.findByUserIdAndPrefixName(toUserId, prefixName).orElse(null);
|
|
|
if (Objects.isNull(assetSuperimposition)) {
|
|
|
assetSuperimposition = new AssetSuperimposition(asset, toUserId);
|
|
|
}
|