diff --git a/deploy/sql/头程数据库统一增量-MySQL8.sql b/deploy/sql/头程数据库统一增量-MySQL8.sql index 3d7234d90..fa5ece41e 100644 --- a/deploy/sql/头程数据库统一增量-MySQL8.sql +++ b/deploy/sql/头程数据库统一增量-MySQL8.sql @@ -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_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_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_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)), @@ -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_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='船期客户与订舱客户不一致'; END IF; IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS ( diff --git a/firstleg/src/main/java/com/baiyue/firstleg/portschedule/dto/PortScheduleDtos.java b/firstleg/src/main/java/com/baiyue/firstleg/portschedule/dto/PortScheduleDtos.java index 3d496b8fd..f21ac4c86 100644 --- a/firstleg/src/main/java/com/baiyue/firstleg/portschedule/dto/PortScheduleDtos.java +++ b/firstleg/src/main/java/com/baiyue/firstleg/portschedule/dto/PortScheduleDtos.java @@ -23,7 +23,7 @@ public final class PortScheduleDtos { 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, @Positive Long containerBookingId, @NotBlank @Size(max = 24) String sourceType, diff --git a/firstleg/src/main/java/com/baiyue/firstleg/portschedule/service/PortScheduleService.java b/firstleg/src/main/java/com/baiyue/firstleg/portschedule/service/PortScheduleService.java index e6d9d38a0..07376f204 100644 --- a/firstleg/src/main/java/com/baiyue/firstleg/portschedule/service/PortScheduleService.java +++ b/firstleg/src/main/java/com/baiyue/firstleg/portschedule/service/PortScheduleService.java @@ -102,7 +102,8 @@ public class PortScheduleService { private void validateLinks(ScheduleData data) { OceanBookingEntity booking = repository.oceanBooking(data.oceanBookingId()); 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 (repository.containerBooking(data.containerBookingId()) == null) { throw new BizException(ResultCode.NOT_FOUND, "关联柜次不存在"); diff --git a/firstleg/src/main/resources/db/phase3-port-schedule-schema.sql b/firstleg/src/main/resources/db/phase3-port-schedule-schema.sql index 0c90d88d5..0d8d114da 100644 --- a/firstleg/src/main/resources/db/phase3-port-schedule-schema.sql +++ b/firstleg/src/main/resources/db/phase3-port-schedule-schema.sql @@ -40,7 +40,7 @@ CREATE TABLE IF NOT EXISTS fl_port_schedule ( 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_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_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), @@ -93,7 +93,7 @@ DROP TRIGGER IF EXISTS trg_port_schedule_before_update; DELIMITER $$ 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='船期客户与订舱客户不一致'; END IF; IF NEW.container_booking_id IS NOT NULL AND NOT EXISTS (