|
|
@@ -26,6 +26,7 @@ import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
@@ -33,6 +34,7 @@ import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -170,4 +172,29 @@ public class GiftOrderService {
|
|
|
}
|
|
|
throw new BusinessException("不支持此付款方式");
|
|
|
}
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 60000)
|
|
|
+ public void batchCancel() {
|
|
|
+ List<GiftOrder> orders = giftOrderRepo.findByStatusAndCreatedAtBeforeAndDelFalse(OrderStatus.NOT_PAID,
|
|
|
+ LocalDateTime.now().minusMinutes(5));
|
|
|
+ orders.forEach(o -> {
|
|
|
+ try {
|
|
|
+ cancel(o);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void cancel(GiftOrder order) {
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
+ throw new BusinessException("已支付订单无法取消");
|
|
|
+ }
|
|
|
+ Asset asset = assetRepo.findById(order.getAssetId()).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
+ asset.setStatus(AssetStatus.NORMAL);
|
|
|
+ assetRepo.save(asset);
|
|
|
+
|
|
|
+ order.setStatus(OrderStatus.CANCELLED);
|
|
|
+ order.setCancelTime(LocalDateTime.now());
|
|
|
+ giftOrderRepo.save(order);
|
|
|
+ }
|
|
|
}
|