longz
2026-04-27 25df88d0ab9d7444ed1d162b9efa1259ac2f6f66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.sinata.appointment.service.event;
 
import com.sinata.appointment.entity.AppointmentOrder;
import com.sinata.appointment.mapper.AppointmentOrderMapper;
import com.sinata.appointment.service.PostApprovalOrchestrationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
 
@Slf4j
@Component
@RequiredArgsConstructor
public class AppointmentLifecycleEventListener {
 
    private final AppointmentOrderMapper appointmentOrderMapper;
    private final PostApprovalOrchestrationService postApprovalOrchestrationService;
 
    @Async("applicationTaskExecutor")
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void handleApproved(AppointmentApprovedEvent event) {
        AppointmentOrder order = appointmentOrderMapper.selectById(event.orderId());
        if (order == null) {
            log.warn("Approved event skipped, order not found orderId={}", event.orderId());
            return;
        }
        postApprovalOrchestrationService.onOrderFullyApproved(order);
    }
 
    @Async("applicationTaskExecutor")
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void handleRejected(AppointmentRejectedEvent event) {
        AppointmentOrder order = appointmentOrderMapper.selectById(event.orderId());
        if (order == null) {
            log.warn("Rejected event skipped, order not found orderId={}", event.orderId());
            return;
        }
        postApprovalOrchestrationService.onOrderRejected(order, event.reason());
    }
}