Explorar el Código

元宇宙销毁

sunkean hace 3 años
padre
commit
9227aff53f

+ 18 - 3
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -35,6 +35,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.Predicate;
+import javax.transaction.Transactional;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
@@ -996,13 +997,26 @@ public class AssetService {
         userRepo.addDestroyPoint(userId, 1);
     }
 
-    public void destroyWithoutTradecode(Long id, Long userId) {
+    @Transactional
+    public void metaDestroyWithoutTradeCode(List<Long> ids, Long userId, OperationSource source) {
+        ids.forEach(id -> {
+            destroyWithoutTradeCode(id, userId, source);
+        });
+    }
+
+    public void destroyWithoutTradeCode(Long id, Long userId, OperationSource source) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         if (!asset.getUserId().equals(userId)) {
             throw new BusinessException("此藏品不属于该用户");
         }
-        if (asset.getStatus() != AssetStatus.DESTROYING) {
-            throw new BusinessException("当前状态不可销毁");
+        if (source.equals(OperationSource.META)) {
+            if (asset.getStatus() != AssetStatus.NORMAL) {
+                throw new BusinessException("当前状态不可销毁");
+            }
+        } else {
+            if (asset.getStatus() != AssetStatus.DESTROYING) {
+                throw new BusinessException("当前状态不可销毁");
+            }
         }
         if (asset.isPublicShow()) {
             throw new BusinessException("请先取消公开展示");
@@ -1041,6 +1055,7 @@ public class AssetService {
                 .record(1)
                 .type(RecordType.OBTAIN)
                 .companyId(asset.getCompanyId())
+                .source(source)
                 .build());
 
         //加积分

+ 3 - 8
src/main/java/com/izouma/nineth/service/PhotoAssetService.java

@@ -3,19 +3,15 @@ package com.izouma.nineth.service;
 import com.izouma.nineth.annotations.RedisLock;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.Asset;
-import com.izouma.nineth.domain.Collection;
-import com.izouma.nineth.domain.IdentityAuth;
 import com.izouma.nineth.domain.PhotoAsset;
 import com.izouma.nineth.dto.PageQuery;
-import com.izouma.nineth.enums.AssetStatus;
-import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.enums.CollectionStatus;
+import com.izouma.nineth.enums.OperationSource;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.AssetRepo;
 import com.izouma.nineth.repo.PhotoAssetRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.utils.JpaUtils;
-import com.izouma.nineth.utils.ObjUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.env.Environment;
@@ -26,7 +22,6 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 @Service
@@ -67,7 +62,7 @@ public class PhotoAssetService {
 
     public void pass(PhotoAsset photoAsset) {
         //销毁原来的藏品
-        assetService.destroyWithoutTradecode(photoAsset.getDestroyAssetId(), photoAsset.getUserId());
+        assetService.destroyWithoutTradeCode(photoAsset.getDestroyAssetId(), photoAsset.getUserId(), OperationSource.RAEX);
         //生成新的藏品
         Long createId = assetService.createAsset(photoAsset, userRepo.findById(photoAsset.getUserId())
                 .orElseThrow(new BusinessException("无用户记录")), null, BigDecimal.ZERO, "星图", null, false).getId();
@@ -84,7 +79,7 @@ public class PhotoAssetService {
 //        Asset asset = assetRepo.findById(photoAsset.getDestroyAssetId()).orElseThrow(new BusinessException("无藏品记录"));
 //        asset.setStatus(AssetStatus.NORMAL);
 //        assetRepo.saveAndFlush(asset);
-        assetService.destroyWithoutTradecode(photoAsset.getDestroyAssetId(), photoAsset.getUserId());
+        assetService.destroyWithoutTradeCode(photoAsset.getDestroyAssetId(), photoAsset.getUserId(), OperationSource.RAEX);;
         photoAssetRepo.save(photoAsset);
     }
 

+ 6 - 0
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -206,6 +206,12 @@ public class AssetController extends BaseController {
         assetService.destroy(id, SecurityUtils.getAuthenticatedUser().getId(), tradeCode, source);
     }
 
+    @ApiOperation("元宇宙销毁")
+    @PostMapping("/metaDestroy")
+    public void metaDestroy(@RequestBody List<Long> ids) {
+        assetService.metaDestroyWithoutTradeCode(ids, SecurityUtils.getAuthenticatedUser().getId(), OperationSource.META);
+    }
+
     @ApiOperation("开盲盒")
     @PostMapping("/open")
     public void open(@RequestParam Long id) {