|
|
|
@ -1,7 +1,10 @@ |
|
|
|
package com.lottery.api.service; |
|
|
|
|
|
|
|
import com.lottery.entity.Seat; |
|
|
|
import com.lottery.entity.SeatStatus; |
|
|
|
import com.lottery.interceptor.SeatRepository; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
@ -16,6 +19,23 @@ public class SeatAsyncSaveService { |
|
|
|
|
|
|
|
@PersistenceContext |
|
|
|
private EntityManager entityManager; |
|
|
|
@Autowired |
|
|
|
private SeatRepository seatRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Async("seatExecutor") // 复用你现有的线程池配置 |
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW) // 确保独立事务提交 |
|
|
|
public void updateStatusByUniqueId(String lockedBy, SeatStatus status) { |
|
|
|
int affected = seatRepository.updateStatusByUniqueId(lockedBy, status); |
|
|
|
|
|
|
|
// 🔥 关键:记录更新结果,便于排查 |
|
|
|
if (affected == 0) { |
|
|
|
log.warn("座位更新失败: uniqueId={}, 可能不存在或已被释放", lockedBy); |
|
|
|
// 可选:集成告警/监控 |
|
|
|
} else { |
|
|
|
log.debug("座位释放成功: uniqueId={}, affected={}", lockedBy, affected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Async("taskExecutor") // 指定线程池 |
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW) |
|
|
|
|