Browse Source

超过1小时自动下架

wangqifan 3 years ago
parent
commit
2f033ff138

+ 2 - 2
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -167,8 +167,8 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Query("select c.vipQuota from Collection c where c.id = ?1")
     Integer getVipQuota(Long id);
 
-    @Query("select c.assetId from Collection  c where c.price >= ?1 and c.source = ?2 and c.createdAt <= ?3 and c.salable = ?4")
-    Set<Long> findResaleCollectionPriceOver20K(BigDecimal price, CollectionSource source, LocalDateTime startTime, boolean salable);
+    @Query(value = "select c.asset_id from collection_info c where  c.source =  'TRANSFER' and c.created_at <= ?1 and c.salable = true and c.on_shelf = true limit 3000", nativeQuery = true)
+    Set<Long> findResaleCollectionOverTime(LocalDateTime startTime);
 
     List<Collection> findAllByNameLike(String name);
 

+ 35 - 30
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -774,29 +774,32 @@ public class AssetService {
 
     @Scheduled(cron = "0 0 0/1 * * ?")
     public void offTheShelfAll() {
-        LocalDateTime lastTime = LocalDateTime.now().minusHours(240);
+        LocalDateTime lastTime = LocalDateTime.now().minusDays(10);
         Set<Long> assetIds = collectionRepo
-                .findResaleCollectionPriceOver20K(BigDecimal
-                        .valueOf(0L), CollectionSource.TRANSFER, lastTime, true);
+                .findResaleCollectionOverTime(lastTime);
         assetIds.forEach(this::cancelConsignmentBySystem);
     }
 
 
     public void cancelConsignmentBySystem(Long id) {
-        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)) {
-                throw new BusinessException("已有订单不可取消");
+        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)) {
+                    throw new BusinessException("已有订单不可取消");
+                }
+                collectionRepo.findById(asset.getPublicCollectionId())
+                        .ifPresent(collection -> {
+                            collection.setSalable(false);
+                            collectionRepo.save(collection);
+                        });
             }
-            collectionRepo.findById(asset.getPublicCollectionId())
-                    .ifPresent(collection -> {
-                        collection.setSalable(false);
-                        collectionRepo.save(collection);
-                    });
+            asset.setConsignment(false);
+            assetRepo.saveAndFlush(asset);
+        } catch (Exception e) {
+            log.info("自动下架报错,assetId:" + id);
         }
-        asset.setConsignment(false);
-        assetRepo.saveAndFlush(asset);
     }
 
     //    @Cacheable(cacheNames = "fmaa", key = "#userId+'#'+#mintActivityId+'#'+#pageable.hashCode()")
@@ -813,16 +816,16 @@ public class AssetService {
             if (tags.isEmpty()) return new PageImpl<>(Collections.emptyList());
             return assetRepo.findAll((Specification<Asset>) (root, query, criteriaBuilder) ->
                     query.distinct(true).where(
-                                    // where userId=some id
-                                    criteriaBuilder.equal(root.get("userId"), userId),
-                                    // and (lockTo is null or (lockTo is not null and lockTo < now))
-                                    criteriaBuilder.or(criteriaBuilder.isNull(root.get("lockTo")),
-                                            criteriaBuilder.and(criteriaBuilder.isNotNull(root.get("lockTo")),
-                                                    criteriaBuilder.lessThan(root.get("lockTo"), LocalDateTime.now()))),
-                                    // and status = 'NORMAL'
-                                    criteriaBuilder.equal(root.get("status"), AssetStatus.NORMAL),
-                                    // and has some tagId
-                                    root.join("tags").get("id").in(tags.stream().map(Tag::getId).toArray()))
+                            // where userId=some id
+                            criteriaBuilder.equal(root.get("userId"), userId),
+                            // and (lockTo is null or (lockTo is not null and lockTo < now))
+                            criteriaBuilder.or(criteriaBuilder.isNull(root.get("lockTo")),
+                                    criteriaBuilder.and(criteriaBuilder.isNotNull(root.get("lockTo")),
+                                            criteriaBuilder.lessThan(root.get("lockTo"), LocalDateTime.now()))),
+                            // and status = 'NORMAL'
+                            criteriaBuilder.equal(root.get("status"), AssetStatus.NORMAL),
+                            // and has some tagId
+                            root.join("tags").get("id").in(tags.stream().map(Tag::getId).toArray()))
                             .getRestriction(), pageable);
         } else {
             return assetRepo.findByUserIdAndStatusAndNameLike(userId, AssetStatus.NORMAL,
@@ -830,7 +833,7 @@ public class AssetService {
         }
     }
 
-    public void destroy(Long id, Long userId ,String tradeCode) {
+    public void destroy(Long id, Long userId, String tradeCode) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         if (!asset.getUserId().equals(userId)) {
             throw new BusinessException("此藏品不属于你");
@@ -843,7 +846,7 @@ public class AssetService {
 //            cancelPublic(asset);
         }
         User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
-        if (StringUtils.isEmpty(user.getTradeCode())){
+        if (StringUtils.isEmpty(user.getTradeCode())) {
             throw new BusinessException("未设置交易密码");
         }
         if (!passwordEncoder.matches(tradeCode, user.getTradeCode())) {
@@ -886,6 +889,7 @@ public class AssetService {
         //加积分
         userRepo.addDestroyPoint(userId, 1);
     }
+
     public double getRoyalties(Long minterId, double royalties, Long userId) {
         if (royalties == 2) {
             return 2;
@@ -980,7 +984,7 @@ public class AssetService {
         MetaPlayerRoleClassify metaPlayerRoleClassify = new MetaPlayerRoleClassify();
         metaPlayerRoleClassify.setClassify(name);
         List<MetaPlayerRole> metaPlayerRoleList;
-        if("MUGEN".equals(name)) {
+        if ("MUGEN".equals(name)) {
             metaPlayerRoleList = Arrays.asList(new MetaPlayerRole(id, "无限集团"),
                     new MetaPlayerRole(id + 1, "苍茫雷道"),
                     new MetaPlayerRole(id + 2, "炼炉天族"),
@@ -996,10 +1000,11 @@ public class AssetService {
         return metaPlayerRoleClassify;
     }
 
-    private List<MetaPlayerRole> build (Long userId, List<MetaPlayerRole> metaPlayerRoleList) {
+    private List<MetaPlayerRole> build(Long userId, List<MetaPlayerRole> metaPlayerRoleList) {
         metaPlayerRoleList.forEach(metaPlayerRole -> {
             metaPlayerRole.setType(UserHoldTypeEnum.ASSET);
-            metaPlayerRole.setAddress("https://www.raex.vip/9th/productSearch?search=" + metaPlayerRole.getName() + "&source=TRANSFER");
+            metaPlayerRole.setAddress("https://www.raex.vip/9th/productSearch?search=" + metaPlayerRole
+                    .getName() + "&source=TRANSFER");
             List<Asset> assets = assetRepo.findAllByUserIdAndNameLike(userId, "%" + metaPlayerRole.getName() + "%");
             metaPlayerRole.setHold(CollectionUtils.isNotEmpty(assets));
         });