Parcourir la source

限价 批量下架

wangqifan il y a 2 ans
Parent
commit
de0444d53a

+ 3 - 0
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -121,6 +121,9 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
     @Query("select a from Asset a where a.status in ?2 and a.userId = ?1 and a.name like ?3 and a.type in (com.izouma.nineth.enums.CollectionType.DEFAULT,com.izouma.nineth.enums.CollectionType.BLIND_BOX)")
     List<Asset> findAllByUserIdAndStatusInAndNameLike(Long userId, List<AssetStatus> status, String name);
 
+    @Query("select a from Asset a where a.status = 'NORMAL' and a.consignment = true and a.name like ?1")
+    List<Asset> findOnShelfByNameLike(String search);
+
     List<Asset> findAllByIdNotInAndUserIdAndStatusInAndOpened(List<Long> ids, Long userId, List<AssetStatus> status, boolean opened);
 
     List<Asset> findAllByUserIdAndStatusInAndOpened(Long userId, List<AssetStatus> status, boolean opened);

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

@@ -661,6 +661,11 @@ public class AssetService {
         return assetRepo.saveAndFlush(asset);
     }
 
+    public void batchCancelConsignment(String search) {
+        List<Asset> onShelf = assetRepo.findOnShelfByNameLike("%" + search + "%");
+        onShelf.forEach(this::cancelConsignmentBySystem);
+    }
+
     public void cancelConsignment(Long id) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
@@ -1012,10 +1017,13 @@ public class AssetService {
         assetIds.forEach(this::cancelConsignmentBySystem);
     }
 
-
     public void cancelConsignmentBySystem(Long id) {
+        Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        cancelConsignmentBySystem(asset);
+    }
+
+    public void cancelConsignmentBySystem(Asset asset) {
         try {
-            Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
             if (asset.getPublicCollectionId() != null) {
                 List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
                 if (orders.stream().anyMatch(o -> o.getStatus() != OrderStatus.CANCELLED)) {
@@ -1032,7 +1040,7 @@ public class AssetService {
             asset.setPublicShow(false);
             assetRepo.saveAndFlush(asset);
         } catch (Exception e) {
-            log.info("自动下架报错,assetId:" + id);
+            log.info("自动下架报错,assetId:" + asset.getId());
         }
     }
 

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

@@ -264,6 +264,13 @@ public class AssetController extends BaseController {
     public List<FuAssetDTO> queryFu() {
         return assetService.queryFu();
     }
+
+    @PostMapping("/batchCancelConsignment")
+    @PreAuthorize("hasRole('ADMIN')")
+    @ApiOperation("批量下架")
+    public void cancelConsignment(@RequestParam String search) {
+        assetService.batchCancelConsignment(search);
+    }
 }