fix(firstleg): support platform scope port schedules
This commit is contained in:
@@ -3721,7 +3721,7 @@ CREATE TABLE fl_port_schedule (
|
|||||||
CONSTRAINT fk_port_schedule_booking FOREIGN KEY (ocean_booking_id) REFERENCES fl_ocean_booking (id),
|
CONSTRAINT fk_port_schedule_booking FOREIGN KEY (ocean_booking_id) REFERENCES fl_ocean_booking (id),
|
||||||
CONSTRAINT fk_port_schedule_container FOREIGN KEY (container_booking_id) REFERENCES fl_container_booking (id),
|
CONSTRAINT fk_port_schedule_container FOREIGN KEY (container_booking_id) REFERENCES fl_container_booking (id),
|
||||||
CONSTRAINT chk_port_schedule_booking_cutoff CHECK (((booking_cutoff_at is null) or (etd_at is null) or (booking_cutoff_at <= etd_at))),
|
CONSTRAINT chk_port_schedule_booking_cutoff CHECK (((booking_cutoff_at is null) or (etd_at is null) or (booking_cutoff_at <= etd_at))),
|
||||||
CONSTRAINT chk_port_schedule_customer CHECK ((customer_id > 0)),
|
CONSTRAINT chk_port_schedule_customer CHECK ((customer_id >= 0)),
|
||||||
CONSTRAINT chk_port_schedule_customs_cutoff CHECK (((customs_cutoff_at is null) or (etd_at is null) or (customs_cutoff_at <= etd_at))),
|
CONSTRAINT chk_port_schedule_customs_cutoff CHECK (((customs_cutoff_at is null) or (etd_at is null) or (customs_cutoff_at <= etd_at))),
|
||||||
CONSTRAINT chk_port_schedule_eta CHECK (((etd_at is null) or (eta_at is null) or (eta_at >= etd_at))),
|
CONSTRAINT chk_port_schedule_eta CHECK (((etd_at is null) or (eta_at is null) or (eta_at >= etd_at))),
|
||||||
CONSTRAINT chk_port_schedule_expiry CHECK ((expires_at > observed_at)),
|
CONSTRAINT chk_port_schedule_expiry CHECK ((expires_at > observed_at)),
|
||||||
@@ -5975,7 +5975,7 @@ CREATE TRIGGER trg_ocean_requirement_before_insert BEFORE INSERT ON fl_ocean_boo
|
|||||||
CREATE TRIGGER trg_ocean_requirement_before_update BEFORE UPDATE ON fl_ocean_booking_container_requirement FOR EACH ROW BEGIN IF (SELECT status FROM fl_ocean_booking WHERE id=OLD.ocean_booking_id) <> 'DRAFT' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='仅草稿可维护箱型需求'; END IF; END$$
|
CREATE TRIGGER trg_ocean_requirement_before_update BEFORE UPDATE ON fl_ocean_booking_container_requirement FOR EACH ROW BEGIN IF (SELECT status FROM fl_ocean_booking WHERE id=OLD.ocean_booking_id) <> 'DRAFT' THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='仅草稿可维护箱型需求'; END IF; END$$
|
||||||
|
|
||||||
CREATE TRIGGER trg_port_schedule_before_insert BEFORE INSERT ON fl_port_schedule FOR EACH ROW BEGIN
|
CREATE TRIGGER trg_port_schedule_before_insert BEFORE INSERT ON fl_port_schedule FOR EACH ROW BEGIN
|
||||||
IF (SELECT customer_id FROM fl_ocean_booking WHERE id=NEW.ocean_booking_id) <> NEW.customer_id THEN
|
IF COALESCE((SELECT customer_id FROM fl_ocean_booking WHERE id=NEW.ocean_booking_id),0) <> NEW.customer_id THEN
|
||||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='船期客户与订舱客户不一致';
|
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='船期客户与订舱客户不一致';
|
||||||
END IF;
|
END IF;
|
||||||
IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (
|
IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public final class PortScheduleDtos {
|
|||||||
public Query { if (page == 0) page = 1; if (size == 0) size = 20; }
|
public Query { if (page == 0) page = 1; if (size == 0) size = 20; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ScheduleData(@NotNull @Positive Long customerId,
|
public record ScheduleData(@NotNull @Min(0) Long customerId,
|
||||||
@NotNull @Positive Long oceanBookingId,
|
@NotNull @Positive Long oceanBookingId,
|
||||||
@Positive Long containerBookingId,
|
@Positive Long containerBookingId,
|
||||||
@NotBlank @Size(max = 24) String sourceType,
|
@NotBlank @Size(max = 24) String sourceType,
|
||||||
|
|||||||
+2
-1
@@ -102,7 +102,8 @@ public class PortScheduleService {
|
|||||||
private void validateLinks(ScheduleData data) {
|
private void validateLinks(ScheduleData data) {
|
||||||
OceanBookingEntity booking = repository.oceanBooking(data.oceanBookingId());
|
OceanBookingEntity booking = repository.oceanBooking(data.oceanBookingId());
|
||||||
if (booking == null) throw new BizException(ResultCode.NOT_FOUND, "关联订舱不存在");
|
if (booking == null) throw new BizException(ResultCode.NOT_FOUND, "关联订舱不存在");
|
||||||
if (!Objects.equals(booking.getCustomerId(), data.customerId())) throw badRequest("customerId与订舱客户不一致");
|
long expectedCustomerId = booking.getCustomerId() == null ? 0L : booking.getCustomerId();
|
||||||
|
if (expectedCustomerId != data.customerId()) throw badRequest("customerId与订舱客户不一致");
|
||||||
if (data.containerBookingId() != null) {
|
if (data.containerBookingId() != null) {
|
||||||
if (repository.containerBooking(data.containerBookingId()) == null) {
|
if (repository.containerBooking(data.containerBookingId()) == null) {
|
||||||
throw new BizException(ResultCode.NOT_FOUND, "关联柜次不存在");
|
throw new BizException(ResultCode.NOT_FOUND, "关联柜次不存在");
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ CREATE TABLE IF NOT EXISTS fl_port_schedule (
|
|||||||
KEY idx_port_schedule_expiry (expires_at,id),
|
KEY idx_port_schedule_expiry (expires_at,id),
|
||||||
CONSTRAINT fk_port_schedule_booking FOREIGN KEY (ocean_booking_id) REFERENCES fl_ocean_booking(id),
|
CONSTRAINT fk_port_schedule_booking FOREIGN KEY (ocean_booking_id) REFERENCES fl_ocean_booking(id),
|
||||||
CONSTRAINT fk_port_schedule_container FOREIGN KEY (container_booking_id) REFERENCES fl_container_booking(id),
|
CONSTRAINT fk_port_schedule_container FOREIGN KEY (container_booking_id) REFERENCES fl_container_booking(id),
|
||||||
CONSTRAINT chk_port_schedule_customer CHECK (customer_id > 0),
|
CONSTRAINT chk_port_schedule_customer CHECK (customer_id >= 0),
|
||||||
CONSTRAINT chk_port_schedule_source_type CHECK (source_type IN ('MANUAL','CARRIER','TERMINAL','API')),
|
CONSTRAINT chk_port_schedule_source_type CHECK (source_type IN ('MANUAL','CARRIER','TERMINAL','API')),
|
||||||
CONSTRAINT chk_port_schedule_eta CHECK (etd_at IS NULL OR eta_at IS NULL OR eta_at >= etd_at),
|
CONSTRAINT chk_port_schedule_eta CHECK (etd_at IS NULL OR eta_at IS NULL OR eta_at >= etd_at),
|
||||||
CONSTRAINT chk_port_schedule_expiry CHECK (expires_at > observed_at),
|
CONSTRAINT chk_port_schedule_expiry CHECK (expires_at > observed_at),
|
||||||
@@ -93,7 +93,7 @@ DROP TRIGGER IF EXISTS trg_port_schedule_before_update;
|
|||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE TRIGGER trg_port_schedule_before_insert BEFORE INSERT ON fl_port_schedule FOR EACH ROW
|
CREATE TRIGGER trg_port_schedule_before_insert BEFORE INSERT ON fl_port_schedule FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
IF (SELECT customer_id FROM fl_ocean_booking WHERE id=NEW.ocean_booking_id) <> NEW.customer_id THEN
|
IF COALESCE((SELECT customer_id FROM fl_ocean_booking WHERE id=NEW.ocean_booking_id),0) <> NEW.customer_id THEN
|
||||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='船期客户与订舱客户不一致';
|
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='船期客户与订舱客户不一致';
|
||||||
END IF;
|
END IF;
|
||||||
IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (
|
IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (
|
||||||
|
|||||||
Reference in New Issue
Block a user