fix(outbound): atomically confirm platform mixed-container dispatch and tracking

This commit is contained in:
2026-09-30 12:37:00 +08:00
parent 5cb2a5145f
commit 125ca34ba4
5 changed files with 109 additions and 15 deletions
@@ -1,10 +1,10 @@
package com.baiyue.firstleg.outbound.dispatch.service;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.firstleg.outbound.dispatch.domain.OutboundDispatchStatus;
import com.baiyue.firstleg.outbound.dispatch.dto.OutboundDispatchDtos.ActionRequest;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/** Real proxy-owned transaction boundary for repeated system convergence after customs completion. */
@@ -12,19 +12,13 @@ import org.springframework.transaction.annotation.Transactional;
public class OutboundDispatchAutoConfirmService {
@Resource private OutboundDispatchService dispatch;
@Transactional
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean confirmIfReady(long containerBookingId) {
var current=dispatch.detail(containerBookingId);
if(OutboundDispatchStatus.WAITING_FOR_LOADING.name().equals(current.aggregate().dispatchStatus()))return true;
if(!current.aggregate().gate().passed())return false;
try{
dispatch.confirm(containerBookingId,0L,"SYSTEM","CUSTOMS-AUTO-DISPATCH-"+containerBookingId,
new ActionRequest(current.aggregate().version(),"整柜报关完成且全部离仓门禁满足,系统自动确认离仓"));
return true;
}catch(BizException ex){
var after=dispatch.detail(containerBookingId);
if(OutboundDispatchStatus.WAITING_FOR_LOADING.name().equals(after.aggregate().dispatchStatus()))return true;
throw ex;
}
dispatch.confirm(containerBookingId,0L,"SYSTEM","CUSTOMS-AUTO-DISPATCH-"+containerBookingId,
new ActionRequest(current.aggregate().version(),"整柜报关完成且全部离仓门禁满足,系统自动确认离仓"));
return true;
}
}
@@ -209,7 +209,7 @@ DELIMITER $$
CREATE TRIGGER trg_carrier_schedule_query_before_insert BEFORE INSERT ON fl_carrier_schedule_query FOR EACH ROW
BEGIN
IF NOT EXISTS (SELECT 1 FROM fl_ocean_booking booking
WHERE booking.id=NEW.ocean_booking_id AND booking.customer_id=NEW.customer_id) THEN
WHERE booking.id=NEW.ocean_booking_id AND COALESCE(booking.customer_id,0)=NEW.customer_id) THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='船司查询客户与订舱不一致';
END IF;
IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (