|
|
@@ -9,6 +9,7 @@ import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.AuctionOrderStatus;
|
|
|
import com.izouma.nineth.enums.TradeAuctionStatus;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.TradeAuctionOrderRepo;
|
|
|
import com.izouma.nineth.repo.TradeAuctionRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.ObjUtils;
|
|
|
@@ -39,6 +40,7 @@ public class TradeAuctionService {
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
private GeneralProperties generalProperties;
|
|
|
+ private TradeAuctionOrderRepo tradeAuctionOrderRepo;
|
|
|
|
|
|
public Page<TradeAuction> all(PageQuery pageQuery) {
|
|
|
return tradeAuctionRepo
|
|
|
@@ -175,9 +177,35 @@ public class TradeAuctionService {
|
|
|
}
|
|
|
|
|
|
@Scheduled(fixedRate = 6000)
|
|
|
- public void batchPassAuction() {
|
|
|
+ public void batchPurchaseAuction() {
|
|
|
List<TradeAuctionStatus> tradeAuctionStatuses = new ArrayList<>();
|
|
|
tradeAuctionStatuses.add(TradeAuctionStatus.ONGOING);
|
|
|
+ List<TradeAuction> tradeAuctions = tradeAuctionRepo
|
|
|
+ .findByStatusInAndCurrentEndTimeBefore(tradeAuctionStatuses,
|
|
|
+ LocalDateTime.now().plusMinutes(1));
|
|
|
+ tradeAuctions.parallelStream().forEach(o -> {
|
|
|
+ try {
|
|
|
+ TradeAuction auction = tradeAuctionRepo.findById(o.getId())
|
|
|
+ .orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (auction.getStatus() == TradeAuctionStatus.ONGOING) {
|
|
|
+ purchase(auction);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("取消易拍订单错误 " + o.getId(), e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void purchase(TradeAuction tradeAuction) {
|
|
|
+ tradeAuction.setStatus(TradeAuctionStatus.PURCHASED);
|
|
|
+ tradeAuctionRepo.save(tradeAuction);
|
|
|
+ decreaseStock(tradeAuction.getId(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 6000)
|
|
|
+ public void batchPassAuction() {
|
|
|
+ List<TradeAuctionStatus> tradeAuctionStatuses = new ArrayList<>();
|
|
|
+ tradeAuctionStatuses.add(TradeAuctionStatus.PURCHASED);
|
|
|
List<TradeAuction> tradeAuctions = tradeAuctionRepo
|
|
|
.findByStatusInAndCurrentEndTimeBefore(tradeAuctionStatuses,
|
|
|
LocalDateTime.now().plusMinutes(1));
|
|
|
@@ -195,8 +223,12 @@ public class TradeAuctionService {
|
|
|
}
|
|
|
|
|
|
public void pass(TradeAuction tradeAuction) {
|
|
|
- tradeAuction.setStatus(TradeAuctionStatus.PURCHASED);
|
|
|
+ tradeAuction.setStatus(TradeAuctionStatus.PASS);
|
|
|
tradeAuctionRepo.save(tradeAuction);
|
|
|
+ TradeAuctionOrder tradeAuctionOrder = tradeAuctionOrderRepo.findById(tradeAuction.getCurrentOrderId())
|
|
|
+ .orElseThrow(new BusinessException("暂无订单"));
|
|
|
+ tradeAuctionOrder.setStatus(AuctionOrderStatus.PASS);
|
|
|
+ tradeAuctionOrderRepo.save(tradeAuctionOrder);
|
|
|
decreaseStock(tradeAuction.getId(), 1);
|
|
|
}
|
|
|
}
|