This commit is contained in:
2026-09-29 18:06:18 +08:00
parent 54ad26c607
commit 2c60a29e0f
30 changed files with 384 additions and 139 deletions
@@ -5,12 +5,17 @@ import com.baiyue.common.event.DeliveryAck;
import com.baiyue.common.event.EventEnvelope;
import com.baiyue.common.event.EventTypes;
import lombok.RequiredArgsConstructor;
import com.baiyue.common.web.EventDeliveryFailure;
import java.util.Set;
import org.springframework.stereotype.Component;
/** Dispatches each supported business event directly to its owning service. */
@Component
@RequiredArgsConstructor
public class DirectEventClient {
private static final Set<String> FINANCE_PERMANENT_CODES = Set.of(
"FIN-EVT-001", "FIN-EVT-002", "FIN-EVT-004", "FIN-EVT-007", "FIN-EVT-008",
"FIN-EVT-012", "FIN-EVT-015", "FIN-EVT-016", "FIN-EVT-401");
private final FirstlegEventClient firstleg;
private final FinanceBusinessEventClient finance;
@@ -20,9 +25,13 @@ public class DirectEventClient {
case EventTypes.OVERSEAS_CONTAINER_UNLOADED,
EventTypes.OVERSEAS_INBOUND_ORDER_DETAINED_CHANGED,
EventTypes.OVERSEAS_DELIVERY_COMPLETED -> firstleg.receive(token, event);
case EventTypes.WALLET_COMMAND_REQUESTED -> finance.wallet(token, event);
case EventTypes.BUSINESS_FEE_SOURCE_CHANGED -> finance.fee(token, event);
default -> throw new IllegalArgumentException("Unsupported outbound event type: " + event.eventType());
case EventTypes.WALLET_COMMAND_REQUESTED -> checkedFinance(finance.wallet(token, event));
case EventTypes.BUSINESS_FEE_SOURCE_CHANGED -> checkedFinance(finance.fee(token, event));
default -> throw new EventDeliveryFailure(true, "Unsupported outbound event type: " + event.eventType());
};
}
private ApiResponse<DeliveryAck> checkedFinance(ApiResponse<DeliveryAck> response) {
EventDeliveryFailure.requireSuccessful(response, FINANCE_PERMANENT_CODES);
return response;
}
}