xiongzhu 4 years ago
parent
commit
11e4983d8e

+ 1 - 9
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -31,8 +31,6 @@ import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.redis.core.BoundValueOperations;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.retry.annotation.Backoff;
-import org.springframework.retry.annotation.Retryable;
 import org.springframework.scheduling.TaskScheduler;
 import org.springframework.stereotype.Service;
 
@@ -287,14 +285,7 @@ public class CollectionService {
                 .build());
     }
 
-    @Retryable(value = {BusinessException.class}, maxAttempts = 3, backoff = @Backoff(delay = 1000))
     public synchronized BlindBoxItem draw(Long collectionId) {
-//        BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps("draw::" + collectionId);
-//        if (ops.get() == null) {
-//            Boolean success = ops.setIfAbsent(blindBoxItemRepo.findByBlindBoxId(collectionId), 7, TimeUnit.DAYS);
-//            log.info("抽盲盒缓存 {} {}", collectionId, success);
-//        }
-        long t = System.currentTimeMillis();
         List<BlindBoxItem> items = blindBoxItemRepo.findByBlindBoxId(collectionId);
 
         Map<BlindBoxItem, Range<Integer>> randomRange = new HashMap<>();
@@ -346,6 +337,7 @@ public class CollectionService {
 //        winItem.setSale(winItem.getSale() + 1);
 //        blindBoxItemRepo.saveAndFlush(winItem);
         blindBoxItemRepo.decreaseStockAndIncreaseSale(winItem.getId(), 1);
+        blindBoxItemRepo.flush();
         return winItem;
     }
 

+ 1 - 5
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -52,7 +52,6 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.Model;
 
-import javax.transaction.Transactional;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
@@ -112,7 +111,6 @@ public class OrderService {
         return String.valueOf(id);
     }
 
-    @Transactional
     public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor, Long id) {
         long t = System.currentTimeMillis();
         qty = 1;
@@ -471,7 +469,6 @@ public class OrderService {
         return restAmount.subtract(divAmount);
     }
 
-    @Transactional
     public void notifyOrder(Long orderId, PayMethod payMethod, String transactionId) {
         log.info("订单回调 orderId: {}, payMethod: {}, transactionId: {}", orderId, payMethod, transactionId);
         BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps("orderLock::" + orderId);
@@ -558,11 +555,10 @@ public class OrderService {
                     .build();
             if (e instanceof BusinessException) {
                 log.error("订单回调出错 orderId: {} {}", orderId, e.getMessage());
-                errorOrder.setErrorMessage(e.getMessage());
             } else {
                 log.error("订单回调出错 orderId: " + orderId, e);
-                errorOrder.setErrorMessage(e.getMessage());
             }
+            errorOrder.setErrorMessage(e.getMessage());
             errorOrderRepo.save(errorOrder);
 
         }