fix: complete October 22 workflow feedback and request failure recovery
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# 单测试环境数据库空库初始化
|
# 单测试环境数据库空库初始化
|
||||||
|
|
||||||
|
放舱后预计到港窄维护需要配套更新 `trg_ocean_booking_before_update`:仅从冻结比较中移除 `estimated_arrival_at`,其余运输、预报、关系方及柜型冻结不变。定义已同步 `firstleg/src/main/resources/db/phase3-ocean-booking-schema.sql` 与国内统一基线;已有 TEST 需另行审阅并授权替换该触发器,不重放空库文件,不回填数据。本轮只准备定义,未执行 SQL 或部署。
|
||||||
|
|
||||||
|
货柜关联已放舱订舱时不再限制 ISO 柜号格式,Firstleg 模块基线与国内统一空库基线已移除 `chk_container_booking_iso6346`,保留同订舱柜号唯一键。既有 TEST 发布前需核对并单独授权移除该约束:`ALTER TABLE baiyue_firstleg.fl_container_booking DROP CHECK chk_container_booking_iso6346;`。配套发布 Firstleg 与 Admin;不重放空库初始化、不修改业务数据。本次仅准备源码与 SQL 定义,未执行环境 SQL 或部署。
|
||||||
|
|
||||||
仓储转运到仓取货、本土卡车接入现有排车的**可重复执行汇总SQL**为 `lastleg-dispatch-transport-tasks.sql`,文件内固定 `USE baiyue_lastleg`,对已存在字段、表安全跳过。新增 `ll_dispatch_order.task_type` 字段、`ll_dispatch_truck_task`、`ll_dispatch_transport_create`、`ll_dispatch_transport_command` 三张表,并确保既有正式排车单号日流水表存在;不回填或删除业务数据。前置是目标库已具备现有整车排车主表、FleetTrip、取货任务及本土卡车原单结构。按序先执行此 SQL,再配套发布 Lastleg 与 Admin;取消释放有效原单关联、完成保留关联。`migrations/overseas/baiyue_lastleg/V32__dispatch_transport_tasks.sql` 是迁移系统中的新增结构记录。本次仅在已授权本机执行并验收,不代表远端已部署。
|
仓储转运到仓取货、本土卡车接入现有排车的**可重复执行汇总SQL**为 `lastleg-dispatch-transport-tasks.sql`,文件内固定 `USE baiyue_lastleg`,对已存在字段、表安全跳过。新增 `ll_dispatch_order.task_type` 字段、`ll_dispatch_truck_task`、`ll_dispatch_transport_create`、`ll_dispatch_transport_command` 三张表,并确保既有正式排车单号日流水表存在;不回填或删除业务数据。前置是目标库已具备现有整车排车主表、FleetTrip、取货任务及本土卡车原单结构。按序先执行此 SQL,再配套发布 Lastleg 与 Admin;取消释放有效原单关联、完成保留关联。`migrations/overseas/baiyue_lastleg/V32__dispatch_transport_tasks.sql` 是迁移系统中的新增结构记录。本次仅在已授权本机执行并验收,不代表远端已部署。
|
||||||
|
|
||||||
排车单号使用`PCyyyyMMdd0001`,日期取`Asia/Shanghai`,全平台跨客户/仓库共用独立日流水。`ll_dispatch_daily_sequence`同步Lastleg源基线与海外空库基线;已有结构的定向新增入口为`lastleg-dispatch-daily-sequence.sql`,只建序列表,不改已有业务号、不回填历史、不重放空库初始化。源码和DDL须配套发布;文件存在不表示已执行或部署。流水在独立短事务分配,回滚或取消不复用,四位范围每日0001至9999,准确单量以主单统计为准。
|
排车单号使用`PCyyyyMMdd0001`,日期取`Asia/Shanghai`,全平台跨客户/仓库共用独立日流水。`ll_dispatch_daily_sequence`同步Lastleg源基线与海外空库基线;已有结构的定向新增入口为`lastleg-dispatch-daily-sequence.sql`,只建序列表,不改已有业务号、不回填历史、不重放空库初始化。源码和DDL须配套发布;文件存在不表示已执行或部署。流水在独立短事务分配,回滚或取消不复用,四位范围每日0001至9999,准确单量以主单统计为准。
|
||||||
|
|||||||
@@ -1484,7 +1484,6 @@ CREATE TABLE fl_container_booking (
|
|||||||
KEY idx_container_booking_voyage (voyage_no,updated_at),
|
KEY idx_container_booking_voyage (voyage_no,updated_at),
|
||||||
KEY idx_container_booking_transit_summary (actual_sailing_at,actual_warehouse_arrival_at,ocean_booking_id,container_type),
|
KEY idx_container_booking_transit_summary (actual_sailing_at,actual_warehouse_arrival_at,ocean_booking_id,container_type),
|
||||||
CONSTRAINT chk_container_booking_capacity CHECK (((capacity_cbm is null) or (capacity_cbm > 0))),
|
CONSTRAINT chk_container_booking_capacity CHECK (((capacity_cbm is null) or (capacity_cbm > 0))),
|
||||||
CONSTRAINT chk_container_booking_iso6346 CHECK (((container_no is null) or regexp_like(container_no,_utf8mb4'^[A-Z]{3}[UJZ][0-9]{7}$'))),
|
|
||||||
CONSTRAINT chk_container_booking_pickup_code CHECK (((pickup_code is null) or regexp_like(pickup_code,_utf8mb4'^[0-9]{1,64}$'))),
|
CONSTRAINT chk_container_booking_pickup_code CHECK (((pickup_code is null) or regexp_like(pickup_code,_utf8mb4'^[0-9]{1,64}$'))),
|
||||||
CONSTRAINT chk_container_booking_record_status CHECK ((record_status in (_utf8mb4'ACTIVE',_utf8mb4'MERGED'))),
|
CONSTRAINT chk_container_booking_record_status CHECK ((record_status in (_utf8mb4'ACTIVE',_utf8mb4'MERGED'))),
|
||||||
CONSTRAINT chk_container_booking_source CHECK ((source_type in (_utf8mb4'SIMULATION',_utf8mb4'OCEAN_BOOKING'))),
|
CONSTRAINT chk_container_booking_source CHECK ((source_type in (_utf8mb4'SIMULATION',_utf8mb4'OCEAN_BOOKING'))),
|
||||||
@@ -6049,7 +6048,7 @@ END$$
|
|||||||
|
|
||||||
CREATE TRIGGER trg_ocean_booking_before_update BEFORE UPDATE ON fl_ocean_booking FOR EACH ROW
|
CREATE TRIGGER trg_ocean_booking_before_update BEFORE UPDATE ON fl_ocean_booking FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
-- 已放舱只允许实货量及其审计元数据变化,运输和预报快照保持冻结。
|
-- 已放舱只允许预计到港、实货量及审计元数据变化,其余运输和预报快照保持冻结。
|
||||||
IF OLD.status = 'RELEASED' AND NOT (
|
IF OLD.status = 'RELEASED' AND NOT (
|
||||||
(NEW.id <=> OLD.id)
|
(NEW.id <=> OLD.id)
|
||||||
AND (NEW.booking_no <=> OLD.booking_no)
|
AND (NEW.booking_no <=> OLD.booking_no)
|
||||||
@@ -6074,7 +6073,6 @@ BEGIN
|
|||||||
AND (NEW.destination_port_name <=> OLD.destination_port_name)
|
AND (NEW.destination_port_name <=> OLD.destination_port_name)
|
||||||
AND (NEW.place_of_delivery <=> OLD.place_of_delivery)
|
AND (NEW.place_of_delivery <=> OLD.place_of_delivery)
|
||||||
AND (NEW.estimated_sailing_at <=> OLD.estimated_sailing_at)
|
AND (NEW.estimated_sailing_at <=> OLD.estimated_sailing_at)
|
||||||
AND (NEW.estimated_arrival_at <=> OLD.estimated_arrival_at)
|
|
||||||
AND (NEW.remark <=> OLD.remark)
|
AND (NEW.remark <=> OLD.remark)
|
||||||
AND (NEW.freight_term <=> OLD.freight_term)
|
AND (NEW.freight_term <=> OLD.freight_term)
|
||||||
AND (NEW.service_term <=> OLD.service_term)
|
AND (NEW.service_term <=> OLD.service_term)
|
||||||
@@ -6089,7 +6087,7 @@ BEGIN
|
|||||||
AND (NEW.created_at <=> OLD.created_at)
|
AND (NEW.created_at <=> OLD.created_at)
|
||||||
AND NEW.version = OLD.version + 1
|
AND NEW.version = OLD.version + 1
|
||||||
) THEN
|
) THEN
|
||||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='已放舱运输资料不可修改,仅允许补录实货量';
|
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='已放舱仅允许维护预计到港及补录实货量';
|
||||||
END IF;
|
END IF;
|
||||||
IF OLD.status <> NEW.status AND NOT (
|
IF OLD.status <> NEW.status AND NOT (
|
||||||
(OLD.status='DRAFT' AND NEW.status='RELEASED')) THEN
|
(OLD.status='DRAFT' AND NEW.status='RELEASED')) THEN
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
- 客户箱规配置必须恰好保持四档且默认算法在四行一致;`ADD` 以实测尺寸为基准对三个维度分别增加命中箱规的尺寸值,`MULTIPLY` 使用当前客户唯一默认计费规则,并由服务端按规则中的规格档位选择系数。测量行必须保存实际尺寸、选用规则和算法快照,页面不得自行重算后覆盖服务端结果;计价使用用户确认的重量/体积选择值并纳入幂等请求哈希。
|
- 客户箱规配置必须恰好保持四档且默认算法在四行一致;`ADD` 以实测尺寸为基准对三个维度分别增加命中箱规的尺寸值,`MULTIPLY` 使用当前客户唯一默认计费规则,并由服务端按规则中的规格档位选择系数。测量行必须保存实际尺寸、选用规则和算法快照,页面不得自行重算后覆盖服务端结果;计价使用用户确认的重量/体积选择值并纳入幂等请求哈希。
|
||||||
- 报关、订舱和拖车引用的供应商必须通过 `WarehouseSupplierSnapshotService` 按 ID 向 Warehouse 校验:报关使用 `CUSTOMS`,订舱使用 `BOOKING`(不区分国内/国外 scope),国内拖车使用 `TRUCKING + truckingScope=DOMESTIC`,清关提柜/目的港码头拖车使用 `TRUCKING + truckingScope=OVERSEAS`;供应商必须为 `ACTIVE`。请求中的名称只能作为一致性提示,持久化名称必须来自 Warehouse 快照,禁止用自由文本绕过 ID、类别或启用状态校验。修改任一供应商引用 DTO、OpenAPI 或内部客户端时,必须同步检查三条业务链、Warehouse `supplier-v1.yaml`、数据库快照字段和对应契约测试。
|
- 报关、订舱和拖车引用的供应商必须通过 `WarehouseSupplierSnapshotService` 按 ID 向 Warehouse 校验:报关使用 `CUSTOMS`,订舱使用 `BOOKING`(不区分国内/国外 scope),国内拖车使用 `TRUCKING + truckingScope=DOMESTIC`,清关提柜/目的港码头拖车使用 `TRUCKING + truckingScope=OVERSEAS`;供应商必须为 `ACTIVE`。请求中的名称只能作为一致性提示,持久化名称必须来自 Warehouse 快照,禁止用自由文本绕过 ID、类别或启用状态校验。修改任一供应商引用 DTO、OpenAPI 或内部客户端时,必须同步检查三条业务链、Warehouse `supplier-v1.yaml`、数据库快照字段和对应契约测试。
|
||||||
- Order 渠道变更门禁必须检查装柜或后续状态、PDA task、预装、分柜及同柜组兼容性;任何不确定结果均失败关闭。`ORDER_DECLARATION_UPDATED_V1` 消费必须校验订单号/入仓码归属,永久保留 `eventId + payload hash` 幂等历史并按版本单调更新申报投影;不得覆盖仓库实测、箱码、测量审核或已确认费用。
|
- Order 渠道变更门禁必须检查装柜或后续状态、PDA task、预装、分柜及同柜组兼容性;任何不确定结果均失败关闭。`ORDER_DECLARATION_UPDATED_V1` 消费必须校验订单号/入仓码归属,永久保留 `eventId + payload hash` 幂等历史并按版本单调更新申报投影;不得覆盖仓库实测、箱码、测量审核或已确认费用。
|
||||||
- 订舱状态固定为 `DRAFT → RELEASED`:草稿允许资料不完整并可替换或删除,放舱时校验完整持久化聚合,放舱后运输、预报货量、三方和柜型需求只读;仅三项实际货量允许通过 `OceanBookingService.updateActualCargo` 按编辑权限、版本、幂等键和原因补录并保存前后审计快照。创建草稿和放舱都只维护订舱聚合、三类参与方及柜型需求,不创建真实 `containerNo`、货柜行或分配关系;真实货柜只在后续提柜关联时占用已放舱柜型需求。
|
- 订舱状态固定为 `DRAFT → RELEASED`:草稿允许资料不完整并可替换或删除,放舱时校验完整持久化聚合,放舱后除预计到港外的运输、预报货量、三方和柜型需求只读;预计到港允许通过 `/estimated-arrival` 按编辑权限、版本与幂等键单独维护,保留前后审计快照且不得清空或早于预计开船,不改实际到港或计划到仓;三项实际货量允许通过 `OceanBookingService.updateActualCargo` 按编辑权限、版本、幂等键和原因补录并保存前后审计快照。创建草稿和放舱都只维护订舱聚合、三类参与方及柜型需求,不创建真实 `containerNo`、货柜行或分配关系;真实货柜只在后续提柜关联时占用已放舱柜型需求。
|
||||||
- 订舱柜型需求至少一项、最多 20 项,数量必须为正整数,容量和限重必须匹配平台柜型规格。起运仓必须是启用的国内中转仓;物流渠道必须来自该仓当前 ACTIVE 价格版本,服务端保存渠道名称快照,渠道失效时失败关闭。预计到港草稿可留空,放舱前必填且不得早于预计开船时间;关联柜次时带入柜级到港来源,供日历和默认到仓日期解析使用。
|
- 订舱柜型需求至少一项、最多 20 项,数量必须为正整数,容量和限重必须匹配平台柜型规格。起运仓必须是启用的国内中转仓;物流渠道必须来自该仓当前 ACTIVE 价格版本,服务端保存渠道名称快照,渠道失效时失败关闭。预计到港草稿可留空,放舱前必填且不得早于预计开船时间;关联柜次时带入柜级到港来源,供日历和默认到仓日期解析使用。
|
||||||
- 订舱号遵循 `../../../docs/业务单据编号契约.md`;不得以实体 ID 拼接生成。提单号在订舱主表全局唯一,柜次表只保存快照;真实集装箱号只在同一订舱内唯一,不同提单允许复用。放舱不要求真实柜号,也不得为满足放舱校验伪造柜号。
|
- 订舱号遵循 `../../../docs/业务单据编号契约.md`;不得以实体 ID 拼接生成。提单号在订舱主表全局唯一,柜次表只保存快照;真实集装箱号只在同一订舱内唯一,不同提单允许复用。放舱不要求真实柜号,也不得为满足放舱校验伪造柜号。
|
||||||
- 订舱列表 `containerCount` 固定为该订舱全部柜型需求 `quantity` 之和,与真实柜关联/解除无关;关联候选只返回 `RELEASED`、剩余数量大于 0 且 `warehouseId + channelCode + containerType` 精确匹配的需求,由服务端集合查询 ACTIVE 分配量。前端不得扇出详情计算或用已关联柜数覆盖该字段,最终关联命令仍须重验目标货柜可修改性。
|
- 订舱列表 `containerCount` 固定为该订舱全部柜型需求 `quantity` 之和,与真实柜关联/解除无关;关联候选只返回 `RELEASED`、剩余数量大于 0 且 `warehouseId + channelCode + containerType` 精确匹配的需求,由服务端集合查询 ACTIVE 分配量。前端不得扇出详情计算或用已关联柜数覆盖该字段,最终关联命令仍须重验目标货柜可修改性。
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
## 国内货柜履约装柜与 PDA 资源结算
|
## 国内货柜履约装柜与 PDA 资源结算
|
||||||
|
|
||||||
- 新增模拟柜只保存智能装柜的 9 类计划渠道 channel_group_code;未关联已放舱订舱时 channel_code/channel_name 为空,关联后才冻结订舱的实际渠道。智能装柜全局工作台和订舱关联候选均按计划渠道组匹配;服务端把业务渠道分组映射为实际渠道,并分别分页查询候选与 `WAIT_LOADING/EDITING/LOADING` 柜次;候选支持按创建日期和预计到货日期闭区间筛选,状态筛选使用最多四项的 `orderStatuses`,未传表示 `PENDING_REVIEW/WAIT_MEASURE/WAIT_SPLIT/LOADING` 全部未完成状态。状态只用于搜索和展示,能否加入以响应 `canAssign` 为准,由有效柜次占用、剩余箱数、容量、组锁和版本等事实决定;人工加入允许订单国内仓及渠道与柜次不同,智能推荐允许跨国内仓但仍只选择柜次渠道。容积和重量均允许达到柜型额定值的 150%,超过即拒绝。待审核事实必须经 `PendingReviewOrderClient` 重新核验 Order 权威 `SUBMITTED` 订单,待审核或待测量可先占位,但确认预装和启动 PDA 前仍必须进入 `WAIT_SPLIT`。计划明细通过 `totalPackageCount/remainingPackageCount` 返回可调总量和余量:测量前取 Order 原始申报箱数,进入 `WAIT_SPLIT/LOADING` 后取最新已审核测量箱数;只读补充失败时保守回退当前已分配数,调整写入仍重新查询并校验权威数量。同柜不可拆组只有全部成员命中状态集合时才返回,且必须成员完整、满箱并作为单个分页与分配单元,不能跨页或拆分。一次性移除未拣明细时,普通未拣项直接移除;同柜组仅全组未拣时整组移除,任一成员已拣则整组保留,单事务只递增一次计划版本。推荐顺序按入库时间先进先出。真实集装箱号允许在关联已放舱订舱时暂缺,但确认预装及创建 PDA 任务前必须补齐;历史已建但缺号的 PDA 任务可在预装详情首次补录,补录后按柜次当前真实集装箱号恢复作业。装柜计划状态为 `EDITING -> LOADING -> COMPLETED`,PDA 全部明细处理完成后自动完成。
|
- 新增模拟柜只保存智能装柜的 9 类计划渠道 channel_group_code;未关联已放舱订舱时 channel_code/channel_name 为空,关联后才冻结订舱的实际渠道。智能装柜全局工作台和订舱关联候选均按计划渠道组匹配;服务端把业务渠道分组映射为实际渠道,并分别分页查询候选与 `WAIT_LOADING/EDITING/LOADING` 柜次;候选支持按创建日期和预计到货日期闭区间筛选,状态筛选使用最多四项的 `orderStatuses`,未传表示 `PENDING_REVIEW/WAIT_MEASURE/WAIT_SPLIT/LOADING` 全部未完成状态。状态只用于搜索和展示,能否加入以响应 `canAssign` 为准,由有效柜次占用、剩余箱数、容量、组锁和版本等事实决定;人工加入允许订单国内仓及渠道与柜次不同,智能推荐允许跨国内仓但仍只选择柜次渠道。容积和重量均允许达到柜型额定值的 150%,超过即拒绝。待审核事实必须经 `PendingReviewOrderClient` 重新核验 Order 权威 `SUBMITTED` 订单,待审核或待测量可先占位,但确认预装和启动 PDA 前仍必须进入 `WAIT_SPLIT`。计划明细通过 `totalPackageCount/remainingPackageCount` 返回可调总量和余量:测量前取 Order 原始申报箱数,进入 `WAIT_SPLIT/LOADING` 后取最新已审核测量箱数;只读补充失败时保守回退当前已分配数,调整写入仍重新查询并校验权威数量。同柜不可拆组只有全部成员命中状态集合时才返回,且必须成员完整、满箱并作为单个分页与分配单元,不能跨页或拆分。一次性移除未拣明细时,普通未拣项直接移除;同柜组仅全组未拣时整组移除,任一成员已拣则整组保留,单事务只递增一次计划版本。推荐顺序按入库时间先进先出。真实集装箱号允许在关联已放舱订舱时暂缺;该关联入口仅规范化空白和大小写,不以 ISO 长度、结构、设备类别或校验位阻断,数据库不设置 ISO 格式 CHECK,仍遵守同订舱唯一及已有柜号一致性。关联已接受的柜号在运输信息未改号时不重复做 ISO 校验;确认预装与创建 PDA 任务前必须校验 ISO 格式并提示在预装运输信息中纠错,避免实物作业后无法完成,PDA 完成及跨服务事件保持原有格式校验;运输或提柜首次录入及纠正为不同柜号保留原有规则。确认预装及创建 PDA 任务前必须补齐;历史已建但缺号的 PDA 任务可在预装详情首次补录,补录后按柜次当前真实集装箱号恢复作业。装柜计划状态为 `EDITING -> LOADING -> COMPLETED`,PDA 全部明细处理完成后自动完成。
|
||||||
- 预装进入 `CONFIRMING/CONFIRMED` 只固化确认快照,不得锁死尚未完成柜次的智能装柜分配;装柜计划仍处于 `EDITING/LOADING` 时可继续新增,未产生实物拣货的明细可调整或移除,已拣明细保持锁定。一件代发智能装柜候选以每个未被有效柜次占用的已封托托盘为独立分页、展示和分配单位;同一入仓单有多托时必须逐托返回,其中一托已分配不得隐藏或禁用其余未分配托盘。智能推荐必须逐个调用整托分配,容量不足时跳过整托,不得回退按箱分配;全局工作台传入当前 `customerId/inboundCode` 筛选范围时,服务端只能推荐同时命中的候选,同一次推荐按受影响客户统一重算费用,不得逐托重复重算。单行删除必须按该行 `palletId` 整托移除。装柜完成事件必须按计划项 `palletId` 精确冻结每托箱唛与 SKU 清单,不得仅按入仓单或货物明细关联而造成多托交叉重复。
|
- 预装进入 `CONFIRMING/CONFIRMED` 只固化确认快照,不得锁死尚未完成柜次的智能装柜分配;装柜计划仍处于 `EDITING/LOADING` 时可继续新增,未产生实物拣货的明细可调整或移除,已拣明细保持锁定。一件代发智能装柜候选以每个未被有效柜次占用的已封托托盘为独立分页、展示和分配单位;同一入仓单有多托时必须逐托返回,其中一托已分配不得隐藏或禁用其余未分配托盘。智能推荐必须逐个调用整托分配,容量不足时跳过整托,不得回退按箱分配;全局工作台传入当前 `customerId/inboundCode` 筛选范围时,服务端只能推荐同时命中的候选,同一次推荐按受影响客户统一重算费用,不得逐托重复重算。单行删除必须按该行 `palletId` 整托移除。装柜完成事件必须按计划项 `palletId` 精确冻结每托箱唛与 SKU 清单,不得仅按入仓单或货物明细关联而造成多托交叉重复。
|
||||||
- 客户入库费用只在登录客户范围、测量审核通过、`feeStatus=SENT` 且存在已发布明细时可见;确认必须具备 `merchant:order:edit`,携带当前 `expectedFeeVersion` 与幂等键。成功后记录确认成员和时间;客户未确认或该票尚未装柜完成时,平台仍可修改箱规规则、生成新费用版本并重新发送,新版本必须清空旧版客户确认快照。仅当“客户已确认且该票已装柜完成”同时成立时最终冻结;装柜完成不得代替客户自动确认。旧版本、未发送或重复异参确认均返回冲突,不做兼容覆盖。
|
- 客户入库费用只在登录客户范围、测量审核通过、`feeStatus=SENT` 且存在已发布明细时可见;确认必须具备 `merchant:order:edit`,携带当前 `expectedFeeVersion` 与幂等键。成功后记录确认成员和时间;客户未确认或该票尚未装柜完成时,平台仍可修改箱规规则、生成新费用版本并重新发送,新版本必须清空旧版客户确认快照。仅当“客户已确认且该票已装柜完成”同时成立时最终冻结;装柜完成不得代替客户自动确认。旧版本、未发送或重复异参确认均返回冲突,不做兼容覆盖。
|
||||||
- PDA 普通散箱拣货以 `fl_inbound_carton_label.box_code` 对应的稳定箱唛箱码为扫描身份;审核建单、重复打印、手工测量和墨家测量复用同一映射,版本字段只用于并发控制,不进入扫码文本。一个有效且未重复的箱码扫描表示拣出一箱,不得以 SKU、商品件数、入库单号或页面展示字段替代箱码。一件代发已封托的 `SEALED_PALLET` 是不可拆整托单元,PDA 可扫描计划快照中的 `palletNo`、用该托任一成员 `boxCode` 反查所属整托,也可在明细卡片手工确认整托;三种入口最终都必须携带权威 `palletNo` 以 `PICK_PALLET` 一次性提交,不能按成员箱逐箱累计、部分拣货或跳拣。PDA 首页从 Warehouse 主档选择启用国内仓,一件代发与装柜待办列表必须按所选 `warehouseId` 服务端过滤;装柜任务内部仍允许跨国内仓,仓库与渠道限制统一由上游装柜编排负责,PDA 只按已生成任务读取各入仓单自身的 `CONFIRMED` 库位资源,不得再用柜次仓库过滤任务明细、库存快照或拣货写入。任务下发与提交契约见 `src/main/resources/openapi/phase3-pda-convergence-v1.yaml`。
|
- PDA 普通散箱拣货以 `fl_inbound_carton_label.box_code` 对应的稳定箱唛箱码为扫描身份;审核建单、重复打印、手工测量和墨家测量复用同一映射,版本字段只用于并发控制,不进入扫码文本。一个有效且未重复的箱码扫描表示拣出一箱,不得以 SKU、商品件数、入库单号或页面展示字段替代箱码。一件代发已封托的 `SEALED_PALLET` 是不可拆整托单元,PDA 可扫描计划快照中的 `palletNo`、用该托任一成员 `boxCode` 反查所属整托,也可在明细卡片手工确认整托;三种入口最终都必须携带权威 `palletNo` 以 `PICK_PALLET` 一次性提交,不能按成员箱逐箱累计、部分拣货或跳拣。PDA 首页从 Warehouse 主档选择启用国内仓,一件代发与装柜待办列表必须按所选 `warehouseId` 服务端过滤;装柜任务内部仍允许跨国内仓,仓库与渠道限制统一由上游装柜编排负责,PDA 只按已生成任务读取各入仓单自身的 `CONFIRMED` 库位资源,不得再用柜次仓库过滤任务明细、库存快照或拣货写入。任务下发与提交契约见 `src/main/resources/openapi/phase3-pda-convergence-v1.yaml`。
|
||||||
|
|||||||
+11
-7
@@ -211,6 +211,7 @@ public class ContainerCustomsService {
|
|||||||
return platformView(planId);
|
return platformView(planId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 全部预录单经客户确认后发送报关行执行,保留版本与发送状态校验。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public ContainerView submitToBroker(long planId, long operatorId, String operatorName, String key, ActionRequest request) {
|
public ContainerView submitToBroker(long planId, long operatorId, String operatorName, String key, ActionRequest request) {
|
||||||
String action = "SUBMIT_CUSTOMS_TO_BROKER_" + planId;
|
String action = "SUBMIT_CUSTOMS_TO_BROKER_" + planId;
|
||||||
@@ -221,8 +222,8 @@ public class ContainerCustomsService {
|
|||||||
ContainerRow container = mapper.lockContainer(planId);
|
ContainerRow container = mapper.lockContainer(planId);
|
||||||
if (container == null || !DECLARING.equals(container.status())) throw conflict("当前柜不在报关中");
|
if (container == null || !DECLARING.equals(container.status())) throw conflict("当前柜不在报关中");
|
||||||
if (!Objects.equals(container.version(), request.expectedVersion())) throw concurrent();
|
if (!Objects.equals(container.version(), request.expectedVersion())) throw concurrent();
|
||||||
if (mapper.taxRefundCount(container.loadingPlanId()) == 0) throw conflict("全买单柜无需发送客户回执给报关行");
|
if (mapper.taxRefundCount(container.loadingPlanId()) == 0) throw conflict("全买单柜无需发送预录单确认结果给报关行");
|
||||||
if (mapper.unconfirmedReceiptCount(container.id()) != 0) throw conflict("仍有报关行回执未完成客户确认");
|
if (mapper.unconfirmedReceiptCount(container.id()) != 0) throw conflict("仍有预录单未完成客户确认");
|
||||||
if (mapper.brokerSubmission(container.id()) == null) throw conflict("当前柜尚未完成首次发送报关行资料");
|
if (mapper.brokerSubmission(container.id()) == null) throw conflict("当前柜尚未完成首次发送报关行资料");
|
||||||
if (mapper.brokerSubmittedAt(container.id()) != null) throw conflict("当前柜已发送给报关行执行");
|
if (mapper.brokerSubmittedAt(container.id()) != null) throw conflict("当前柜已发送给报关行执行");
|
||||||
if (mapper.submitToBroker(container.id(), container.version(), operatorId, operatorName) != 1) throw concurrent();
|
if (mapper.submitToBroker(container.id(), container.version(), operatorId, operatorName) != 1) throw concurrent();
|
||||||
@@ -231,6 +232,7 @@ public class ContainerCustomsService {
|
|||||||
return platformView(planId);
|
return platformView(planId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 上传预录单并保存文件版本,已发送报关行执行后仍禁止替换。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public DocumentView uploadCompletion(long documentId, long operatorId, String operatorName, String key,
|
public DocumentView uploadCompletion(long documentId, long operatorId, String operatorName, String key,
|
||||||
int expectedVersion, MultipartFile file) {
|
int expectedVersion, MultipartFile file) {
|
||||||
@@ -246,7 +248,7 @@ public class ContainerCustomsService {
|
|||||||
throw conflict("当前客户资料不在报关中冻结版本");
|
throw conflict("当前客户资料不在报关中冻结版本");
|
||||||
}
|
}
|
||||||
if (mapper.brokerSubmittedAt(container.id()) != null) {
|
if (mapper.brokerSubmittedAt(container.id()) != null) {
|
||||||
throw conflict("客户确认回执已发送给报关行,不可再修改回执");
|
throw conflict("客户确认的预录单已发送给报关行,不可再修改预录单");
|
||||||
}
|
}
|
||||||
if (mapper.brokerSubmission(container.id()) == null) {
|
if (mapper.brokerSubmission(container.id()) == null) {
|
||||||
throw conflict("当前柜尚未完成首次发送报关行资料");
|
throw conflict("当前柜尚未完成首次发送报关行资料");
|
||||||
@@ -300,6 +302,7 @@ public class ContainerCustomsService {
|
|||||||
return merchantViewForDocument(tenantId, source);
|
return merchantViewForDocument(tenantId, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 预录单确认并发送报关行执行后,接收真实报关完税文件。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public DocumentView uploadFinalDocument(long documentId, long operatorId, String operatorName, String key,
|
public DocumentView uploadFinalDocument(long documentId, long operatorId, String operatorName, String key,
|
||||||
int expectedVersion, MultipartFile file) {
|
int expectedVersion, MultipartFile file) {
|
||||||
@@ -316,7 +319,7 @@ public class ContainerCustomsService {
|
|||||||
}
|
}
|
||||||
if (mapper.brokerSubmittedAt(container.id()) == null) throw conflict("客户确认结果尚未发送给报关行");
|
if (mapper.brokerSubmittedAt(container.id()) == null) throw conflict("客户确认结果尚未发送给报关行");
|
||||||
CompletionRow receipt = mapper.lockCompletion(documentId);
|
CompletionRow receipt = mapper.lockCompletion(documentId);
|
||||||
if (receipt == null || !"CONFIRMED".equals(receipt.customerConfirmStatus())) throw conflict("该客户回执尚未确认");
|
if (receipt == null || !"CONFIRMED".equals(receipt.customerConfirmStatus())) throw conflict("该客户的预录单尚未确认");
|
||||||
FinalRow existing = mapper.lockFinalDocument(documentId);
|
FinalRow existing = mapper.lockFinalDocument(documentId);
|
||||||
CustomsFileClient.Metadata metadata = upload(source.tenantId(), RESULT_FILE_TYPE, Long.toString(container.loadingPlanId()), operatorId, file);
|
CustomsFileClient.Metadata metadata = upload(source.tenantId(), RESULT_FILE_TYPE, Long.toString(container.loadingPlanId()), operatorId, file);
|
||||||
long finalId;
|
long finalId;
|
||||||
@@ -371,7 +374,7 @@ public class ContainerCustomsService {
|
|||||||
if (container == null || !(DECLARING.equals(container.status()) || COMPLETED.equals(container.status()))) throw conflict("当前柜尚未进入报关行执行阶段,不能创建正式申报批次");
|
if (container == null || !(DECLARING.equals(container.status()) || COMPLETED.equals(container.status()))) throw conflict("当前柜尚未进入报关行执行阶段,不能创建正式申报批次");
|
||||||
if (mapper.taxRefundCount(planId) == 0) throw conflict("全买单柜不创建退税正式申报批次");
|
if (mapper.taxRefundCount(planId) == 0) throw conflict("全买单柜不创建退税正式申报批次");
|
||||||
if (mapper.unconfirmedReceiptCount(container.id()) != 0 || mapper.brokerSubmittedAt(container.id()) == null) {
|
if (mapper.unconfirmedReceiptCount(container.id()) != 0 || mapper.brokerSubmittedAt(container.id()) == null) {
|
||||||
throw conflict("当前柜尚未完成退税资料、回执确认和报关行执行");
|
throw conflict("当前柜尚未完成退税资料、预录单确认和报关行执行");
|
||||||
}
|
}
|
||||||
if (!Objects.equals(container.version(), request.expectedVersion())) throw concurrent();
|
if (!Objects.equals(container.version(), request.expectedVersion())) throw concurrent();
|
||||||
long batchId = IdWorker.getId();
|
long batchId = IdWorker.getId();
|
||||||
@@ -536,14 +539,15 @@ public class ContainerCustomsService {
|
|||||||
row.operatorName(), row.createdAt())).toList();
|
row.operatorName(), row.createdAt())).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 按既有客户范围与可见状态下载预录单,沿用文件真实名称。 */
|
||||||
public Download downloadCompletion(long tenantId, long documentId, boolean platform) {
|
public Download downloadCompletion(long tenantId, long documentId, boolean platform) {
|
||||||
DocumentRow source = requiredDocument(documentId);
|
DocumentRow source = requiredDocument(documentId);
|
||||||
ContainerRow container = mapper.containerById(source.customsContainerId());
|
ContainerRow container = mapper.containerById(source.customsContainerId());
|
||||||
if (!platform && (source.tenantId() != tenantId || container == null || !Set.of(DECLARING, COMPLETED).contains(container.status()))) {
|
if (!platform && (source.tenantId() != tenantId || container == null || !Set.of(DECLARING, COMPLETED).contains(container.status()))) {
|
||||||
throw notFound("报关行回执不存在");
|
throw notFound("预录单不存在");
|
||||||
}
|
}
|
||||||
CompletionRow completion = mapper.completion(documentId);
|
CompletionRow completion = mapper.completion(documentId);
|
||||||
if (completion == null) throw notFound("报关行回执不存在");
|
if (completion == null) throw notFound("预录单不存在");
|
||||||
return download(source.tenantId(), RECEIPT_FILE_TYPE, Long.toString(container.loadingPlanId()), completion.fileId(), completion.fileName());
|
return download(source.tenantId(), RECEIPT_FILE_TYPE, Long.toString(container.loadingPlanId()), completion.fileId(), completion.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
@@ -126,6 +126,17 @@ public class PlatformOceanBookingController {
|
|||||||
@PutMapping("/{oceanBookingId}") @PreAuthorize("hasAuthority('platform:firstleg:ocean-booking:edit')")
|
@PutMapping("/{oceanBookingId}") @PreAuthorize("hasAuthority('platform:firstleg:ocean-booking:edit')")
|
||||||
@BusinessAudit(event="OCEAN_BOOKING_UPDATE_DRAFT", resourceType="OCEAN_BOOKING", resourceId="#oceanBookingId", description="编辑海运订舱草稿")
|
@BusinessAudit(event="OCEAN_BOOKING_UPDATE_DRAFT", resourceType="OCEAN_BOOKING", resourceId="#oceanBookingId", description="编辑海运订舱草稿")
|
||||||
public ApiResponse<Detail> updateDraft(@AuthenticationPrincipal AuthenticatedUser user, @PathVariable @Positive long oceanBookingId, @RequestHeader("Idempotency-Key") String key, @Valid @RequestBody UpdateRequest request) { validateOptionalCustomer(user, request.data().customerId()); return ApiResponse.success(service.updateDraft(oceanBookingId, user.userId(), user.username(), key, request)); }
|
public ApiResponse<Detail> updateDraft(@AuthenticationPrincipal AuthenticatedUser user, @PathVariable @Positive long oceanBookingId, @RequestHeader("Idempotency-Key") String key, @Valid @RequestBody UpdateRequest request) { validateOptionalCustomer(user, request.data().customerId()); return ApiResponse.success(service.updateDraft(oceanBookingId, user.userId(), user.username(), key, request)); }
|
||||||
|
/** 放舱后单独维护预计到港,其他运输资料仍冻结。 */
|
||||||
|
@PutMapping("/{oceanBookingId}/estimated-arrival")
|
||||||
|
@PreAuthorize("hasAuthority('platform:firstleg:ocean-booking:edit')")
|
||||||
|
@BusinessAudit(event="OCEAN_BOOKING_UPDATE_ESTIMATED_ARRIVAL", resourceType="OCEAN_BOOKING", resourceId="#oceanBookingId", description="维护订舱预计到港")
|
||||||
|
public ApiResponse<Detail> updateEstimatedArrival(@AuthenticationPrincipal AuthenticatedUser user,
|
||||||
|
@PathVariable @Positive long oceanBookingId, @RequestHeader("Idempotency-Key") String key,
|
||||||
|
@Valid @RequestBody EstimatedArrivalRequest request) {
|
||||||
|
FirstlegScopeGuard.platform(user);
|
||||||
|
return ApiResponse.success(service.updateEstimatedArrival(oceanBookingId, user.userId(), user.username(), key, request));
|
||||||
|
}
|
||||||
|
|
||||||
/** 客服在放舱后补录实货量,沿用订舱编辑权限并记录审计。 */
|
/** 客服在放舱后补录实货量,沿用订舱编辑权限并记录审计。 */
|
||||||
@PutMapping("/{oceanBookingId}/actual-cargo")
|
@PutMapping("/{oceanBookingId}/actual-cargo")
|
||||||
@PreAuthorize("hasAuthority('platform:firstleg:ocean-booking:edit')")
|
@PreAuthorize("hasAuthority('platform:firstleg:ocean-booking:edit')")
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ public final class OceanBookingDtos {
|
|||||||
@jakarta.validation.constraints.DecimalMin(value = "0", inclusive = false)
|
@jakarta.validation.constraints.DecimalMin(value = "0", inclusive = false)
|
||||||
@jakarta.validation.constraints.Digits(integer = 12, fraction = 3) BigDecimal actualVolumeCbm) {}
|
@jakarta.validation.constraints.Digits(integer = 12, fraction = 3) BigDecimal actualVolumeCbm) {}
|
||||||
|
|
||||||
|
/** 放舱后仅维护预计到港,不接收其他运输资料。 */
|
||||||
|
public record EstimatedArrivalRequest(@NotNull @Min(0) Integer expectedVersion,
|
||||||
|
@NotNull LocalDateTime estimatedArrivalAt) {}
|
||||||
|
|
||||||
/** 放舱后的受控实货量补录,不接收运输资料。 */
|
/** 放舱后的受控实货量补录,不接收运输资料。 */
|
||||||
public record ActualCargoRequest(@NotNull @Min(0) Integer expectedVersion,
|
public record ActualCargoRequest(@NotNull @Min(0) Integer expectedVersion,
|
||||||
@Min(1) @Max(999999999) Integer actualPackageCount,
|
@Min(1) @Max(999999999) Integer actualPackageCount,
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ public interface OceanBookingMapper extends BaseMapper<OceanBookingEntity> {
|
|||||||
@Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
@Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
||||||
@Update("UPDATE fl_ocean_booking SET customer_id=#{value.customerId},customer_name=#{value.customerName},channel_code=#{value.channelCode},channel_name=#{value.channelName},warehouse_id=#{value.warehouseId},warehouse_name=#{value.warehouseName},bill_of_lading_no=#{value.billOfLadingNo},shipping_company_id=#{value.shippingCompanyId},shipping_company_name=#{value.shippingCompanyName},carrier_code=#{value.carrierCode},booking_agent_id=#{value.bookingAgentId},booking_agent_name=#{value.bookingAgentName},vessel_name=#{value.vesselName},voyage_no=#{value.voyageNo},departure_port_code=#{value.departurePortCode},departure_port_name=#{value.departurePortName},destination_port_code=#{value.destinationPortCode},destination_port_name=#{value.destinationPortName},place_of_delivery=#{value.placeOfDelivery},estimated_sailing_at=#{value.estimatedSailingAt},estimated_arrival_at=#{value.estimatedArrivalAt},remark=#{value.remark},freight_term=#{value.freightTerm},service_term=#{value.serviceTerm},package_unit=#{value.packageUnit},cargo_description=#{value.cargoDescription},marks_and_nos=#{value.marksAndNos},declared_package_count=#{value.declaredPackageCount},declared_gross_weight_kg=#{value.declaredGrossWeightKg},declared_volume_cbm=#{value.declaredVolumeCbm},actual_package_count=#{value.actualPackageCount},actual_gross_weight_kg=#{value.actualGrossWeightKg},actual_volume_cbm=#{value.actualVolumeCbm},updated_by=#{operatorId},updated_by_name=#{operatorName},version=version+1,updated_at=NOW() WHERE id=#{id} AND status='DRAFT' AND version=#{version}")
|
@Update("UPDATE fl_ocean_booking SET customer_id=#{value.customerId},customer_name=#{value.customerName},channel_code=#{value.channelCode},channel_name=#{value.channelName},warehouse_id=#{value.warehouseId},warehouse_name=#{value.warehouseName},bill_of_lading_no=#{value.billOfLadingNo},shipping_company_id=#{value.shippingCompanyId},shipping_company_name=#{value.shippingCompanyName},carrier_code=#{value.carrierCode},booking_agent_id=#{value.bookingAgentId},booking_agent_name=#{value.bookingAgentName},vessel_name=#{value.vesselName},voyage_no=#{value.voyageNo},departure_port_code=#{value.departurePortCode},departure_port_name=#{value.departurePortName},destination_port_code=#{value.destinationPortCode},destination_port_name=#{value.destinationPortName},place_of_delivery=#{value.placeOfDelivery},estimated_sailing_at=#{value.estimatedSailingAt},estimated_arrival_at=#{value.estimatedArrivalAt},remark=#{value.remark},freight_term=#{value.freightTerm},service_term=#{value.serviceTerm},package_unit=#{value.packageUnit},cargo_description=#{value.cargoDescription},marks_and_nos=#{value.marksAndNos},declared_package_count=#{value.declaredPackageCount},declared_gross_weight_kg=#{value.declaredGrossWeightKg},declared_volume_cbm=#{value.declaredVolumeCbm},actual_package_count=#{value.actualPackageCount},actual_gross_weight_kg=#{value.actualGrossWeightKg},actual_volume_cbm=#{value.actualVolumeCbm},updated_by=#{operatorId},updated_by_name=#{operatorName},version=version+1,updated_at=NOW() WHERE id=#{id} AND status='DRAFT' AND version=#{version}")
|
||||||
int updateDraft(@Param("id") long id, @Param("value") OceanBookingEntity value, @Param("version") int version, @Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
int updateDraft(@Param("id") long id, @Param("value") OceanBookingEntity value, @Param("version") int version, @Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
||||||
|
/** 已放舱预计到港窄更新,保留状态、版本和操作审计。 */
|
||||||
|
@Update("UPDATE fl_ocean_booking SET estimated_arrival_at=#{estimatedArrivalAt},updated_by=#{operatorId},updated_by_name=#{operatorName},updated_at=CURRENT_TIMESTAMP(3),version=version+1 WHERE id=#{id} AND status='RELEASED' AND version=#{version}")
|
||||||
|
int updateEstimatedArrival(@Param("id") long id, @Param("estimatedArrivalAt") java.time.LocalDateTime estimatedArrivalAt,
|
||||||
|
@Param("version") int version, @Param("operatorId") long operatorId, @Param("operatorName") String operatorName);
|
||||||
|
|
||||||
/** 已放舱补实只更新白名单字段,保留乐观锁及状态门禁。 */
|
/** 已放舱补实只更新白名单字段,保留乐观锁及状态门禁。 */
|
||||||
@Update("""
|
@Update("""
|
||||||
UPDATE fl_ocean_booking SET actual_package_count=#{value.actualPackageCount},
|
UPDATE fl_ocean_booking SET actual_package_count=#{value.actualPackageCount},
|
||||||
|
|||||||
+5
@@ -54,6 +54,11 @@ public class OceanBookingRepository {
|
|||||||
public int touchDraft(long id, int version, long operatorId, String operatorName) {
|
public int touchDraft(long id, int version, long operatorId, String operatorName) {
|
||||||
return bookings.touchDraft(id, version, operatorId, operatorName);
|
return bookings.touchDraft(id, version, operatorId, operatorName);
|
||||||
}
|
}
|
||||||
|
/** 按订舱版本仅更新已放舱预计到港,不重写其他运输或货量资料。 */
|
||||||
|
public int updateEstimatedArrival(long id, java.time.LocalDateTime estimatedArrivalAt, int version, long operatorId, String operatorName) {
|
||||||
|
return bookings.updateEstimatedArrival(id, estimatedArrivalAt, version, operatorId, operatorName);
|
||||||
|
}
|
||||||
|
|
||||||
/** 只更新已放舱订舱的实际货量,运输快照保持冻结。 */
|
/** 只更新已放舱订舱的实际货量,运输快照保持冻结。 */
|
||||||
public int updateActualCargo(OceanBookingEntity value, int version, long operatorId, String operatorName) {
|
public int updateActualCargo(OceanBookingEntity value, int version, long operatorId, String operatorName) {
|
||||||
return bookings.updateActualCargo(value, version, operatorId, operatorName);
|
return bookings.updateActualCargo(value, version, operatorId, operatorName);
|
||||||
|
|||||||
+18
@@ -145,6 +145,24 @@ public class OceanBookingService {
|
|||||||
addHistory(id, OceanBookingStatus.DRAFT.name(), OceanBookingStatus.DRAFT.name(), action, null, before, after, operatorId, operatorName);
|
addHistory(id, OceanBookingStatus.DRAFT.name(), OceanBookingStatus.DRAFT.name(), action, null, before, after, operatorId, operatorName);
|
||||||
return complete(id, operatorId, action, key, detail(after));
|
return complete(id, operatorId, action, key, detail(after));
|
||||||
}
|
}
|
||||||
|
/** 放舱后单独维护预计到港,按版本和幂等键保存并审计前后快照。 */
|
||||||
|
@Transactional
|
||||||
|
public Detail updateEstimatedArrival(long id, long operatorId, String name, String key, EstimatedArrivalRequest request) {
|
||||||
|
String action = "UPDATE_ESTIMATED_ARRIVAL";
|
||||||
|
Detail replay = claimOrReplay(id, operatorId, action, key, hash(action, id, request));
|
||||||
|
if (replay != null) return replay;
|
||||||
|
OceanBookingEntity before = requiredVersionForUpdate(id, request.expectedVersion());
|
||||||
|
requireStatus(before, OceanBookingStatus.RELEASED);
|
||||||
|
if (request.estimatedArrivalAt() == null) throw badRequest("预计到港时间不能为空");
|
||||||
|
if (before.getEstimatedSailingAt() != null && request.estimatedArrivalAt().isBefore(before.getEstimatedSailingAt())) {
|
||||||
|
throw badRequest("预计到港时间不能早于预计开船时间");
|
||||||
|
}
|
||||||
|
if (repository.updateEstimatedArrival(id, request.estimatedArrivalAt(), request.expectedVersion(), operatorId, name) != 1) throw concurrent();
|
||||||
|
OceanBookingEntity saved = required(id);
|
||||||
|
addHistory(id, before.getStatus(), saved.getStatus(), action, "维护预计到港", before, saved, operatorId, name);
|
||||||
|
return complete(id, operatorId, action, key, detail(saved));
|
||||||
|
}
|
||||||
|
|
||||||
/** 放舱后仅补录实货量,版本、幂等结果和修改前后快照在同一事务保存。 */
|
/** 放舱后仅补录实货量,版本、幂等结果和修改前后快照在同一事务保存。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public Detail updateActualCargo(long id, long operatorId, String name, String key, ActualCargoRequest request) {
|
public Detail updateActualCargo(long id, long operatorId, String name, String key, ActualCargoRequest request) {
|
||||||
|
|||||||
@@ -82,15 +82,19 @@ public class ContainerService {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 首次关联已放舱订舱,仅规范化柜号并保留关联资格与并发校验。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public ContainerBookingEntity linkOceanBooking(long id, long operatorId, String operatorName, OceanBookingLinkRequest request) {
|
public ContainerBookingEntity linkOceanBooking(long id, long operatorId, String operatorName, OceanBookingLinkRequest request) {
|
||||||
ContainerBookingEntity container = required(id); requireVersion(container, request.expectedVersion()); requireFirstLinkMutable(container);
|
ContainerBookingEntity container = required(id); requireVersion(container, request.expectedVersion()); requireFirstLinkMutable(container);
|
||||||
if (container.getOceanBookingId() != null) throw conflict("模拟柜已关联真实订舱柜");
|
if (container.getOceanBookingId() != null) throw conflict("模拟柜已关联真实订舱柜");
|
||||||
String existingContainerNo = trim(container.getContainerNo());
|
String existingContainerNo = trim(container.getContainerNo());
|
||||||
String requestedContainerNo = trim(request.containerNo());
|
String requestedContainerNo = trim(request.containerNo());
|
||||||
String containerNo = requestedContainerNo == null
|
// 本关联入口不按 ISO 长度、结构或校验位阻断,仍统一空白与大小写以核对唯一性。
|
||||||
? existingContainerNo
|
if (requestedContainerNo != null) {
|
||||||
: Iso6346ContainerNumber.require(requestedContainerNo);
|
requestedContainerNo = trim(requestedContainerNo.replaceAll("[\\p{javaWhitespace}\\p{Z}]", "")
|
||||||
|
.toUpperCase(java.util.Locale.ROOT));
|
||||||
|
}
|
||||||
|
String containerNo = requestedContainerNo == null ? existingContainerNo : requestedContainerNo;
|
||||||
if (existingContainerNo != null && !existingContainerNo.equals(containerNo)) {
|
if (existingContainerNo != null && !existingContainerNo.equals(containerNo)) {
|
||||||
throw conflict("输入的真实集装箱号与当前柜次已录入柜号不一致,请先在预装运输信息中纠正");
|
throw conflict("输入的真实集装箱号与当前柜次已录入柜号不一致,请先在预装运输信息中纠正");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -493,10 +493,15 @@ public class LoadingListService {
|
|||||||
return repository.preloadDetail(requirePlan(planId));
|
return repository.preloadDetail(requirePlan(planId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 保留关联入口已接受的柜号,运输入口首次录入或纠错仍执行原有校验。 */
|
||||||
private static String targetContainerNo(AggregateRow before, String requested) {
|
private static String targetContainerNo(AggregateRow before, String requested) {
|
||||||
if (requested != null) return Iso6346ContainerNumber.require(requested);
|
if (requested == null) return StringUtils.hasText(before.getContainerNo()) ? before.getContainerNo() : null;
|
||||||
return StringUtils.hasText(before.getContainerNo())
|
String normalized = requested.replaceAll("[\\p{javaWhitespace}\\p{Z}]", "")
|
||||||
? Iso6346ContainerNumber.require(before.getContainerNo()) : null;
|
.toUpperCase(java.util.Locale.ROOT);
|
||||||
|
if (StringUtils.hasText(normalized) && normalized.equals(before.getContainerNo())) {
|
||||||
|
return before.getContainerNo();
|
||||||
|
}
|
||||||
|
return Iso6346ContainerNumber.require(requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String transportHash(long planId, int version, String containerNo,
|
private static String transportHash(long planId, int version, String containerNo,
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ public class LoadingPickService {
|
|||||||
smartLoadingRepository.items(plan.getId()));
|
smartLoadingRepository.items(plan.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 确认预装前验证作业资格和真实柜号,格式问题必须在实物作业前纠正。 */
|
||||||
public List<Link> requirePreloadConfirmationReady(long loadingPlanId) {
|
public List<Link> requirePreloadConfirmationReady(long loadingPlanId) {
|
||||||
inboundHoldGuard.requirePlanNotHeld(loadingPlanId);
|
inboundHoldGuard.requirePlanNotHeld(loadingPlanId);
|
||||||
List<Link> links = loadingModelBridge.requireAllocatedLinksForConfirmation(loadingPlanId);
|
List<Link> links = loadingModelBridge.requireAllocatedLinksForConfirmation(loadingPlanId);
|
||||||
@@ -151,6 +152,7 @@ public class LoadingPickService {
|
|||||||
if (booking == null || !StringUtils.hasText(booking.getContainerNo())) {
|
if (booking == null || !StringUtils.hasText(booking.getContainerNo())) {
|
||||||
throw conflict("确认预装前必须录入真实集装箱号");
|
throw conflict("确认预装前必须录入真实集装箱号");
|
||||||
}
|
}
|
||||||
|
requireContainerNumberBeforeStarting(booking.getContainerNo());
|
||||||
var allocation = oceanBookingRepository.allocationByContainer(link.containerBookingId());
|
var allocation = oceanBookingRepository.allocationByContainer(link.containerBookingId());
|
||||||
if (allocation == null) throw conflict("确认预装前必须关联真实订舱柜");
|
if (allocation == null) throw conflict("确认预装前必须关联真实订舱柜");
|
||||||
var oceanBooking = oceanBookingRepository.find(allocation.getOceanBookingId());
|
var oceanBooking = oceanBookingRepository.find(allocation.getOceanBookingId());
|
||||||
@@ -164,12 +166,14 @@ public class LoadingPickService {
|
|||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 仅在柜号已满足完成事件要求时创建 PDA 任务,已有任务的重复同步保持原语义。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public void begin(long planId, String containerNo, long operatorId, String operatorName,
|
public void begin(long planId, String containerNo, long operatorId, String operatorName,
|
||||||
List<LoadingPlanItemEntity> planItems) {
|
List<LoadingPlanItemEntity> planItems) {
|
||||||
inboundHoldGuard.requirePlanNotHeld(planId);
|
inboundHoldGuard.requirePlanNotHeld(planId);
|
||||||
LoadingPickTaskEntity task = repository.taskByPlan(planId);
|
LoadingPickTaskEntity task = repository.taskByPlan(planId);
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
|
requireContainerNumberBeforeStarting(containerNo);
|
||||||
task = new LoadingPickTaskEntity();
|
task = new LoadingPickTaskEntity();
|
||||||
task.setLoadingPlanId(planId);
|
task.setLoadingPlanId(planId);
|
||||||
var booking = smartLoadingRepository.booking(smartLoadingRepository.plan(planId).getContainerBookingId());
|
var booking = smartLoadingRepository.booking(smartLoadingRepository.plan(planId).getContainerBookingId());
|
||||||
@@ -610,6 +614,16 @@ public class LoadingPickService {
|
|||||||
/** 本进程事务提交后的唤醒信号,权威命令和恢复事实仍保存在数据库。 */
|
/** 本进程事务提交后的唤醒信号,权威命令和恢复事实仍保存在数据库。 */
|
||||||
public record CompletionAccepted(long commandId, long acceptedAtNanos) {}
|
public record CompletionAccepted(long commandId, long acceptedAtNanos) {}
|
||||||
|
|
||||||
|
/** 在仍可纠错的预装阶段提示格式错误,避免领取或实物作业后卡在完成门禁。 */
|
||||||
|
private static void requireContainerNumberBeforeStarting(String containerNo) {
|
||||||
|
try {
|
||||||
|
Iso6346ContainerNumber.require(containerNo);
|
||||||
|
} catch (BizException exception) {
|
||||||
|
throw conflict("请先在预装运输信息中纠正真实集装箱号后再确认预装或启动PDA,需符合ISO 6346");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 完成前复核真实柜号,以生成一致的跨服务装柜完成事件。 */
|
||||||
private void requireCompletionContainerNumber(long taskId) {
|
private void requireCompletionContainerNumber(long taskId) {
|
||||||
ContainerBookingEntity booking = repository.activeBookingByTask(taskId);
|
ContainerBookingEntity booking = repository.activeBookingByTask(taskId);
|
||||||
if (booking == null || !StringUtils.hasText(booking.getContainerNo())) {
|
if (booking == null || !StringUtils.hasText(booking.getContainerNo())) {
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ DROP TRIGGER IF EXISTS trg_ocean_booking_before_update;
|
|||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE TRIGGER trg_ocean_booking_before_update BEFORE UPDATE ON fl_ocean_booking FOR EACH ROW
|
CREATE TRIGGER trg_ocean_booking_before_update BEFORE UPDATE ON fl_ocean_booking FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
-- 已放舱只允许实货量及其审计元数据变化,运输和预报快照保持冻结。
|
-- 已放舱只允许预计到港、实货量及审计元数据变化,其余运输和预报快照保持冻结。
|
||||||
IF OLD.status = 'RELEASED' AND NOT (
|
IF OLD.status = 'RELEASED' AND NOT (
|
||||||
(NEW.id <=> OLD.id)
|
(NEW.id <=> OLD.id)
|
||||||
AND (NEW.booking_no <=> OLD.booking_no)
|
AND (NEW.booking_no <=> OLD.booking_no)
|
||||||
@@ -257,7 +257,6 @@ BEGIN
|
|||||||
AND (NEW.destination_port_name <=> OLD.destination_port_name)
|
AND (NEW.destination_port_name <=> OLD.destination_port_name)
|
||||||
AND (NEW.place_of_delivery <=> OLD.place_of_delivery)
|
AND (NEW.place_of_delivery <=> OLD.place_of_delivery)
|
||||||
AND (NEW.estimated_sailing_at <=> OLD.estimated_sailing_at)
|
AND (NEW.estimated_sailing_at <=> OLD.estimated_sailing_at)
|
||||||
AND (NEW.estimated_arrival_at <=> OLD.estimated_arrival_at)
|
|
||||||
AND (NEW.remark <=> OLD.remark)
|
AND (NEW.remark <=> OLD.remark)
|
||||||
AND (NEW.freight_term <=> OLD.freight_term)
|
AND (NEW.freight_term <=> OLD.freight_term)
|
||||||
AND (NEW.service_term <=> OLD.service_term)
|
AND (NEW.service_term <=> OLD.service_term)
|
||||||
@@ -272,7 +271,7 @@ BEGIN
|
|||||||
AND (NEW.created_at <=> OLD.created_at)
|
AND (NEW.created_at <=> OLD.created_at)
|
||||||
AND NEW.version = OLD.version + 1
|
AND NEW.version = OLD.version + 1
|
||||||
) THEN
|
) THEN
|
||||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='已放舱运输资料不可修改,仅允许补录实货量';
|
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='已放舱仅允许维护预计到港及补录实货量';
|
||||||
END IF;
|
END IF;
|
||||||
IF OLD.status <> NEW.status AND NOT (
|
IF OLD.status <> NEW.status AND NOT (
|
||||||
(OLD.status='DRAFT' AND NEW.status='RELEASED')) THEN
|
(OLD.status='DRAFT' AND NEW.status='RELEASED')) THEN
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS fl_document_sequence (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS fl_container_booking (
|
CREATE TABLE IF NOT EXISTS fl_container_booking (
|
||||||
id BIGINT UNSIGNED NOT NULL COMMENT '货柜预订ID(雪花ID)',
|
id BIGINT UNSIGNED NOT NULL COMMENT '货柜预订ID(雪花ID)',
|
||||||
container_no VARCHAR(64) NULL COMMENT '国内柜次真实集装箱号权威快照;ISO 6346标准格式;同一订舱内唯一,不同提单允许复用;订舱关联可选写入、提柜后可原子补录、预装纠错命令可修改',
|
container_no VARCHAR(64) NULL COMMENT '国内柜次真实集装箱号权威快照;订舱关联不限制ISO格式;同一订舱内唯一,不同提单允许复用;订舱关联可选写入、提柜后可原子补录、预装纠错命令可修改',
|
||||||
cabinet_no VARCHAR(64) NOT NULL COMMENT '平台唯一内部柜号',
|
cabinet_no VARCHAR(64) NOT NULL COMMENT '平台唯一内部柜号',
|
||||||
source_type VARCHAR(24) NOT NULL DEFAULT 'SIMULATION' COMMENT '记录来源:SIMULATION内部模拟柜、OCEAN_BOOKING订舱真实柜',
|
source_type VARCHAR(24) NOT NULL DEFAULT 'SIMULATION' COMMENT '记录来源:SIMULATION内部模拟柜、OCEAN_BOOKING订舱真实柜',
|
||||||
record_status VARCHAR(16) NOT NULL DEFAULT 'ACTIVE' COMMENT '记录状态:ACTIVE可操作、MERGED已合并历史',
|
record_status VARCHAR(16) NOT NULL DEFAULT 'ACTIVE' COMMENT '记录状态:ACTIVE可操作、MERGED已合并历史',
|
||||||
@@ -100,9 +100,7 @@ CREATE TABLE IF NOT EXISTS fl_container_booking (
|
|||||||
CONSTRAINT chk_container_booking_record_status CHECK (record_status IN ('ACTIVE','MERGED')),
|
CONSTRAINT chk_container_booking_record_status CHECK (record_status IN ('ACTIVE','MERGED')),
|
||||||
CONSTRAINT chk_container_booking_capacity CHECK (capacity_cbm IS NULL OR capacity_cbm > 0),
|
CONSTRAINT chk_container_booking_capacity CHECK (capacity_cbm IS NULL OR capacity_cbm > 0),
|
||||||
CONSTRAINT chk_container_booking_weight CHECK (max_weight_kg IS NULL OR max_weight_kg > 0),
|
CONSTRAINT chk_container_booking_weight CHECK (max_weight_kg IS NULL OR max_weight_kg > 0),
|
||||||
CONSTRAINT chk_container_booking_pickup_code CHECK (pickup_code IS NULL OR pickup_code REGEXP '^[0-9]{1,64}$'),
|
CONSTRAINT chk_container_booking_pickup_code CHECK (pickup_code IS NULL OR pickup_code REGEXP '^[0-9]{1,64}$')
|
||||||
CONSTRAINT chk_container_booking_iso6346 CHECK
|
|
||||||
(container_no IS NULL OR container_no REGEXP '^[A-Z]{3}[UJZ][0-9]{7}$')
|
|
||||||
) ENGINE=InnoDB COMMENT='平台货柜预订资料;预装状态唯一来源为装柜计划';
|
) ENGINE=InnoDB COMMENT='平台货柜预订资料;预装状态唯一来源为装柜计划';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS fl_container_event_inbox (
|
CREATE TABLE IF NOT EXISTS fl_container_event_inbox (
|
||||||
@@ -228,11 +226,6 @@ BEGIN
|
|||||||
ALTER TABLE fl_container_booking ADD CONSTRAINT chk_container_booking_record_status
|
ALTER TABLE fl_container_booking ADD CONSTRAINT chk_container_booking_record_status
|
||||||
CHECK (record_status IN ('ACTIVE','MERGED'));
|
CHECK (record_status IN ('ACTIVE','MERGED'));
|
||||||
END IF;
|
END IF;
|
||||||
IF NOT EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=DATABASE()
|
|
||||||
AND table_name='fl_container_booking' AND constraint_name='chk_container_booking_iso6346') THEN
|
|
||||||
ALTER TABLE fl_container_booking ADD CONSTRAINT chk_container_booking_iso6346
|
|
||||||
CHECK (container_no IS NULL OR container_no REGEXP '^[A-Z]{3}[UJZ][0-9]{7}$');
|
|
||||||
END IF;
|
|
||||||
IF NOT EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=DATABASE()
|
IF NOT EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=DATABASE()
|
||||||
AND table_name='fl_container_booking' AND constraint_name='chk_container_booking_pickup_code') THEN
|
AND table_name='fl_container_booking' AND constraint_name='chk_container_booking_pickup_code') THEN
|
||||||
ALTER TABLE fl_container_booking ADD CONSTRAINT chk_container_booking_pickup_code
|
ALTER TABLE fl_container_booking ADD CONSTRAINT chk_container_booking_pickup_code
|
||||||
|
|||||||
@@ -118,9 +118,9 @@ paths:
|
|||||||
x-permission: platform:firstleg:customs:list
|
x-permission: platform:firstleg:customs:list
|
||||||
parameters: [{$ref: '#/components/parameters/DocumentId'}]
|
parameters: [{$ref: '#/components/parameters/DocumentId'}]
|
||||||
responses: {'200': {$ref: '#/components/responses/BinaryResponse'}}
|
responses: {'200': {$ref: '#/components/responses/BinaryResponse'}}
|
||||||
/api/platform/v1/customs/loading-plans/documents/{documentId}/receipt/download:
|
/api/platform/v1/customs/loading-plans/documents/{documentId}/completion/download:
|
||||||
get:
|
get:
|
||||||
summary: 平台下载报关行回执
|
summary: 平台下载预录单
|
||||||
x-permission: platform:firstleg:customs:list
|
x-permission: platform:firstleg:customs:list
|
||||||
parameters: [{$ref: '#/components/parameters/DocumentId'}]
|
parameters: [{$ref: '#/components/parameters/DocumentId'}]
|
||||||
responses: {'200': {$ref: '#/components/responses/BinaryResponse'}}
|
responses: {'200': {$ref: '#/components/responses/BinaryResponse'}}
|
||||||
|
|||||||
@@ -607,7 +607,7 @@ paths:
|
|||||||
/api/platform/v1/containers/{id}/ocean-booking-link:
|
/api/platform/v1/containers/{id}/ocean-booking-link:
|
||||||
post:
|
post:
|
||||||
summary: 将内部模拟柜关联到已发布订舱需求
|
summary: 将内部模拟柜关联到已发布订舱需求
|
||||||
description: 需要 platform:firstleg:container:edit;请求指定 RELEASED oceanBookingId 和未满配 requirementId,containerNo 可空。首次关联允许 WAIT_LOADING 或已有预排货的 EDITING 模拟柜,保留原 containerBookingId/cabinetNo/loadingPlanId/items,原子写入订舱、运输和范围快照并创建 allocation;提柜后由拖车链调用柜次服务原子补录真实柜号。若关联请求已提供 containerNo,服务端仍规范化并校验 ISO 6346 结构、设备类别和校验位,并保证同一订舱内唯一;不同提单允许复用同一集装箱号。存在跨仓、跨渠道、柜型规格不一致、超量、同提单重复柜号、PDA、有效装柜证据、业务单证或 LOADING/COMPLETED 等事实时拒绝。
|
description: 需要 platform:firstleg:container:edit;请求指定 RELEASED oceanBookingId 和未满配 requirementId,containerNo 可空。首次关联允许 WAIT_LOADING 或已有预排货的 EDITING 模拟柜,保留原 containerBookingId/cabinetNo/loadingPlanId/items,原子写入订舱、运输和范围快照并创建 allocation;提柜后由拖车链调用柜次服务原子补录真实柜号。若关联请求已提供 containerNo,服务端仅移除空白并转大写,不校验 ISO 6346 长度、结构或校验位,并保证同一订舱内唯一;不同提单允许复用同一集装箱号。关联接受的柜号在运输信息未修改柜号时不重复执行ISO校验;确认预装和创建PDA任务前仍校验ISO格式,并提示在预装运输信息中纠错,防止实物作业后才发现无法完成。存在跨仓、跨渠道、柜型规格不一致、超量、同提单重复柜号、PDA、有效装柜证据、业务单证或 LOADING/COMPLETED 等事实时拒绝。
|
||||||
parameters: [{$ref: '#/components/parameters/ContainerBookingId'}]
|
parameters: [{$ref: '#/components/parameters/ContainerBookingId'}]
|
||||||
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ContainerOceanBookingLinkRequest'}}}}
|
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ContainerOceanBookingLinkRequest'}}}}
|
||||||
responses: {'200': {description: 关联后的同一模拟柜 containerBookingId/cabinetNo;列表仍只有这一条 ACTIVE 操作身份}}
|
responses: {'200': {description: 关联后的同一模拟柜 containerBookingId/cabinetNo;列表仍只有这一条 ACTIVE 操作身份}}
|
||||||
@@ -2947,7 +2947,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
oceanBookingId: {type: integer, format: int64, minimum: 1, description: RELEASED订舱ID}
|
oceanBookingId: {type: integer, format: int64, minimum: 1, description: RELEASED订舱ID}
|
||||||
requirementId: {type: integer, format: int64, minimum: 1, description: 未满配的订舱柜型需求ID}
|
requirementId: {type: integer, format: int64, minimum: 1, description: 未满配的订舱柜型需求ID}
|
||||||
containerNo: {type: string, nullable: true, maxLength: 64, description: 可选;港口提柜后可由拖车链另行原子补录。非空时服务端移除格式空白、转大写并校验ISO 6346结构、设备类别、校验位和同一订舱内唯一性}
|
containerNo: {type: string, nullable: true, maxLength: 64, description: 可选;港口提柜后可由拖车链另行原子补录。关联时移除格式空白并转大写,不校验ISO长度、结构或校验位,仍保证同一订舱内唯一;确认预装及创建PDA任务前需纠正为符合ISO格式的真实柜号}
|
||||||
expectedVersion: {type: integer, minimum: 0}
|
expectedVersion: {type: integer, minimum: 0}
|
||||||
ContainerFeeAdjustRequest:
|
ContainerFeeAdjustRequest:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ paths:
|
|||||||
summary: 修改预装运输信息
|
summary: 修改预装运输信息
|
||||||
description: >-
|
description: >-
|
||||||
可在 EDITING 或 LOADING 阶段首次补录真实集装箱号;已有柜号的纠正仅限仍为 EDITING、PDA任务尚未领取且无任何物理作业事实时,并必须提供原因和当前版本;
|
可在 EDITING 或 LOADING 阶段首次补录真实集装箱号;已有柜号的纠正仅限仍为 EDITING、PDA任务尚未领取且无任何物理作业事实时,并必须提供原因和当前版本;
|
||||||
containerNo 为 null 表示保持当前值,非空时服务端移除格式空白、转大写并校验ISO 6346结构、设备类别和校验位,空白字符串非法且禁止清空。
|
containerNo 为 null 或规范化后等于当前值时保留关联入口已接受的柜号,不重复校验格式;首次录入或纠正为不同值时服务端移除格式空白、转大写并校验ISO 6346结构、设备类别和校验位,空白字符串非法且禁止清空。
|
||||||
x-permission: platform:firstleg:preload:edit
|
x-permission: platform:firstleg:preload:edit
|
||||||
parameters:
|
parameters:
|
||||||
- {$ref: '#/components/parameters/PlanId'}
|
- {$ref: '#/components/parameters/PlanId'}
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ paths:
|
|||||||
parameters: [{$ref: '#/components/parameters/OceanBookingId'}, {$ref: '#/components/parameters/IdempotencyKey'}]
|
parameters: [{$ref: '#/components/parameters/OceanBookingId'}, {$ref: '#/components/parameters/IdempotencyKey'}]
|
||||||
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ActionRequest'}}}}
|
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ActionRequest'}}}}
|
||||||
responses: {'200': {description: Deleted}}
|
responses: {'200': {description: Deleted}}
|
||||||
|
/api/platform/v1/ocean-bookings/{oceanBookingId}/estimated-arrival:
|
||||||
|
put:
|
||||||
|
summary: 放舱后维护预计到港
|
||||||
|
description: 仅允许RELEASED订舱按当前版本与幂等键维护estimatedArrivalAt,不得清空或早于预计开船时间;其他运输、预报、关系方、柜型与附件仍冻结,保存前后快照及操作人。不修改实际到港或计划到仓。
|
||||||
|
x-permission: platform:firstleg:ocean-booking:edit
|
||||||
|
parameters: [{$ref: '#/components/parameters/OceanBookingId'}, {$ref: '#/components/parameters/IdempotencyKey'}]
|
||||||
|
requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/EstimatedArrivalRequest'}}}}
|
||||||
|
responses: {'200': {description: 已保存的RELEASED订舱详情,包含当前版本和预计到港}}
|
||||||
/api/platform/v1/ocean-bookings/{oceanBookingId}/actual-cargo:
|
/api/platform/v1/ocean-bookings/{oceanBookingId}/actual-cargo:
|
||||||
put:
|
put:
|
||||||
summary: Supplement manual actual cargo on a RELEASED booking
|
summary: Supplement manual actual cargo on a RELEASED booking
|
||||||
@@ -217,6 +225,13 @@ components:
|
|||||||
containerRequirements: {type: array, nullable: true, items: {$ref: '#/components/schemas/ContainerRequirementRequest'}}
|
containerRequirements: {type: array, nullable: true, items: {$ref: '#/components/schemas/ContainerRequirementRequest'}}
|
||||||
PartyRequest: {type: object, required: [partyType, partyName], properties: {partyType: {type: string, enum: [SHIPPER, CONSIGNEE, NOTIFY_PARTY]}, partyName: {type: string}, address: {type: string, nullable: true}, contactName: {type: string, nullable: true}, contactPhone: {type: string, nullable: true}, contactEmail: {type: string, format: email, maxLength: 255, nullable: true}, taxNo: {type: string, maxLength: 128, nullable: true}}}
|
PartyRequest: {type: object, required: [partyType, partyName], properties: {partyType: {type: string, enum: [SHIPPER, CONSIGNEE, NOTIFY_PARTY]}, partyName: {type: string}, address: {type: string, nullable: true}, contactName: {type: string, nullable: true}, contactPhone: {type: string, nullable: true}, contactEmail: {type: string, format: email, maxLength: 255, nullable: true}, taxNo: {type: string, maxLength: 128, nullable: true}}}
|
||||||
ContainerRequirementRequest: {type: object, required: [containerType, containerKind, quantity, capacityCbm, maxWeightKg], properties: {containerType: {type: string, enum: [40GP, 40HQ, 45HQ], default: 40HQ}, containerKind: {type: string}, quantity: {type: integer, minimum: 1}, capacityCbm: {type: number, exclusiveMinimum: true, minimum: 0, description: 统一实装上限;40GP=58、40HQ=68、45HQ=86}, maxWeightKg: {type: number, enum: [19500], description: 统一货重上限}}}
|
ContainerRequirementRequest: {type: object, required: [containerType, containerKind, quantity, capacityCbm, maxWeightKg], properties: {containerType: {type: string, enum: [40GP, 40HQ, 45HQ], default: 40HQ}, containerKind: {type: string}, quantity: {type: integer, minimum: 1}, capacityCbm: {type: number, exclusiveMinimum: true, minimum: 0, description: 统一实装上限;40GP=58、40HQ=68、45HQ=86}, maxWeightKg: {type: number, enum: [19500], description: 统一货重上限}}}
|
||||||
|
EstimatedArrivalRequest:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required: [expectedVersion, estimatedArrivalAt]
|
||||||
|
properties:
|
||||||
|
expectedVersion: {type: integer, minimum: 0}
|
||||||
|
estimatedArrivalAt: {type: string, format: date-time}
|
||||||
ActualCargoRequest:
|
ActualCargoRequest:
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
|||||||
+3
-2
@@ -88,7 +88,7 @@ class ContainerControllerContractTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("OpenAPI声明平台级货柜路径和冻结规则")
|
@DisplayName("OpenAPI声明平台级货柜路径、关联柜号格式放行及冻结规则")
|
||||||
void documentsContainerContract() throws Exception {
|
void documentsContainerContract() throws Exception {
|
||||||
String openapi = new ClassPathResource("openapi/firstleg-v1.yaml")
|
String openapi = new ClassPathResource("openapi/firstleg-v1.yaml")
|
||||||
.getContentAsString(StandardCharsets.UTF_8);
|
.getContentAsString(StandardCharsets.UTF_8);
|
||||||
@@ -106,7 +106,8 @@ class ContainerControllerContractTest {
|
|||||||
.contains("未满配 requirementId")
|
.contains("未满配 requirementId")
|
||||||
.contains("containerNo 可空")
|
.contains("containerNo 可空")
|
||||||
.contains("提柜后由拖车链调用柜次服务原子补录真实柜号")
|
.contains("提柜后由拖车链调用柜次服务原子补录真实柜号")
|
||||||
.contains("校验 ISO 6346 结构、设备类别和校验位,并保证同一订舱内唯一")
|
.contains("不校验 ISO 6346 长度、结构或校验位,并保证同一订舱内唯一")
|
||||||
|
.contains("确认预装和创建PDA任务前仍校验ISO格式")
|
||||||
.doesNotContain("/api/platform/v1/containers/{id}/transport:")
|
.doesNotContain("/api/platform/v1/containers/{id}/transport:")
|
||||||
.doesNotContain("ContainerOceanBookingUnlinkRequest")
|
.doesNotContain("ContainerOceanBookingUnlinkRequest")
|
||||||
.doesNotContain("ContainerTransportUpdateRequest")
|
.doesNotContain("ContainerTransportUpdateRequest")
|
||||||
|
|||||||
+17
@@ -4,6 +4,7 @@ import com.baiyue.firstleg.customs.container.controller.*;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
@@ -12,6 +13,22 @@ import java.lang.reflect.Method;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class ContainerCustomsControllerContractTest {
|
class ContainerCustomsControllerContractTest {
|
||||||
|
/** 下载契约必须跟随实际 Controller,避免前端和文档共同固化不存在的地址。 */
|
||||||
|
@Test void platformPreEntryDownloadMatchesActualControllerAndOpenApi() throws Exception {
|
||||||
|
Method download = java.util.Arrays.stream(PlatformContainerCustomsController.class.getDeclaredMethods())
|
||||||
|
.filter(method -> method.getName().equals("downloadCompletion")).findFirst().orElseThrow();
|
||||||
|
String root = PlatformContainerCustomsController.class.getAnnotation(RequestMapping.class).value()[0];
|
||||||
|
String path = root + download.getAnnotation(GetMapping.class).value()[0];
|
||||||
|
String source = new ClassPathResource("openapi/customs-v1.yaml").getContentAsString(java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
java.util.Map<?, ?> specification = new Yaml().load(source);
|
||||||
|
java.util.Map<?, ?> paths = (java.util.Map<?, ?>) specification.get("paths");
|
||||||
|
|
||||||
|
assertThat(path).isEqualTo("/api/platform/v1/customs/loading-plans/documents/{documentId}/completion/download");
|
||||||
|
assertThat(paths.containsKey(path)).isTrue();
|
||||||
|
assertThat(paths.containsKey(root + "/documents/{documentId}/receipt/download")).isFalse();
|
||||||
|
assertThat(download.getAnnotation(PreAuthorize.class).value()).contains("platform:firstleg:customs:list");
|
||||||
|
}
|
||||||
|
|
||||||
@Test void platformUsesListForReadsAndManageForWrites() {
|
@Test void platformUsesListForReadsAndManageForWrites() {
|
||||||
assertThat(PlatformContainerCustomsController.class.getAnnotation(RequestMapping.class).value())
|
assertThat(PlatformContainerCustomsController.class.getAnnotation(RequestMapping.class).value())
|
||||||
.containsExactly("/api/platform/v1/customs/loading-plans");
|
.containsExactly("/api/platform/v1/customs/loading-plans");
|
||||||
|
|||||||
+38
-2
@@ -442,6 +442,7 @@ class ContainerCustomsServiceTest {
|
|||||||
verifyNoInteractions(files);
|
verifyNoInteractions(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 上传被拒绝时使用预录单名称,并保留报关行执行后的替换门禁。 */
|
||||||
@Test void receiptCannotBeReplacedAfterBrokerSubmission(){
|
@Test void receiptCannotBeReplacedAfterBrokerSubmission(){
|
||||||
var source=document(1L);when(mapper.document(1L)).thenReturn(source);
|
var source=document(1L);when(mapper.document(1L)).thenReturn(source);
|
||||||
when(mapper.claimCommand(anyLong(),eq(5L),eq("UPLOAD_COMPLETION_1"),eq("broker-sent-key"),anyString())).thenReturn(1);
|
when(mapper.claimCommand(anyLong(),eq(5L),eq("UPLOAD_COMPLETION_1"),eq("broker-sent-key"),anyString())).thenReturn(1);
|
||||||
@@ -450,7 +451,10 @@ class ContainerCustomsServiceTest {
|
|||||||
when(mapper.brokerSubmittedAt(2L)).thenReturn(java.time.LocalDateTime.now());
|
when(mapper.brokerSubmittedAt(2L)).thenReturn(java.time.LocalDateTime.now());
|
||||||
var file=new MockMultipartFile("file","result.bin","application/octet-stream",new byte[]{1});
|
var file=new MockMultipartFile("file","result.bin","application/octet-stream",new byte[]{1});
|
||||||
assertThatThrownBy(()->service.uploadCompletion(1L,5L,"admin","broker-sent-key",0,file))
|
assertThatThrownBy(()->service.uploadCompletion(1L,5L,"admin","broker-sent-key",0,file))
|
||||||
.isInstanceOf(BizException.class).hasMessageContaining("不可再修改回执");
|
.isInstanceOfSatisfying(BizException.class, error -> {
|
||||||
|
assertThat(error.getResultCode()).isEqualTo(ResultCode.CONFLICT);
|
||||||
|
assertThat(error).hasMessage("客户确认的预录单已发送给报关行,不可再修改预录单");
|
||||||
|
});
|
||||||
verifyNoInteractions(files);
|
verifyNoInteractions(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,11 +516,43 @@ class ContainerCustomsServiceTest {
|
|||||||
verify(mapper,never()).complete(anyLong(),anyInt(),anyLong(),anyString());
|
verify(mapper,never()).complete(anyLong(),anyInt(),anyLong(),anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 下载不可见或缺失的预录单时使用正式名称,不改变客户范围校验。 */
|
||||||
@Test void merchantCannotDownloadCompletionBeforeWholeContainerCompletes(){
|
@Test void merchantCannotDownloadCompletionBeforeWholeContainerCompletes(){
|
||||||
var source=document(1L);when(mapper.document(1L)).thenReturn(source);
|
var source=document(1L);when(mapper.document(1L)).thenReturn(source);
|
||||||
when(mapper.containerById(2L)).thenReturn(container(ContainerCustomsService.DECLARING,3));
|
when(mapper.containerById(2L)).thenReturn(container(ContainerCustomsService.DECLARING,3));
|
||||||
assertThatThrownBy(()->service.downloadCompletion(7L,1L,false)).isInstanceOf(BizException.class)
|
assertThatThrownBy(()->service.downloadCompletion(7L,1L,false)).isInstanceOf(BizException.class)
|
||||||
.hasMessageContaining("报关行回执不存在");
|
.hasMessageContaining("预录单不存在");
|
||||||
|
verifyNoInteractions(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 平台下载的当前预录单不存在时仍返回原业务错误码和正式名称。 */
|
||||||
|
@Test void platformMissingPreEntryDocumentUsesCurrentName() {
|
||||||
|
when(mapper.document(1L)).thenReturn(document(1L));
|
||||||
|
when(mapper.completion(1L)).thenReturn(null);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> service.downloadCompletion(0L, 1L, true))
|
||||||
|
.isInstanceOfSatisfying(BizException.class, error -> {
|
||||||
|
assertThat(error.getResultCode()).isEqualTo(ResultCode.NOT_FOUND);
|
||||||
|
assertThat(error).hasMessage("预录单不存在");
|
||||||
|
});
|
||||||
|
verifyNoInteractions(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发送前置校验仅调整用户可见名称,不改变全买单或客户确认门禁。 */
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource({"0,0,全买单柜无需发送预录单确认结果给报关行", "1,1,仍有预录单未完成客户确认"})
|
||||||
|
void brokerSubmissionErrorsUsePreEntryDocumentName(int taxRefundCount, int unconfirmedCount, String message) {
|
||||||
|
when(mapper.claimCommand(anyLong(), eq(5L), eq("SUBMIT_CUSTOMS_TO_BROKER_9"), eq("pre-entry-name"), anyString())).thenReturn(1);
|
||||||
|
when(mapper.lockContainer(9L)).thenReturn(container(ContainerCustomsService.DECLARING, 3));
|
||||||
|
when(mapper.taxRefundCount(9L)).thenReturn(taxRefundCount);
|
||||||
|
when(mapper.unconfirmedReceiptCount(2L)).thenReturn(unconfirmedCount);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> service.submitToBroker(9L, 5L, "admin", "pre-entry-name", new ActionRequest(3, true, null)))
|
||||||
|
.isInstanceOfSatisfying(BizException.class, error -> {
|
||||||
|
assertThat(error.getResultCode()).isEqualTo(ResultCode.CONFLICT);
|
||||||
|
assertThat(error).hasMessage(message);
|
||||||
|
});
|
||||||
|
verify(mapper, never()).submitToBroker(anyLong(), anyInt(), anyLong(), anyString());
|
||||||
verifyNoInteractions(files);
|
verifyNoInteractions(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+31
@@ -14,6 +14,37 @@ import java.nio.file.Path;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class PlatformOceanBookingControllerContractTest {
|
class PlatformOceanBookingControllerContractTest {
|
||||||
|
/** 预计到港命令仅接收版本与时间,沿用编辑权限及独立审计。 */
|
||||||
|
@Test void estimatedArrivalCommandHasNarrowDtoAndEditPermission() throws Exception {
|
||||||
|
var endpoint = method("updateEstimatedArrival");
|
||||||
|
assertThat(endpoint.getAnnotation(org.springframework.web.bind.annotation.PutMapping.class).value()).containsExactly("/{oceanBookingId}/estimated-arrival");
|
||||||
|
assertThat(endpoint.getAnnotation(PreAuthorize.class).value()).isEqualTo("hasAuthority('platform:firstleg:ocean-booking:edit')");
|
||||||
|
assertThat(endpoint.getAnnotation(BusinessAudit.class)).isNotNull();
|
||||||
|
assertThat(Arrays.stream(com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.EstimatedArrivalRequest.class.getRecordComponents())
|
||||||
|
.map(java.lang.reflect.RecordComponent::getName)).containsExactly("expectedVersion", "estimatedArrivalAt");
|
||||||
|
assertThat(Files.readString(Path.of("src/main/resources/openapi/ocean-bookings-v1.yaml")))
|
||||||
|
.contains("/api/platform/v1/ocean-bookings/{oceanBookingId}/estimated-arrival:", "#/components/schemas/EstimatedArrivalRequest");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 真实方法权限拦截器拒绝只有读取权限的账号,命令不会进入服务层。 */
|
||||||
|
@Test void estimatedArrivalRejectsReadOnlyAccountBeforeServiceCall() {
|
||||||
|
var service = org.mockito.Mockito.mock(com.baiyue.firstleg.oceanbooking.service.OceanBookingService.class);
|
||||||
|
var target = new PlatformOceanBookingController();
|
||||||
|
org.springframework.test.util.ReflectionTestUtils.setField(target, "service", service);
|
||||||
|
var factory = new org.springframework.aop.framework.ProxyFactory(target);
|
||||||
|
factory.setProxyTargetClass(true);
|
||||||
|
factory.addAdvisor(org.springframework.security.authorization.method.AuthorizationManagerBeforeMethodInterceptor.preAuthorize());
|
||||||
|
var secured = (PlatformOceanBookingController) factory.getProxy();
|
||||||
|
var context = org.springframework.security.core.context.SecurityContextHolder.getContext();
|
||||||
|
context.setAuthentication(new org.springframework.security.authentication.UsernamePasswordAuthenticationToken("reader", "",
|
||||||
|
java.util.List.of(new org.springframework.security.core.authority.SimpleGrantedAuthority("platform:firstleg:ocean-booking:list"))));
|
||||||
|
try {
|
||||||
|
org.assertj.core.api.Assertions.assertThatThrownBy(() -> secured.updateEstimatedArrival(null, 1L, "eta-denied",
|
||||||
|
new com.baiyue.firstleg.oceanbooking.dto.OceanBookingDtos.EstimatedArrivalRequest(3, java.time.LocalDateTime.now())))
|
||||||
|
.isInstanceOf(org.springframework.security.access.AccessDeniedException.class);
|
||||||
|
org.mockito.Mockito.verifyNoInteractions(service);
|
||||||
|
} finally { org.springframework.security.core.context.SecurityContextHolder.clearContext(); }
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
void usesDedicatedResourceAndPermissions() {
|
void usesDedicatedResourceAndPermissions() {
|
||||||
assertThat(PlatformOceanBookingController.class.getAnnotation(RequestMapping.class).value())
|
assertThat(PlatformOceanBookingController.class.getAnnotation(RequestMapping.class).value())
|
||||||
|
|||||||
+7
@@ -14,6 +14,13 @@ import java.util.Arrays;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class OceanBookingMapperContractTest {
|
class OceanBookingMapperContractTest {
|
||||||
|
/** 放舱后预计到港只更新该字段及版本审计,不允许带出其他冻结资料。 */
|
||||||
|
@Test void estimatedArrivalUpdateIsNarrowAndVersioned() throws Exception {
|
||||||
|
String sql = String.join("\n", OceanBookingMapper.class.getDeclaredMethod("updateEstimatedArrival", long.class,
|
||||||
|
java.time.LocalDateTime.class, int.class, long.class, String.class).getAnnotation(Update.class).value());
|
||||||
|
assertThat(sql).contains("estimated_arrival_at=#{estimatedArrivalAt}", "status='RELEASED'", "version=#{version}", "version=version+1")
|
||||||
|
.doesNotContain("vessel_name=", "voyage_no=", "estimated_sailing_at=", "actual_", "declared_", "warehouse_id=");
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
void listUsesPlatformAggregateFilters() throws Exception {
|
void listUsesPlatformAggregateFilters() throws Exception {
|
||||||
String sql = String.join("\n", OceanBookingMapper.class.getDeclaredMethod("selectPage",
|
String sql = String.join("\n", OceanBookingMapper.class.getDeclaredMethod("selectPage",
|
||||||
|
|||||||
+8
@@ -10,6 +10,14 @@ import java.nio.file.Path;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class OceanBookingSqlContractTest {
|
class OceanBookingSqlContractTest {
|
||||||
|
/** 两份触发器基线只放开预计到港,继续冻结船名、开船、预报和其他运输资料。 */
|
||||||
|
@Test void releasedFreezeAllowsEstimatedArrivalOnly() throws Exception {
|
||||||
|
for (String source : new String[] {sql(), Files.readString(Path.of("../deploy/sql/头程数据库统一增量-MySQL8.sql"))}) {
|
||||||
|
assertThat(source).doesNotContain("NEW.estimated_arrival_at <=> OLD.estimated_arrival_at")
|
||||||
|
.contains("NEW.vessel_name <=> OLD.vessel_name", "NEW.estimated_sailing_at <=> OLD.estimated_sailing_at",
|
||||||
|
"NEW.declared_package_count <=> OLD.declared_package_count", "NEW.version = OLD.version + 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
void definesDedicatedAggregateWithoutChangingContainerSemantics() throws Exception {
|
void definesDedicatedAggregateWithoutChangingContainerSemantics() throws Exception {
|
||||||
String sql = sql();
|
String sql = sql();
|
||||||
|
|||||||
+51
@@ -399,6 +399,57 @@ class OceanBookingServiceTest {
|
|||||||
verify(repository, never()).transition(anyLong(), anyString(), anyString(), anyInt(), anyLong(), anyString());
|
verify(repository, never()).transition(anyLong(), anyString(), anyString(), anyInt(), anyLong(), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 预计到港独立更新、回显并保留修改前后审计,不能触及其他冻结字段。 */
|
||||||
|
@Test void maintainsReleasedEstimatedArrivalWithVersionAndAudit() {
|
||||||
|
var before = completeBooking("RELEASED", 3);
|
||||||
|
var after = objectMapper.convertValue(before, OceanBookingEntity.class);
|
||||||
|
var arrival = before.getEstimatedSailingAt().plusDays(20);
|
||||||
|
after.setEstimatedArrivalAt(arrival); after.setVersion(4);
|
||||||
|
when(repository.find(1L)).thenReturn(before, after);
|
||||||
|
when(repository.updateEstimatedArrival(1L, arrival, 3, 9L, "admin")).thenReturn(1);
|
||||||
|
|
||||||
|
var result = service.updateEstimatedArrival(1L, 9L, "admin", "eta-save", new EstimatedArrivalRequest(3, arrival));
|
||||||
|
|
||||||
|
assertThat(result.oceanBooking().getEstimatedArrivalAt()).isEqualTo(arrival);
|
||||||
|
assertThat(result.oceanBooking().getVersion()).isEqualTo(4);
|
||||||
|
assertThat(result.oceanBooking().getVesselName()).isEqualTo(before.getVesselName());
|
||||||
|
var history = ArgumentCaptor.forClass(com.baiyue.firstleg.oceanbooking.entity.OceanBookingStatusHistoryEntity.class);
|
||||||
|
verify(repository).insert(history.capture());
|
||||||
|
assertThat(history.getValue().getAction()).isEqualTo("UPDATE_ESTIMATED_ARRIVAL");
|
||||||
|
assertThat(history.getValue().getBeforeSnapshot()).contains("estimatedArrivalAt");
|
||||||
|
assertThat(history.getValue().getAfterSnapshot()).contains("estimatedArrivalAt");
|
||||||
|
verify(repository, never()).updateDraft(any(), anyInt(), anyLong(), any());
|
||||||
|
verify(repository, never()).replaceRequirements(anyLong(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 草稿、旧版本、空值及逆序时间均不能走放舱后的预计到港命令。 */
|
||||||
|
@Test void rejectsInvalidEstimatedArrivalCommands() {
|
||||||
|
var value = completeBooking("DRAFT", 3);
|
||||||
|
when(repository.find(1L)).thenReturn(value);
|
||||||
|
var arrival = value.getEstimatedSailingAt().plusDays(20);
|
||||||
|
assertThatThrownBy(() -> service.updateEstimatedArrival(1L, 9L, "admin", "eta-draft", new EstimatedArrivalRequest(3, arrival))).isInstanceOf(BizException.class);
|
||||||
|
value.setStatus("RELEASED");
|
||||||
|
assertThatThrownBy(() -> service.updateEstimatedArrival(1L, 9L, "admin", "eta-stale", new EstimatedArrivalRequest(2, arrival))).isInstanceOf(BizException.class);
|
||||||
|
assertThatThrownBy(() -> service.updateEstimatedArrival(1L, 9L, "admin", "eta-empty", new EstimatedArrivalRequest(3, null))).hasMessageContaining("不能为空");
|
||||||
|
assertThatThrownBy(() -> service.updateEstimatedArrival(1L, 9L, "admin", "eta-early", new EstimatedArrivalRequest(3, value.getEstimatedSailingAt().minusSeconds(1)))).hasMessageContaining("不能早于");
|
||||||
|
when(repository.updateEstimatedArrival(anyLong(), any(), anyInt(), anyLong(), any())).thenReturn(0);
|
||||||
|
assertThatThrownBy(() -> service.updateEstimatedArrival(1L, 9L, "admin", "eta-conflict", new EstimatedArrivalRequest(3, arrival))).isInstanceOf(BizException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同一预计到港命令重放复用原结果,不重复保存或追加审计。 */
|
||||||
|
@Test void estimatedArrivalReplayDoesNotWriteAgain() throws Exception {
|
||||||
|
var request = new EstimatedArrivalRequest(3, LocalDateTime.of(2026, 10, 25, 10, 0));
|
||||||
|
var replay = new Detail(completeBooking("RELEASED", 4), List.of(), List.of(), List.of(), List.of(), List.of());
|
||||||
|
var operation = new OceanBookingOperationEntity();
|
||||||
|
operation.setRequestHash(hash("UPDATE_ESTIMATED_ARRIVAL", 1L, request));
|
||||||
|
operation.setStatus("SUCCESS"); operation.setResultJson(objectMapper.writeValueAsString(replay));
|
||||||
|
when(repository.claimOperation(1L, 9L, "UPDATE_ESTIMATED_ARRIVAL", "eta-replay", operation.getRequestHash())).thenReturn(false);
|
||||||
|
when(repository.operation(9L, "UPDATE_ESTIMATED_ARRIVAL", "eta-replay")).thenReturn(operation);
|
||||||
|
assertThat(service.updateEstimatedArrival(1L, 9L, "admin", "eta-replay", request).oceanBooking().getVersion()).isEqualTo(4);
|
||||||
|
verify(repository, never()).updateEstimatedArrival(anyLong(), any(), anyInt(), anyLong(), any());
|
||||||
|
verify(repository, never()).insert(any(com.baiyue.firstleg.oceanbooking.entity.OceanBookingStatusHistoryEntity.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void supplementsReleasedActualCargoWithVersionAndBeforeAfterAudit() {
|
void supplementsReleasedActualCargoWithVersionAndBeforeAfterAudit() {
|
||||||
OceanBookingEntity before = completeBooking("RELEASED", 3);
|
OceanBookingEntity before = completeBooking("RELEASED", 3);
|
||||||
|
|||||||
+47
-3
@@ -8,12 +8,23 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||||
|
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||||
|
import com.baiyue.firstleg.oceanbooking.entity.OceanBookingEntity;
|
||||||
|
import org.h2.jdbcx.JdbcDataSource;
|
||||||
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@DisplayName("货柜数据库映射契约")
|
@DisplayName("货柜数据库映射契约")
|
||||||
class ContainerBookingMapperContractTest {
|
class ContainerBookingMapperContractTest {
|
||||||
@@ -106,7 +117,7 @@ class ContainerBookingMapperContractTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("初始化与统一增量锁定真实柜号权威、订舱内唯一和ISO结构约束")
|
@DisplayName("初始化与统一增量保留柜号权威及订舱内唯一,不限制关联柜号ISO格式")
|
||||||
void databaseContractsFreezeAuthoritativeContainerNumber() throws Exception {
|
void databaseContractsFreezeAuthoritativeContainerNumber() throws Exception {
|
||||||
String module = Files.readString(Path.of("src/main/resources/db/phase3-smart-loading-schema.sql"));
|
String module = Files.readString(Path.of("src/main/resources/db/phase3-smart-loading-schema.sql"));
|
||||||
String unified = Files.readString(Path.of("../deploy/sql/头程数据库统一增量-MySQL8.sql"));
|
String unified = Files.readString(Path.of("../deploy/sql/头程数据库统一增量-MySQL8.sql"));
|
||||||
@@ -118,8 +129,41 @@ class ContainerBookingMapperContractTest {
|
|||||||
assertThat(source.toLowerCase())
|
assertThat(source.toLowerCase())
|
||||||
.contains("unique key uk_container_booking_ocean_container (ocean_booking_id,container_no)")
|
.contains("unique key uk_container_booking_ocean_container (ocean_booking_id,container_no)")
|
||||||
.contains("key idx_container_booking_container_no (container_no,updated_at,id)")
|
.contains("key idx_container_booking_container_no (container_no,updated_at,id)")
|
||||||
.contains("constraint chk_container_booking_iso6346")
|
.doesNotContain("chk_container_booking_iso6346", "^[a-z]{3}[ujz][0-9]{7}$");
|
||||||
.contains("^[a-z]{3}[ujz][0-9]{7}$");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 从当前建表基线创建隔离数据库,真实执行关联 Mapper 并验证唯一键和版本。 */
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"MSCU6639871", "ABC", "ABCU123456789012", "LOCAL-2026-001"})
|
||||||
|
void linksNonIsoContainerNumbersThroughActualSchemaAndMapper(String containerNo) throws Exception {
|
||||||
|
var dataSource = new JdbcDataSource();
|
||||||
|
dataSource.setURL("jdbc:h2:mem:container-link-" + java.util.UUID.randomUUID() + ";MODE=MySQL;DB_CLOSE_DELAY=-1");
|
||||||
|
var jdbc = new JdbcTemplate(dataSource);
|
||||||
|
String source = Files.readString(Path.of("src/main/resources/db/phase3-smart-loading-schema.sql"));
|
||||||
|
int start = source.indexOf("CREATE TABLE IF NOT EXISTS fl_container_booking (");
|
||||||
|
jdbc.execute(source.substring(start, source.indexOf(';', source.indexOf(") ENGINE=InnoDB", start)) + 1));
|
||||||
|
for (long id = 1; id <= 3; id++) {
|
||||||
|
jdbc.update("INSERT INTO fl_container_booking(id,cabinet_no,warehouse_id,warehouse_name,container_type,created_by,updated_by) VALUES(?,?,8,'测试仓','40HQ',9,9)",
|
||||||
|
id, "D" + id);
|
||||||
|
}
|
||||||
|
var configuration = new MybatisConfiguration();
|
||||||
|
configuration.setMapUnderscoreToCamelCase(true);
|
||||||
|
configuration.addMapper(ContainerBookingMapper.class);
|
||||||
|
var factory = new MybatisSqlSessionFactoryBean();
|
||||||
|
factory.setDataSource(dataSource);
|
||||||
|
factory.setConfiguration(configuration);
|
||||||
|
var session = new SqlSessionTemplate(factory.getObject());
|
||||||
|
var repository = new ContainerRepository();
|
||||||
|
ReflectionTestUtils.setField(repository, "mapper", session.getMapper(ContainerBookingMapper.class));
|
||||||
|
var booking = new OceanBookingEntity();
|
||||||
|
|
||||||
|
assertThat(repository.linkReleasedBooking(1L, 21L, 31L, containerNo, booking, 0, 9L, "操作员")).isEqualTo(1);
|
||||||
|
assertThat(jdbc.queryForObject("SELECT container_no FROM fl_container_booking WHERE id=1", String.class)).isEqualTo(containerNo);
|
||||||
|
assertThat(jdbc.queryForObject("SELECT version FROM fl_container_booking WHERE id=1", Integer.class)).isEqualTo(1);
|
||||||
|
assertThat(repository.linkReleasedBooking(1L, 21L, 31L, containerNo, booking, 0, 9L, "操作员")).isZero();
|
||||||
|
assertThatThrownBy(() -> repository.linkReleasedBooking(2L, 21L, 31L, containerNo, booking, 0, 9L, "操作员"))
|
||||||
|
.isInstanceOf(DuplicateKeyException.class);
|
||||||
|
assertThat(repository.linkReleasedBooking(3L, 22L, 32L, containerNo, booking, 0, 9L, "操作员")).isEqualTo(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,17 +329,21 @@ class ContainerServiceTest {
|
|||||||
verify(repository, never()).assignRealContainerNo(anyLong(), anyString(), anyInt(), anyLong(), anyString());
|
verify(repository, never()).assignRealContainerNo(anyLong(), anyString(), anyInt(), anyLong(), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/** 关联入口允许非 ISO 柜号,继续按原版本和关联范围保存。 */
|
||||||
@DisplayName("首次关联拒绝错误ISO 6346校验位")
|
@ParameterizedTest
|
||||||
void rejectsInvalidContainerNumberCheckDigit() {
|
@ValueSource(strings = {"MSCU6639871", "ABC", "ABCU123456789012", "LOCAL-2026-001"})
|
||||||
|
@DisplayName("首次关联不因柜号长度结构或校验位阻断")
|
||||||
|
void linksWithoutIsoContainerNumberValidation(String containerNo) {
|
||||||
stubLinkContext();
|
stubLinkContext();
|
||||||
|
when(repository.linkReleasedBooking(eq(11L), eq(21L), eq(31L), eq(containerNo),
|
||||||
|
any(OceanBookingEntity.class), eq(2), eq(9L), eq("admin"))).thenReturn(1);
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.linkOceanBooking(11L, 9L, "admin",
|
service.linkOceanBooking(11L, 9L, "admin", new OceanBookingLinkRequest(21L, 31L, containerNo, 2));
|
||||||
new OceanBookingLinkRequest(21L, 31L, "MSCU6639871", 2)))
|
|
||||||
.isInstanceOf(BizException.class).hasMessageContaining("校验位");
|
|
||||||
|
|
||||||
verify(repository, never()).linkReleasedBooking(anyLong(), anyLong(), anyLong(), anyString(),
|
verify(repository).containerNoExists(21L, containerNo, 11L);
|
||||||
any(), anyInt(), anyLong(), anyString());
|
verify(repository).linkReleasedBooking(eq(11L), eq(21L), eq(31L), eq(containerNo),
|
||||||
|
any(OceanBookingEntity.class), eq(2), eq(9L), eq("admin"));
|
||||||
|
verify(oceanBookings).insert(any(OceanBookingContainerAllocationEntity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.NullSource;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
@@ -147,10 +150,42 @@ class LoadingListServiceTest {
|
|||||||
verifyNoInteractions(loadingPickService);
|
verifyNoInteractions(loadingPickService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 只更新航次时,关联已接受的非 ISO 柜号不应被重新校验或改写。 */
|
||||||
|
@ParameterizedTest
|
||||||
|
@NullSource
|
||||||
|
@ValueSource(strings = {"LOCAL-1", " local-1 "})
|
||||||
|
void preservesLinkedNonIsoNumberWhenOnlyVoyageChanges(String requested) {
|
||||||
|
AggregateRow before = row("EDITING", 3);
|
||||||
|
before.setContainerNo("LOCAL-1");
|
||||||
|
before.setVoyageNo("001E");
|
||||||
|
when(repository.aggregate(10L)).thenReturn(before);
|
||||||
|
when(repository.updateTransport(10L, 3, "LOCAL-1", "023E", 9L, "operator")).thenReturn(1);
|
||||||
|
|
||||||
|
service.updateTransport(10L, 100L, 9L, "operator", "preserve-linked-number",
|
||||||
|
new TransportUpdateRequest(requested, "023E", 3, null));
|
||||||
|
|
||||||
|
verify(repository).updateTransport(10L, 3, "LOCAL-1", "023E", 9L, "operator");
|
||||||
|
verify(loadingPickService).beginIfReady(30L, 9L, "operator");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 非关联入口新录入或纠正柜号仍使用原有规则,不放宽到所有录入场景。 */
|
||||||
|
@Test
|
||||||
|
void stillRejectsNewNonIsoNumberInTransportCorrection() {
|
||||||
|
AggregateRow before = row("EDITING", 3);
|
||||||
|
before.setContainerNo("LOCAL-1");
|
||||||
|
when(repository.aggregate(10L)).thenReturn(before);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> service.updateTransport(10L, 100L, 9L, "operator", "invalid-correction",
|
||||||
|
new TransportUpdateRequest("OTHER-2", null, 3, "纠错")))
|
||||||
|
.isInstanceOf(BizException.class).hasMessageContaining("ISO 6346");
|
||||||
|
verify(repository, never()).updateTransport(anyLong(), anyInt(), any(), any(), anyLong(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 关联入口接受的非 ISO 柜号,在 PDA 领取前仍可按版本和原因纠正为真实柜号。 */
|
||||||
@Test
|
@Test
|
||||||
void pushedEditingPreloadCanCorrectExistingContainerNumberBeforePdaClaim() {
|
void pushedEditingPreloadCanCorrectExistingContainerNumberBeforePdaClaim() {
|
||||||
AggregateRow before = row("EDITING", 3);
|
AggregateRow before = row("EDITING", 3);
|
||||||
before.setContainerNo("MSCU6639870");
|
before.setContainerNo("LOCAL-1");
|
||||||
AggregateRow after = row("EDITING", 4);
|
AggregateRow after = row("EDITING", 4);
|
||||||
after.setContainerNo("CSQU3054383");
|
after.setContainerNo("CSQU3054383");
|
||||||
when(repository.aggregate(10L)).thenReturn(before, after);
|
when(repository.aggregate(10L)).thenReturn(before, after);
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ class LoadingPickServiceTest {
|
|||||||
Link link = new Link(1L, 1L, 50L, 2L, "PENDING", 1,
|
Link link = new Link(1L, 1L, 50L, 2L, "PENDING", 1,
|
||||||
10L, 40L, "MSCU-001", "EDITING", 3, 2, null);
|
10L, 40L, "MSCU-001", "EDITING", 3, 2, null);
|
||||||
var booking = new com.baiyue.firstleg.entity.ContainerBookingEntity();
|
var booking = new com.baiyue.firstleg.entity.ContainerBookingEntity();
|
||||||
booking.setId(40L); booking.setContainerNo("MSCU-001");
|
booking.setId(40L); booking.setContainerNo("MSCU6639870");
|
||||||
var allocation = new OceanBookingContainerAllocationEntity();
|
var allocation = new OceanBookingContainerAllocationEntity();
|
||||||
allocation.setOceanBookingId(90L);
|
allocation.setOceanBookingId(90L);
|
||||||
var ocean = new OceanBookingEntity();
|
var ocean = new OceanBookingEntity();
|
||||||
@@ -962,6 +962,57 @@ class LoadingPickServiceTest {
|
|||||||
verify(repository, never()).acceptCompletion(anyLong(), anyInt());
|
verify(repository, never()).acceptCompletion(anyLong(), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 关联放行的非 ISO 柜号必须在可纠错阶段明确反馈,纠正后可继续确认。 */
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"MSCU6639871", "ABC", "ABCU123456789012", "LOCAL-2026-001"})
|
||||||
|
void rejectsNonIsoNumberBeforeConfirmationAndAllowsCorrection(String containerNo) {
|
||||||
|
Link link = new Link(1L, 1L, 50L, 2L, "PENDING", 1,
|
||||||
|
10L, 40L, containerNo, "EDITING", 3, 2, null);
|
||||||
|
var booking = new ContainerBookingEntity();
|
||||||
|
booking.setId(40L);
|
||||||
|
booking.setContainerNo(containerNo);
|
||||||
|
when(loadingModelBridge.requireAllocatedLinksForConfirmation(10L)).thenReturn(List.of(link));
|
||||||
|
when(smartLoadingRepository.booking(40L)).thenReturn(booking);
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> service.requirePreloadConfirmationReady(10L))
|
||||||
|
.isInstanceOf(BizException.class).hasMessageContaining("预装运输信息");
|
||||||
|
verify(repository, never()).insert(any(LoadingPickTaskEntity.class));
|
||||||
|
verify(completionCommands, never()).insert(any());
|
||||||
|
|
||||||
|
booking.setContainerNo("MSCU6639870");
|
||||||
|
var allocation = new OceanBookingContainerAllocationEntity();
|
||||||
|
allocation.setOceanBookingId(90L);
|
||||||
|
var ocean = new OceanBookingEntity();
|
||||||
|
ocean.setId(90L);
|
||||||
|
ocean.setStatus("RELEASED");
|
||||||
|
when(oceanBookingRepository.allocationByContainer(40L)).thenReturn(allocation);
|
||||||
|
when(oceanBookingRepository.find(90L)).thenReturn(ocean);
|
||||||
|
assertThat(service.requirePreloadConfirmationReady(10L)).containsExactly(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 任务创建入口同样先校验格式,不能绕过确认门禁进入实物作业。 */
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"MSCU6639871", "ABC", "ABCU123456789012", "LOCAL-2026-001"})
|
||||||
|
void rejectsNonIsoNumberBeforeCreatingPdaTask(String containerNo) {
|
||||||
|
assertThatThrownBy(() -> service.begin(10L, containerNo, 9L, "operator", List.of()))
|
||||||
|
.isInstanceOf(BizException.class).hasMessageContaining("预装运输信息");
|
||||||
|
verify(repository, never()).insert(any(LoadingPickTaskEntity.class));
|
||||||
|
verify(repository, never()).insert(any(LoadingPickItemEntity.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 完成前的最终校验仍保留,不能让异常柜号生成无法投递的装柜完成事件。 */
|
||||||
|
@Test
|
||||||
|
void completionStillRequiresIsoNumberForCrossServiceFacts() {
|
||||||
|
repository.activeBookingByTask(20L).setContainerNo("MSCU6639871");
|
||||||
|
when(repository.taskForUpdate(20L)).thenReturn(task());
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> service.complete(20L,
|
||||||
|
new CompleteLoadingRequest(0, "invalid-final-container", "checked"), 9L, "operator"))
|
||||||
|
.isInstanceOf(BizException.class).hasMessageContaining("ISO 6346");
|
||||||
|
verify(completionCommands, never()).insert(any());
|
||||||
|
verify(repository, never()).acceptCompletion(anyLong(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void differentOperationIdIsRejectedImmediatelyWithConflict() {
|
void differentOperationIdIsRejectedImmediatelyWithConflict() {
|
||||||
// different operationId is a canonical A0409 CONFLICT while the durable command is active.
|
// different operationId is a canonical A0409 CONFLICT while the durable command is active.
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
退货预报、签收、库存、合箱与退货出库:
|
退货预报、签收、库存、合箱与退货出库:
|
||||||
|
|
||||||
- 客户预报 `returnreceipt/controller/MerchantReturnOrderController.java` → `returnreceipt/service/ReturnReceiptService.java`,路径 `/api/merchant/v1/last-leg/return-orders`;客户范围取认证身份,预报按 SKU 保存期望数量。状态 `PENDING_RECEIPT → PARTIALLY_RECEIVED → COMPLETED` 表示签收进度,不等于换标或出库完成。
|
- 客户预报 `returnreceipt/controller/MerchantReturnOrderController.java` → `returnreceipt/service/ReturnReceiptService.java`,路径 `/api/merchant/v1/last-leg/return-orders`;客户范围取认证身份,预报按 SKU 保存期望数量。状态 `PENDING_RECEIPT → PARTIALLY_RECEIVED → COMPLETED` 表示签收进度,不等于换标或出库完成。
|
||||||
- PDA 后端签收 `returnreceipt/controller/PdaReturnReceiptController.java`,前缀 `/api/pda/v1/last-leg/return-receipts`,依次 `start/sku-candidates/confirm`;按冻结仓和退货单校验实收,不允许未预报 SKU 或超量,幂等重放不得重复入账。确认同时生成签收箱与 SKU 库存;设备页面是否接通另查 PDA 工作台,不能以 Controller 存在代替前端接入。
|
- PDA 后端签收 `returnreceipt/controller/PdaReturnReceiptController.java`,前缀 `/api/pda/v1/last-leg/return-receipts`,依次 `start/sku-candidates/confirm`;按冻结仓和退货单校验实收,不允许未预报 SKU 或超量。确认必须传提交前全单累计实收量 `expectedReceivedQuantity`,在订单锁内校验;响应丢失后换新键重复提交旧快照返回冲突,刷新后重新操作,同键幂等请求不得重复入账。确认同时生成签收箱与 SKU 库存;设备页面是否接通另查 PDA 工作台,不能以 Controller 存在代替前端接入。
|
||||||
- 库存/箱号 `returnreceipt/controller/PlatformReturnInventoryController.java`、`MerchantReturnInventoryController.java` → `returnreceipt/service/ReturnInventoryService.java`,前缀分别为 `/api/platform/v1/last-leg/return-inventory`、`/api/merchant/v1/last-leg/return-inventory`;PDA 合箱入口 `PdaReturnInventoryController.java` 的 `/packing/orders`、`/cartons/merge`、`/cartons/{cartonMark}/label`。同仓同客户选取退货单及可用 SKU,合箱扣减来源箱数量并生成目标箱,空来源箱标为 `MERGED`,不得跨客户或超出可用量。
|
- 库存/箱号 `returnreceipt/controller/PlatformReturnInventoryController.java`、`MerchantReturnInventoryController.java` → `returnreceipt/service/ReturnInventoryService.java`,前缀分别为 `/api/platform/v1/last-leg/return-inventory`、`/api/merchant/v1/last-leg/return-inventory`;PDA 合箱入口 `PdaReturnInventoryController.java` 的 `/packing/orders`、`/cartons/merge`、`/cartons/{cartonMark}/label`。同仓同客户选取退货单及可用 SKU,合箱扣减来源箱数量并生成目标箱,空来源箱标为 `MERGED`,不得跨客户或超出可用量。实物合箱 `/cartons/merge-boxes` 必须提交扫码时全部来源箱 SKU 数量 `expectedSourceQuantities`,来源行锁内核对完整快照;旧快照换新键也拒绝扣减,重新扫描后才能提交当前实物。内部退货换标调用从已锁定任务及来源库存生成快照。
|
||||||
- 退货出库继续进入 `delivery/service/DeliveryTransferService.java` 的 `RETURN_OUTBOUND`,按退货库存可用箱唛创建与拣货;不能与 `exceptionorder/` 的派送退回恢复库存混用。契约见 `src/main/resources/openapi/overseas-business-v1.yaml`,表入口 `src/main/resources/db/lastleg.sql` 的 `ll_return_*`。
|
- 退货出库继续进入 `delivery/service/DeliveryTransferService.java` 的 `RETURN_OUTBOUND`,按退货库存可用箱唛创建与拣货;不能与 `exceptionorder/` 的派送退回恢复库存混用。契约见 `src/main/resources/openapi/overseas-business-v1.yaml`,表入口 `src/main/resources/db/lastleg.sql` 的 `ll_return_*`。
|
||||||
- 客户箱号管理使用 `GET /api/merchant/v1/last-leg/return-inventory/cartons` 按实物箱分页,库存箱内 SKU 明细仍使用根查询;两者均按登录客户精确隔离。合箱 `sourceBatchNo/sourceReturnNo` 保存实际消耗来源的去重业务编号(多个以逗号分隔),不得写状态或包含未取货订单。`ReturnCartonBarcode` 按箱号生成 Code 128 SVG,打印内容不得使用内部客户/仓库 ID。
|
- 客户箱号管理使用 `GET /api/merchant/v1/last-leg/return-inventory/cartons` 按实物箱分页,库存箱内 SKU 明细仍使用根查询;两者均按登录客户精确隔离。合箱 `sourceBatchNo/sourceReturnNo` 保存实际消耗来源的去重业务编号(多个以逗号分隔),不得写状态或包含未取货订单。`ReturnCartonBarcode` 按箱号生成 Code 128 SVG,打印内容不得使用内部客户/仓库 ID。
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -19,7 +19,20 @@ public interface DispatchAggregateMapper {
|
|||||||
OR EXISTS(SELECT 1 FROM ll_dispatch_truck_task t WHERE t.dispatch_no=d.dispatch_no AND t.customer_id=#{q.customerId})
|
OR EXISTS(SELECT 1 FROM ll_dispatch_truck_task t WHERE t.dispatch_no=d.dispatch_no AND t.customer_id=#{q.customerId})
|
||||||
OR EXISTS(SELECT 1 FROM ll_fleet_pickup_task p JOIN ll_fleet_trip f ON f.trip_no=p.trip_no WHERE f.id=d.trip_id AND p.customer_id=#{q.customerId})
|
OR EXISTS(SELECT 1 FROM ll_fleet_pickup_task p JOIN ll_fleet_trip f ON f.trip_no=p.trip_no WHERE f.id=d.trip_id AND p.customer_id=#{q.customerId})
|
||||||
)</if>
|
)</if>
|
||||||
<if test='q.fbaAppointmentNo != null'> AND EXISTS(SELECT 1 FROM ll_dispatch_appointment_allocation a JOIN ll_inbound_fba_appointment ap ON a.batch_key=CONCAT('FBA_APPOINTMENT:',ap.id) WHERE a.dispatch_id=d.id AND ap.confirmation_no=#{q.fbaAppointmentNo})</if>
|
<if test='q.fbaAppointmentNo != null'> AND (
|
||||||
|
EXISTS(SELECT 1 FROM ll_dispatch_item i WHERE i.dispatch_order_id=d.id AND i.destination_type='FBA'
|
||||||
|
AND JSON_CONTAINS(COALESCE(JSON_EXTRACT(d.resources_json,'$.maintenance.destinationAppointments'),'[]'),
|
||||||
|
JSON_OBJECT('destinationKey',CONCAT('FBA:',UPPER(TRIM(COALESCE(NULLIF(i.destination_warehouse_code,''),i.fba_warehouse_code)))),'appointmentNo',#{q.fbaAppointmentNo}))=1)
|
||||||
|
OR EXISTS(SELECT 1 FROM ll_dispatch_appointment_allocation a
|
||||||
|
WHERE a.dispatch_id=d.id AND a.batch_key LIKE 'FBA_APPOINTMENT:%' AND
|
||||||
|
""" + DispatchReceivingSql.CONFIRMATION_NO + """
|
||||||
|
=#{q.fbaAppointmentNo}
|
||||||
|
AND NOT EXISTS(SELECT 1 FROM JSON_TABLE(
|
||||||
|
COALESCE(JSON_EXTRACT(d.resources_json,'$.maintenance.destinationAppointments'),'[]'),
|
||||||
|
'$[*]' COLUMNS(destination_key VARCHAR(256) PATH '$.destinationKey',
|
||||||
|
appointment_no VARCHAR(128) PATH '$.appointmentNo' NULL ON EMPTY)) saved
|
||||||
|
WHERE saved.destination_key=a.destination_key AND NULLIF(TRIM(saved.appointment_no),'') IS NOT NULL))
|
||||||
|
)</if>
|
||||||
""";
|
""";
|
||||||
String REVIEW_DISPATCH = "CASE d.review_state WHEN 'DRAFT' THEN 'NOT_SUBMITTED' WHEN 'DISPATCH_PENDING' THEN 'PENDING' WHEN 'DISPATCH_REJECTED' THEN 'REJECTED' ELSE 'APPROVED' END";
|
String REVIEW_DISPATCH = "CASE d.review_state WHEN 'DRAFT' THEN 'NOT_SUBMITTED' WHEN 'DISPATCH_PENDING' THEN 'PENDING' WHEN 'DISPATCH_REJECTED' THEN 'REJECTED' ELSE 'APPROVED' END";
|
||||||
String REVIEW_LOADING = "CASE d.review_state WHEN 'LOADING_PENDING' THEN 'PENDING' WHEN 'LOADING_REJECTED' THEN 'REJECTED' WHEN 'APPROVED' THEN 'APPROVED' ELSE 'NOT_SUBMITTED' END";
|
String REVIEW_LOADING = "CASE d.review_state WHEN 'LOADING_PENDING' THEN 'PENDING' WHEN 'LOADING_REJECTED' THEN 'REJECTED' WHEN 'APPROVED' THEN 'APPROVED' ELSE 'NOT_SUBMITTED' END";
|
||||||
|
|||||||
+4
-2
@@ -49,11 +49,13 @@ public interface DispatchBolMapper {
|
|||||||
""")
|
""")
|
||||||
List<Cargo> findWholeDispatch(@Param("dispatchOrderId") long dispatchOrderId);
|
List<Cargo> findWholeDispatch(@Param("dispatchOrderId") long dispatchOrderId);
|
||||||
|
|
||||||
/** 原batch+客户+稳定来源+目的地定位预约货物;BOOKING使用持久化order_id,绝不自行拼ORDER键。 */
|
/** 原batch+客户+稳定来源+目的地定位货物,编号取当前客户收货确认;BOOKING保留持久化order_id。 */
|
||||||
@Select("""
|
@Select("""
|
||||||
SELECT a.dispatch_item_id AS dispatchItemId,a.plan_pallet_id AS planPalletId,a.batch_key AS batchKey,
|
SELECT a.dispatch_item_id AS dispatchItemId,a.plan_pallet_id AS planPalletId,a.batch_key AS batchKey,
|
||||||
a.customer_id AS customerId,a.source_key AS sourceKey,a.destination_key AS destinationKey,
|
a.customer_id AS customerId,a.source_key AS sourceKey,a.destination_key AS destinationKey,
|
||||||
a.package_count AS packageCount,p.id AS appointmentId,i.order_id AS orderId,p.confirmation_no AS confirmationNo
|
a.package_count AS packageCount,p.id AS appointmentId,i.order_id AS orderId,
|
||||||
|
""" + DispatchReceivingSql.CONFIRMATION_NO + """
|
||||||
|
AS confirmationNo
|
||||||
FROM ll_dispatch_appointment_allocation a
|
FROM ll_dispatch_appointment_allocation a
|
||||||
LEFT JOIN ll_inbound_fba_appointment p ON a.batch_key=CONCAT('FBA_APPOINTMENT:',p.id)
|
LEFT JOIN ll_inbound_fba_appointment p ON a.batch_key=CONCAT('FBA_APPOINTMENT:',p.id)
|
||||||
LEFT JOIN ll_inbound_fba_appointment_item i ON i.appointment_id=p.id AND i.customer_id=a.customer_id
|
LEFT JOIN ll_inbound_fba_appointment_item i ON i.appointment_id=p.id AND i.customer_id=a.customer_id
|
||||||
|
|||||||
+18
@@ -55,6 +55,24 @@ public interface DispatchReadMapper {
|
|||||||
""")
|
""")
|
||||||
List<BatchRow> batches(@Param("id") long dispatchId);
|
List<BatchRow> batches(@Param("id") long dispatchId);
|
||||||
|
|
||||||
|
record CargoShipment(String customerId, String destinationKey, String shipmentNo) { }
|
||||||
|
/** 逐票实际货物决定货件号;手填预约号或没有正式批次引用也能读取,客户严格随来源关联。 */
|
||||||
|
@Select("""
|
||||||
|
SELECT DISTINCT i.customer_id AS customerId,
|
||||||
|
CONCAT('FBA:',UPPER(TRIM(COALESCE(NULLIF(TRIM(l.fba_warehouse_code),''),NULLIF(TRIM(i.destination_warehouse_code),''),NULLIF(TRIM(i.fba_warehouse_code),''))))) AS destinationKey,
|
||||||
|
CASE WHEN o.order_type='WAREHOUSE_TRANSFER' THEN wt.fba_shipment_no ELSE d.shipment_no END AS shipmentNo
|
||||||
|
FROM ll_dispatch_item i
|
||||||
|
LEFT JOIN ll_inbound_plan_pallet_allocation a ON a.pallet_id=i.plan_pallet_id AND a.customer_id=i.customer_id
|
||||||
|
AND i.return_receipt_id IS NULL AND COALESCE(i.source_business_type,'')<>'RELABEL_ORDER'
|
||||||
|
LEFT JOIN ll_inbound_plan_line l ON l.id=a.line_id AND l.customer_id=i.customer_id
|
||||||
|
JOIN ll_order o ON o.id=CASE WHEN l.id IS NULL THEN i.order_id ELSE l.order_id END AND o.customer_id=i.customer_id
|
||||||
|
LEFT JOIN ll_order_detail d ON d.order_id=o.id AND d.customer_id=o.customer_id
|
||||||
|
AND UPPER(TRIM(d.destination_warehouse_code))=UPPER(TRIM(COALESCE(NULLIF(TRIM(l.fba_warehouse_code),''),NULLIF(TRIM(i.destination_warehouse_code),''),NULLIF(TRIM(i.fba_warehouse_code),''))))
|
||||||
|
LEFT JOIN ll_warehouse_transfer_order wt ON wt.lastleg_order_id=o.id AND wt.customer_id=o.customer_id
|
||||||
|
WHERE i.dispatch_order_id=#{id} AND i.destination_type='FBA'
|
||||||
|
""")
|
||||||
|
List<CargoShipment> cargoShipmentNumbers(@Param("id") long dispatchId);
|
||||||
|
|
||||||
/** 未接通跨客户批次写提供者前必须阻断静默丢批次,不能写无依据运输。 */
|
/** 未接通跨客户批次写提供者前必须阻断静默丢批次,不能写无依据运输。 */
|
||||||
@Select("""
|
@Select("""
|
||||||
SELECT COUNT(*) FROM ll_inbound_plan_pallet_allocation a JOIN ll_inbound_plan_line l ON l.id=a.line_id
|
SELECT COUNT(*) FROM ll_inbound_plan_pallet_allocation a JOIN ll_inbound_plan_line l ON l.id=a.line_id
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.mapper;
|
||||||
|
|
||||||
|
/** 排车列表和BOL共用当前客户收货确认;调用方的a必须是逐票预约分配。 */
|
||||||
|
final class DispatchReceivingSql {
|
||||||
|
/** 只读当前有效覆盖,不使用多客户批次头汇总值,历史退出记录不能提供编号。 */
|
||||||
|
static final String CONFIRMATION_NO = """
|
||||||
|
(SELECT rg.confirmation_no
|
||||||
|
FROM ll_fba_receiving_member rm
|
||||||
|
JOIN ll_fba_receiving_agreement rg ON rg.agreement_key=rm.agreement_key
|
||||||
|
WHERE rm.batch_key=a.batch_key AND rm.customer_id=a.customer_id AND rm.active_ref IS NOT NULL
|
||||||
|
AND rg.destination_key=a.destination_key AND rg.status='ACTIVE'
|
||||||
|
AND JSON_UNQUOTE(JSON_EXTRACT(rg.snapshot_json,'$.details.appointmentStatus'))='SUCCESS'
|
||||||
|
AND NULLIF(JSON_UNQUOTE(JSON_EXTRACT(rg.snapshot_json,'$.details.appointmentAt')),'null') IS NOT NULL)
|
||||||
|
""";
|
||||||
|
|
||||||
|
/** 仅提供Mapper编译期SQL片段。 */
|
||||||
|
private DispatchReceivingSql() { }
|
||||||
|
}
|
||||||
+17
-2
@@ -49,7 +49,7 @@ public final class DispatchContracts {
|
|||||||
@JsonDeserialize(using = DispatchMaintenanceDateDeserializer.class)
|
@JsonDeserialize(using = DispatchMaintenanceDateDeserializer.class)
|
||||||
LocalDate plannedDeliveryDate, String deliveryMethod, String pickupMethod,
|
LocalDate plannedDeliveryDate, String deliveryMethod, String pickupMethod,
|
||||||
String loadType, String fleetEmail, String vehicleType,
|
String loadType, String fleetEmail, String vehicleType,
|
||||||
String appointmentAccount, String appointmentNo) {
|
String appointmentAccount, List<DestinationAppointment> destinationAppointments) {
|
||||||
/** 空白统一为空;只约束已填写的选项及长度,不阻止空草稿保存。 */
|
/** 空白统一为空;只约束已填写的选项及长度,不阻止空草稿保存。 */
|
||||||
public Maintenance {
|
public Maintenance {
|
||||||
deliveryMethod = option(deliveryMethod, "派送方式", "FBA自提", "客户自提", "卡派打托", "卡派地板", "快递", "外配");
|
deliveryMethod = option(deliveryMethod, "派送方式", "FBA自提", "客户自提", "卡派打托", "卡派地板", "快递", "外配");
|
||||||
@@ -58,7 +58,10 @@ public final class DispatchContracts {
|
|||||||
vehicleType = option(vehicleType, "车辆类型", "厢式货车", "平板车", "集装箱卡车");
|
vehicleType = option(vehicleType, "车辆类型", "厢式货车", "平板车", "集装箱卡车");
|
||||||
fleetEmail = limited(fleetEmail, "车队邮箱", 254);
|
fleetEmail = limited(fleetEmail, "车队邮箱", 254);
|
||||||
appointmentAccount = limited(appointmentAccount, "预约账号", 128);
|
appointmentAccount = limited(appointmentAccount, "预约账号", 128);
|
||||||
appointmentNo = limited(appointmentNo, "本趟预约号", 128);
|
if (destinationAppointments != null && destinationAppointments.stream().anyMatch(java.util.Objects::isNull)) throw new IllegalArgumentException("预约目的仓不能空缺");
|
||||||
|
destinationAppointments = destinationAppointments == null ? List.of() : List.copyOf(destinationAppointments);
|
||||||
|
if (destinationAppointments.size() > 500 || destinationAppointments.stream().map(DestinationAppointment::destinationKey).distinct().count() != destinationAppointments.size())
|
||||||
|
throw new IllegalArgumentException("同一目的仓只能填写一个预约号");
|
||||||
}
|
}
|
||||||
/** 选项按正式文案保存,拒绝未知值而不猜测业务含义。 */
|
/** 选项按正式文案保存,拒绝未知值而不猜测业务含义。 */
|
||||||
private static String option(String value, String label, String... allowed) {
|
private static String option(String value, String label, String... allowed) {
|
||||||
@@ -74,6 +77,18 @@ public final class DispatchContracts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 同一排车按目的仓登记约好的编号,不要求客服逐票或逐托分配。 */
|
||||||
|
public record DestinationAppointment(String destinationKey, String appointmentNo) {
|
||||||
|
/** 草稿允许暂缺编号,目的仓身份及文本长度仍须明确。 */
|
||||||
|
public DestinationAppointment {
|
||||||
|
destinationKey = destinationKey == null ? null : destinationKey.trim();
|
||||||
|
appointmentNo = appointmentNo == null || appointmentNo.isBlank() ? null : appointmentNo.trim();
|
||||||
|
if (destinationKey == null || !destinationKey.startsWith("FBA:") || destinationKey.length() <= 4 || destinationKey.length() > 256)
|
||||||
|
throw new IllegalArgumentException("预约目的仓无效");
|
||||||
|
if (appointmentNo != null && appointmentNo.length() > 128) throw new IllegalArgumentException("预约号最多128字符");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public record Resources(VehicleSnapshot vehicle, DriverSnapshot driver, Maintenance maintenance) { }
|
public record Resources(VehicleSnapshot vehicle, DriverSnapshot driver, Maintenance maintenance) { }
|
||||||
|
|
||||||
public record Destination(String key, String type, String warehouseId, String warehouseCode,
|
public record Destination(String key, String type, String warehouseId, String warehouseCode,
|
||||||
|
|||||||
@@ -32,15 +32,15 @@ public final class DispatchViews {
|
|||||||
public record ListRow(String dispatchNo, String taskType, Status status, Stage stage, long recordVersion,
|
public record ListRow(String dispatchNo, String taskType, Status status, Stage stage, long recordVersion,
|
||||||
ReviewState reviewState, Reviews reviews, Resources resources,
|
ReviewState reviewState, Reviews reviews, Resources resources,
|
||||||
String warehouseId, String warehouseCode, String warehouseName,
|
String warehouseId, String warehouseCode, String warehouseName,
|
||||||
Instant plannedDepartureAt, Instant departedAt, Counts counts,
|
Instant createdAt, Instant plannedDepartureAt, Instant departedAt, Counts counts,
|
||||||
boolean pickingReconciled, boolean arranged,
|
boolean pickingReconciled, boolean arranged,
|
||||||
Map<Action, Gate> actions) { }
|
Map<Action, Gate> actions, List<FbaAppointment> fbaAppointments) { }
|
||||||
|
|
||||||
public record VehicleInfo(VehicleSnapshot vehicle, DriverSnapshot driver, Maintenance maintenance) { }
|
public record VehicleInfo(VehicleSnapshot vehicle, DriverSnapshot driver, Maintenance maintenance) { }
|
||||||
|
|
||||||
public record FbaAppointment(String batchKey, String batchNo, String appointmentNo,
|
public record FbaAppointment(String batchKey, String batchNo, String appointmentNo,
|
||||||
String destinationKey, String destinationWarehouseCode,
|
String destinationKey, String destinationWarehouseCode,
|
||||||
String status, Instant confirmedAt, String blockReason) { }
|
String status, Instant confirmedAt, String blockReason, String customerId, List<String> shipmentNumbers) { }
|
||||||
|
|
||||||
public record DispatchInfo(String route, Instant plannedDepartureAt, Instant departedAt,
|
public record DispatchInfo(String route, Instant plannedDepartureAt, Instant departedAt,
|
||||||
Instant estimatedArrivalAt, List<FbaAppointment> fbaAppointments,
|
Instant estimatedArrivalAt, List<FbaAppointment> fbaAppointments,
|
||||||
|
|||||||
+2
@@ -65,6 +65,8 @@ public class DispatchAggregateRepository {
|
|||||||
public List<DispatchReadMapper.DeliveryRow> deliveries(long id) { return reads.deliveries(id); }
|
public List<DispatchReadMapper.DeliveryRow> deliveries(long id) { return reads.deliveries(id); }
|
||||||
/** 已有关联预约批次只读事实。 */
|
/** 已有关联预约批次只读事实。 */
|
||||||
public List<DispatchReadMapper.BatchRow> batches(long id) { return reads.batches(id); }
|
public List<DispatchReadMapper.BatchRow> batches(long id) { return reads.batches(id); }
|
||||||
|
/** 本车实际货物的权威货件号,不依赖预约分配,也不把重复托盘当作新货件。 */
|
||||||
|
public List<DispatchReadMapper.CargoShipment> cargoShipmentNumbers(long id) { return reads.cargoShipmentNumbers(id); }
|
||||||
/** 是否必须走受保护提供者核验批次分配。 */
|
/** 是否必须走受保护提供者核验批次分配。 */
|
||||||
public long activeAppointments(String customer, Long pallet) { return reads.activeAppointments(customer,pallet); }
|
public long activeAppointments(String customer, Long pallet) { return reads.activeAppointments(customer,pallet); }
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-20
@@ -177,7 +177,6 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
var fact=type!=SourceType.INBOUND_PLAN || row.planPalletId()==null?null:batchFacts.get(new com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.CandidatePhysical(row.customerId(),row.planPalletId()));
|
var fact=type!=SourceType.INBOUND_PLAN || row.planPalletId()==null?null:batchFacts.get(new com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.CandidatePhysical(row.customerId(),row.planPalletId()));
|
||||||
var references=new ArrayList<BatchReference>();var reasons=new LinkedHashSet<String>();
|
var references=new ArrayList<BatchReference>();var reasons=new LinkedHashSet<String>();
|
||||||
reasons.addAll(group.blockReasons());
|
reasons.addAll(group.blockReasons());
|
||||||
if(type==SourceType.INBOUND_PLAN && "FBA".equals(destination.type()) && fact==null)reasons.add("本票FBA货物缺少可核对的正式预约来源,请先确认送仓时间");
|
|
||||||
if(fact!=null) {
|
if(fact!=null) {
|
||||||
reasons.addAll(fact.blockReasons());
|
reasons.addAll(fact.blockReasons());
|
||||||
// 来源候选已验证当前草稿拥有者并过滤其他作业占用,不能把本草稿占用再次当禁用。
|
// 来源候选已验证当前草稿拥有者并过滤其他作业占用,不能把本草稿占用再次当禁用。
|
||||||
@@ -269,14 +268,14 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
}
|
}
|
||||||
return evidence.download(row.getId(),kind,fileId);
|
return evidence.download(row.getId(),kind,fileId);
|
||||||
}
|
}
|
||||||
/** 未命中冻结MASTER引用的文件仅可按原排车归属读取,保留编辑中尚未保存的本车外配上传。 */
|
/** 主档驾驶证按明确来源标记读取,本趟补传照片保持排车文件归属。 */
|
||||||
private Long masterEvidenceDriverId(DispatchAggregate row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind kind,long fileId) {
|
private Long masterEvidenceDriverId(DispatchAggregate row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind kind,long fileId) {
|
||||||
if(kind!=com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER)return null;
|
if(kind!=com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER)return null;
|
||||||
var resources=read(row.getResourcesJson(),Resources.class);var driver=resources==null?null:resources.driver();
|
var resources=read(row.getResourcesJson(),Resources.class);var driver=resources==null?null:resources.driver();
|
||||||
if(driver==null || driver.mode()!=ResourceMode.MASTER || driver.evidence()==null || driver.evidence().fileIds()==null
|
if(driver==null || driver.mode()!=ResourceMode.MASTER || driver.evidence()==null || driver.evidence().fileIds()==null
|
||||||
|| !driver.evidence().fileIds().contains(fileId))return null;
|
|| !driver.evidence().fileIds().contains(fileId))return null;
|
||||||
// 取货允许补传本车驾驶证,仅明确冻结的主档引用才走司机归属。
|
// 只有车队解析并冻结的主档引用才走司机归属,不能把补传图片当作主档文件。
|
||||||
if("PICKUP".equals(row.getTaskType()) && !Objects.equals(driver.evidence().masterLicenseFileId(),fileId))return null;
|
if(!Objects.equals(driver.evidence().masterLicenseFileId(),fileId))return null;
|
||||||
if(driver.driverId()==null || driver.driverId()<=0)throw bad("排车冻结司机档案身份无效,不能读取证照");
|
if(driver.driverId()==null || driver.driverId()<=0)throw bad("排车冻结司机档案身份无效,不能读取证照");
|
||||||
return driver.driverId();
|
return driver.driverId();
|
||||||
}
|
}
|
||||||
@@ -442,8 +441,15 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
if(!photos.isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER_PHOTO,photos);
|
if(!photos.isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER_PHOTO,photos);
|
||||||
var vehiclePhotos=request.vehicle()==null?null:request.vehicle().evidenceFileIds();
|
var vehiclePhotos=request.vehicle()==null?null:request.vehicle().evidenceFileIds();
|
||||||
if(vehiclePhotos!=null && !vehiclePhotos.isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.VEHICLE,vehiclePhotos);
|
if(vehiclePhotos!=null && !vehiclePhotos.isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.VEHICLE,vehiclePhotos);
|
||||||
var actual=fleet.dispatchResources(number,fleetVehicle(request.vehicle()),fleetDriver(request.driver()));
|
var actual=fleet.dispatchResources(number,fleetVehicle(request.vehicle()),updatedFleetDriver(request.driver(),read(row.getResourcesJson(),Resources.class)));
|
||||||
row.setResourcesJson(write(resources(actual,photos,request.maintenance())));row.setVehiclePlate(actual.vehicle()==null?null:actual.vehicle().plate());
|
DispatchDestinationAppointments.validate(request.maintenance(),reviewAppointments(row));
|
||||||
|
var savedResources=resources(actual,photos,request.maintenance());
|
||||||
|
// 主档引用只能由车队解析产生;补传照片必须核验本车归属后才允许保存。
|
||||||
|
var savedDriver=savedResources.driver();
|
||||||
|
if(savedDriver!=null && savedDriver.evidence()!=null)for(var id:savedDriver.evidence().fileIds()) {
|
||||||
|
if(!Objects.equals(id,savedDriver.evidence().masterLicenseFileId()))evidence.metadata(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER,id);
|
||||||
|
}
|
||||||
|
row.setResourcesJson(write(savedResources));row.setVehiclePlate(actual.vehicle()==null?null:actual.vehicle().plate());
|
||||||
row.setPlannedDepartureAt(utc(request.plannedDepartureAt()));row.setEstimatedArrivalAt(utc(request.estimatedArrivalAt()));row.setRemark(request.remark());
|
row.setPlannedDepartureAt(utc(request.plannedDepartureAt()));row.setEstimatedArrivalAt(utc(request.estimatedArrivalAt()));row.setRemark(request.remark());
|
||||||
row.setPublishLooseboardDemand(request.publishLooseboardDemand());
|
row.setPublishLooseboardDemand(request.publishLooseboardDemand());
|
||||||
if(!Objects.equals(before,basis(row)))invalidate(row,"车辆、司机或计划信息已修改");
|
if(!Objects.equals(before,basis(row)))invalidate(row,"车辆、司机或计划信息已修改");
|
||||||
@@ -613,7 +619,8 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
if(items.isEmpty() || items.stream().anyMatch(i->i.getWarehousePalletId()==null))throw conflict("逐项真实拣货尚未核平");
|
if(items.isEmpty() || items.stream().anyMatch(i->i.getWarehousePalletId()==null))throw conflict("逐项真实拣货尚未核平");
|
||||||
lockExecutionSources(row,items);
|
lockExecutionSources(row,items);
|
||||||
var preview=loading(actor,number);if(!preview.pickingReconciled())throw conflict("逐项真实拣货尚未核平");
|
var preview=loading(actor,number);if(!preview.pickingReconciled())throw conflict("逐项真实拣货尚未核平");
|
||||||
String appointmentBlock=appointments.departureBlockReason(number);
|
String appointmentBlock=reviewAppointmentBlock(row);
|
||||||
|
if(appointmentBlock==null)appointmentBlock=appointments.departureBlockReason(number);
|
||||||
if(appointmentBlock!=null)throw conflict(appointmentBlock);
|
if(appointmentBlock!=null)throw conflict(appointmentBlock);
|
||||||
if(!Objects.equals(preview.manifestHash(),request.manifestHash()))throw conflict("真实装载清单已变化,请重新核对");
|
if(!Objects.equals(preview.manifestHash(),request.manifestHash()))throw conflict("真实装载清单已变化,请重新核对");
|
||||||
if(preview.pallets().stream().anyMatch(p->p.deliveryIndex()==null))throw conflict("托盘卸货站尚未匹配,请调度核对路线");
|
if(preview.pallets().stream().anyMatch(p->p.deliveryIndex()==null))throw conflict("托盘卸货站尚未匹配,请调度核对路线");
|
||||||
@@ -698,7 +705,7 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
// 客户仓的DISPATCH引用属于本车自身,扫码递增公共版本不代表预约或货物依据变化。
|
// 客户仓的DISPATCH引用属于本车自身,扫码递增公共版本不代表预约或货物依据变化。
|
||||||
for(var batch:batches)if(("DISPATCH:"+row.getId()).equals(batch.path("batchKey").asText()))
|
for(var batch:batches)if(("DISPATCH:"+row.getId()).equals(batch.path("batchKey").asText()))
|
||||||
((com.fasterxml.jackson.databind.node.ObjectNode)batch).remove("recordVersion");
|
((com.fasterxml.jackson.databind.node.ObjectNode)batch).remove("recordVersion");
|
||||||
facts.put("batches",batches);facts.put("route",fleet.dispatchStops(row.getDispatchNo()));facts.put("receiving",appointments.reviewEvidence(row.getDispatchNo()));
|
facts.put("batches",batches);facts.put("route",fleet.dispatchStops(row.getDispatchNo()));facts.put("receiving",reviewAppointments(row));
|
||||||
}
|
}
|
||||||
return hashes.source(facts);
|
return hashes.source(facts);
|
||||||
}
|
}
|
||||||
@@ -747,20 +754,37 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
var capacity=v.capacity();if(capacity==null || capacity.palletSpaces()==null || capacity.palletSpaces()<=0 || capacity.maxLoadKg()==null || capacity.maxLoadKg().signum()<=0 || capacity.maxVolumeCbm()==null || capacity.maxVolumeCbm().signum()<=0)throw bad("请补齐车辆真实托位、载重及容积");
|
var capacity=v.capacity();if(capacity==null || capacity.palletSpaces()==null || capacity.palletSpaces()<=0 || capacity.maxLoadKg()==null || capacity.maxLoadKg().signum()<=0 || capacity.maxVolumeCbm()==null || capacity.maxVolumeCbm().signum()<=0)throw bad("请补齐车辆真实托位、载重及容积");
|
||||||
var e=d.evidence();if(e==null || e.expectedTaskEndAt()==null || row.getPlannedDepartureAt()==null || !e.expectedTaskEndAt().isAfter(instant(row.getPlannedDepartureAt())) || !e.expectedTaskEndAt().isAfter(Instant.now()))throw bad("预计任务结束须晚于发车及当前时间");
|
var e=d.evidence();if(e==null || e.expectedTaskEndAt()==null || row.getPlannedDepartureAt()==null || !e.expectedTaskEndAt().isAfter(instant(row.getPlannedDepartureAt())) || !e.expectedTaskEndAt().isAfter(Instant.now()))throw bad("预计任务结束须晚于发车及当前时间");
|
||||||
if(trim(e.licenseNo())==null || e.licenseExpiresOn()==null || e.licenseExpiresOn().isBefore(e.expectedTaskEndAt().atZone(ZoneOffset.UTC).toLocalDate()))throw bad("司机证照须覆盖预计任务结束日期");
|
if(trim(e.licenseNo())==null || e.licenseExpiresOn()==null || e.licenseExpiresOn().isBefore(e.expectedTaskEndAt().atZone(ZoneOffset.UTC).toLocalDate()))throw bad("司机证照须覆盖预计任务结束日期");
|
||||||
if(v.mode()==ResourceMode.EXTERNAL || v.evidenceFileIds()!=null && !v.evidenceFileIds().isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.VEHICLE,v.evidenceFileIds());
|
verifyReviewPhotos(row,r);
|
||||||
if(d.mode()==ResourceMode.EXTERNAL)verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER,e.fileIds());
|
|
||||||
if(!e.photoFileIds().isEmpty())verifyEvidence(row.getId(),com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER_PHOTO,e.photoFileIds());
|
|
||||||
var actual=fleet.dispatchResources(row.getDispatchNo(),new FleetExecutionModels.DispatchVehicle(v.mode().name(),v.vehicleId(),v.plate(),v.carrierName(),capacity.palletSpaces(),capacity.maxLoadKg(),capacity.maxVolumeCbm(),v.evidenceFileIds()),
|
var actual=fleet.dispatchResources(row.getDispatchNo(),new FleetExecutionModels.DispatchVehicle(v.mode().name(),v.vehicleId(),v.plate(),v.carrierName(),capacity.palletSpaces(),capacity.maxLoadKg(),capacity.maxVolumeCbm(),v.evidenceFileIds()),
|
||||||
new FleetExecutionModels.DispatchDriver(d.mode().name(),d.driverId(),d.name(),d.phone(),e.licenseNo(),e.licenseExpiresOn(),e.fileIds(),e.expectedTaskEndAt()));
|
new FleetExecutionModels.DispatchDriver(d.mode().name(),d.driverId(),d.name(),d.phone(),e.licenseNo(),e.licenseExpiresOn(),e.fileIds(),e.expectedTaskEndAt()));
|
||||||
if(!Objects.equals(hashes.source(r),hashes.source(resources(actual,e.photoFileIds(),r.maintenance()))))throw conflict("车辆或司机主档已变化,请重新保存并提交审核");
|
if(!Objects.equals(hashes.source(r),hashes.source(resources(actual,e.photoFileIds(),r.maintenance()))))throw conflict("车辆或司机主档已变化,请重新保存并提交审核");
|
||||||
}
|
}
|
||||||
|
/** 三类均须含至少一张当前有效图片;保存草稿不调用此送审/通过门禁。 */
|
||||||
|
private void verifyReviewPhotos(DispatchAggregate row,Resources resources) {
|
||||||
|
var driver=resources.driver();var proof=driver.evidence();
|
||||||
|
requireReviewPhoto(row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.VEHICLE,resources.vehicle().evidenceFileIds(),"车辆图片");
|
||||||
|
requireReviewPhoto(row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER_PHOTO,proof.photoFileIds(),"司机照片");
|
||||||
|
requireReviewPhoto(row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind.DRIVER,proof.fileIds(),"驾驶证照片");
|
||||||
|
}
|
||||||
|
/** 文件存在、归属及有效性由原文件提供者复验,PDF不能充当照片。 */
|
||||||
|
private void requireReviewPhoto(DispatchAggregate row,com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.Kind kind,List<Long> ids,String label) {
|
||||||
|
if(ids==null || ids.isEmpty() || ids.size()>20 || ids.stream().anyMatch(id->id==null || id<=0) || ids.stream().distinct().count()!=ids.size())throw bad("请上传至少一张有效"+label);
|
||||||
|
boolean image=false;
|
||||||
|
for(var id:ids) {
|
||||||
|
var master=masterEvidenceDriverId(row,kind,id);
|
||||||
|
var file=master==null?evidence.metadata(row.getId(),kind,id):driverEvidenceMetadata(fleet.dispatchDriverLicense(master,id).metadata(),id);
|
||||||
|
if(file!=null && ("image/jpeg".equals(file.contentType()) || "image/png".equals(file.contentType())))image=true;
|
||||||
|
}
|
||||||
|
if(!image)throw bad("请上传至少一张有效"+label);
|
||||||
|
}
|
||||||
/** 从客服提交到真实扫码共用预约及时间复验,保留预排但不放行未确认货物。 */
|
/** 从客服提交到真实扫码共用预约及时间复验,保留预排但不放行未确认货物。 */
|
||||||
void requireReviewAppointment(DispatchAggregate row) {
|
void requireReviewAppointment(DispatchAggregate row) {
|
||||||
String reason=reviewAppointmentBlock(row);
|
String reason=reviewAppointmentBlock(row);
|
||||||
if(reason!=null)throw conflict(reason);
|
if(reason!=null)throw conflict(reason);
|
||||||
}
|
}
|
||||||
private String reviewAppointmentBlock(DispatchAggregate row) {
|
private String reviewAppointmentBlock(DispatchAggregate row) {
|
||||||
String reason=appointments.reviewBlockReason(row.getDispatchNo(),instant(row.getPlannedDepartureAt()),instant(row.getEstimatedArrivalAt()));
|
String reason=DispatchDestinationAppointments.blockReason(reviewAppointments(row),instant(row.getPlannedDepartureAt()),instant(row.getEstimatedArrivalAt()),appointments.reviewEvidence(row.getDispatchNo()));
|
||||||
|
if(reason==null)reason=appointments.reviewBlockReason(row.getDispatchNo(),instant(row.getPlannedDepartureAt()),instant(row.getEstimatedArrivalAt()));
|
||||||
if(reason==null && row.getReviewBasisHash()!=null && !canSubmitReview(row.getReviewState()) && !Objects.equals(row.getReviewBasisHash(),basis(row)))
|
if(reason==null && row.getReviewBasisHash()!=null && !canSubmitReview(row.getReviewState()) && !Objects.equals(row.getReviewBasisHash(),basis(row)))
|
||||||
return "预约或运输安排已变化,原审核依据失效,请重新核对审核";
|
return "预约或运输安排已变化,原审核依据失效,请重新核对审核";
|
||||||
return reason;
|
return reason;
|
||||||
@@ -822,20 +846,26 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
statistics(repository.summaries(filter)),Instant.now());
|
statistics(repository.summaries(filter)),Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Admin与PDA审核读取相同的当前有效预约,未确认成员不能被已确认成员覆盖。 */
|
/** Admin与PDA共用本车目的仓预约,每个目的仓仅返回一行。 */
|
||||||
List<DispatchViews.FbaAppointment> reviewAppointments(DispatchAggregate row) {
|
List<DispatchViews.FbaAppointment> reviewAppointments(DispatchAggregate row) {
|
||||||
String number=row.getDispatchNo();var batches=repository.batches(row.getId());
|
var resources=read(row.getResourcesJson(),Resources.class);
|
||||||
|
return DispatchDestinationAppointments.resolve(repository.cargo(row.getId()),resources==null?null:resources.maintenance(),bookedAppointments(row),repository.cargoShipmentNumbers(row.getId()));
|
||||||
|
}
|
||||||
|
/** 原预约仅用于带出已有确认号,客服按目的仓维护后不再逐票录入。 */
|
||||||
|
private List<DispatchViews.FbaAppointment> bookedAppointments(DispatchAggregate row) {
|
||||||
|
String number=row.getDispatchNo();var batches=repository.batches(row.getId()).stream().filter(b->b.batchKey().startsWith("FBA_APPOINTMENT:")).toList();
|
||||||
|
if(batches.isEmpty())return List.of();
|
||||||
var confirmedAppointments=this.appointments.reviewEvidence(number);
|
var confirmedAppointments=this.appointments.reviewEvidence(number);
|
||||||
return batches.stream().filter(b -> b.batchKey().startsWith("FBA_APPOINTMENT:")).collect(Collectors.toMap(
|
return batches.stream().collect(Collectors.toMap(
|
||||||
b -> List.of(b.batchKey(),b.customerId(),b.destinationKey()),b->b,(a,b)->a,LinkedHashMap::new)).values().stream().map(b -> {
|
b -> List.of(b.batchKey(),b.customerId(),b.destinationKey()),b->b,(a,b)->a,LinkedHashMap::new)).values().stream().map(b -> {
|
||||||
var confirmed=confirmedAppointments.stream().filter(w->w.batchKey().equals(b.batchKey()) && w.customerId().equals(b.customerId()) && w.destinationKey().equals(b.destinationKey())).findFirst().orElse(null);
|
var confirmed=confirmedAppointments.stream().filter(w->w.batchKey().equals(b.batchKey()) && w.customerId().equals(b.customerId()) && w.destinationKey().equals(b.destinationKey())).findFirst().orElse(null);
|
||||||
return new DispatchViews.FbaAppointment(b.batchKey(),b.batchNo(),confirmed==null?null:confirmed.confirmationNo(),b.destinationKey(),b.warehouseCode(),
|
return new DispatchViews.FbaAppointment(b.batchKey(),b.batchNo(),confirmed==null?null:confirmed.confirmationNo(),b.destinationKey(),b.warehouseCode(),
|
||||||
confirmed==null?"PENDING":"SUCCESS",confirmed==null?null:confirmed.startAt(),confirmed==null?"尚无当前有效收货确认":null);
|
confirmed==null?"PENDING":"SUCCESS",confirmed==null?null:confirmed.startAt(),confirmed==null?"尚无当前有效收货确认":null,b.customerId(),List.of());
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 一次读取真实全部客户明细和单据,客户端不暴露整车入口。 */
|
/** 一次读取真实全部客户明细和单据,客户端不暴露整车入口。 */
|
||||||
/** 四页签读取同一资源快照,维护资料和本趟车辆照片不回退为主档或备注。 */
|
/** 四页签读取同一资源快照,维护资料及本趟照片保持直接业务归属。 */
|
||||||
@Transactional(readOnly=true,isolation=Isolation.REPEATABLE_READ)
|
@Transactional(readOnly=true,isolation=Isolation.REPEATABLE_READ)
|
||||||
public DispatchViews.Detail detail(Actor actor, String number) {
|
public DispatchViews.Detail detail(Actor actor, String number) {
|
||||||
var row=required(actor,number,false); var cargo=repository.cargo(row.getId());
|
var row=required(actor,number,false); var cargo=repository.cargo(row.getId());
|
||||||
@@ -1055,10 +1085,10 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
new DispatchViews.ReviewCounts(dispatch[0],dispatch[1],dispatch[2],dispatch[3]),new DispatchViews.ReviewCounts(loading[0],loading[1],loading[2],loading[3])));
|
new DispatchViews.ReviewCounts(dispatch[0],dispatch[1],dispatch[2],dispatch[3]),new DispatchViews.ReviewCounts(loading[0],loading[1],loading[2],loading[3])));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 列表不逐行读取明细、附件或派送。 */
|
/** 列表带出与详情相同的正式预约投影,不读取附件或派送。 */
|
||||||
private DispatchViews.ListRow listRow(Actor actor,DispatchAggregate row) {
|
private DispatchViews.ListRow listRow(Actor actor,DispatchAggregate row) {
|
||||||
return new DispatchViews.ListRow(row.getDispatchNo(),row.getTaskType()==null?"DELIVERY":row.getTaskType(),Status.valueOf(row.getStatus()),Stage.valueOf(row.getStage()),row.getRecordVersion(),ReviewState.valueOf(row.getReviewState()),
|
return new DispatchViews.ListRow(row.getDispatchNo(),row.getTaskType()==null?"DELIVERY":row.getTaskType(),Status.valueOf(row.getStatus()),Stage.valueOf(row.getStage()),row.getRecordVersion(),ReviewState.valueOf(row.getReviewState()),
|
||||||
reviews(row),read(row.getResourcesJson(),Resources.class),row.getOverseasWarehouseId(),row.getOverseasWarehouseCode(),row.getOverseasWarehouseName(),instant(row.getPlannedDepartureAt()),instant(row.getDepartedAt()),counts(row),reconciled(row),row.getArrangementKey()!=null,actions(actor,row));
|
reviews(row),read(row.getResourcesJson(),Resources.class),row.getOverseasWarehouseId(),row.getOverseasWarehouseCode(),row.getOverseasWarehouseName(),instant(row.getCreatedAt()),instant(row.getPlannedDepartureAt()),instant(row.getDepartedAt()),counts(row),reconciled(row),row.getArrangementKey()!=null,actions(actor,row),reviewAppointments(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 混托多订单无法真实分摊重量体积时保持未知,不能给每票复制整托总量。 */
|
/** 混托多订单无法真实分摊重量体积时保持未知,不能给每票复制整托总量。 */
|
||||||
@@ -1079,7 +1109,8 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
var v=shell.vehicle(); var d=shell.driver();
|
var v=shell.vehicle(); var d=shell.driver();
|
||||||
return new Resources(v==null?null:new VehicleSnapshot(ResourceMode.valueOf(v.mode()),v.vehicleId(),v.plate(),v.carrierName(),shell.vehicleStatus(),
|
return new Resources(v==null?null:new VehicleSnapshot(ResourceMode.valueOf(v.mode()),v.vehicleId(),v.plate(),v.carrierName(),shell.vehicleStatus(),
|
||||||
new Capacity(v.palletSpaces(),v.maxLoadKg(),v.maxVolumeCbm()),v.evidenceFileIds()),d==null?null:new DriverSnapshot(ResourceMode.valueOf(d.mode()),d.driverId(),d.name(),d.phone(),
|
new Capacity(v.palletSpaces(),v.maxLoadKg(),v.maxVolumeCbm()),v.evidenceFileIds()),d==null?null:new DriverSnapshot(ResourceMode.valueOf(d.mode()),d.driverId(),d.name(),d.phone(),
|
||||||
new DriverEvidence(d.licenseNo(),d.licenseExpiresOn(),d.evidenceFileIds(),d.expectedTaskEndAt(),photos)),maintenance);
|
new DriverEvidence(d.licenseNo(),d.licenseExpiresOn(),d.evidenceFileIds(),d.expectedTaskEndAt(),photos,
|
||||||
|
"MASTER".equals(d.mode()) && !d.evidenceFileIds().isEmpty()?d.evidenceFileIds().get(0):null)),maintenance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 主档选择不接受请求覆盖其车牌和容量。 */
|
/** 主档选择不接受请求覆盖其车牌和容量。 */
|
||||||
@@ -1089,6 +1120,17 @@ public class DispatchAggregateService implements DispatchExecutionPort,DispatchA
|
|||||||
v.capacity()==null?null:v.capacity().maxLoadKg(),v.capacity()==null?null:v.capacity().maxVolumeCbm(),v.evidenceFileIds()==null?List.of():List.copyOf(v.evidenceFileIds()));
|
v.capacity()==null?null:v.capacity().maxLoadKg(),v.capacity()==null?null:v.capacity().maxVolumeCbm(),v.evidenceFileIds()==null?List.of():List.copyOf(v.evidenceFileIds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 旧主档证照由服务端保存的来源标记识别;换证后只向车队传本趟补传文件,不能信任请求自报来源。 */
|
||||||
|
private static FleetExecutionModels.DispatchDriver updatedFleetDriver(DispatchCommands.Driver requested,Resources previous) {
|
||||||
|
var driver=fleetDriver(requested);
|
||||||
|
var old=previous==null?null:previous.driver();
|
||||||
|
if(driver==null || old==null || old.mode()!=ResourceMode.MASTER || requested.mode()!=ResourceMode.MASTER
|
||||||
|
|| !Objects.equals(old.driverId(),requested.driverId()) || old.evidence()==null || old.evidence().masterLicenseFileId()==null)return driver;
|
||||||
|
var oldMaster=old.evidence().masterLicenseFileId();
|
||||||
|
return new FleetExecutionModels.DispatchDriver(driver.mode(),driver.driverId(),driver.name(),driver.phone(),driver.licenseNo(),driver.licenseExpiresOn(),
|
||||||
|
driver.evidenceFileIds().stream().filter(id->!Objects.equals(id,oldMaster)).toList(),driver.expectedTaskEndAt());
|
||||||
|
}
|
||||||
|
|
||||||
/** 司机证据是本趟输入,主档事实仍由Fleet提供者核验。 */
|
/** 司机证据是本趟输入,主档事实仍由Fleet提供者核验。 */
|
||||||
private static FleetExecutionModels.DispatchDriver fleetDriver(DispatchCommands.Driver d) {
|
private static FleetExecutionModels.DispatchDriver fleetDriver(DispatchCommands.Driver d) {
|
||||||
if(d==null) return null; if(d.mode()==null) throw bad("请选择司机来源方式"); var e=d.evidence();
|
if(d==null) return null; if(d.mode()==null) throw bad("请选择司机来源方式"); var e=d.evidence();
|
||||||
|
|||||||
+6
@@ -58,6 +58,12 @@ public class DispatchBolReadService {
|
|||||||
remaining.forEach((key,count)->{if(count>0)result.add(copy(cargo.get(key),count,null));});
|
remaining.forEach((key,count)->{if(count>0)result.add(copy(cargo.get(key),count,null));});
|
||||||
var printedTotals=new HashMap<Long,Integer>();result.forEach(line->printedTotals.merge(line.dispatchItemId(),line.packageCount(),Math::addExact));
|
var printedTotals=new HashMap<Long,Integer>();result.forEach(line->printedTotals.merge(line.dispatchItemId(),line.packageCount(),Math::addExact));
|
||||||
if(!printedTotals.equals(totals))throw invalid();
|
if(!printedTotals.equals(totals))throw invalid();
|
||||||
|
// 仅已填写编号覆盖同仓来源;空草稿保留后来取得的正式预约号,不改变各客户货量。
|
||||||
|
if(resources.maintenance()!=null) {
|
||||||
|
var numbers=new HashMap<String,String>();resources.maintenance().destinationAppointments().stream()
|
||||||
|
.filter(a->a.appointmentNo()!=null).forEach(a->numbers.put(a.destinationKey(),a.appointmentNo()));
|
||||||
|
result.replaceAll(line->numbers.containsKey(line.destinationKey())?copy(line,line.packageCount(),numbers.get(line.destinationKey())):line);
|
||||||
|
}
|
||||||
return new DispatchBolData(row.getDispatchNo(),row.getOverseasWarehouseId(),row.getOverseasWarehouseName(),resources.vehicle()==null?null:resources.vehicle().carrierName(),resources.vehicle()==null?null:resources.vehicle().plate(),
|
return new DispatchBolData(row.getDispatchNo(),row.getOverseasWarehouseId(),row.getOverseasWarehouseName(),resources.vehicle()==null?null:resources.vehicle().carrierName(),resources.vehicle()==null?null:resources.vehicle().plate(),
|
||||||
row.getEstimatedArrivalAt()==null?null:LocalDateTime.ofInstant(row.getEstimatedArrivalAt().toInstant(ZoneOffset.UTC),ZoneId.systemDefault()),List.copyOf(result));
|
row.getEstimatedArrivalAt()==null?null:LocalDateTime.ofInstant(row.getEstimatedArrivalAt().toInstant(ZoneOffset.UTC),ZoneId.systemDefault()),List.copyOf(result));
|
||||||
}
|
}
|
||||||
|
|||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.service;
|
||||||
|
|
||||||
|
import com.baiyue.lastleg.dispatch.entity.DispatchItem;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchContracts.Maintenance;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchViews.FbaAppointment;
|
||||||
|
import com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.ReceivingWindow;
|
||||||
|
import com.baiyue.common.core.api.ResultCode;
|
||||||
|
import com.baiyue.common.core.exception.BizException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/** 本车送仓预约按目的仓汇总;货物的客户归属及真实数量仍由原明细维护。 */
|
||||||
|
final class DispatchDestinationAppointments {
|
||||||
|
/** 纯规则容器不持有数据访问或单据状态。 */
|
||||||
|
private DispatchDestinationAppointments() { }
|
||||||
|
|
||||||
|
/** 先预约的唯一确认号自动带入;同仓多个不同号时交由客服填写本车实际使用的一个号。 */
|
||||||
|
static List<FbaAppointment> resolve(List<DispatchItem> cargo, Maintenance maintenance, List<FbaAppointment> booked, List<com.baiyue.lastleg.dispatch.mapper.DispatchReadMapper.CargoShipment> cargoShipments) {
|
||||||
|
var destinations = new TreeMap<String,String>();
|
||||||
|
for (var item : cargo) if ("FBA".equals(item.getDestinationType())) {
|
||||||
|
var key = com.baiyue.lastleg.fleet.trip.FleetDispatchGateway.destinationKey(item.getDestinationType(),item.getDestinationWarehouseCode(),item.getFbaWarehouseCode(),item.getDeliveryAddress(),item.getPostalCode());
|
||||||
|
if (key == null) throw new BizException(ResultCode.CONFLICT,"本车FBA货物缺少目的仓码");
|
||||||
|
destinations.put(key, key.substring(4));
|
||||||
|
}
|
||||||
|
var entered = new HashMap<String,String>();
|
||||||
|
if (maintenance != null) for (var entry : maintenance.destinationAppointments()) entered.put(entry.destinationKey(),entry.appointmentNo());
|
||||||
|
var result = new ArrayList<FbaAppointment>();
|
||||||
|
destinations.forEach((key,code) -> {
|
||||||
|
var confirmed = booked.stream().filter(a -> key.equals(a.destinationKey()) && "SUCCESS".equals(a.status()) && a.appointmentNo() != null && !a.appointmentNo().isBlank()).toList();
|
||||||
|
var numbers = confirmed.stream().map(FbaAppointment::appointmentNo).distinct().toList();
|
||||||
|
// 草稿暂未填写不能遮挡后来取得的唯一正式确认号,已填写值仍保留。
|
||||||
|
var enteredNumber = entered.get(key);
|
||||||
|
var number = enteredNumber != null ? enteredNumber : numbers.size() == 1 ? numbers.get(0) : null;
|
||||||
|
var matching = confirmed.stream().filter(a -> Objects.equals(number,a.appointmentNo())).toList();
|
||||||
|
var at = matching.stream().map(FbaAppointment::confirmedAt).filter(Objects::nonNull).min(Comparator.naturalOrder()).orElse(null);
|
||||||
|
var shipments = cargoShipments.stream().filter(a -> key.equals(a.destinationKey())).map(com.baiyue.lastleg.dispatch.mapper.DispatchReadMapper.CargoShipment::shipmentNo).filter(Objects::nonNull).map(String::trim).filter(s -> !s.isEmpty()).distinct().sorted().toList();
|
||||||
|
result.add(new FbaAppointment(null,null,number,key,code,number == null ? "PENDING" : at == null ? "REGISTERED" : "SUCCESS",at,
|
||||||
|
number == null ? "请填写目的仓 " + code + " 的预约号" : null,null,shipments));
|
||||||
|
});
|
||||||
|
return List.copyOf(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存允许暂缺编号,但不能把别的目的仓写入本车。 */
|
||||||
|
static void validate(Maintenance maintenance, List<FbaAppointment> destinations) {
|
||||||
|
if (maintenance == null) return;
|
||||||
|
var keys = destinations.stream().map(FbaAppointment::destinationKey).toList();
|
||||||
|
if (maintenance.destinationAppointments().stream().anyMatch(a -> !keys.contains(a.destinationKey())))
|
||||||
|
throw new BizException(ResultCode.BAD_REQUEST,"预约只能填写本车已有的目的仓");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 预约完整性只在提交审核及后续执行检查;明确已知的正式时间继续参与核对。 */
|
||||||
|
static String blockReason(List<FbaAppointment> destinations, Instant departure, Instant arrival, List<ReceivingWindow> windows) {
|
||||||
|
var missing = destinations.stream().filter(a -> a.appointmentNo() == null).map(FbaAppointment::destinationWarehouseCode).toList();
|
||||||
|
if (!missing.isEmpty()) return "请填写目的仓 " + String.join("、",missing) + " 的预约号后提交审核";
|
||||||
|
if (destinations.isEmpty()) return null;
|
||||||
|
if (departure != null && arrival != null && arrival.isBefore(departure)) return "预计送达时间不能早于计划发车时间";
|
||||||
|
var first = windows.stream().filter(w -> destinations.stream().anyMatch(a -> w.destinationKey().equals(a.destinationKey()) && Objects.equals(w.confirmationNo(),a.appointmentNo())))
|
||||||
|
.min(Comparator.comparing(ReceivingWindow::startAt)).orElse(null);
|
||||||
|
if (first != null) {
|
||||||
|
if (departure == null || arrival == null) return "请先明确计划发车时间和预计送达时间,再提交审核";
|
||||||
|
if (!departure.isBefore(first.startAt())) return "计划发车时间须早于本车最早的FBA预约送达时间";
|
||||||
|
if (arrival.isAfter(first.endAt() == null ? first.startAt() : first.endAt())) return "预计送达时间晚于本车首个FBA预约收货时间,请调度重新核对";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,5 +21,12 @@ public interface FleetResourceMapper {
|
|||||||
int reserve(@Param("kind") String kind, @Param("id") long id, @Param("tripId") long tripId, @Param("tripNo") String tripNo);
|
int reserve(@Param("kind") String kind, @Param("id") long id, @Param("tripId") long tripId, @Param("tripNo") String tripNo);
|
||||||
@Delete("DELETE FROM ll_fleet_resource_assignment WHERE resource_kind=#{kind} AND resource_id=#{id} AND trip_id=#{tripId}")
|
@Delete("DELETE FROM ll_fleet_resource_assignment WHERE resource_kind=#{kind} AND resource_id=#{id} AND trip_id=#{tripId}")
|
||||||
int release(@Param("kind") String kind, @Param("id") long id, @Param("tripId") long tripId);
|
int release(@Param("kind") String kind, @Param("id") long id, @Param("tripId") long tripId);
|
||||||
|
/** 排除其他车次占用;当前排车绑定的原资源允许保留。 */
|
||||||
|
@Select("""
|
||||||
|
SELECT a.resource_id FROM ll_fleet_resource_assignment a
|
||||||
|
WHERE a.resource_kind='VEHICLE' AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM ll_fleet_trip_dispatch d WHERE d.trip_id=a.trip_id AND d.dispatch_no=#{dispatchNo})
|
||||||
|
""")
|
||||||
|
List<Long> unavailableVehicles(@Param("dispatchNo") String dispatchNo);
|
||||||
record Assignment(String resourceKind, long resourceId, long tripId, String tripNo) { }
|
record Assignment(String resourceKind, long resourceId, long tripId, String tripNo) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,8 +323,12 @@ public class FleetTripService {
|
|||||||
if(!"OVERSEAS".equals(actual.details().region()))throw conflict("司机当前不可执行海外任务");
|
if(!"OVERSEAS".equals(actual.details().region()))throw conflict("司机当前不可执行海外任务");
|
||||||
var assignment=repository.resource("DRIVER",driver.driverId());
|
var assignment=repository.resource("DRIVER",driver.driverId());
|
||||||
if(assignment!=null && assignment.tripId()!=trip.getId())throw conflict("司机已被其他车次占用");
|
if(assignment!=null && assignment.tripId()!=trip.getId())throw conflict("司机已被其他车次占用");
|
||||||
|
// 主档证照固定在首位,本趟补传的驾驶证照片独立保留;排车域负责逐个核验本车文件归属。
|
||||||
|
var licenseFiles=new java.util.LinkedHashSet<Long>();
|
||||||
|
if(actual.licenseFileId()!=null)licenseFiles.add(Long.valueOf(actual.licenseFileId()));
|
||||||
|
if(driver.evidenceFileIds()!=null)licenseFiles.addAll(driver.evidenceFileIds());
|
||||||
driver=new FleetExecutionModels.DispatchDriver("MASTER",Long.valueOf(actual.id()),actual.details().name(),actual.details().phone(),
|
driver=new FleetExecutionModels.DispatchDriver("MASTER",Long.valueOf(actual.id()),actual.details().name(),actual.details().phone(),
|
||||||
actual.details().licenseNumber(),actual.details().licenseExpiresOn(),actual.licenseFileId()==null?List.of():List.of(Long.valueOf(actual.licenseFileId())),driver.expectedTaskEndAt());
|
actual.details().licenseNumber(),actual.details().licenseExpiresOn(),List.copyOf(licenseFiles),driver.expectedTaskEndAt());
|
||||||
} else if(driver!=null && (!"EXTERNAL".equals(driver.mode()) || driver.driverId()!=null))throw bad("临时司机不得关联司机档案");
|
} else if(driver!=null && (!"EXTERNAL".equals(driver.mode()) || driver.driverId()!=null))throw bad("临时司机不得关联司机档案");
|
||||||
return new FleetExecutionModels.DispatchShell(trip.getId(),trip.getTripNo(),trip.getWarehouseId().toString(),trip.getWarehouseCode(),trip.getWarehouseName(),vehicle,driver,vehicleStatus);
|
return new FleetExecutionModels.DispatchShell(trip.getId(),trip.getTripNo(),trip.getWarehouseId().toString(),trip.getWarehouseCode(),trip.getWarehouseName(),vehicle,driver,vehicleStatus);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -8,9 +8,12 @@ import org.springframework.stereotype.Component;
|
|||||||
public class FleetVehicleAssignmentGuard implements VehicleAssignmentGuard {
|
public class FleetVehicleAssignmentGuard implements VehicleAssignmentGuard {
|
||||||
private final FleetResourceMapper resources;
|
private final FleetResourceMapper resources;
|
||||||
public FleetVehicleAssignmentGuard(FleetResourceMapper resources) { this.resources = resources; }
|
public FleetVehicleAssignmentGuard(FleetResourceMapper resources) { this.resources = resources; }
|
||||||
|
/** 主档变更仍要求车辆没有真实车次占用。 */
|
||||||
@Override public void requireUnassigned(long vehicleId) {
|
@Override public void requireUnassigned(long vehicleId) {
|
||||||
var assignment = resources.find("VEHICLE", vehicleId);
|
var assignment = resources.find("VEHICLE", vehicleId);
|
||||||
if (assignment != null) throw new VehicleApplicationService.VehicleFailure(VehicleApplicationService.FailureKind.CONFLICT,
|
if (assignment != null) throw new VehicleApplicationService.VehicleFailure(VehicleApplicationService.FailureKind.CONFLICT,
|
||||||
"车辆正在车次 " + assignment.tripNo() + " 中使用,请先在车次中改派或取消安排");
|
"车辆正在车次 " + assignment.tripNo() + " 中使用,请先在车次中改派或取消安排");
|
||||||
}
|
}
|
||||||
|
/** 由车队权威占用记录提供候选排除集。 */
|
||||||
|
@Override public java.util.List<Long> unavailableForDispatch(String dispatchNo) { return resources.unavailableVehicles(dispatchNo); }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.time.*;
|
import java.time.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** FBA选入排车前必须已有覆盖本客户、来源和目的仓的正式时间确认。 */
|
/** 读取既有正式预约的确认范围,供自动带入及预约业务自身核验使用。 */
|
||||||
@Service
|
@Service
|
||||||
public class AppointmentDispatchAvailability {
|
public class AppointmentDispatchAvailability {
|
||||||
private final FbaReceivingStore receiving;
|
private final FbaReceivingStore receiving;
|
||||||
|
|||||||
+5
-41
@@ -104,7 +104,6 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
for(var item:items) if(item.planPalletId()!=null) {
|
for(var item:items) if(item.planPalletId()!=null) {
|
||||||
var selected=allocations.stream().filter(a->item.customerId().equals(a.customerId()) && item.planPalletId().equals(a.planPalletId())).toList();
|
var selected=allocations.stream().filter(a->item.customerId().equals(a.customerId()) && item.planPalletId().equals(a.planPalletId())).toList();
|
||||||
if(selected.isEmpty()) {
|
if(selected.isEmpty()) {
|
||||||
requireNoBatch(item.customerId(),item.planPalletId());
|
|
||||||
next.addAll(privateAllocation(item.customerId(),dispatch,item));
|
next.addAll(privateAllocation(item.customerId(),dispatch,item));
|
||||||
} else {
|
} else {
|
||||||
validatePhysical(item.customerId(),item,selected,"RECEIVED".equals(item.sourceStage()),false);
|
validatePhysical(item.customerId(),item,selected,"RECEIVED".equals(item.sourceStage()),false);
|
||||||
@@ -122,8 +121,7 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
for(var customer:effective.stream().filter(a->batch.equals(a.batchKey())).map(AppointmentWorkDispatchMapper.Bound::customerId).distinct().sorted().toList()) {
|
for(var customer:effective.stream().filter(a->batch.equals(a.batchKey())).map(AppointmentWorkDispatchMapper.Bound::customerId).distinct().sorted().toList()) {
|
||||||
requireCurrentAllocation(appointment,customer,dispatch,effective.stream().filter(a->batch.equals(a.batchKey()) && customer.equals(a.customerId()))
|
requireCurrentAllocation(appointment,customer,dispatch,effective.stream().filter(a->batch.equals(a.batchKey()) && customer.equals(a.customerId()))
|
||||||
.map(a->allocation(a,appointment.version().longValue())).toList());
|
.map(a->allocation(a,appointment.version().longValue())).toList());
|
||||||
// FBA确认前不能把货物加入车辆;提交审核仍复验运输时间。
|
// 建单允许先排车;本车预约号在客服提交审核时按目的仓核对。
|
||||||
requireReceiving(batch,customer,effective.stream().filter(a->batch.equals(a.batchKey()) && customer.equals(a.customerId())).toList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 所有校验结束后才按明确item删除;没有整车清空操作。
|
// 所有校验结束后才按明确item删除;没有整车清空操作。
|
||||||
@@ -160,14 +158,6 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
public String reviewBlockReason(String dispatchNo,java.time.Instant departure,java.time.Instant arrival) {
|
public String reviewBlockReason(String dispatchNo,java.time.Instant departure,java.time.Instant arrival) {
|
||||||
try {
|
try {
|
||||||
checkDeparture(dispatchNo,false,false);
|
checkDeparture(dispatchNo,false,false);
|
||||||
var windows=reviewEvidence(dispatchNo);
|
|
||||||
if(!windows.isEmpty()) {
|
|
||||||
if(departure==null || arrival==null)return "请先明确计划来车/发车时间和预计送达时间,再提交审核";
|
|
||||||
if(arrival.isBefore(departure))return "预计送达时间不能早于计划发车时间";
|
|
||||||
var first=windows.stream().min(Comparator.comparing(ReceivingWindow::startAt)).orElseThrow();
|
|
||||||
if(!departure.isBefore(first.startAt()))return "计划发车时间须早于本车最早的FBA预约送达时间";
|
|
||||||
if(arrival.isAfter(first.endAt()==null?first.startAt():first.endAt()))return "预计送达时间晚于本车首个FBA预约收货时间,请调度重新核对";
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} catch(org.springframework.web.server.ResponseStatusException error) {
|
} catch(org.springframework.web.server.ResponseStatusException error) {
|
||||||
if(error.getStatusCode().value()!=409)throw error;
|
if(error.getStatusCode().value()!=409)throw error;
|
||||||
@@ -210,9 +200,8 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
var batches=rows.stream().map(AppointmentWorkDispatchMapper.Bound::batchKey).filter(b->!b.startsWith("DISPATCH:")).distinct().sorted().toList();
|
var batches=rows.stream().map(AppointmentWorkDispatchMapper.Bound::batchKey).filter(b->!b.startsWith("DISPATCH:")).distinct().sorted().toList();
|
||||||
if(locked) for(var batch:batches) lock(batch);
|
if(locked) for(var batch:batches) lock(batch);
|
||||||
for(var item:physical) if(item.planPalletId()!=null && rows.stream().noneMatch(r->r.itemId()==item.itemId() && r.customerId().equals(item.customerId()) && item.planPalletId().equals(r.palletId()))) {
|
for(var item:physical) if(item.planPalletId()!=null && rows.stream().noneMatch(r->r.itemId()==item.itemId() && r.customerId().equals(item.customerId()) && item.planPalletId().equals(r.palletId()))) {
|
||||||
requireNoBatch(item.customerId(),item.planPalletId());
|
if(mapper.physical(item.planPalletId(),item.customerId()).stream().anyMatch(p->p.destinationKey()!=null && (p.destinationKey().startsWith("FBA:") || p.destinationKey().startsWith("CUSTOMER:"))))
|
||||||
if(!picked && mapper.physical(item.planPalletId(),item.customerId()).stream().anyMatch(p->p.destinationKey()!=null && p.destinationKey().startsWith("FBA:")))throw conflict("本车FBA货物尚未关联已确认预约,请客服核对送达时间后提交审核");
|
throw conflict("本车货物缺少真实来源明细,请重新核对排车");
|
||||||
if(mapper.physical(item.planPalletId(),item.customerId()).stream().anyMatch(p->p.destinationKey()!=null && p.destinationKey().startsWith("CUSTOMER:"))) throw conflict("客户仓排车缺少逐票实物批次关联,请重新核对排车");
|
|
||||||
}
|
}
|
||||||
for(var batch:batches) {
|
for(var batch:batches) {
|
||||||
var a=appointments.batchContext(batch).appointment();
|
var a=appointments.batchContext(batch).appointment();
|
||||||
@@ -221,7 +210,6 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
var dispatchIds=allocated.stream().map(AppointmentWorkDispatchMapper.Bound::dispatchId).distinct().toList();
|
var dispatchIds=allocated.stream().map(AppointmentWorkDispatchMapper.Bound::dispatchId).distinct().toList();
|
||||||
if(dispatchIds.size()!=1) throw conflict("排车批次关联不一致,请重新核对实物分配");
|
if(dispatchIds.size()!=1) throw conflict("排车批次关联不一致,请重新核对实物分配");
|
||||||
for(var customer:allocated.stream().map(AppointmentWorkDispatchMapper.Bound::customerId).distinct().toList()) {
|
for(var customer:allocated.stream().map(AppointmentWorkDispatchMapper.Bound::customerId).distinct().toList()) {
|
||||||
requireReceiving(batch,customer,allocated.stream().filter(row->customer.equals(row.customerId())).toList());
|
|
||||||
requireCurrentAllocation(a,customer,dispatchIds.get(0),allocated.stream().filter(row->customer.equals(row.customerId()))
|
requireCurrentAllocation(a,customer,dispatchIds.get(0),allocated.stream().filter(row->customer.equals(row.customerId()))
|
||||||
.map(row->allocation(row,a.version()==null?null:a.version().longValue())).toList());
|
.map(row->allocation(row,a.version()==null?null:a.version().longValue())).toList());
|
||||||
}
|
}
|
||||||
@@ -233,22 +221,6 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
group.stream().map(a->allocation(a,null)).toList(),picked || "RECEIVED".equals(item.sourceStage()),picked);
|
group.stream().map(a->allocation(a,null)).toList(),picked || "RECEIVED".equals(item.sourceStage()),picked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void requireReceiving(String batch,String customer,List<AppointmentWorkDispatchMapper.Bound> rows) {
|
|
||||||
if(receiving.hasPending(batch,customer)) throw conflict("本客户有待仓库确认的变化,保留原安排但禁止发车,请先完成明确回复");
|
|
||||||
var agreement=receiving.currentAgreement(batch,customer);
|
|
||||||
if(agreement==null || !"ACTIVE".equals(agreement.status()) || agreement.details()==null || !"SUCCESS".equals(agreement.details().appointmentStatus())
|
|
||||||
|| agreement.details().appointmentAt()==null) throw conflict("本客户尚无有效收货确认,请先预约成功并明确送仓时间,再加入排车或发车");
|
|
||||||
receivingInstant(agreement.details().appointmentAt(),agreement.timezone(),agreement.details().startOffset());
|
|
||||||
var members=agreement.members().stream().filter(m->batch.equals(m.batchKey()) && customer.equals(m.customerId())).toList();
|
|
||||||
if(members.size()!=1) throw conflict("当前收货确认未唯一覆盖本客户批次,请重新核对");
|
|
||||||
for(var group:rows.stream().collect(Collectors.groupingBy(r->List.of(r.sourceKey(),r.destinationKey()))).values()) {
|
|
||||||
var first=group.get(0);
|
|
||||||
var sources=members.get(0).sources().stream().filter(s->first.sourceKey().equals(s.sourceKey()) && first.destinationKey().equals(s.destinationKey())).toList();
|
|
||||||
if(sources.size()!=1 || mapper.allocated(batch,customer,first.sourceKey(),first.destinationKey(),first.dispatchId())
|
|
||||||
+group.stream().mapToLong(AppointmentWorkDispatchMapper.Bound::packages).sum()>sources.get(0).packageCount())
|
|
||||||
throw conflict("当前收货确认未完整覆盖本次逐票实物,请重新核对");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void requireCurrentAllocation(com.baiyue.lastleg.inboundplan.dto.FbaAppointmentResponse appointment,String customer,long dispatch,List<Allocation> allocations) {
|
private void requireCurrentAllocation(com.baiyue.lastleg.inboundplan.dto.FbaAppointmentResponse appointment,String customer,long dispatch,List<Allocation> allocations) {
|
||||||
var grouped=allocations.stream().collect(Collectors.groupingBy(a->List.of(a.sourceKey(),a.destinationKey())));
|
var grouped=allocations.stream().collect(Collectors.groupingBy(a->List.of(a.sourceKey(),a.destinationKey())));
|
||||||
for(var group:grouped.values()) {
|
for(var group:grouped.values()) {
|
||||||
@@ -262,14 +234,6 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
throw conflict("所选实物超过当前批次逐票分配量,请重新核对");
|
throw conflict("所选实物超过当前批次逐票分配量,请重新核对");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void requireNoBatch(String customer,long pallet) {
|
|
||||||
var physical=mapper.physical(pallet,customer).stream().filter(p->p.destinationKey()!=null && p.destinationKey().startsWith("FBA:")).toList();
|
|
||||||
var canonical=AppointmentWorkPhysicalSources.canonical(physical,sources);
|
|
||||||
var refs=physical.stream().map(p->new AppointmentCoverageService.SourceRef(customer,AppointmentWorkPhysicalSources.ref(canonical,p).sourceKey(),p.destinationKey())).distinct().toList();
|
|
||||||
if(!refs.isEmpty() && appointments.relatedBatchSnapshots(refs).stream().anyMatch(a->a.replacementBatchKeys().isEmpty()))
|
|
||||||
throw conflict("所选实物已有预约批次,必须明确逐批逐票分配后才能排车或发车");
|
|
||||||
if(!physical.isEmpty())throw conflict("FBA货物须先预约成功并明确送仓时间,再加入排车");
|
|
||||||
}
|
|
||||||
/** 实收只更新原逐票绑定后,仍在业务提交末尾刷新工作视图。 */
|
/** 实收只更新原逐票绑定后,仍在业务提交末尾刷新工作视图。 */
|
||||||
void receiptQuantitiesChanged() { invalidateAtBusinessEnd(); }
|
void receiptQuantitiesChanged() { invalidateAtBusinessEnd(); }
|
||||||
|
|
||||||
@@ -296,8 +260,8 @@ public class AppointmentWorkDispatchBinding implements AppointmentWorkDispatchPo
|
|||||||
}
|
}
|
||||||
private List<AppointmentWorkDispatchMapper.Bound> privateAllocation(String customer,long dispatch,PhysicalItem item) {
|
private List<AppointmentWorkDispatchMapper.Bound> privateAllocation(String customer,long dispatch,PhysicalItem item) {
|
||||||
var physical=mapper.physical(item.planPalletId(),customer);
|
var physical=mapper.physical(item.planPalletId(),customer);
|
||||||
if(physical.isEmpty() || physical.stream().noneMatch(p->p.destinationKey()!=null && p.destinationKey().startsWith("CUSTOMER:"))) return List.of();
|
if(physical.isEmpty()) return List.of();
|
||||||
if(physical.stream().anyMatch(p->p.destinationKey()==null || !p.destinationKey().startsWith("CUSTOMER:"))) throw conflict("客户仓实物不能混入FBA批次,请先核对托盘目的地");
|
if(physical.stream().anyMatch(p->p.destinationKey()==null)) throw conflict("实物目的地尚未核实");
|
||||||
var canonical=AppointmentWorkPhysicalSources.canonical(physical,sources); var rows=new ArrayList<AppointmentWorkDispatchMapper.Bound>();
|
var canonical=AppointmentWorkPhysicalSources.canonical(physical,sources); var rows=new ArrayList<AppointmentWorkDispatchMapper.Bound>();
|
||||||
for(var part:physical) {
|
for(var part:physical) {
|
||||||
var count="RECEIVED".equals(item.sourceStage())?part.countedPackages():part.plannedPackages();
|
var count="RECEIVED".equals(item.sourceStage())?part.countedPackages():part.plannedPackages();
|
||||||
|
|||||||
+8
-7
@@ -40,7 +40,7 @@ public class AppointmentWorkDispatchCandidates {
|
|||||||
for(var identity:identities) {
|
for(var identity:identities) {
|
||||||
var selected=rows.stream().filter(r->r.planPalletId()==identity.planPalletId() && identity.customerId().equals(r.customerId())).toList();
|
var selected=rows.stream().filter(r->r.planPalletId()==identity.planPalletId() && identity.customerId().equals(r.customerId())).toList();
|
||||||
var reasons=new LinkedHashSet<String>();var references=new LinkedHashMap<List<String>,List<BatchSource>>();
|
var reasons=new LinkedHashSet<String>();var references=new LinkedHashMap<List<String>,List<BatchSource>>();
|
||||||
boolean related=false,unassigned=false;boolean occupied=selected.stream().anyMatch(AppointmentWorkDispatchMapper.CandidateSource::locked);
|
boolean unassigned=false;boolean occupied=selected.stream().anyMatch(AppointmentWorkDispatchMapper.CandidateSource::locked);
|
||||||
if(selected.isEmpty()) reasons.add("客户实物托盘不存在或归属已变化");
|
if(selected.isEmpty()) reasons.add("客户实物托盘不存在或归属已变化");
|
||||||
for(var row:selected) {
|
for(var row:selected) {
|
||||||
var count="RECEIVED".equals(row.sourceStage())?row.countedPackages():row.plannedPackages();
|
var count="RECEIVED".equals(row.sourceStage())?row.countedPackages():row.plannedPackages();
|
||||||
@@ -48,18 +48,19 @@ public class AppointmentWorkDispatchCandidates {
|
|||||||
if(!row.destinationKey().startsWith("FBA:")) continue;
|
if(!row.destinationKey().startsWith("FBA:")) continue;
|
||||||
var source=AppointmentWorkPhysicalSources.ref(canonical,new AppointmentWorkDispatchMapper.Physical(row.orderId(),row.customerId(),row.destinationKey(),row.plannedPackages(),row.countedPackages())).sourceKey();
|
var source=AppointmentWorkPhysicalSources.ref(canonical,new AppointmentWorkDispatchMapper.Physical(row.orderId(),row.customerId(),row.destinationKey(),row.plannedPackages(),row.countedPackages())).sourceKey();
|
||||||
var matched=batches.stream().filter(b->identity.customerId().equals(b.customerId()) && (source.equals(b.sourceKey()) || row.orderId().equals(b.orderId())) && row.destinationKey().equals(b.destinationKey())).toList();
|
var matched=batches.stream().filter(b->identity.customerId().equals(b.customerId()) && (source.equals(b.sourceKey()) || row.orderId().equals(b.orderId())) && row.destinationKey().equals(b.destinationKey())).toList();
|
||||||
if(matched.isEmpty()) {unassigned=true;reasons.add("FBA货物须先预约成功并明确送仓时间,再加入排车");continue;}
|
if(matched.isEmpty()) {unassigned=true;continue;}
|
||||||
related=true;long available=0;var seen=new HashSet<String>();
|
long available=0;var seen=new HashSet<String>();
|
||||||
for(var b:matched) {
|
for(var b:matched) {
|
||||||
if(!source.equals(b.sourceKey())) {reasons.add("原预约逐票来源与当前真实规范不一致,请先核对原批次");continue;}
|
if(!source.equals(b.sourceKey())) {unassigned=true;continue;}
|
||||||
if(b.batchKey()==null || !seen.add(b.batchKey()) || b.batchNo()==null || b.batchNo().isBlank() || b.recordVersion()==null || b.recordVersion()<0 || b.packages()==null || b.packages()<=0 || b.allocated()<0 || b.allocated()>b.packages()) {reasons.add("原预约批次版本、逐票分配或占用不完整");continue;}
|
if(b.batchKey()==null || !seen.add(b.batchKey()) || b.batchNo()==null || b.batchNo().isBlank() || b.recordVersion()==null || b.recordVersion()<0 || b.packages()==null || b.packages()<=0 || b.allocated()<0 || b.allocated()>b.packages()) {unassigned=true;continue;}
|
||||||
int confirmed=availability.confirmedPackages(confirmations.get(b.batchKey()),b.customerId(),source,row.destinationKey());
|
int confirmed=availability.confirmedPackages(confirmations.get(b.batchKey()),b.customerId(),source,row.destinationKey());
|
||||||
int remaining=Math.toIntExact(Math.max(0,Math.min(b.packages(),confirmed)-b.allocated()));available=Math.addExact(available,remaining);
|
int remaining=Math.toIntExact(Math.max(0,Math.min(b.packages(),confirmed)-b.allocated()));available=Math.addExact(available,remaining);
|
||||||
if(remaining>0) references.computeIfAbsent(List.of(b.batchKey(),b.batchNo(),b.recordVersion().toString(),b.customerId()),ignored->new ArrayList<>()).add(new BatchSource(source,row.destinationKey(),Math.min(remaining,count)));
|
if(remaining>0) references.computeIfAbsent(List.of(b.batchKey(),b.batchNo(),b.recordVersion().toString(),b.customerId()),ignored->new ArrayList<>()).add(new BatchSource(source,row.destinationKey(),Math.min(remaining,count)));
|
||||||
}
|
}
|
||||||
if(available<count) reasons.add("FBA已确认预约及逐票剩余量不足,请先确认送仓时间和本票箱数再排车");
|
if(available<count || matched.size()!=1) unassigned=true;
|
||||||
}
|
}
|
||||||
if(related && unassigned) reasons.add("托盘含未归属当前预约批次的货物,请先核对逐票分配");
|
// 未约、未确认或多个批次均允许先排;只有完整且唯一的已约来源才自动携带。
|
||||||
|
if(unassigned)references.clear();
|
||||||
var result=references.entrySet().stream().map(e->new BatchReference(e.getKey().get(0),e.getKey().get(1),Long.valueOf(e.getKey().get(2)),e.getKey().get(3),List.copyOf(e.getValue()))).toList();
|
var result=references.entrySet().stream().map(e->new BatchReference(e.getKey().get(0),e.getKey().get(1),Long.valueOf(e.getKey().get(2)),e.getKey().get(3),List.copyOf(e.getValue()))).toList();
|
||||||
output.put(identity,new CandidateBatches(result,List.copyOf(reasons),occupied));
|
output.put(identity,new CandidateBatches(result,List.copyOf(reasons),occupied));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -103,6 +103,7 @@ public class VehiclePersistenceAdapter implements VehicleRepository {
|
|||||||
.set(VehicleRecord::getUpdatedAt, updatedAt).setSql("record_version = record_version + 1")) == 1;
|
.set(VehicleRecord::getUpdatedAt, updatedAt).setSql("record_version = record_version + 1")) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 可用性排除在数据库分页前执行,保持候选总数与结果一致。 */
|
||||||
private LambdaQueryWrapper<VehicleRecord> wrapper(SearchCriteria criteria) {
|
private LambdaQueryWrapper<VehicleRecord> wrapper(SearchCriteria criteria) {
|
||||||
return new LambdaQueryWrapper<VehicleRecord>()
|
return new LambdaQueryWrapper<VehicleRecord>()
|
||||||
.and(StringUtils.hasText(criteria.keyword()), wrapper -> wrapper.like(VehicleRecord::getPlateNumber, criteria.keyword())
|
.and(StringUtils.hasText(criteria.keyword()), wrapper -> wrapper.like(VehicleRecord::getPlateNumber, criteria.keyword())
|
||||||
@@ -111,6 +112,7 @@ public class VehiclePersistenceAdapter implements VehicleRepository {
|
|||||||
.eq(criteria.ownership() != null, VehicleRecord::getOwnership, criteria.ownership())
|
.eq(criteria.ownership() != null, VehicleRecord::getOwnership, criteria.ownership())
|
||||||
.eq(criteria.region() != null, VehicleRecord::getRegion, criteria.region())
|
.eq(criteria.region() != null, VehicleRecord::getRegion, criteria.region())
|
||||||
.eq(criteria.status() != null, VehicleRecord::getStatus, criteria.status())
|
.eq(criteria.status() != null, VehicleRecord::getStatus, criteria.status())
|
||||||
|
.notIn(criteria.excludedIds()!=null && !criteria.excludedIds().isEmpty(), VehicleRecord::getId, criteria.excludedIds())
|
||||||
.orderByDesc(VehicleRecord::getUpdatedAt).orderByDesc(VehicleRecord::getId);
|
.orderByDesc(VehicleRecord::getUpdatedAt).orderByDesc(VehicleRecord::getId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -100,11 +100,13 @@ public class VehicleApplicationService {
|
|||||||
return detail(id);
|
return detail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 候选资格在分页前排除真实占用,不按显示文案推断可用。 */
|
||||||
private SearchCriteria criteria(VehicleModels.Query query) {
|
private SearchCriteria criteria(VehicleModels.Query query) {
|
||||||
return new SearchCriteria(query.page(), query.size(), trim(query.keyword()),
|
return new SearchCriteria(query.page(), query.size(), trim(query.keyword()),
|
||||||
optional(query.ownership(), OWNERSHIPS, "车辆归属"),
|
optional(query.ownership(), OWNERSHIPS, "车辆归属"),
|
||||||
optional(query.region(), REGIONS, "车辆区域"),
|
optional(query.region(), REGIONS, "车辆区域"),
|
||||||
optional(query.status(), STATUSES, "车辆状态"));
|
optional(query.status(), STATUSES, "车辆状态"),
|
||||||
|
trim(query.dispatchNo())==null?java.util.List.of():assignments.unavailableForDispatch(trim(query.dispatchNo())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private VehicleSnapshot required(long id) {
|
private VehicleSnapshot required(long id) {
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ public final class VehicleModels {
|
|||||||
private VehicleModels() { }
|
private VehicleModels() { }
|
||||||
|
|
||||||
public record Query(@Min(1) Integer page, @Min(1) @Max(200) Integer size,
|
public record Query(@Min(1) Integer page, @Min(1) @Max(200) Integer size,
|
||||||
@Size(max = 128) String keyword, String ownership, String region, String status) {
|
@Size(max = 128) String keyword, String ownership, String region, String status, @Size(max = 64) String dispatchNo) {
|
||||||
public Query { page = page == null ? 1 : page; size = size == null ? 20 : size; }
|
public Query { page = page == null ? 1 : page; size = size == null ? 20 : size; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -3,4 +3,6 @@ package com.baiyue.lastleg.masterdata.vehicle.application.port.out;
|
|||||||
/** Called while the vehicle row is locked; fleet owns the active assignment. */
|
/** Called while the vehicle row is locked; fleet owns the active assignment. */
|
||||||
public interface VehicleAssignmentGuard {
|
public interface VehicleAssignmentGuard {
|
||||||
void requireUnassigned(long vehicleId);
|
void requireUnassigned(long vehicleId);
|
||||||
|
/** 排车候选排除其他车次的真实占用,本车已选车辆仍可维护。 */
|
||||||
|
java.util.List<Long> unavailableForDispatch(String dispatchNo);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ public interface VehicleRepository {
|
|||||||
|
|
||||||
boolean updateStatus(long id, long expectedVersion, String status, String operator, LocalDateTime updatedAt);
|
boolean updateStatus(long id, long expectedVersion, String status, String operator, LocalDateTime updatedAt);
|
||||||
|
|
||||||
record SearchCriteria(int page, int size, String keyword, String ownership, String region, String status) { }
|
record SearchCriteria(int page, int size, String keyword, String ownership, String region, String status, List<Long> excludedIds) { }
|
||||||
|
|
||||||
record PageSlice(List<VehicleSnapshot> records, long page, long size, long total, long pages) { }
|
record PageSlice(List<VehicleSnapshot> records, long page, long size, long total, long pages) { }
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -25,6 +25,7 @@ public class ReturnRelabelPackingService {
|
|||||||
@Resource private com.baiyue.lastleg.relabel.pda.mapper.PdaRelabelTaskMapper tasks;
|
@Resource private com.baiyue.lastleg.relabel.pda.mapper.PdaRelabelTaskMapper tasks;
|
||||||
@Resource private com.fasterxml.jackson.databind.ObjectMapper json;
|
@Resource private com.fasterxml.jackson.databind.ObjectMapper json;
|
||||||
|
|
||||||
|
/** 换标任务锁定来源后生成当前库存快照,随精确换标数量提交合箱。 */
|
||||||
@org.springframework.transaction.annotation.Transactional
|
@org.springframework.transaction.annotation.Transactional
|
||||||
public ReturnInventoryResponses.MergeResult pack(PdaWarehouseIdentity identity, RelabelApplication app,
|
public ReturnInventoryResponses.MergeResult pack(PdaWarehouseIdentity identity, RelabelApplication app,
|
||||||
List<RelabelItem> selected, ReturnInventoryRequests.BoxMerge request) {
|
List<RelabelItem> selected, ReturnInventoryRequests.BoxMerge request) {
|
||||||
@@ -37,17 +38,21 @@ public class ReturnRelabelPackingService {
|
|||||||
if (request.sourceDeductions() != null && !totals(deductions).equals(totals(request.sourceDeductions())))
|
if (request.sourceDeductions() != null && !totals(deductions).equals(totals(request.sourceDeductions())))
|
||||||
throw conflict("合箱数量必须等于本次已完成换标的明细数量");
|
throw conflict("合箱数量必须等于本次已完成换标的明细数量");
|
||||||
var inheritedTransfers = new ArrayList<Map<String, Object>>();
|
var inheritedTransfers = new ArrayList<Map<String, Object>>();
|
||||||
|
var expectedSourceQuantities = new ArrayList<ReturnInventoryRequests.SourceQuantity>();
|
||||||
for (String mark : marks) {
|
for (String mark : marks) {
|
||||||
var source = cartons.lockMark(mark);
|
var source = cartons.lockMark(mark);
|
||||||
if (source == null || !app.getCustomerId().equals(source.getCustomerId())
|
if (source == null || !app.getCustomerId().equals(source.getCustomerId())
|
||||||
|| !app.getId().equals(source.getRelabelApplicationId()) || !"RELABEL_PENDING".equals(source.getStatus()))
|
|| !app.getId().equals(source.getRelabelApplicationId()) || !"RELABEL_PENDING".equals(source.getStatus()))
|
||||||
throw conflict("来源包裹/箱已变化,请刷新");
|
throw conflict("来源包裹/箱已变化,请刷新");
|
||||||
|
var sourceContents = cartonItems.lockCarton(source.getId());
|
||||||
|
sourceContents.forEach(line -> expectedSourceQuantities.add(
|
||||||
|
new ReturnInventoryRequests.SourceQuantity(mark, line.getSkuCode(), line.getQuantity())));
|
||||||
var prior = items.priorCompletedReturnItems(app.getCustomerId(), source.getId(), app.getId());
|
var prior = items.priorCompletedReturnItems(app.getCustomerId(), source.getId(), app.getId());
|
||||||
if (!prior.isEmpty()) {
|
if (!prior.isEmpty()) {
|
||||||
var ids = prior.stream().map(i -> i.getId().toString()).toList();
|
var ids = prior.stream().map(i -> i.getId().toString()).toList();
|
||||||
var raw = inheritedQuantities(prior);
|
var raw = inheritedQuantities(prior);
|
||||||
var physical = new HashMap<String, Long>();
|
var physical = new HashMap<String, Long>();
|
||||||
cartonItems.lockCarton(source.getId()).forEach(i -> physical.merge(i.getSkuCode().toUpperCase(Locale.ROOT), i.getQuantity(), Math::addExact));
|
sourceContents.forEach(i -> physical.merge(i.getSkuCode().toUpperCase(Locale.ROOT), i.getQuantity(), Math::addExact));
|
||||||
var moved = new ArrayList<Map<String, Object>>();
|
var moved = new ArrayList<Map<String, Object>>();
|
||||||
for (var entry : totals(deductions).entrySet()) {
|
for (var entry : totals(deductions).entrySet()) {
|
||||||
if (!mark.equals(entry.getKey().get(0))) continue;
|
if (!mark.equals(entry.getKey().get(0))) continue;
|
||||||
@@ -66,7 +71,7 @@ public class ReturnRelabelPackingService {
|
|||||||
}
|
}
|
||||||
var result = inventory.mergeBoxes(identity, new ReturnInventoryRequests.BoxMerge(marks, null,
|
var result = inventory.mergeBoxes(identity, new ReturnInventoryRequests.BoxMerge(marks, null,
|
||||||
"RELABEL-PACK:" + app.getId() + ":" + request.idempotencyKey(), deductions,
|
"RELABEL-PACK:" + app.getId() + ":" + request.idempotencyKey(), deductions,
|
||||||
request.length(), request.width(), request.height(), request.weight()));
|
request.length(), request.width(), request.height(), request.weight(), expectedSourceQuantities));
|
||||||
for (String mark : marks) {
|
for (String mark : marks) {
|
||||||
var source = cartons.lockMark(mark);
|
var source = cartons.lockMark(mark);
|
||||||
cartons.clearRelabel(source.getId());
|
cartons.clearRelabel(source.getId());
|
||||||
|
|||||||
+4
-14
@@ -3,7 +3,9 @@ package com.baiyue.lastleg.returnreceipt.dto;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Positive;
|
import jakarta.validation.constraints.Positive;
|
||||||
|
import jakarta.validation.constraints.PositiveOrZero;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -25,20 +27,8 @@ public final class PdaReturnReceiptRequests {
|
|||||||
@Size(max = 16) String unitType,
|
@Size(max = 16) String unitType,
|
||||||
@Size(max = 128) String unitCode,
|
@Size(max = 128) String unitCode,
|
||||||
BigDecimal length, BigDecimal width, BigDecimal height, BigDecimal weight,
|
BigDecimal length, BigDecimal width, BigDecimal height, BigDecimal weight,
|
||||||
Long totalBoxCount, Boolean originalPackaging) {
|
Long totalBoxCount, Boolean originalPackaging,
|
||||||
public Confirm(String returnNo, String trackingNo, String startedBy, String palletCode,
|
@NotNull @PositiveOrZero Long expectedReceivedQuantity) { }
|
||||||
List<@Valid Item> items, String idempotencyKey) {
|
|
||||||
this(returnNo, trackingNo, startedBy, palletCode, items, idempotencyKey,
|
|
||||||
null, null, null, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
public Confirm(String returnNo, String trackingNo, String startedBy, String palletCode,
|
|
||||||
List<@Valid Item> items, String idempotencyKey, String unitType, String unitCode,
|
|
||||||
BigDecimal length, BigDecimal width, BigDecimal height, BigDecimal weight,
|
|
||||||
Long totalBoxCount) {
|
|
||||||
this(returnNo, trackingNo, startedBy, palletCode, items, idempotencyKey, unitType, unitCode,
|
|
||||||
length, width, height, weight, totalBoxCount, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public record Item(@NotBlank @Size(max = 128) String skuCode,
|
public record Item(@NotBlank @Size(max = 128) String skuCode,
|
||||||
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = ReturnQuantityDeserializer.class)
|
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = ReturnQuantityDeserializer.class)
|
||||||
@Positive long receivedQuantity,
|
@Positive long receivedQuantity,
|
||||||
|
|||||||
+4
-5
@@ -73,6 +73,8 @@ public final class ReturnInventoryRequests {
|
|||||||
public PackingPlanComplete(List<PlanBox> boxes, String idempotencyKey) { this(boxes, idempotencyKey, null); }
|
public PackingPlanComplete(List<PlanBox> boxes, String idempotencyKey) { this(boxes, idempotencyKey, null); }
|
||||||
}
|
}
|
||||||
public record SourceDeduction(@NotBlank String cartonMark, @NotBlank String skuCode, @Positive long quantity) { }
|
public record SourceDeduction(@NotBlank String cartonMark, @NotBlank String skuCode, @Positive long quantity) { }
|
||||||
|
/** 扫码时来源箱各 SKU 的库存快照,用于拒绝过期页面重复扣减。 */
|
||||||
|
public record SourceQuantity(@NotBlank String cartonMark, @NotBlank String skuCode, @Min(0) long quantity) { }
|
||||||
|
|
||||||
public record PackingExecution(@NotEmpty @Size(max = 100) List<@NotBlank String> returnNos,
|
public record PackingExecution(@NotEmpty @Size(max = 100) List<@NotBlank String> returnNos,
|
||||||
@NotEmpty @Size(max = 100) List<@Valid PlanBox> boxes,
|
@NotEmpty @Size(max = 100) List<@Valid PlanBox> boxes,
|
||||||
@@ -99,9 +101,6 @@ public final class ReturnInventoryRequests {
|
|||||||
@NotBlank @Size(max = 255) String idempotencyKey,
|
@NotBlank @Size(max = 255) String idempotencyKey,
|
||||||
@Size(max = 1000) List<@Valid SourceDeduction> sourceDeductions,
|
@Size(max = 1000) List<@Valid SourceDeduction> sourceDeductions,
|
||||||
@Positive BigDecimal length, @Positive BigDecimal width,
|
@Positive BigDecimal length, @Positive BigDecimal width,
|
||||||
@Positive BigDecimal height, @Positive BigDecimal weight) {
|
@Positive BigDecimal height, @Positive BigDecimal weight,
|
||||||
public BoxMerge(List<String> sourceCartonMarks, String targetCartonMark, String idempotencyKey) {
|
@Size(max = 1000) List<@NotNull @Valid SourceQuantity> expectedSourceQuantities) { }
|
||||||
this(sourceCartonMarks, targetCartonMark, idempotencyKey, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -928,16 +928,26 @@ public class ReturnInventoryService {
|
|||||||
return cartonDetail(carton);
|
return cartonDetail(carton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 校验全部来源箱的扫码库存快照,再执行单事务合箱。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public ReturnInventoryResponses.MergeResult mergeBoxes(PdaWarehouseIdentity identity, ReturnInventoryRequests.BoxMerge request) {
|
public ReturnInventoryResponses.MergeResult mergeBoxes(PdaWarehouseIdentity identity, ReturnInventoryRequests.BoxMerge request) {
|
||||||
// Bind replay to the complete scan command before looking up emptied sources.
|
// 同键结果先返回;新键必须在来源行锁内校验扫码库存,避免重复扣减。
|
||||||
ReturnInventoryOperation replay = operations.lockKey(identity.operatorKey(), request.idempotencyKey());
|
ReturnInventoryOperation replay = operations.lockKey(identity.operatorKey(), request.idempotencyKey());
|
||||||
String digest = hash(request);
|
String digest = hash(request);
|
||||||
if (replay != null) return replayMerge(replay, digest);
|
if (replay != null) return replayMerge(replay, digest);
|
||||||
|
if (request.expectedSourceQuantities() == null || request.expectedSourceQuantities().isEmpty())
|
||||||
|
throw badRequest("缺少来源箱库存快照,请重新扫描来源箱");
|
||||||
|
Map<List<String>, Long> expectedQuantities = new LinkedHashMap<>();
|
||||||
|
for (var snapshot : request.expectedSourceQuantities()) {
|
||||||
|
if (snapshot == null || snapshot.quantity() < 0 || !StringUtils.hasText(snapshot.skuCode()) || !request.sourceCartonMarks().contains(snapshot.cartonMark())
|
||||||
|
|| expectedQuantities.putIfAbsent(List.of(snapshot.cartonMark(), snapshot.skuCode()), snapshot.quantity()) != null)
|
||||||
|
throw badRequest("来源箱库存快照无效,请重新扫描来源箱");
|
||||||
|
}
|
||||||
java.util.stream.Stream.concat(request.sourceCartonMarks().stream(), java.util.stream.Stream.of(request.targetCartonMark()))
|
java.util.stream.Stream.concat(request.sourceCartonMarks().stream(), java.util.stream.Stream.of(request.targetCartonMark()))
|
||||||
.filter(StringUtils::hasText).distinct().sorted().forEach(cartons::lockMark);
|
.filter(StringUtils::hasText).distinct().sorted().forEach(cartons::lockMark);
|
||||||
Map<String, Map<String, Long>> limits = new LinkedHashMap<>();
|
Map<String, Map<String, Long>> limits = new LinkedHashMap<>();
|
||||||
Map<String, Long> quantities = new LinkedHashMap<>();
|
Map<String, Long> quantities = new LinkedHashMap<>();
|
||||||
|
Map<List<String>, Long> currentQuantities = new LinkedHashMap<>();
|
||||||
LinkedHashSet<String> returnNos = new LinkedHashSet<>();
|
LinkedHashSet<String> returnNos = new LinkedHashSet<>();
|
||||||
String customer = null;
|
String customer = null;
|
||||||
for (String mark : request.sourceCartonMarks().stream().distinct().sorted().toList()) {
|
for (String mark : request.sourceCartonMarks().stream().distinct().sorted().toList()) {
|
||||||
@@ -950,6 +960,7 @@ public class ReturnInventoryService {
|
|||||||
customer = carton.getCustomerId(); returnNos.addAll(java.util.Arrays.asList(required(carton.getSourceReturnNo(), "来源退货单缺失").split(",")));
|
customer = carton.getCustomerId(); returnNos.addAll(java.util.Arrays.asList(required(carton.getSourceReturnNo(), "来源退货单缺失").split(",")));
|
||||||
Map<String, Long> items = new LinkedHashMap<>();
|
Map<String, Long> items = new LinkedHashMap<>();
|
||||||
for (var item : cartonItems.lockCarton(carton.getId())) {
|
for (var item : cartonItems.lockCarton(carton.getId())) {
|
||||||
|
currentQuantities.put(List.of(mark, item.getSkuCode()), value(item.getQuantity()));
|
||||||
if (value(item.getPackingReservedQuantity()) > 0) throw conflict("来源箱已被合箱计划占用");
|
if (value(item.getPackingReservedQuantity()) > 0) throw conflict("来源箱已被合箱计划占用");
|
||||||
long selected = request.sourceDeductions() == null ? value(item.getQuantity()) : request.sourceDeductions().stream()
|
long selected = request.sourceDeductions() == null ? value(item.getQuantity()) : request.sourceDeductions().stream()
|
||||||
.filter(d -> mark.equals(d.cartonMark()) && item.getSkuCode().equals(d.skuCode())).mapToLong(ReturnInventoryRequests.SourceDeduction::quantity).sum();
|
.filter(d -> mark.equals(d.cartonMark()) && item.getSkuCode().equals(d.skuCode())).mapToLong(ReturnInventoryRequests.SourceDeduction::quantity).sum();
|
||||||
@@ -958,6 +969,7 @@ public class ReturnInventoryService {
|
|||||||
}
|
}
|
||||||
limits.put(mark, items);
|
limits.put(mark, items);
|
||||||
}
|
}
|
||||||
|
if (!expectedQuantities.equals(currentQuantities)) throw conflict("来源箱库存已变化,请重新扫描来源箱后操作");
|
||||||
if(request.sourceDeductions() != null && request.sourceDeductions().stream().anyMatch(d -> !limits.containsKey(d.cartonMark()) || !limits.get(d.cartonMark()).containsKey(d.skuCode()))) throw badRequest("扣除明细不属于已扫描来源箱");
|
if(request.sourceDeductions() != null && request.sourceDeductions().stream().anyMatch(d -> !limits.containsKey(d.cartonMark()) || !limits.get(d.cartonMark()).containsKey(d.skuCode()))) throw badRequest("扣除明细不属于已扫描来源箱");
|
||||||
String targetMark = text(request.targetCartonMark());
|
String targetMark = text(request.targetCartonMark());
|
||||||
if (targetMark != null && request.sourceCartonMarks().stream().anyMatch(mark ->
|
if (targetMark != null && request.sourceCartonMarks().stream().anyMatch(mark ->
|
||||||
|
|||||||
+9
-3
@@ -571,7 +571,7 @@ public class ReturnReceiptService {
|
|||||||
return detail(order.getCustomerId(), order.getReturnNo());
|
return detail(order.getCustomerId(), order.getReturnNo());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 确认退货实收,新增实物箱码沿用原编码,不使用单据日流水。 */
|
/** 锁定退货单并校验提交前实收量,避免响应丢失后换新请求重复入账。 */
|
||||||
@Transactional
|
@Transactional
|
||||||
public PdaReturnReceiptResponses.Confirmed confirm(PdaWarehouseIdentity identity, PdaReturnReceiptRequests.Confirm request) {
|
public PdaReturnReceiptResponses.Confirmed confirm(PdaWarehouseIdentity identity, PdaReturnReceiptRequests.Confirm request) {
|
||||||
String key = text(request.idempotencyKey());
|
String key = text(request.idempotencyKey());
|
||||||
@@ -591,8 +591,7 @@ public class ReturnReceiptService {
|
|||||||
if (order == null || !String.valueOf(identity.overseasWarehouseId()).equals(order.getOverseasWarehouseId())) {
|
if (order == null || !String.valueOf(identity.overseasWarehouseId()).equals(order.getOverseasWarehouseId())) {
|
||||||
throw notFound("当前绑定仓没有该退货单");
|
throw notFound("当前绑定仓没有该退货单");
|
||||||
}
|
}
|
||||||
// Lock the order before any consistent read: a snapshot opened before
|
// 先锁订单再读取幂等记录,避免等待锁前的快照遗漏已提交的实物箱。
|
||||||
// waiting would hide the winner's cartons when rendering replay labels.
|
|
||||||
ReturnReceipt concurrentReplay = receipts.lockKey(identity.operatorKey(), key);
|
ReturnReceipt concurrentReplay = receipts.lockKey(identity.operatorKey(), key);
|
||||||
if (concurrentReplay != null) {
|
if (concurrentReplay != null) {
|
||||||
if (!requestHash.equals(concurrentReplay.getRequestHash())) throw conflict("幂等键已用于不同的签收请求");
|
if (!requestHash.equals(concurrentReplay.getRequestHash())) throw conflict("幂等键已用于不同的签收请求");
|
||||||
@@ -602,6 +601,13 @@ public class ReturnReceiptService {
|
|||||||
throw conflict("仅待签收或签收中的退货单允许 PDA 签收");
|
throw conflict("仅待签收或签收中的退货单允许 PDA 签收");
|
||||||
}
|
}
|
||||||
List<ReturnOrderItem> lockedItems = orderItems.lockOrder(order.getId());
|
List<ReturnOrderItem> lockedItems = orderItems.lockOrder(order.getId());
|
||||||
|
if (request.expectedReceivedQuantity() == null || request.expectedReceivedQuantity() < 0) {
|
||||||
|
throw badRequest("必须提供提交前的退货单实收数量");
|
||||||
|
}
|
||||||
|
long currentReceivedQuantity = lockedItems.stream().mapToLong(item -> value(item.getReceivedQuantity())).sum();
|
||||||
|
if (request.expectedReceivedQuantity() != currentReceivedQuantity) {
|
||||||
|
throw conflict("退货单实收数量已变化,请刷新退货单后重新操作");
|
||||||
|
}
|
||||||
Map<String, Long> receivedBySku = aggregate(request.items());
|
Map<String, Long> receivedBySku = aggregate(request.items());
|
||||||
Map<String, Long> boxCountBySku = request.items().stream().filter(item -> item.boxCount() != null)
|
Map<String, Long> boxCountBySku = request.items().stream().filter(item -> item.boxCount() != null)
|
||||||
.collect(java.util.stream.Collectors.toMap(item -> text(item.skuCode()), PdaReturnReceiptRequests.Item::boxCount, Math::addExact, LinkedHashMap::new));
|
.collect(java.util.stream.Collectors.toMap(item -> text(item.skuCode()), PdaReturnReceiptRequests.Item::boxCount, Math::addExact, LinkedHashMap::new));
|
||||||
|
|||||||
@@ -3229,6 +3229,13 @@ paths:
|
|||||||
security: [{ bearerAuth: [] }]
|
security: [{ bearerAuth: [] }]
|
||||||
requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReturnInventoryMerge' } } } }
|
requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReturnInventoryMerge' } } } }
|
||||||
responses: { '200': { description: 新箱号、SKU 汇总数量及可打印箱唛 }, '409': { description: 箱状态、客户或 SKU 不满足合箱条件,或幂等键冲突 } }
|
responses: { '200': { description: 新箱号、SKU 汇总数量及可打印箱唛 }, '409': { description: 箱状态、客户或 SKU 不满足合箱条件,或幂等键冲突 } }
|
||||||
|
/api/pda/v1/last-leg/return-inventory/cartons/merge-boxes:
|
||||||
|
post:
|
||||||
|
summary: PDA 按实物来源箱合箱
|
||||||
|
description: 同一客户、当前绑定仓内合箱;新请求必须携带扫码时全部来源箱 SKU 数量,在来源行锁内校验,过期返回冲突,重新扫描后操作。
|
||||||
|
security: [{ bearerAuth: [] }]
|
||||||
|
requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ReturnInventoryBoxMerge' } } } }
|
||||||
|
responses: { '200': { description: 合箱实物箱号与标签 }, '400': { description: 缺少或无效来源库存快照 }, '409': { description: 来源库存或资格已变化,或幂等键冲突 } }
|
||||||
/api/pda/v1/last-leg/return-inventory/packing/orders:
|
/api/pda/v1/last-leg/return-inventory/packing/orders:
|
||||||
get:
|
get:
|
||||||
summary: PDA 查询可合箱退货单和 SKU 库存
|
summary: PDA 查询可合箱退货单和 SKU 库存
|
||||||
@@ -3426,8 +3433,9 @@ components:
|
|||||||
expectedQuantity: { type: integer, minimum: 1 }
|
expectedQuantity: { type: integer, minimum: 1 }
|
||||||
ReturnReceiptConfirm:
|
ReturnReceiptConfirm:
|
||||||
type: object
|
type: object
|
||||||
required: [returnNo, startedBy, items, idempotencyKey]
|
required: [returnNo, startedBy, items, idempotencyKey, expectedReceivedQuantity]
|
||||||
properties:
|
properties:
|
||||||
|
expectedReceivedQuantity: { type: integer, format: int64, minimum: 0, description: '提交前退货单全部 SKU 的累计实收数量;在订单锁内校验,过期返回冲突,刷新后重新操作' }
|
||||||
returnNo: { type: string, maxLength: 128 }
|
returnNo: { type: string, maxLength: 128 }
|
||||||
trackingNo: { type: string, nullable: true, maxLength: 128, description: '本次签收包裹有快递面单时扫描绑定;没有时为空' }
|
trackingNo: { type: string, nullable: true, maxLength: 128, description: '本次签收包裹有快递面单时扫描绑定;没有时为空' }
|
||||||
startedBy: { type: string, enum: [RETURN_NO, SKU], description: '本次通过退货单号查询或 SKU 候选开始签收' }
|
startedBy: { type: string, enum: [RETURN_NO, SKU], description: '本次通过退货单号查询或 SKU 候选开始签收' }
|
||||||
@@ -3450,6 +3458,39 @@ components:
|
|||||||
skuCode: { type: string, maxLength: 128 }
|
skuCode: { type: string, maxLength: 128 }
|
||||||
receivedQuantity: { type: integer, minimum: 1 }
|
receivedQuantity: { type: integer, minimum: 1 }
|
||||||
boxCount: { type: integer, nullable: true, minimum: 1, description: 托盘或箱子签收时该 SKU 对应箱数,包裹签收不填 }
|
boxCount: { type: integer, nullable: true, minimum: 1, description: 托盘或箱子签收时该 SKU 对应箱数,包裹签收不填 }
|
||||||
|
ReturnInventoryBoxMerge:
|
||||||
|
type: object
|
||||||
|
required: [sourceCartonMarks, idempotencyKey, expectedSourceQuantities]
|
||||||
|
properties:
|
||||||
|
sourceCartonMarks: { type: array, minItems: 1, maxItems: 100, items: { type: string } }
|
||||||
|
targetCartonMark: { type: string, nullable: true, description: 不填时生成新箱 }
|
||||||
|
idempotencyKey: { type: string, maxLength: 255 }
|
||||||
|
expectedSourceQuantities:
|
||||||
|
type: array
|
||||||
|
minItems: 1
|
||||||
|
maxItems: 1000
|
||||||
|
description: 扫码时全部来源箱各 SKU 的数量,必须完整且不能重复
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
required: [cartonMark, skuCode, quantity]
|
||||||
|
properties:
|
||||||
|
cartonMark: { type: string }
|
||||||
|
skuCode: { type: string }
|
||||||
|
quantity: { type: integer, format: int64, minimum: 0 }
|
||||||
|
sourceDeductions:
|
||||||
|
type: array
|
||||||
|
maxItems: 1000
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
required: [cartonMark, skuCode, quantity]
|
||||||
|
properties:
|
||||||
|
cartonMark: { type: string }
|
||||||
|
skuCode: { type: string }
|
||||||
|
quantity: { type: integer, format: int64, minimum: 1 }
|
||||||
|
length: { type: number, minimum: 0, exclusiveMinimum: true }
|
||||||
|
width: { type: number, minimum: 0, exclusiveMinimum: true }
|
||||||
|
height: { type: number, minimum: 0, exclusiveMinimum: true }
|
||||||
|
weight: { type: number, minimum: 0, exclusiveMinimum: true }
|
||||||
ReturnInventoryMerge:
|
ReturnInventoryMerge:
|
||||||
type: object
|
type: object
|
||||||
required: [returnNos, items, length, width, height, weight, idempotencyKey]
|
required: [returnNos, items, length, width, height, weight, idempotencyKey]
|
||||||
@@ -5447,7 +5488,7 @@ components:
|
|||||||
DispatchMaintenance:
|
DispatchMaintenance:
|
||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchContracts.Maintenance
|
x-java-record: DispatchContracts.Maintenance
|
||||||
description: 保存于排车resourcesJson.maintenance的唯一正式资料结构,不新增费用金额或审核门禁。
|
description: 保存于排车resourcesJson.maintenance;预约按本车目的仓登记,保存可暂缺,提交审核及后续执行须填写完整。
|
||||||
properties:
|
properties:
|
||||||
plannedDeliveryDate:
|
plannedDeliveryDate:
|
||||||
type: string
|
type: string
|
||||||
@@ -5477,10 +5518,18 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
maxLength: 128
|
maxLength: 128
|
||||||
nullable: true
|
nullable: true
|
||||||
appointmentNo:
|
destinationAppointments:
|
||||||
type: string
|
type: array
|
||||||
maxLength: 128
|
maxItems: 500
|
||||||
nullable: true
|
items: { $ref: '#/components/schemas/DispatchDestinationAppointment' }
|
||||||
|
DispatchDestinationAppointment:
|
||||||
|
type: object
|
||||||
|
x-java-record: DispatchContracts.DestinationAppointment
|
||||||
|
description: 同一排车同一FBA目的仓仅一个预约号,空白可暂存。
|
||||||
|
required: [destinationKey, appointmentNo]
|
||||||
|
properties:
|
||||||
|
destinationKey: { type: string, pattern: '^FBA:.+', maxLength: 256 }
|
||||||
|
appointmentNo: { type: string, maxLength: 128, nullable: true }
|
||||||
DispatchResources:
|
DispatchResources:
|
||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchContracts.Resources
|
x-java-record: DispatchContracts.Resources
|
||||||
@@ -6363,6 +6412,14 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchViews.ListRow
|
x-java-record: DispatchViews.ListRow
|
||||||
properties:
|
properties:
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
nullable: true
|
||||||
|
description: 排车单真实创建时间,取原排车主单created_at。
|
||||||
|
fbaAppointments:
|
||||||
|
type: array
|
||||||
|
items: { $ref: '#/components/schemas/DispatchFbaAppointment' }
|
||||||
dispatchNo:
|
dispatchNo:
|
||||||
type: string
|
type: string
|
||||||
nullable: true
|
nullable: true
|
||||||
@@ -6424,6 +6481,7 @@ components:
|
|||||||
$ref: '#/components/schemas/DispatchGate'
|
$ref: '#/components/schemas/DispatchGate'
|
||||||
nullable: true
|
nullable: true
|
||||||
required:
|
required:
|
||||||
|
- createdAt
|
||||||
- dispatchNo
|
- dispatchNo
|
||||||
- status
|
- status
|
||||||
- stage
|
- stage
|
||||||
@@ -6440,6 +6498,7 @@ components:
|
|||||||
- pickingReconciled
|
- pickingReconciled
|
||||||
- arranged
|
- arranged
|
||||||
- actions
|
- actions
|
||||||
|
- fbaAppointments
|
||||||
DispatchVehicleInfo:
|
DispatchVehicleInfo:
|
||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchViews.VehicleInfo
|
x-java-record: DispatchViews.VehicleInfo
|
||||||
@@ -6463,7 +6522,14 @@ components:
|
|||||||
DispatchFbaAppointment:
|
DispatchFbaAppointment:
|
||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchViews.FbaAppointment
|
x-java-record: DispatchViews.FbaAppointment
|
||||||
|
description: 按本车目的仓汇总的预约;唯一已约编号自动带入,人工登记不冒充正式确认时间。批次及客户在目的仓汇总行为空。
|
||||||
properties:
|
properties:
|
||||||
|
customerId:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
shipmentNumbers:
|
||||||
|
type: array
|
||||||
|
items: { type: string }
|
||||||
batchKey:
|
batchKey:
|
||||||
type: string
|
type: string
|
||||||
nullable: true
|
nullable: true
|
||||||
@@ -6498,6 +6564,8 @@ components:
|
|||||||
- status
|
- status
|
||||||
- confirmedAt
|
- confirmedAt
|
||||||
- blockReason
|
- blockReason
|
||||||
|
- customerId
|
||||||
|
- shipmentNumbers
|
||||||
DispatchDispatchInfo:
|
DispatchDispatchInfo:
|
||||||
type: object
|
type: object
|
||||||
x-java-record: DispatchViews.DispatchInfo
|
x-java-record: DispatchViews.DispatchInfo
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ paths:
|
|||||||
- { name: ownership, in: query, schema: { $ref: '#/components/schemas/VehicleOwnership' } }
|
- { name: ownership, in: query, schema: { $ref: '#/components/schemas/VehicleOwnership' } }
|
||||||
- { name: region, in: query, schema: { $ref: '#/components/schemas/VehicleRegion' } }
|
- { name: region, in: query, schema: { $ref: '#/components/schemas/VehicleRegion' } }
|
||||||
- { name: status, in: query, schema: { $ref: '#/components/schemas/VehicleStatus' } }
|
- { name: status, in: query, schema: { $ref: '#/components/schemas/VehicleStatus' } }
|
||||||
|
- { name: dispatchNo, in: query, description: 排车维护候选,分页前排除其他车次实际占用,保留本车资源, schema: { type: string, maxLength: 64 } }
|
||||||
responses: { '200': { description: 业务响应,data为PageResult<Vehicle> } }
|
responses: { '200': { description: 业务响应,data为PageResult<Vehicle> } }
|
||||||
post:
|
post:
|
||||||
summary: 创建车辆主数据
|
summary: 创建车辆主数据
|
||||||
|
|||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/** 核对分页、总数、分组统计及BOL接入同一正式编号查询;JSON函数适配仅用于隔离H2测试。 */
|
||||||
|
public class DispatchReceivingSqlTest {
|
||||||
|
/** 三种列表查询必须在SQL分页前使用当前客户确认,且保留非空人工编号的覆盖条件。 */
|
||||||
|
@Test void allListQueriesUseCurrentReceivingAuthorityBeforePagination() {
|
||||||
|
var config=new MybatisConfiguration();config.addMapper(DispatchAggregateMapper.class);
|
||||||
|
var query=new DispatchAggregateMapper.Search(null,null,null,null,"ISA-CURRENT","ALL",null,null,null,0,20);
|
||||||
|
for(var method:new String[]{"page","count","summaries"}) {
|
||||||
|
var bound=config.getMappedStatement(DispatchAggregateMapper.class.getName()+"."+method).getBoundSql(Map.of("q",query));
|
||||||
|
var sql=normalize(bound.getSql());
|
||||||
|
assertThat(sql).contains(normalize(DispatchReceivingSql.CONFIRMATION_NO)+" =?");
|
||||||
|
assertThat(sql).doesNotContain("ll_inbound_fba_appointment ap","ap.confirmation_no");
|
||||||
|
assertThat(sql).contains("saved.destination_key=a.destination_key AND NULLIF(TRIM(saved.appointment_no),'') IS NOT NULL");
|
||||||
|
assertThat(bound.getParameterMappings().stream().filter(p->"q.fbaAppointmentNo".equals(p.getProperty())).count()).isEqualTo(2);
|
||||||
|
if(method.equals("page"))assertThat(sql.indexOf("LIMIT")).isGreaterThan(sql.indexOf("ll_fba_receiving_member"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** BOL只替换编号来源,仍由原批次item核对客户、来源和订单映射。 */
|
||||||
|
@Test void bolUsesSameCurrentConfirmationAndKeepsSourceMapping() {
|
||||||
|
var config=new MybatisConfiguration();config.addMapper(DispatchBolMapper.class);
|
||||||
|
var sql=normalize(config.getMappedStatement(DispatchBolMapper.class.getName()+".findAppointmentAllocations")
|
||||||
|
.getBoundSql(Map.of("dispatchOrderId",1L)).getSql());
|
||||||
|
assertThat(sql).contains(normalize(DispatchReceivingSql.CONFIRMATION_NO)+" AS confirmationNo");
|
||||||
|
assertThat(sql).contains("i.customer_id=a.customer_id","i.source_key=a.source_key","i.order_id AS orderId");
|
||||||
|
assertThat(sql).doesNotContain("p.confirmation_no");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** H2没有MySQL JSON函数;仅适配标量路径读取,SQL关联、过滤和数量计算仍执行真实Mapper。 */
|
||||||
|
public static void installJsonFunctions(JdbcTemplate db) {
|
||||||
|
db.execute("CREATE ALIAS JSON_EXTRACT FOR 'com.baiyue.lastleg.dispatch.mapper.DispatchReceivingSqlTest.jsonExtract'");
|
||||||
|
db.execute("CREATE ALIAS JSON_UNQUOTE FOR 'com.baiyue.lastleg.dispatch.mapper.DispatchReceivingSqlTest.jsonUnquote'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 区分缺失路径的SQL NULL与JSON显式null,覆盖未填写确认时间的两种存储形态。 */
|
||||||
|
public static String jsonExtract(String document,String path) throws Exception {
|
||||||
|
if(document==null)return null;
|
||||||
|
var node=new ObjectMapper().readTree(document);
|
||||||
|
for(var key:path.substring(2).split("\\."))node=node.path(key);
|
||||||
|
return node.isMissingNode()?null:node.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 与MySQL标量JSON_UNQUOTE一致,保留JSON null文本供生产SQL判断。 */
|
||||||
|
public static String jsonUnquote(String value) throws Exception {
|
||||||
|
if(value==null)return null;
|
||||||
|
var node=new ObjectMapper().readTree(value);
|
||||||
|
return node.isTextual()?node.textValue():node.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 去除文本块换行差异,仅比较实际SQL表达式。 */
|
||||||
|
private static String normalize(String sql) {return sql.replaceAll("\\s+"," ").trim();}
|
||||||
|
}
|
||||||
+27
-9
@@ -167,7 +167,7 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
String dispatch(ResourceMode mode,Long driverId,List<Long> ids) throws Exception {
|
String dispatch(ResourceMode mode,Long driverId,List<Long> ids) throws Exception {
|
||||||
var created=f.tx.execute(t->f.service.create(f.actor,f.create("evidence-"+UUID.randomUUID(),List.of())));
|
var created=f.tx.execute(t->f.service.create(f.actor,f.create("evidence-"+UUID.randomUUID(),List.of())));
|
||||||
var resource=new DispatchContracts.Resources(null,new DispatchContracts.DriverSnapshot(mode,driverId,"测试司机","123456789",
|
var resource=new DispatchContracts.Resources(null,new DispatchContracts.DriverSnapshot(mode,driverId,"测试司机","123456789",
|
||||||
new DispatchContracts.DriverEvidence("TEST-LICENSE",LocalDate.of(2099,1,1),ids,Instant.parse("2098-01-01T00:00:00Z"),List.of())), null);
|
new DispatchContracts.DriverEvidence("TEST-LICENSE",LocalDate.of(2099,1,1),ids,Instant.parse("2098-01-01T00:00:00Z"),List.of(),mode==ResourceMode.MASTER && !ids.isEmpty()?ids.get(0):null)), null);
|
||||||
f.db.update("UPDATE ll_dispatch_order SET resources_json=? WHERE dispatch_no=?",f.json.writeValueAsString(resource),created.dispatchNo());return created.dispatchNo();
|
f.db.update("UPDATE ll_dispatch_order SET resources_json=? WHERE dispatch_no=?",f.json.writeValueAsString(resource),created.dispatchNo());return created.dispatchNo();
|
||||||
}
|
}
|
||||||
/** File内容固定为离线测试字节;真实复合归属由既有两个HTTP网关合同分别覆盖。 */
|
/** File内容固定为离线测试字节;真实复合归属由既有两个HTTP网关合同分别覆盖。 */
|
||||||
@@ -374,6 +374,7 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
try {
|
try {
|
||||||
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
||||||
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("submission-gate-create",List.of(source))));
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("submission-gate-create",List.of(source))));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
var request=new DispatchCommands.SubmitReview(created.recordVersion(),"submission-gate-original",null);
|
var request=new DispatchCommands.SubmitReview(created.recordVersion(),"submission-gate-original",null);
|
||||||
var submitted=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),request));
|
var submitted=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),request));
|
||||||
var detail=f.tx.execute(s->f.service.detail(f.actor,created.dispatchNo()));
|
var detail=f.tx.execute(s->f.service.detail(f.actor,created.dispatchNo()));
|
||||||
@@ -403,6 +404,7 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
try {
|
try {
|
||||||
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
||||||
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("submission-states-create",List.of(source))));
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("submission-states-create",List.of(source))));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
assertSubmissionGate(f,created.dispatchNo(),ReviewState.DRAFT,true);
|
assertSubmissionGate(f,created.dispatchNo(),ReviewState.DRAFT,true);
|
||||||
var submitted=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submission-states-1",null)));
|
var submitted=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submission-states-1",null)));
|
||||||
assertSubmissionGate(f,created.dispatchNo(),ReviewState.DISPATCH_PENDING,false);
|
assertSubmissionGate(f,created.dispatchNo(),ReviewState.DISPATCH_PENDING,false);
|
||||||
@@ -428,6 +430,7 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
@Test void reviewsUseActualRootRoundAndImmutableCommandsBeforeAndAfterLoading() throws Exception {
|
@Test void reviewsUseActualRootRoundAndImmutableCommandsBeforeAndAfterLoading() throws Exception {
|
||||||
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
var f=new Fixture();var source=f.source(1,"101",501,"ONT8",3);
|
||||||
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("review-create",List.of(source))));
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("review-create",List.of(source))));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
var submit=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submit-1",null)));
|
var submit=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submit-1",null)));
|
||||||
assertThatThrownBy(()->f.tx.execute(s->f.service.review(f.actor,created.dispatchNo(),true,new DispatchCommands.ReviewCommand(submit.recordVersion(),"wrong-order",Decision.APPROVED,null,null)))).isInstanceOf(BizException.class);
|
assertThatThrownBy(()->f.tx.execute(s->f.service.review(f.actor,created.dispatchNo(),true,new DispatchCommands.ReviewCommand(submit.recordVersion(),"wrong-order",Decision.APPROVED,null,null)))).isInstanceOf(BizException.class);
|
||||||
var rejected=f.tx.execute(s->f.service.review(f.actor,created.dispatchNo(),false,new DispatchCommands.ReviewCommand(submit.recordVersion(),"reject-1",Decision.REJECTED,"补核装载计划",null)));
|
var rejected=f.tx.execute(s->f.service.review(f.actor,created.dispatchNo(),false,new DispatchCommands.ReviewCommand(submit.recordVersion(),"reject-1",Decision.REJECTED,"补核装载计划",null)));
|
||||||
@@ -505,7 +508,7 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
var provider=mock(com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.class);
|
var provider=mock(com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.class);
|
||||||
when(provider.reviewEvidence(original.dispatchNo())).thenReturn(List.of(new com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.ReceivingWindow("FBA_APPOINTMENT:900","AP-EXISTING","101","FBA:ONT8","CURRENT-CONFIRM",Instant.parse("2026-10-20T17:00:00Z"),null,"AGR-1",1)));
|
when(provider.reviewEvidence(original.dispatchNo())).thenReturn(List.of(new com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.ReceivingWindow("FBA_APPOINTMENT:900","AP-EXISTING","101","FBA:ONT8","CURRENT-CONFIRM",Instant.parse("2026-10-20T17:00:00Z"),null,"AGR-1",1)));
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(f.service,"appointments",new DispatchAppointmentAllocations(provider));
|
org.springframework.test.util.ReflectionTestUtils.setField(f.service,"appointments",new DispatchAppointmentAllocations(provider));
|
||||||
var current=f.tx.execute(s->f.service.detail(f.actor,original.dispatchNo())).dispatchInfo().fbaAppointments().get(0);
|
var current=f.tx.execute(s->f.service.detail(f.actor,original.dispatchNo())).dispatchInfo().fbaAppointments().stream().filter(a0->"FBA:ONT8".equals(a0.destinationKey())).findFirst().orElseThrow();
|
||||||
assertThat(current.appointmentNo()).isEqualTo("CURRENT-CONFIRM");assertThat(current.confirmedAt()).isEqualTo(Instant.parse("2026-10-20T17:00:00Z"));
|
assertThat(current.appointmentNo()).isEqualTo("CURRENT-CONFIRM");assertThat(current.confirmedAt()).isEqualTo(Instant.parse("2026-10-20T17:00:00Z"));
|
||||||
var c=f.source(3,"101",503,"ONT8",2);
|
var c=f.source(3,"101",503,"ONT8",2);
|
||||||
f.tx.executeWithoutResult(s->f.service.addCargo(f.actor,original.dispatchNo(),new DispatchCommands.AddCargo(original.recordVersion(),"add-third",List.of(c),List.of())));
|
f.tx.executeWithoutResult(s->f.service.addCargo(f.actor,original.dispatchNo(),new DispatchCommands.AddCargo(original.recordVersion(),"add-third",List.of(c),List.of())));
|
||||||
@@ -588,19 +591,20 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
db.execute("CREATE TABLE ll_dispatch_history(id BIGINT PRIMARY KEY,dispatch_id BIGINT,record_version BIGINT,action VARCHAR(40),operator_id VARCHAR(128),reason VARCHAR(1000),snapshot_json CLOB,occurred_at TIMESTAMP(3))");
|
db.execute("CREATE TABLE ll_dispatch_history(id BIGINT PRIMARY KEY,dispatch_id BIGINT,record_version BIGINT,action VARCHAR(40),operator_id VARCHAR(128),reason VARCHAR(1000),snapshot_json CLOB,occurred_at TIMESTAMP(3))");
|
||||||
db.execute("CREATE TABLE ll_dispatch_pda_pick(id BIGINT,customer_id VARCHAR(64),dispatch_item_id BIGINT,inventory_position_id BIGINT,packages BIGINT,product_quantity BIGINT)");
|
db.execute("CREATE TABLE ll_dispatch_pda_pick(id BIGINT,customer_id VARCHAR(64),dispatch_item_id BIGINT,inventory_position_id BIGINT,packages BIGINT,product_quantity BIGINT)");
|
||||||
db.execute("CREATE TABLE ll_dispatch_pda_pick_order(id BIGINT,customer_id VARCHAR(64),pick_id BIGINT,order_id BIGINT,receipt_id BIGINT,return_receipt_id BIGINT,return_carton_id BIGINT,dispatch_item_source_id BIGINT,packages BIGINT,product_quantity BIGINT)");
|
db.execute("CREATE TABLE ll_dispatch_pda_pick_order(id BIGINT,customer_id VARCHAR(64),pick_id BIGINT,order_id BIGINT,receipt_id BIGINT,return_receipt_id BIGINT,return_carton_id BIGINT,dispatch_item_source_id BIGINT,packages BIGINT,product_quantity BIGINT)");
|
||||||
db.execute("CREATE TABLE ll_order(id BIGINT,customer_id VARCHAR(64),order_no VARCHAR(128),source_region VARCHAR(64),source_inbound_id VARCHAR(128))");
|
db.execute("CREATE TABLE ll_order(id BIGINT,customer_id VARCHAR(64),order_no VARCHAR(128),source_region VARCHAR(64),source_inbound_id VARCHAR(128),order_type VARCHAR(64))");
|
||||||
|
db.execute("CREATE TABLE ll_order_detail(order_id BIGINT,customer_id VARCHAR(128),shipment_no VARCHAR(128),destination_warehouse_code VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_inbound_stock_receipt(id BIGINT,customer_id VARCHAR(64),inbound_code VARCHAR(128))");
|
db.execute("CREATE TABLE ll_inbound_stock_receipt(id BIGINT,customer_id VARCHAR(64),inbound_code VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_return_stock_receipt(id BIGINT,customer_id VARCHAR(64),inventory_balance_id BIGINT,order_id BIGINT,inventory_position_id BIGINT,received_packages BIGINT)");
|
db.execute("CREATE TABLE ll_return_stock_receipt(id BIGINT,customer_id VARCHAR(64),inventory_balance_id BIGINT,order_id BIGINT,inventory_position_id BIGINT,received_packages BIGINT)");
|
||||||
db.execute("CREATE TABLE ll_inventory_balance(id BIGINT,customer_id VARCHAR(64),inbound_code VARCHAR(128))");
|
db.execute("CREATE TABLE ll_inventory_balance(id BIGINT,customer_id VARCHAR(64),inbound_code VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_return_inventory_carton(id BIGINT,customer_id VARCHAR(64),carton_mark VARCHAR(128),pallet_code VARCHAR(128),relabel_no VARCHAR(128),overseas_warehouse_id VARCHAR(64),total_quantity BIGINT,status VARCHAR(32))");
|
db.execute("CREATE TABLE ll_return_inventory_carton(id BIGINT,customer_id VARCHAR(64),carton_mark VARCHAR(128),pallet_code VARCHAR(128),relabel_no VARCHAR(128),overseas_warehouse_id VARCHAR(64),total_quantity BIGINT,status VARCHAR(32))");
|
||||||
db.execute("CREATE TABLE ll_warehouse_transfer_order(id BIGINT,customer_id VARCHAR(64),transfer_no VARCHAR(128))");
|
db.execute("CREATE TABLE ll_warehouse_transfer_order(id BIGINT,customer_id VARCHAR(64),transfer_no VARCHAR(128),lastleg_order_id BIGINT,fba_shipment_no VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_warehouse_transfer_pallet(transfer_order_id BIGINT,customer_id VARCHAR(64),warehouse_pallet_id BIGINT,carton_count INT,status VARCHAR(32),completed_at TIMESTAMP(3),gross_weight_kg DECIMAL(18,6),volume_cbm DECIMAL(18,6))");
|
db.execute("CREATE TABLE ll_warehouse_transfer_pallet(transfer_order_id BIGINT,customer_id VARCHAR(64),warehouse_pallet_id BIGINT,carton_count INT,status VARCHAR(32),completed_at TIMESTAMP(3),gross_weight_kg DECIMAL(18,6),volume_cbm DECIMAL(18,6))");
|
||||||
db.execute("CREATE TABLE ll_inventory_ledger(customer_id VARCHAR(64),pallet_id BIGINT,created_at TIMESTAMP(3),business_type VARCHAR(64))");
|
db.execute("CREATE TABLE ll_inventory_ledger(customer_id VARCHAR(64),pallet_id BIGINT,created_at TIMESTAMP(3),business_type VARCHAR(64))");
|
||||||
db.execute("CREATE TABLE ll_fleet_resource_assignment(resource_kind VARCHAR(32),resource_id BIGINT,trip_id BIGINT,trip_no VARCHAR(32),PRIMARY KEY(resource_kind,resource_id))");
|
db.execute("CREATE TABLE ll_fleet_resource_assignment(resource_kind VARCHAR(32),resource_id BIGINT,trip_id BIGINT,trip_no VARCHAR(32),PRIMARY KEY(resource_kind,resource_id))");
|
||||||
db.execute("CREATE TABLE ll_dispatch_appointment_allocation(dispatch_id BIGINT,dispatch_item_id BIGINT,plan_pallet_id BIGINT,batch_key VARCHAR(128),customer_id VARCHAR(128),source_key VARCHAR(128),destination_key VARCHAR(128),package_count INT)");
|
db.execute("CREATE TABLE ll_dispatch_appointment_allocation(dispatch_id BIGINT,dispatch_item_id BIGINT,plan_pallet_id BIGINT,batch_key VARCHAR(128),customer_id VARCHAR(128),source_key VARCHAR(128),destination_key VARCHAR(128),package_count INT)");
|
||||||
db.execute("CREATE TABLE ll_inbound_fba_appointment(id BIGINT,version INT DEFAULT 0,appointment_no VARCHAR(64),confirmation_no VARCHAR(128),appointment_status VARCHAR(32),fba_warehouse_code VARCHAR(128),appointment_start_utc TIMESTAMP(3))");
|
db.execute("CREATE TABLE ll_inbound_fba_appointment(id BIGINT,version INT DEFAULT 0,appointment_no VARCHAR(64),confirmation_no VARCHAR(128),appointment_status VARCHAR(32),fba_warehouse_code VARCHAR(128),appointment_start_utc TIMESTAMP(3))");
|
||||||
db.execute("CREATE TABLE ll_inbound_fba_appointment_item(order_id BIGINT,customer_id VARCHAR(128),active INT)");
|
db.execute("CREATE TABLE ll_inbound_fba_appointment_item(order_id BIGINT,customer_id VARCHAR(128),active INT,appointment_id BIGINT,source_key VARCHAR(128),fba_warehouse_code VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_inbound_plan_pallet_allocation(pallet_id BIGINT,line_id BIGINT)"); db.execute("CREATE TABLE ll_inbound_plan_line(id BIGINT,order_id BIGINT,customer_id VARCHAR(128))");
|
db.execute("CREATE TABLE ll_inbound_plan_pallet_allocation(pallet_id BIGINT,line_id BIGINT,customer_id VARCHAR(128))"); db.execute("CREATE TABLE ll_inbound_plan_line(id BIGINT,order_id BIGINT,customer_id VARCHAR(128),fba_warehouse_code VARCHAR(128))");
|
||||||
json=new ObjectMapper().registerModule(new JavaTimeModule());
|
json=new ObjectMapper().registerModule(new JavaTimeModule());
|
||||||
var fleetRepo=new FleetTripRepository(session.getMapper(FleetTripMapper.class),session.getMapper(FleetResourceMapper.class),session.getMapper(FleetTripHistoryMapper.class),session.getMapper(FleetTripDispatchMapper.class));
|
var fleetRepo=new FleetTripRepository(session.getMapper(FleetTripMapper.class),session.getMapper(FleetResourceMapper.class),session.getMapper(FleetTripHistoryMapper.class),session.getMapper(FleetTripDispatchMapper.class));
|
||||||
var warehouses=mock(FleetWarehouseDirectory.class); when(warehouses.required(9L,"OVERSEAS")).thenReturn(new DriverModels.WarehouseOption("9","WH9","测试起运仓","OVERSEAS"));
|
var warehouses=mock(FleetWarehouseDirectory.class); when(warehouses.required(9L,"OVERSEAS")).thenReturn(new DriverModels.WarehouseOption("9","WH9","测试起运仓","OVERSEAS"));
|
||||||
@@ -632,7 +636,9 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
var numbers=mock(DispatchNumberGenerator.class);var dailySequence=new java.util.concurrent.atomic.AtomicInteger();
|
var numbers=mock(DispatchNumberGenerator.class);var dailySequence=new java.util.concurrent.atomic.AtomicInteger();
|
||||||
when(numbers.next()).thenAnswer(invocation->"PC20261020"+String.format(java.util.Locale.ROOT,"%04d",dailySequence.incrementAndGet()));
|
when(numbers.next()).thenAnswer(invocation->"PC20261020"+String.format(java.util.Locale.ROOT,"%04d",dailySequence.incrementAndGet()));
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(service,"numbers",numbers);
|
org.springframework.test.util.ReflectionTestUtils.setField(service,"numbers",numbers);
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(service,"evidence",mock(com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.class));
|
var dispatchEvidence=mock(com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.class);
|
||||||
|
when(dispatchEvidence.metadata(anyLong(),any(),anyLong())).thenAnswer(call->new com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway.File(call.getArgument(2),"照片.png","image/png",10));
|
||||||
|
org.springframework.test.util.ReflectionTestUtils.setField(service,"evidence",dispatchEvidence);
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(service,"ownedBusinessOwnership",ownedBusinessOwnership);
|
org.springframework.test.util.ReflectionTestUtils.setField(service,"ownedBusinessOwnership",ownedBusinessOwnership);
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(gateway,"workflow",service);
|
org.springframework.test.util.ReflectionTestUtils.setField(gateway,"workflow",service);
|
||||||
org.springframework.test.util.ReflectionTestUtils.setField(service,"appointments",new DispatchAppointmentAllocations(mock(com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.class)));
|
org.springframework.test.util.ReflectionTestUtils.setField(service,"appointments",new DispatchAppointmentAllocations(mock(com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.class)));
|
||||||
@@ -663,20 +669,32 @@ public class DispatchAggregatePersistenceTest {
|
|||||||
return new DispatchCommands.Create(key,"9",new DispatchCommands.Vehicle(ResourceMode.EXTERNAL,null,"TEST-TRUCK","测试承运方",
|
return new DispatchCommands.Create(key,"9",new DispatchCommands.Vehicle(ResourceMode.EXTERNAL,null,"TEST-TRUCK","测试承运方",
|
||||||
new DispatchContracts.Capacity(15,new BigDecimal("10000"),new BigDecimal("50")),List.of(101L)),
|
new DispatchContracts.Capacity(15,new BigDecimal("10000"),new BigDecimal("50")),List.of(101L)),
|
||||||
new DispatchCommands.Driver(ResourceMode.EXTERNAL,null,"测试司机","123456789",
|
new DispatchCommands.Driver(ResourceMode.EXTERNAL,null,"测试司机","123456789",
|
||||||
new DispatchContracts.DriverEvidence("TEST-LICENSE",java.time.LocalDate.of(2099,1,1),List.of(202L),departure.plusSeconds(86400),List.of())),
|
new DispatchContracts.DriverEvidence("TEST-LICENSE",java.time.LocalDate.of(2099,1,1),List.of(202L),departure.plusSeconds(86400),List.of(303L))),
|
||||||
departure,null,null,sources,List.of(), true);
|
departure,null,null,sources,List.of(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 通过实际两级流程进入装车,测试不直接伪造通过状态。 */
|
/** 通过实际两级流程进入装车,测试不直接伪造通过状态。 */
|
||||||
public DispatchContracts.CommandResult approve(DispatchContracts.CommandResult created) {
|
public DispatchContracts.CommandResult approve(DispatchContracts.CommandResult created) {
|
||||||
|
prepareAppointmentNumbers(created.dispatchNo());
|
||||||
var submitted=tx.execute(s->service.submitReview(actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),created.dispatchNo()+"-submit",null)));
|
var submitted=tx.execute(s->service.submitReview(actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),created.dispatchNo()+"-submit",null)));
|
||||||
var reviewed=tx.execute(s->service.review(actor,created.dispatchNo(),false,new DispatchCommands.ReviewCommand(submitted.recordVersion(),created.dispatchNo()+"-dispatch",Decision.APPROVED,null,null)));
|
var reviewed=tx.execute(s->service.review(actor,created.dispatchNo(),false,new DispatchCommands.ReviewCommand(submitted.recordVersion(),created.dispatchNo()+"-dispatch",Decision.APPROVED,null,null)));
|
||||||
return tx.execute(s->service.review(actor,created.dispatchNo(),true,new DispatchCommands.ReviewCommand(reviewed.recordVersion(),created.dispatchNo()+"-loading",Decision.APPROVED,null,null)));
|
return tx.execute(s->service.review(actor,created.dispatchNo(),true,new DispatchCommands.ReviewCommand(reviewed.recordVersion(),created.dispatchNo()+"-loading",Decision.APPROVED,null,null)));
|
||||||
}
|
}
|
||||||
|
/** 普通装车夹具预置已约编号;预约缺失及填写流程由专项测试单独验证。 */
|
||||||
|
public void prepareAppointmentNumbers(String number) {
|
||||||
|
try {
|
||||||
|
var row=repository.find(number);var resources=(com.fasterxml.jackson.databind.node.ObjectNode)json.readTree(row.getResourcesJson());
|
||||||
|
var maintenance=resources.withObject("/maintenance");var entries=maintenance.withArray("destinationAppointments");
|
||||||
|
var known=new java.util.HashSet<String>();entries.forEach(e->known.add(e.path("destinationKey").asText()));
|
||||||
|
for(var item:repository.cargo(row.getId()))if("FBA".equals(item.getDestinationType()) && known.add("FBA:"+item.getFbaWarehouseCode()))
|
||||||
|
entries.addObject().put("destinationKey","FBA:"+item.getFbaWarehouseCode()).put("appointmentNo","TEST-ISA-"+item.getFbaWarehouseCode());
|
||||||
|
db.update("UPDATE ll_dispatch_order SET resources_json=? WHERE dispatch_no=?",json.writeValueAsString(resources),number);
|
||||||
|
} catch(com.fasterxml.jackson.core.JsonProcessingException error) {throw new IllegalStateException(error);}
|
||||||
|
}
|
||||||
/** 只为实载端口夹具准备真实扫码/归属记录,不声称运行库存命令。 */
|
/** 只为实载端口夹具准备真实扫码/归属记录,不声称运行库存命令。 */
|
||||||
public void picked(long source,String customer,long pallet,int packages) {
|
public void picked(long source,String customer,long pallet,int packages) {
|
||||||
long item=db.queryForObject("SELECT id FROM ll_dispatch_item WHERE plan_pallet_id=?",Long.class,source);
|
long item=db.queryForObject("SELECT id FROM ll_dispatch_item WHERE plan_pallet_id=?",Long.class,source);
|
||||||
db.update("INSERT INTO ll_order VALUES(?,?,?,'OVERSEAS',?)",9000+source,customer,"ORDER-"+source,"SOURCE-"+source);
|
db.update("INSERT INTO ll_order(id,customer_id,order_no,source_region,source_inbound_id) VALUES(?,?,?,'OVERSEAS',?)",9000+source,customer,"ORDER-"+source,"SOURCE-"+source);
|
||||||
db.update("INSERT INTO ll_inbound_stock_receipt VALUES(?,?,?)",source,customer,"IN-"+source);
|
db.update("INSERT INTO ll_inbound_stock_receipt VALUES(?,?,?)",source,customer,"IN-"+source);
|
||||||
db.update("INSERT INTO ll_dispatch_pda_pick VALUES(?,?,?,?,?,?)",source,customer,item,pallet*10,packages,packages*2);
|
db.update("INSERT INTO ll_dispatch_pda_pick VALUES(?,?,?,?,?,?)",source,customer,item,pallet*10,packages,packages*2);
|
||||||
db.update("INSERT INTO ll_dispatch_pda_pick_order(id,customer_id,pick_id,order_id,receipt_id,packages,product_quantity) VALUES(?,?,?,?,?,?,?)",source,customer,source,9000+source,source,packages,packages*2);
|
db.update("INSERT INTO ll_dispatch_pda_pick_order(id,customer_id,pick_id,order_id,receipt_id,packages,product_quantity) VALUES(?,?,?,?,?,?,?)",source,customer,source,9000+source,source,packages,packages*2);
|
||||||
|
|||||||
+84
-5
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|||||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||||
import com.baiyue.common.core.exception.BizException;
|
import com.baiyue.common.core.exception.BizException;
|
||||||
import com.baiyue.lastleg.dispatch.mapper.DispatchBolMapper;
|
import com.baiyue.lastleg.dispatch.mapper.DispatchBolMapper;
|
||||||
|
import com.baiyue.lastleg.dispatch.mapper.DispatchReceivingSqlTest;
|
||||||
import com.baiyue.lastleg.dispatch.entity.DispatchAggregate;
|
import com.baiyue.lastleg.dispatch.entity.DispatchAggregate;
|
||||||
import com.baiyue.lastleg.dispatch.model.DispatchBolData;
|
import com.baiyue.lastleg.dispatch.model.DispatchBolData;
|
||||||
import com.baiyue.lastleg.dispatch.repository.DispatchAggregateRepository;
|
import com.baiyue.lastleg.dispatch.repository.DispatchAggregateRepository;
|
||||||
@@ -23,6 +24,78 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
/** 真实H2/MyBatis读取来源与预约分配;不通过mock返回新模型自证数量守恒。 */
|
/** 真实H2/MyBatis读取来源与预约分配;不通过mock返回新模型自证数量守恒。 */
|
||||||
class DispatchBolReadPersistenceTest {
|
class DispatchBolReadPersistenceTest {
|
||||||
|
/** 同一批次仅客户A确认,批次头仍为空,BOL只给A带出当前编号且不改变两方箱数。 */
|
||||||
|
@Test void partialBatchConfirmationUsesCurrentCustomerAuthority() throws Exception {
|
||||||
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);f.source(12,"102",2,2000,5,"ONT8","RECEIVED",0);
|
||||||
|
f.appointment(1,"ISA-CURRENT","101","ORDER:1000",1000,"ONT8");
|
||||||
|
f.db.update("INSERT INTO ll_inbound_fba_appointment_item VALUES(2,1,'ORDER:2000','102',2000,'ONT8')");
|
||||||
|
f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);f.allocate(12,2,1,"102","ORDER:2000","FBA:ONT8",5);
|
||||||
|
var lines=f.read().bolLines();
|
||||||
|
assertThat(lines).extracting(DispatchBolData.Line::appointmentNo).containsExactly("ISA-CURRENT",null);
|
||||||
|
assertThat(lines).extracting(DispatchBolData.Line::customerId).containsExactly("101","102");
|
||||||
|
assertThat(lines).extracting(DispatchBolData.Line::packageCount).containsExactly(3,5);
|
||||||
|
f.db.update("UPDATE ll_inbound_fba_appointment SET confirmation_no='ISA-STALE'");
|
||||||
|
assertThat(f.read().bolLines()).extracting(DispatchBolData.Line::appointmentNo).containsExactly("ISA-CURRENT",null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 当前覆盖退出、失效或确认资料不完整时,不借用历史编号、其他客户或其他仓的编号。 */
|
||||||
|
@Test void invalidReceivingConfirmationCannotProvideBolNumber() throws Exception {
|
||||||
|
for(var change:List.of(
|
||||||
|
"UPDATE ll_fba_receiving_member SET active_ref=NULL",
|
||||||
|
"UPDATE ll_fba_receiving_member SET customer_id='102'",
|
||||||
|
"UPDATE ll_fba_receiving_member SET batch_key='FBA_APPOINTMENT:2'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET destination_key='FBA:LAX9'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET status='CANCELLED'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET status='SUPERSEDED'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET snapshot_json='{\"details\":{\"appointmentStatus\":\"PENDING\",\"appointmentAt\":\"2026-10-22T10:00:00\"}}'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET snapshot_json='{\"details\":{\"appointmentStatus\":\"SUCCESS\",\"appointmentAt\":null}}'",
|
||||||
|
"UPDATE ll_fba_receiving_agreement SET snapshot_json='{\"details\":{\"appointmentStatus\":\"SUCCESS\"}}'")) {
|
||||||
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);
|
||||||
|
f.appointment(1,"ISA-CURRENT","101","ORDER:1000",1000,"ONT8");f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);
|
||||||
|
f.db.update("UPDATE ll_inbound_fba_appointment SET confirmation_no='ISA-STALE'");f.db.update(change);
|
||||||
|
assertThat(f.read().bolLines()).as(change).singleElement().satisfies(line->{
|
||||||
|
assertThat(line.appointmentNo()).isNull();assertThat(line.packageCount()).isEqualTo(3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同一客户改约后历史关联仍保留,打印只取新的有效关联,不重复分配货量。 */
|
||||||
|
@Test void replacedReceivingMemberUsesOnlySuccessorNumber() throws Exception {
|
||||||
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);
|
||||||
|
f.appointment(1,"ISA-OLD","101","ORDER:1000",1000,"ONT8");f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);
|
||||||
|
f.db.update("UPDATE ll_fba_receiving_member SET active_ref=NULL");
|
||||||
|
f.db.update("INSERT INTO ll_fba_receiving_agreement SELECT 'RA-NEW',status,destination_key,'ISA-NEW',snapshot_json FROM ll_fba_receiving_agreement");
|
||||||
|
f.db.update("INSERT INTO ll_fba_receiving_member VALUES('RA-NEW','FBA_APPOINTMENT:1','101','FBA_APPOINTMENT:1/101')");
|
||||||
|
assertThat(f.read().bolLines()).singleElement().satisfies(line->{
|
||||||
|
assertThat(line.appointmentNo()).isEqualTo("ISA-NEW");assertThat(line.packageCount()).isEqualTo(3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同一车目的仓填写一次编号,打印逐行归属及各客户原数量保持不变。 */
|
||||||
|
@Test void destinationNumberAppliesToAllCustomersWithoutDuplicatingCargo() throws Exception {
|
||||||
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);f.source(12,"102",2,2000,5,"ONT8","RECEIVED",0);
|
||||||
|
f.appointment(1,"ISA-OLD-A","101","ORDER:1000",1000,"ONT8");f.appointment(2,"ISA-OLD-B","102","ORDER:2000",2000,"ONT8");
|
||||||
|
f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);f.allocate(12,2,2,"102","ORDER:2000","FBA:ONT8",5);
|
||||||
|
f.row.setResourcesJson(new ObjectMapper().writeValueAsString(new DispatchContracts.Resources(null,null,
|
||||||
|
new DispatchContracts.Maintenance(null,null,null,null,null,null,null,List.of(new DispatchContracts.DestinationAppointment("FBA:ONT8","ISA-CAR"))))));
|
||||||
|
var result=f.read();assertThat(result.bolLines()).extracting(DispatchBolData.Line::customerId).containsExactly("101","102");
|
||||||
|
assertThat(result.bolLines()).extracting(DispatchBolData.Line::packageCount).containsExactly(3,5);
|
||||||
|
assertThat(result.bolLines()).allSatisfy(line->assertThat(line.appointmentNo()).isEqualTo("ISA-CAR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 先保存空目的仓草稿,再取得正式预约号时,打印仍带出正式编号。 */
|
||||||
|
@Test void blankDestinationDraftDoesNotEraseLaterOfficialNumber() throws Exception {
|
||||||
|
for(var blank:Arrays.asList(null,""," ")) {
|
||||||
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);
|
||||||
|
f.row.setResourcesJson(new ObjectMapper().writeValueAsString(new DispatchContracts.Resources(null,null,
|
||||||
|
new DispatchContracts.Maintenance(null,null,null,null,null,null,null,List.of(new DispatchContracts.DestinationAppointment("FBA:ONT8",blank))))));
|
||||||
|
assertThat(f.read().bolLines()).singleElement().satisfies(line->assertThat(line.appointmentNo()).isNull());
|
||||||
|
f.appointment(1,"ISA-REAL","101","ORDER:1000",1000,"ONT8");f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);
|
||||||
|
assertThat(f.read().bolLines()).singleElement().satisfies(line->{
|
||||||
|
assertThat(line.appointmentNo()).isEqualTo("ISA-REAL");assertThat(line.packageCount()).isEqualTo(3);assertThat(line.customerId()).isEqualTo("101");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
/** 同仓同目的地无号货物跨客户合并文档,逐行客户和来源仍独立。 */
|
/** 同仓同目的地无号货物跨客户合并文档,逐行客户和来源仍独立。 */
|
||||||
@Test void wholeTruckBolReadsBothTrueOwnersAndPreservesTheirOriginalLineComposition() throws Exception {
|
@Test void wholeTruckBolReadsBothTrueOwnersAndPreservesTheirOriginalLineComposition() throws Exception {
|
||||||
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);f.source(12,"102",2,2000,5,"ONT8","RECEIVED",0);
|
var f=new Fixture();f.source(11,"101",1,1000,3,"ONT8","RECEIVED",0);f.source(12,"102",2,2000,5,"ONT8","RECEIVED",0);
|
||||||
@@ -108,7 +181,7 @@ class DispatchBolReadPersistenceTest {
|
|||||||
f.appointment(1,"SAME","101","ORDER:1000",1000,"ONT8");f.appointment(2,"SAME","102","ORDER:2000",2000,"LAX9");
|
f.appointment(1,"SAME","101","ORDER:1000",1000,"ONT8");f.appointment(2,"SAME","102","ORDER:2000",2000,"LAX9");
|
||||||
f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);f.allocate(12,2,2,"102","ORDER:2000","FBA:LAX9",5);
|
f.allocate(11,1,1,"101","ORDER:1000","FBA:ONT8",3);f.allocate(12,2,2,"102","ORDER:2000","FBA:LAX9",5);
|
||||||
assertThat(f.read().bolLines().stream().map(DispatchBolData.Line::groupKey).distinct().count()).isEqualTo(2);
|
assertThat(f.read().bolLines().stream().map(DispatchBolData.Line::groupKey).distinct().count()).isEqualTo(2);
|
||||||
f.db.update("UPDATE ll_inbound_fba_appointment SET confirmation_no=' '");
|
f.db.update("UPDATE ll_fba_receiving_agreement SET confirmation_no=' '");
|
||||||
assertThat(f.read().bolLines()).allSatisfy(line->{assertThat(line.appointmentNo()).isNull();assertThat(line.packageCount()).isPositive();});
|
assertThat(f.read().bolLines()).allSatisfy(line->{assertThat(line.appointmentNo()).isNull();assertThat(line.packageCount()).isPositive();});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,10 +246,13 @@ class DispatchBolReadPersistenceTest {
|
|||||||
|
|
||||||
/** 测试表仅取完整模块DDL中实际引用列,保留来源/分配唯一键,事务覆盖两个真实Mapper查询。 */
|
/** 测试表仅取完整模块DDL中实际引用列,保留来源/分配唯一键,事务覆盖两个真实Mapper查询。 */
|
||||||
private static final class Fixture {
|
private static final class Fixture {
|
||||||
final JdbcTemplate db;final DispatchBolReadService service;final TransactionTemplate tx;
|
final JdbcTemplate db;final DispatchBolReadService service;final TransactionTemplate tx;final DispatchAggregate row;
|
||||||
/** 根主单只提供身份,全部货物和预约事实均经实际Mapper读取。 */
|
/** 根主单只提供身份,全部货物和预约事实均经实际Mapper读取。 */
|
||||||
Fixture() throws Exception {
|
Fixture() throws Exception {
|
||||||
var ds=new DriverManagerDataSource("jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1","sa","");db=new JdbcTemplate(ds);
|
var ds=new DriverManagerDataSource("jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1","sa","");db=new JdbcTemplate(ds);
|
||||||
|
DispatchReceivingSqlTest.installJsonFunctions(db);
|
||||||
|
db.execute("CREATE TABLE ll_fba_receiving_agreement(agreement_key VARCHAR(64) PRIMARY KEY,status VARCHAR(24),destination_key VARCHAR(128),confirmation_no VARCHAR(128),snapshot_json VARCHAR(4000))");
|
||||||
|
db.execute("CREATE TABLE ll_fba_receiving_member(agreement_key VARCHAR(64),batch_key VARCHAR(128),customer_id VARCHAR(128),active_ref VARCHAR(260) UNIQUE,PRIMARY KEY(agreement_key,batch_key,customer_id))");
|
||||||
db.execute("CREATE TABLE ll_dispatch_item(id BIGINT PRIMARY KEY,dispatch_order_id BIGINT,customer_id VARCHAR(128),plan_pallet_id BIGINT,return_receipt_id BIGINT,source_business_type VARCHAR(32),source_stage VARCHAR(32),order_id BIGINT,destination_type VARCHAR(32),delivery_address VARCHAR(1000),postal_code VARCHAR(32),pallet_no VARCHAR(64),fba_warehouse_code VARCHAR(128),destination_warehouse_code VARCHAR(128),destination_warehouse_name VARCHAR(255),inbound_code VARCHAR(128),package_count INT)");
|
db.execute("CREATE TABLE ll_dispatch_item(id BIGINT PRIMARY KEY,dispatch_order_id BIGINT,customer_id VARCHAR(128),plan_pallet_id BIGINT,return_receipt_id BIGINT,source_business_type VARCHAR(32),source_stage VARCHAR(32),order_id BIGINT,destination_type VARCHAR(32),delivery_address VARCHAR(1000),postal_code VARCHAR(32),pallet_no VARCHAR(64),fba_warehouse_code VARCHAR(128),destination_warehouse_code VARCHAR(128),destination_warehouse_name VARCHAR(255),inbound_code VARCHAR(128),package_count INT)");
|
||||||
db.execute("CREATE TABLE ll_inbound_plan_pallet(id BIGINT PRIMARY KEY,plan_id BIGINT)");db.execute("CREATE TABLE ll_inbound_plan(id BIGINT PRIMARY KEY,customer_id VARCHAR(128),container_no VARCHAR(64))");
|
db.execute("CREATE TABLE ll_inbound_plan_pallet(id BIGINT PRIMARY KEY,plan_id BIGINT)");db.execute("CREATE TABLE ll_inbound_plan(id BIGINT PRIMARY KEY,customer_id VARCHAR(128),container_no VARCHAR(64))");
|
||||||
db.execute("CREATE TABLE ll_inbound_plan_pallet_allocation(id BIGINT PRIMARY KEY,customer_id VARCHAR(128),plan_id BIGINT,pallet_id BIGINT,line_id BIGINT,picked_package_count INT,planned_package_count INT,counted_package_count INT,UNIQUE(line_id,pallet_id))");
|
db.execute("CREATE TABLE ll_inbound_plan_pallet_allocation(id BIGINT PRIMARY KEY,customer_id VARCHAR(128),plan_id BIGINT,pallet_id BIGINT,line_id BIGINT,picked_package_count INT,planned_package_count INT,counted_package_count INT,UNIQUE(line_id,pallet_id))");
|
||||||
@@ -186,7 +262,7 @@ class DispatchBolReadPersistenceTest {
|
|||||||
db.execute("CREATE TABLE ll_inbound_fba_appointment(id BIGINT PRIMARY KEY,appointment_no VARCHAR(64),confirmation_no VARCHAR(128))");
|
db.execute("CREATE TABLE ll_inbound_fba_appointment(id BIGINT PRIMARY KEY,appointment_no VARCHAR(64),confirmation_no VARCHAR(128))");
|
||||||
db.execute("CREATE TABLE ll_inbound_fba_appointment_item(id BIGINT PRIMARY KEY,appointment_id BIGINT NOT NULL,source_key VARCHAR(160) NOT NULL,customer_id VARCHAR(128) NOT NULL,order_id BIGINT,fba_warehouse_code VARCHAR(128) NOT NULL,UNIQUE(appointment_id,source_key))");
|
db.execute("CREATE TABLE ll_inbound_fba_appointment_item(id BIGINT PRIMARY KEY,appointment_id BIGINT NOT NULL,source_key VARCHAR(160) NOT NULL,customer_id VARCHAR(128) NOT NULL,order_id BIGINT,fba_warehouse_code VARCHAR(128) NOT NULL,UNIQUE(appointment_id,source_key))");
|
||||||
var config=new MybatisConfiguration();config.addMapper(DispatchBolMapper.class);var factory=new MybatisSqlSessionFactoryBean();factory.setDataSource(ds);factory.setConfiguration(config);factory.afterPropertiesSet();var mapper=new SqlSessionTemplate(factory.getObject()).getMapper(DispatchBolMapper.class);
|
var config=new MybatisConfiguration();config.addMapper(DispatchBolMapper.class);var factory=new MybatisSqlSessionFactoryBean();factory.setDataSource(ds);factory.setConfiguration(config);factory.afterPropertiesSet();var mapper=new SqlSessionTemplate(factory.getObject()).getMapper(DispatchBolMapper.class);
|
||||||
var roots=mock(DispatchAggregateRepository.class);var row=new DispatchAggregate();row.setId(1L);row.setDispatchNo("DP-ONE");row.setOverseasWarehouseId("9");row.setResourcesJson(new ObjectMapper().writeValueAsString(new DispatchContracts.Resources(null,null, null)));when(roots.find("DP-ONE")).thenReturn(row);
|
var roots=mock(DispatchAggregateRepository.class);row=new DispatchAggregate();row.setId(1L);row.setDispatchNo("DP-ONE");row.setOverseasWarehouseId("9");row.setResourcesJson(new ObjectMapper().writeValueAsString(new DispatchContracts.Resources(null,null, null)));when(roots.find("DP-ONE")).thenReturn(row);
|
||||||
service=new DispatchBolReadService(roots,new DispatchBolRepository(mapper),new ObjectMapper());
|
service=new DispatchBolReadService(roots,new DispatchBolRepository(mapper),new ObjectMapper());
|
||||||
tx=new TransactionTemplate(new DataSourceTransactionManager(ds));tx.setReadOnly(true);tx.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
|
tx=new TransactionTemplate(new DataSourceTransactionManager(ds));tx.setReadOnly(true);tx.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
|
||||||
}
|
}
|
||||||
@@ -201,10 +277,13 @@ class DispatchBolReadPersistenceTest {
|
|||||||
db.update("INSERT INTO ll_order VALUES(?,?,?)",order,customer,"CN-"+order);
|
db.update("INSERT INTO ll_order VALUES(?,?,?)",order,customer,"CN-"+order);
|
||||||
db.update("INSERT INTO ll_dispatch_item VALUES(?,1,?,?,NULL,NULL,?,?, 'FBA',NULL,NULL,?,?,?,?,?,?)",item,customer,pallet,stage,order,"P-"+pallet,code,code,code,"IN-"+order,packages);
|
db.update("INSERT INTO ll_dispatch_item VALUES(?,1,?,?,NULL,NULL,?,?, 'FBA',NULL,NULL,?,?,?,?,?,?)",item,customer,pallet,stage,order,"P-"+pallet,code,code,code,"IN-"+order,packages);
|
||||||
}
|
}
|
||||||
/** 系统预约业务号与对外确认号分开,稳定来源键原样保存。 */
|
/** 系统批次头可为空;正式编号来自当前客户收货确认,稳定来源键原样保存。 */
|
||||||
void appointment(long id,String confirmation,String customer,String source,long order,String code) {
|
void appointment(long id,String confirmation,String customer,String source,long order,String code) {
|
||||||
db.update("INSERT INTO ll_inbound_fba_appointment VALUES(?,?,?)",id,"SYSTEM-APPOINTMENT-"+id,confirmation);
|
db.update("INSERT INTO ll_inbound_fba_appointment VALUES(?,?,NULL)",id,"SYSTEM-APPOINTMENT-"+id);
|
||||||
db.update("INSERT INTO ll_inbound_fba_appointment_item VALUES(?,?,?,?,?,?)",id,id,source,customer,order,code);
|
db.update("INSERT INTO ll_inbound_fba_appointment_item VALUES(?,?,?,?,?,?)",id,id,source,customer,order,code);
|
||||||
|
db.update("INSERT INTO ll_fba_receiving_agreement VALUES(?,'ACTIVE',?,?,?)","RA-"+id,"FBA:"+code,confirmation,
|
||||||
|
"{\"details\":{\"appointmentStatus\":\"SUCCESS\",\"appointmentAt\":\"2026-10-22T10:00:00\"}}");
|
||||||
|
db.update("INSERT INTO ll_fba_receiving_member VALUES(?,?,?,?)","RA-"+id,"FBA_APPOINTMENT:"+id,customer,"FBA_APPOINTMENT:"+id+"/"+customer);
|
||||||
}
|
}
|
||||||
/** 按模块实际主键建立本车明细的真实逐票分配,不以客户目的地总量替代。 */
|
/** 按模块实际主键建立本车明细的真实逐票分配,不以客户目的地总量替代。 */
|
||||||
void allocate(long item,long pallet,long appointment,String customer,String source,String destination,int packages) {
|
void allocate(long item,long pallet,long appointment,String customer,String source,String destination,int packages) {
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.service;
|
||||||
|
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchCommands;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchContracts.*;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchTypes.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
|
/** 真实排车持久化验证先排后约、同仓跨客户、缺约拒审及补齐后继续。 */
|
||||||
|
class DispatchDestinationAppointmentPersistenceTest {
|
||||||
|
@Test void canCreateWithoutAppointmentAndSubmitAfterOneNumberForTwoCustomers() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();var input=f.configured("dest-create",List.of(f.source(1,"101",501,"ONT8",3),f.source(2,"202",502,"ONT8",5)));
|
||||||
|
var created=f.tx.execute(t->f.service.create(f.actor,input));
|
||||||
|
assertThat(f.tx.execute(t->f.service.detail(f.actor,created.dispatchNo())).dispatchInfo().fbaAppointments()).hasSize(1);
|
||||||
|
assertThatThrownBy(()->f.tx.execute(t->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"missing",null)))).hasMessageContaining("ONT8");
|
||||||
|
var saved=f.tx.execute(t->f.service.update(f.actor,created.dispatchNo(),new DispatchCommands.Update(created.recordVersion(),"dest-save",input.vehicle(),input.driver(),input.plannedDepartureAt(),null,null,true,new Maintenance(null,null,null,null,null,null,null,List.of(new DestinationAppointment("FBA:ONT8","ISA-ONE"))))));
|
||||||
|
var loaded=f.approve(saved);assertThat(loaded.stage()).isEqualTo(Stage.LOADING);
|
||||||
|
var detail=f.tx.execute(t->f.service.detail(f.actor,created.dispatchNo()));
|
||||||
|
assertThat(detail.dispatchInfo().fbaAppointments()).singleElement().satisfies(a->assertThat(a.appointmentNo()).isEqualTo("ISA-ONE"));
|
||||||
|
assertThat(detail.orderDetails()).extracting(d->d.customerId()).containsExactlyInAnyOrder("101","202");
|
||||||
|
}
|
||||||
|
@Test void savingOneOfTwoNumbersIsAllowedButReviewNeedsBoth() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();var input=f.configured("two-dest-create",List.of(f.source(1,"101",501,"ONT8",3),f.source(2,"202",502,"LGB8",5)));
|
||||||
|
var created=f.tx.execute(t->f.service.create(f.actor,input));
|
||||||
|
var saved=f.tx.execute(t->f.service.update(f.actor,created.dispatchNo(),new DispatchCommands.Update(created.recordVersion(),"partial-save",input.vehicle(),input.driver(),input.plannedDepartureAt(),null,null,true,new Maintenance(null,null,null,null,null,null,null,List.of(new DestinationAppointment("FBA:ONT8","ISA-ONE"))))));
|
||||||
|
assertThatThrownBy(()->f.tx.execute(t->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(saved.recordVersion(),"second-missing",null)))).hasMessageContaining("LGB8");
|
||||||
|
var complete=f.tx.execute(t->f.service.update(f.actor,created.dispatchNo(),new DispatchCommands.Update(saved.recordVersion(),"complete-save",input.vehicle(),input.driver(),input.plannedDepartureAt(),null,null,true,new Maintenance(null,null,null,null,null,null,null,List.of(new DestinationAppointment("FBA:ONT8","ISA-ONE"),new DestinationAppointment("FBA:LGB8","ISA-TWO"))))));
|
||||||
|
assertThat(f.approve(complete).stage()).isEqualTo(Stage.LOADING);
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.service;
|
||||||
|
|
||||||
|
import com.baiyue.lastleg.dispatch.entity.DispatchItem;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchContracts.*;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.DispatchViews.FbaAppointment;
|
||||||
|
import java.util.*;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
|
/** 本车同目的仓跨客户只填一次,先约自动带号,先排可暂缺。 */
|
||||||
|
class DispatchDestinationAppointmentsTest {
|
||||||
|
@Test void groupsMultipleCustomersAndPalletsByDestination() {
|
||||||
|
var rows=resolve(List.of(item("A","ONT8"),item("B","ONT8"),item("A","LGB8")),null,List.of());
|
||||||
|
assertThat(rows).extracting(FbaAppointment::destinationWarehouseCode).containsExactly("LGB8","ONT8");
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,null,null,List.of())).contains("LGB8、ONT8");
|
||||||
|
}
|
||||||
|
/** 十票跨客户货物同目的仓,只带入一个编号,全部不同货件保留。 */
|
||||||
|
@Test void takesTheUniqueAlreadyConfirmedNumberAndAggregatesShipments() {
|
||||||
|
var customers=java.util.stream.IntStream.range(0,10).mapToObj(i->"A"+i).toList();
|
||||||
|
var rows=resolve(customers.stream().map(c->item(c,"ONT8")).toList(),null,customers.stream().map(c->booked(c,"ISA-1")).toList());
|
||||||
|
assertThat(rows).singleElement().satisfies(a->{assertThat(a.appointmentNo()).isEqualTo("ISA-1");assertThat(a.shipmentNumbers()).containsExactlyElementsOf(customers.stream().map(c->"SHIP-"+c).toList());assertThat(a.customerId()).isNull();});
|
||||||
|
}
|
||||||
|
@Test void conflictingExistingNumbersRequireOneExplicitDestinationNumber() {
|
||||||
|
var cargo=List.of(item("A","ONT8"),item("B","ONT8"));var booked=List.of(booked("A","ISA-A"),booked("B","ISA-B"));
|
||||||
|
assertThat(resolve(cargo,null,booked).get(0).appointmentNo()).isNull();
|
||||||
|
var rows=resolve(cargo,maintenance(new DestinationAppointment("FBA:ONT8"," ISA-CAR ")),booked);
|
||||||
|
assertThat(rows).singleElement().satisfies(a->{assertThat(a.appointmentNo()).isEqualTo("ISA-CAR");assertThat(a.confirmedAt()).isNull();});
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,null,null,List.of())).isNull();
|
||||||
|
}
|
||||||
|
/** 先保存空草稿、后取得正式预约时,同仓仍自动带出一次,无需重新手填。 */
|
||||||
|
@Test void blankDraftDoesNotHideTheUniqueConfirmedNumber() {
|
||||||
|
var rows=resolve(List.of(item("A","ONT8"),item("B","ONT8")),maintenance(new DestinationAppointment("FBA:ONT8",null)),List.of(booked("A","ISA-ONE"),booked("B","ISA-ONE")));
|
||||||
|
assertThat(rows).singleElement().satisfies(a->assertThat(a.appointmentNo()).isEqualTo("ISA-ONE"));
|
||||||
|
}
|
||||||
|
@Test void missingSecondDestinationDoesNotPassWithTheFirstNumber() {
|
||||||
|
var rows=resolve(List.of(item("A","ONT8"),item("B","LGB8")),maintenance(new DestinationAppointment("FBA:ONT8","ISA-1")),List.of());
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,null,null,List.of())).contains("LGB8").doesNotContain("ONT8");
|
||||||
|
assertThatThrownBy(()->DispatchDestinationAppointments.validate(maintenance(new DestinationAppointment("FBA:OTHER","ISA")),rows)).hasMessageContaining("本车已有");
|
||||||
|
}
|
||||||
|
@Test void rejectsDuplicateDestinationsAndOverlongNumbers() {
|
||||||
|
assertThatThrownBy(()->maintenance(new DestinationAppointment("FBA:ONT8","A"),new DestinationAppointment("FBA:ONT8","B"))).hasMessageContaining("一个预约号");
|
||||||
|
assertThatThrownBy(()->new DestinationAppointment("FBA:ONT8","A".repeat(129))).hasMessageContaining("128");
|
||||||
|
}
|
||||||
|
@Test void knownConfirmedWindowKeepsDepartureAndArrivalValidation() {
|
||||||
|
var at=java.time.Instant.parse("2026-11-01T18:00:00Z");
|
||||||
|
var rows=resolve(List.of(item("A","ONT8")),null,List.of(booked("A","ISA-1")));
|
||||||
|
var window=new com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort.ReceivingWindow("FBA_APPOINTMENT:1","AP-1","A","FBA:ONT8","ISA-1",at,at.plusSeconds(3600),"AGR-1",1);
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,at.minusSeconds(3600),at.plusSeconds(1800),List.of(window))).isNull();
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,at.plusSeconds(60),at.plusSeconds(120),List.of(window))).contains("早于");
|
||||||
|
assertThat(DispatchDestinationAppointments.blockReason(rows,at.minusSeconds(3600),at.plusSeconds(3601),List.of(window))).contains("晚于");
|
||||||
|
}
|
||||||
|
/** 将测试中的货物引用显式构造为真实货物投影,预约编号仅提供确认事实。 */
|
||||||
|
private static List<FbaAppointment> resolve(List<DispatchItem> cargo,Maintenance maintenance,List<FbaAppointment> booked) {
|
||||||
|
var shipments=booked.stream().flatMap(b->b.shipmentNumbers().stream().map(no->new com.baiyue.lastleg.dispatch.mapper.DispatchReadMapper.CargoShipment(b.customerId(),b.destinationKey(),no))).toList();
|
||||||
|
return DispatchDestinationAppointments.resolve(cargo,maintenance,booked,shipments);
|
||||||
|
}
|
||||||
|
private static DispatchItem item(String customer,String code){var item=new DispatchItem();item.setCustomerId(customer);item.setDestinationType("FBA");item.setFbaWarehouseCode(code);return item;}
|
||||||
|
private static FbaAppointment booked(String customer,String no){return new FbaAppointment("FBA_APPOINTMENT:1","AP-1",no,"FBA:ONT8","ONT8","SUCCESS",null,null,customer,List.of("SHIP-"+customer));}
|
||||||
|
private static Maintenance maintenance(DestinationAppointment... appointments){return new Maintenance(null,null,null,null,null,null,null,List.of(appointments));}
|
||||||
|
}
|
||||||
+134
@@ -0,0 +1,134 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.service;
|
||||||
|
|
||||||
|
import com.baiyue.lastleg.appointmentwork.AppointmentWorkDispatchPort;
|
||||||
|
import com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.*;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import static com.baiyue.lastleg.dispatch.port.DispatchTypes.*;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/** 排车反馈直接回归:图片送审门禁与正式预约的多货件投影。 */
|
||||||
|
class DispatchFeedbackRegressionTest {
|
||||||
|
/** 主档PDF与本趟补传图片分属各自文件域,补传不能被主档重建清空。 */
|
||||||
|
@Test void masterLicenseKeepsAdditionalDispatchPhotoAndItsOwner() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("master-photo",List.of(f.source(1,"101",501,"ONT8",3)))));
|
||||||
|
f.db.execute("CREATE TABLE ll_fleet_driver(id BIGINT PRIMARY KEY)");f.db.update("INSERT INTO ll_fleet_driver VALUES(71)");
|
||||||
|
var drivers=(com.baiyue.lastleg.fleet.driver.DriverService)ReflectionTestUtils.getField(f.nativeFleetService,"drivers");
|
||||||
|
var driver=mock(com.baiyue.lastleg.fleet.driver.DriverModels.Response.class);
|
||||||
|
var details=mock(com.baiyue.lastleg.fleet.driver.DriverModels.Draft.class);
|
||||||
|
when(driver.id()).thenReturn("71");when(driver.details()).thenReturn(details);when(driver.licenseFileId()).thenReturn("81");
|
||||||
|
when(details.region()).thenReturn("OVERSEAS");when(details.name()).thenReturn("主档司机");when(details.phone()).thenReturn("555-0100");
|
||||||
|
when(details.licenseNumber()).thenReturn("LICENSE");when(details.licenseExpiresOn()).thenReturn(java.time.LocalDate.of(2099,1,1));
|
||||||
|
when(drivers.requireDispatchable(eq(71L),any())).thenReturn(driver);
|
||||||
|
when(drivers.download(71L,81L)).thenReturn(new com.baiyue.lastleg.fleet.driver.DriverModels.Download(new com.baiyue.lastleg.fleet.driver.DriverModels.File("81","主档证照.pdf","application/pdf",3),new byte[]{1,2,3}));
|
||||||
|
var input=f.configured("update",List.of());
|
||||||
|
var update=new DispatchCommands.Update(created.recordVersion(),"save-master",input.vehicle(),
|
||||||
|
new DispatchCommands.Driver(ResourceMode.MASTER,71L,null,null,new DispatchContracts.DriverEvidence(null,null,List.of(91L),input.driver().evidence().expectedTaskEndAt(),List.of(303L))),
|
||||||
|
input.plannedDepartureAt(),null,null,true,null);
|
||||||
|
var saved=f.tx.execute(s->f.service.update(f.actor,created.dispatchNo(),update));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
|
var proof=f.service.detail(f.actor,created.dispatchNo()).vehicleInfo().driver().evidence();
|
||||||
|
assertThat(proof.fileIds()).containsExactly(81L,91L);assertThat(proof.masterLicenseFileId()).isEqualTo(81L);
|
||||||
|
assertThat(f.service.evidenceMetadata(f.actor,created.dispatchNo(),DispatchEvidenceGateway.Kind.DRIVER,91L).contentType()).isEqualTo("image/png");
|
||||||
|
assertThat(f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(saved.recordVersion(),"submit-master",null))).recordVersion()).isGreaterThan(saved.recordVersion());
|
||||||
|
verify(drivers,never()).download(71L,91L);
|
||||||
|
}
|
||||||
|
/** 车辆候选使用真实资源占用,本车已选资源保留,其他车次占用排除。 */
|
||||||
|
@Test void vehicleAvailabilityKeepsOnlyOwnReservation() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var first=f.tx.execute(s->f.service.create(f.actor,f.create("first",List.of())));
|
||||||
|
var second=f.tx.execute(s->f.service.create(f.actor,f.create("second",List.of())));
|
||||||
|
long own=f.repository.find(first.dispatchNo()).getTripId(), other=f.repository.find(second.dispatchNo()).getTripId();
|
||||||
|
f.db.update("INSERT INTO ll_fleet_resource_assignment VALUES('VEHICLE',11,?,'OWN'),('VEHICLE',12,?,'OTHER')",own,other);
|
||||||
|
var guard=new com.baiyue.lastleg.fleet.trip.FleetVehicleAssignmentGuard(f.session.getMapper(com.baiyue.lastleg.fleet.trip.FleetResourceMapper.class));
|
||||||
|
assertThat(guard.unavailableForDispatch(first.dispatchNo())).containsExactly(12L);
|
||||||
|
assertThat(guard.unavailableForDispatch(second.dispatchNo())).containsExactly(11L);
|
||||||
|
assertThat(guard.unavailableForDispatch("UNRELATED")).containsExactlyInAnyOrder(11L,12L);
|
||||||
|
}
|
||||||
|
/** 三类各自缺失均不能提交,不能用其他类别照片顶替。 */
|
||||||
|
@ParameterizedTest @ValueSource(strings={"VEHICLE","DRIVER_PHOTO","DRIVER"})
|
||||||
|
void missingPhotoBlocksSubmission(String kind) throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("missing-"+kind,List.of(f.source(1,"101",501,"ONT8",3)))));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
|
var row=f.repository.find(created.dispatchNo());
|
||||||
|
var json=(ObjectNode)f.json.readTree(row.getResourcesJson());
|
||||||
|
ObjectNode target=kind.equals("VEHICLE")?(ObjectNode)json.path("vehicle"):(ObjectNode)json.path("driver").path("evidence");
|
||||||
|
target.set(kind.equals("VEHICLE")?"evidenceFileIds":kind.equals("DRIVER")?"fileIds":"photoFileIds",f.json.valueToTree(List.of()));
|
||||||
|
f.db.update("UPDATE ll_dispatch_order SET resources_json=? WHERE id=?",f.json.writeValueAsString(json),row.getId());
|
||||||
|
assertThatThrownBy(()->f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submit",null))))
|
||||||
|
.hasMessageContaining("至少一张有效");
|
||||||
|
assertThat(f.repository.find(created.dispatchNo()).getRecordVersion()).isEqualTo(created.recordVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 上传未成功不产生有效引用;草稿可先保存空照片,送审才拦截。 */
|
||||||
|
@Test void incompletePhotosCanBeSavedAsDraft() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.create("draft",List.of(f.source(1,"101",501,"ONT8",3)))));
|
||||||
|
var input=f.configured("resource",List.of());var v=input.vehicle();var d=input.driver();var e=d.evidence();
|
||||||
|
var update=new DispatchCommands.Update(created.recordVersion(),"save-draft",
|
||||||
|
new DispatchCommands.Vehicle(v.mode(),null,v.plate(),v.carrierName(),v.capacity(),List.of()),
|
||||||
|
new DispatchCommands.Driver(d.mode(),null,d.name(),d.phone(),new DispatchContracts.DriverEvidence(e.licenseNo(),e.licenseExpiresOn(),List.of(),e.expectedTaskEndAt(),List.of())),
|
||||||
|
input.plannedDepartureAt(),null,null,true,null);
|
||||||
|
var saved=f.tx.execute(s->f.service.update(f.actor,created.dispatchNo(),update));
|
||||||
|
assertThat(saved.recordVersion()).isGreaterThan(created.recordVersion());
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
|
assertThatThrownBy(()->f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(saved.recordVersion(),"submit-draft",null))))
|
||||||
|
.hasMessageContaining("车辆图片");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PDF不计为图片,失效文件在审核通过时重新核验,失败保持待审。 */
|
||||||
|
@Test void pdfAndRevokedUploadCannotPassReview() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("valid",List.of(f.source(1,"101",501,"ONT8",3)))));
|
||||||
|
f.prepareAppointmentNumbers(created.dispatchNo());
|
||||||
|
var gateway=(DispatchEvidenceGateway)ReflectionTestUtils.getField(f.service,"evidence");
|
||||||
|
when(gateway.metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.VEHICLE),eq(101L)))
|
||||||
|
.thenReturn(new DispatchEvidenceGateway.File(101L,"车辆.pdf","application/pdf",10));
|
||||||
|
assertThatThrownBy(()->f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"pdf",null))))
|
||||||
|
.hasMessageContaining("车辆图片");
|
||||||
|
when(gateway.metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.VEHICLE),eq(101L)))
|
||||||
|
.thenReturn(new DispatchEvidenceGateway.File(101L,"车辆.png","image/png",10));
|
||||||
|
var submitted=f.tx.execute(s->f.service.submitReview(f.actor,created.dispatchNo(),new DispatchCommands.SubmitReview(created.recordVersion(),"submit-valid",null)));
|
||||||
|
doThrow(new IllegalArgumentException("文件已作废")).when(gateway).metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.DRIVER_PHOTO),eq(303L));
|
||||||
|
assertThatThrownBy(()->f.tx.execute(s->f.service.review(f.actor,created.dispatchNo(),false,new DispatchCommands.ReviewCommand(submitted.recordVersion(),"approve-revoked",Decision.APPROVED,null,null))))
|
||||||
|
.hasMessageContaining("文件已作废");
|
||||||
|
assertThat(f.repository.find(created.dispatchNo()).getRecordVersion()).isEqualTo(submitted.recordVersion());
|
||||||
|
assertThat(f.repository.find(created.dispatchNo()).getReviewState()).isEqualTo("DISPATCH_PENDING");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同仓预约汇总一行,多托及重复分配不重复显示,全部真实货件保留。 */
|
||||||
|
@Test void appointmentsGroupByDestinationAndKeepAllShipmentNumbers() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("projection",List.of(f.source(1,"101",501,"ONT8",3),f.source(2,"101",502,"ONT8",2)))));
|
||||||
|
long id=f.repository.find(created.dispatchNo()).getId();
|
||||||
|
long item=f.db.queryForObject("SELECT id FROM ll_dispatch_item WHERE plan_pallet_id=1",Long.class);
|
||||||
|
f.db.update("INSERT INTO ll_inbound_fba_appointment(id,appointment_no,fba_warehouse_code) VALUES(900,'AP-1','ONT8'),(901,'AP-2','ONT8')");
|
||||||
|
f.db.update("INSERT INTO ll_order(id,customer_id,order_no,order_type) VALUES(9001,'101','LM-1','FIRST_LEG'),(9002,'101','LM-2','FIRST_LEG')");
|
||||||
|
f.db.update("INSERT INTO ll_order_detail VALUES(9001,'101','SHIP-1','ONT8'),(9001,'101','SHIP-2','ONT8'),(9001,'101','SHIP-1','ONT8'),(9001,'999','FOREIGN','ONT8'),(9002,'101','SHIP-3','ONT8')");
|
||||||
|
f.db.update("INSERT INTO ll_inbound_fba_appointment_item VALUES(9001,'101',1,900,'ORDER:9001','ONT8'),(9002,'101',1,900,'ORDER:9002','ONT8'),(9001,'101',1,901,'ORDER:9001','ONT8')");
|
||||||
|
for(String source:List.of("ORDER:9001","ORDER:9001","ORDER:9002"))
|
||||||
|
f.db.update("INSERT INTO ll_dispatch_appointment_allocation VALUES(?,?,1,'FBA_APPOINTMENT:900','101',?,'FBA:ONT8',1)",id,item,source);
|
||||||
|
f.db.update("INSERT INTO ll_dispatch_appointment_allocation VALUES(?,?,1,'FBA_APPOINTMENT:901','101','ORDER:9001','FBA:ONT8',1)",id,item);
|
||||||
|
var provider=mock(AppointmentWorkDispatchPort.class);var at=Instant.parse("2026-10-25T17:00:00Z");
|
||||||
|
when(provider.reviewEvidence(created.dispatchNo())).thenReturn(List.of(
|
||||||
|
new AppointmentWorkDispatchPort.ReceivingWindow("FBA_APPOINTMENT:900","AP-1","101","FBA:ONT8","CONF-SAME",at,null,"AGR-1",1),
|
||||||
|
new AppointmentWorkDispatchPort.ReceivingWindow("FBA_APPOINTMENT:901","AP-2","101","FBA:ONT8","CONF-SAME",at.plusSeconds(3600),null,"AGR-2",1)));
|
||||||
|
ReflectionTestUtils.setField(f.service,"appointments",new DispatchAppointmentAllocations(provider));
|
||||||
|
var appointments=f.tx.execute(s->f.service.detail(f.actor,created.dispatchNo())).dispatchInfo().fbaAppointments();
|
||||||
|
assertThat(appointments).hasSize(1);
|
||||||
|
assertThat(appointments.get(0).shipmentNumbers()).containsExactly("SHIP-1","SHIP-2","SHIP-3");
|
||||||
|
assertThat(appointments.get(0).confirmedAt()).isEqualTo(at);
|
||||||
|
var page=f.tx.execute(s->f.service.page(f.actor,new DispatchViews.Query(1,10,null,null,null,null,null,StatusFilter.ACTIVE,Stage.BEFORE_LOADING,null,null)));
|
||||||
|
assertThat(page.records().get(0).fbaAppointments()).isEqualTo(appointments);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -82,13 +82,13 @@ class DispatchInboundReceiptPersistenceTest {
|
|||||||
assertThatThrownBy(()->f.p.f.service.requireReviewAppointment(f.p.f.repository.find(f.p.number))).hasMessageContaining("审核依据失效");
|
assertThatThrownBy(()->f.p.f.service.requireReviewAppointment(f.p.f.repository.find(f.p.number))).hasMessageContaining("审核依据失效");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 仓库预约回复尚待处理不改变实收数量,收货成功后出货门禁仍明确阻止发运。 */
|
/** 本车已按目的仓维护编号,逐票预约回复不再重新引入车辆送审门禁。 */
|
||||||
@Test void receivingConfirmsFactsWhileAppointmentStillBlocksShipping() throws Exception {
|
@Test void receivingKeepsFactsWithoutReintroducingPerTicketAppointmentGate() throws Exception {
|
||||||
var f=new Fixture();when(f.receiving.hasPending("FBA_APPOINTMENT:1","101")).thenReturn(true);
|
var f=new Fixture();when(f.receiving.hasPending("FBA_APPOINTMENT:1","101")).thenReturn(true);
|
||||||
f.confirm();
|
f.confirm();
|
||||||
assertThat(f.quantities()).containsExactly(9,11);
|
assertThat(f.quantities()).containsExactly(9,11);
|
||||||
assertThat(f.allocations()).containsExactly(9,11);
|
assertThat(f.allocations()).containsExactly(9,11);
|
||||||
assertThatThrownBy(()->f.p.f.service.requireReviewAppointment(f.p.f.repository.find(f.p.number))).hasMessageContaining("待仓库确认");
|
assertThatCode(()->f.p.f.service.requireReviewAppointment(f.p.f.repository.find(f.p.number))).doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 未关联有效排车的正常收货也可完成,不能要求存在车辆或预约。 */
|
/** 未关联有效排车的正常收货也可完成,不能要求存在车辆或预约。 */
|
||||||
@@ -161,8 +161,8 @@ class DispatchInboundReceiptPersistenceTest {
|
|||||||
doReturn(List.of(p.f.candidates.get(id))).when(p.sources).confirmedPlan("101",id);
|
doReturn(List.of(p.f.candidates.get(id))).when(p.sources).confirmedPlan("101",id);
|
||||||
doReturn(1).when(p.sources).materialize(anyLong(),eq("101"),eq(id),eq(500+id),anyLong(),any());
|
doReturn(1).when(p.sources).materialize(anyLong(),eq("101"),eq(id),eq(500+id),anyLong(),any());
|
||||||
}
|
}
|
||||||
p.f.db.execute("ALTER TABLE ll_inbound_plan_line ADD (destination_type VARCHAR(20),fba_warehouse_code VARCHAR(20))");
|
p.f.db.execute("ALTER TABLE ll_inbound_plan_line ADD destination_type VARCHAR(20)");
|
||||||
p.f.db.execute("ALTER TABLE ll_inbound_plan_pallet_allocation ADD (customer_id VARCHAR(40),planned_package_count INT,counted_package_count INT)");
|
p.f.db.execute("ALTER TABLE ll_inbound_plan_pallet_allocation ADD (planned_package_count INT,counted_package_count INT)");
|
||||||
p.f.db.update("INSERT INTO ll_inbound_plan_line(id,order_id,customer_id,destination_type,fba_warehouse_code) VALUES(1,9001,'101','FBA','ONT8')");
|
p.f.db.update("INSERT INTO ll_inbound_plan_line(id,order_id,customer_id,destination_type,fba_warehouse_code) VALUES(1,9001,'101','FBA','ONT8')");
|
||||||
for(long id=1;id<=2;id++) {
|
for(long id=1;id<=2;id++) {
|
||||||
p.f.db.update("INSERT INTO ll_inbound_plan_pallet_allocation VALUES(?,1,'101',10,0)",id);
|
p.f.db.update("INSERT INTO ll_inbound_plan_pallet_allocation VALUES(?,1,'101',10,0)",id);
|
||||||
|
|||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
package com.baiyue.lastleg.dispatch.service;
|
||||||
|
|
||||||
|
import com.baiyue.lastleg.dispatch.gateway.DispatchEvidenceGateway;
|
||||||
|
import com.baiyue.lastleg.dispatch.port.*;
|
||||||
|
import com.baiyue.lastleg.fleet.driver.*;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
import java.time.*;
|
||||||
|
import java.util.List;
|
||||||
|
import static com.baiyue.lastleg.dispatch.port.DispatchTypes.*;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
|
|
||||||
|
/** 创建时间公共投影、实际货件来源及司机换证保存的直接回归。 */
|
||||||
|
class DispatchListAndResourceRegressionTest {
|
||||||
|
/** 各阶段、审核分区和任务类型均取同一主单创建时间,不借用计划或更新时间。 */
|
||||||
|
@Test void creationTimeIsPreservedAcrossAllListScopes() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var createdAt=LocalDateTime.of(2026,10,22,1,23,45);
|
||||||
|
for(var stage:Stage.values())for(var type:List.of("DELIVERY","PICKUP","LOCAL_TRUCK")) {
|
||||||
|
var result=f.tx.execute(s->f.service.create(f.actor,f.create(stage+type,List.of())));
|
||||||
|
f.db.update("UPDATE ll_dispatch_order SET task_type=?,stage=?,created_at=?,planned_departure_at=?,updated_at=? WHERE dispatch_no=?",
|
||||||
|
type,stage.name(),createdAt,createdAt.plusDays(1),createdAt.plusDays(2),result.dispatchNo());
|
||||||
|
}
|
||||||
|
for(var stage:Stage.values()) {
|
||||||
|
var page=f.tx.execute(s->f.service.page(f.actor,query(stage,null)));
|
||||||
|
assertThat(page.records()).hasSize(3).allSatisfy(row->assertThat(row.createdAt()).isEqualTo(createdAt.toInstant(ZoneOffset.UTC)));
|
||||||
|
}
|
||||||
|
for(var section:BeforeLoadingSection.values()) {
|
||||||
|
var state=section==BeforeLoadingSection.VEHICLE_INFO?"DRAFT":section==BeforeLoadingSection.DISPATCH_REVIEW?"DISPATCH_PENDING":"LOADING_PENDING";
|
||||||
|
f.db.update("UPDATE ll_dispatch_order SET review_state=? WHERE stage='BEFORE_LOADING'",state);
|
||||||
|
var page=f.tx.execute(s->f.service.page(f.actor,query(Stage.BEFORE_LOADING,section)));
|
||||||
|
assertThat(page.records()).hasSize(3).allSatisfy(row->assertThat(row.createdAt()).isEqualTo(createdAt.toInstant(ZoneOffset.UTC)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 手填预约与内部实物引用不妨碍逐票货件读取,同仓跨客户去重且不串入别的客户。 */
|
||||||
|
@Test void manualAppointmentReadsShipmentsFromActualPlanAllocations() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var result=f.tx.execute(s->f.service.create(f.actor,f.configured("actual-shipments",List.of(f.source(1,"101",501,"ONT8",2),f.source(2,"202",502,"ONT8",1)))));
|
||||||
|
f.prepareAppointmentNumbers(result.dispatchNo());
|
||||||
|
f.db.update("INSERT INTO ll_order(id,customer_id,order_no,order_type) VALUES(9001,'101','LM-1','FIRST_LEG'),(9002,'101','LM-2','FIRST_LEG'),(9003,'202','LM-3','FIRST_LEG')");
|
||||||
|
f.db.update("INSERT INTO ll_order_detail VALUES(9001,'101','SHIP-1','ONT8'),(9001,'101','SHIP-1','ONT8'),(9001,'999','FOREIGN','ONT8'),(9001,'101','OTHER-WAREHOUSE','LGB8'),(9002,'101','SHIP-2','ONT8'),(9003,'202','SHIP-3','ONT8')");
|
||||||
|
f.db.update("INSERT INTO ll_inbound_plan_line VALUES(11,9001,'101','ONT8'),(12,9002,'101',' ont8 '),(13,9003,'202','ONT8')");
|
||||||
|
f.db.update("INSERT INTO ll_inbound_plan_pallet_allocation VALUES(1,11,'101'),(1,12,'101'),(2,13,'202')");
|
||||||
|
f.db.update("INSERT INTO ll_dispatch_appointment_allocation SELECT dispatch_order_id,id,plan_pallet_id,CONCAT('DISPATCH:',dispatch_order_id),customer_id,CONCAT('ORDER:',order_id),'FBA:ONT8',package_count FROM ll_dispatch_item");
|
||||||
|
var appointments=f.service.detail(f.actor,result.dispatchNo()).dispatchInfo().fbaAppointments();
|
||||||
|
assertThat(appointments).singleElement().satisfies(a->{
|
||||||
|
assertThat(a.appointmentNo()).isEqualTo("TEST-ISA-ONT8");
|
||||||
|
assertThat(a.shipmentNumbers()).containsExactly("SHIP-1","SHIP-2","SHIP-3");
|
||||||
|
});
|
||||||
|
assertThat(f.service.page(f.actor,query(Stage.BEFORE_LOADING,null)).records().get(0).fbaAppointments()).isEqualTo(appointments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 换证后排除服务端冻结的旧主档引用,本车补传图保留,请求不能伪造文件来源来移除补传图。 */
|
||||||
|
@Test void savingAfterMasterReplacementKeepsOnlyTheNewMasterAndDispatchImages() throws Exception {
|
||||||
|
var f=new DispatchAggregatePersistenceTest.Fixture();
|
||||||
|
var created=f.tx.execute(s->f.service.create(f.actor,f.configured("driver-replacement",List.of(f.source(1,"101",501,"ONT8",3)))));
|
||||||
|
f.db.execute("CREATE TABLE ll_fleet_driver(id BIGINT PRIMARY KEY)");f.db.update("INSERT INTO ll_fleet_driver VALUES(71)");
|
||||||
|
var drivers=(DriverService)ReflectionTestUtils.getField(f.nativeFleetService,"drivers");
|
||||||
|
var driver=mock(DriverModels.Response.class);var details=mock(DriverModels.Draft.class);
|
||||||
|
when(driver.id()).thenReturn("71");when(driver.details()).thenReturn(details);when(driver.licenseFileId()).thenReturn("81");
|
||||||
|
when(details.region()).thenReturn("OVERSEAS");when(details.name()).thenReturn("主档司机");when(details.phone()).thenReturn("555-0100");
|
||||||
|
when(details.licenseNumber()).thenReturn("LICENSE");when(details.licenseExpiresOn()).thenReturn(LocalDate.of(2099,1,1));
|
||||||
|
when(drivers.requireDispatchable(eq(71L),any())).thenReturn(driver);
|
||||||
|
var input=f.configured("input",List.of());
|
||||||
|
var requestDriver=new DispatchCommands.Driver(ResourceMode.MASTER,71L,null,null,new DispatchContracts.DriverEvidence(null,null,List.of(91L),input.driver().evidence().expectedTaskEndAt(),List.of(303L)));
|
||||||
|
var first=f.tx.execute(s->f.service.update(f.actor,created.dispatchNo(),new DispatchCommands.Update(created.recordVersion(),"first",input.vehicle(),requestDriver,input.plannedDepartureAt(),null,null,true,null)));
|
||||||
|
var snapshot=f.service.detail(f.actor,created.dispatchNo()).vehicleInfo().driver();var proof=snapshot.evidence();
|
||||||
|
when(driver.licenseFileId()).thenReturn("82");
|
||||||
|
var evidence=(DispatchEvidenceGateway)ReflectionTestUtils.getField(f.service,"evidence");clearInvocations(evidence);
|
||||||
|
doThrow(new IllegalArgumentException("旧主档证照不能按本车附件读取")).when(evidence).metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.DRIVER),eq(81L));
|
||||||
|
var changedDriver=new DispatchCommands.Driver(ResourceMode.MASTER,71L,snapshot.name(),snapshot.phone(),new DispatchContracts.DriverEvidence(proof.licenseNo(),proof.licenseExpiresOn(),proof.fileIds(),proof.expectedTaskEndAt(),proof.photoFileIds(),91L));
|
||||||
|
f.tx.execute(s->f.service.update(f.actor,created.dispatchNo(),new DispatchCommands.Update(first.recordVersion(),"second",input.vehicle(),changedDriver,input.plannedDepartureAt(),null,null,true,null)));
|
||||||
|
var saved=f.service.detail(f.actor,created.dispatchNo()).vehicleInfo().driver().evidence();
|
||||||
|
assertThat(saved.fileIds()).containsExactly(82L,91L);assertThat(saved.masterLicenseFileId()).isEqualTo(82L);
|
||||||
|
verify(evidence,never()).metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.DRIVER),eq(81L));
|
||||||
|
verify(evidence).metadata(anyLong(),eq(DispatchEvidenceGateway.Kind.DRIVER),eq(91L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 只读列表查询保持正式阶段与审核分区组合。 */
|
||||||
|
private static DispatchViews.Query query(Stage stage,BeforeLoadingSection section) {
|
||||||
|
return new DispatchViews.Query(1,20,null,null,null,null,null,StatusFilter.ACTIVE,stage,section,null);
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-6
@@ -29,7 +29,7 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
var created = f.tx.execute(t -> f.service.create(f.actor, input));
|
var created = f.tx.execute(t -> f.service.create(f.actor, input));
|
||||||
var vehicle = vehicle(f, mode, List.of(301L));
|
var vehicle = vehicle(f, mode, List.of(301L));
|
||||||
var maintenance = new Maintenance(LocalDate.of(2026, 11, 1), " FBA自提 ", "一提多卸", "混装",
|
var maintenance = new Maintenance(LocalDate.of(2026, 11, 1), " FBA自提 ", "一提多卸", "混装",
|
||||||
" fleet@example.test ", "厢式货车", " account ", " appointment ");
|
" fleet@example.test ", "厢式货车", " account ", List.of(new com.baiyue.lastleg.dispatch.port.DispatchContracts.DestinationAppointment("FBA:ONT8", " appointment ")));
|
||||||
var request = new DispatchCommands.Update(created.recordVersion(), "maintenance-save", vehicle, input.driver(),
|
var request = new DispatchCommands.Update(created.recordVersion(), "maintenance-save", vehicle, input.driver(),
|
||||||
input.plannedDepartureAt(), input.estimatedArrivalAt(), "保留原备注", true, maintenance);
|
input.plannedDepartureAt(), input.estimatedArrivalAt(), "保留原备注", true, maintenance);
|
||||||
var saved = f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), request));
|
var saved = f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), request));
|
||||||
@@ -73,7 +73,7 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
@Test void emptyMaintenanceCanBeSavedAndCleared() throws Exception {
|
@Test void emptyMaintenanceCanBeSavedAndCleared() throws Exception {
|
||||||
var f = new DispatchAggregatePersistenceTest.Fixture();
|
var f = new DispatchAggregatePersistenceTest.Fixture();
|
||||||
var created = f.tx.execute(t -> f.service.create(f.actor, f.create("empty-maintenance", List.of())));
|
var created = f.tx.execute(t -> f.service.create(f.actor, f.create("empty-maintenance", List.of())));
|
||||||
var empty = f.json.readValue("{\"plannedDeliveryDate\":\" \",\"deliveryMethod\":\" \",\"pickupMethod\":\"\",\"loadType\":\" \",\"fleetEmail\":\" \",\"vehicleType\":\"\",\"appointmentAccount\":\" \",\"appointmentNo\":\"\"}", Maintenance.class);
|
var empty = f.json.readValue("{\"plannedDeliveryDate\":\" \",\"deliveryMethod\":\" \",\"pickupMethod\":\"\",\"loadType\":\" \",\"fleetEmail\":\" \",\"vehicleType\":\"\",\"appointmentAccount\":\" \",\"destinationAppointments\":[]}", Maintenance.class);
|
||||||
assertThat(empty).isEqualTo(new Maintenance(null, null, null, null, null, null, null, null));
|
assertThat(empty).isEqualTo(new Maintenance(null, null, null, null, null, null, null, null));
|
||||||
var saved = f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), new DispatchCommands.Update(
|
var saved = f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), new DispatchCommands.Update(
|
||||||
created.recordVersion(), "empty-maintenance-save", null, null, null, null, null, true, empty)));
|
created.recordVersion(), "empty-maintenance-save", null, null, null, null, null, true, empty)));
|
||||||
@@ -91,7 +91,7 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
assertThatThrownBy(() -> json.treeToValue(json.createObjectNode().put(field, "未知"), Maintenance.class))
|
assertThatThrownBy(() -> json.treeToValue(json.createObjectNode().put(field, "未知"), Maintenance.class))
|
||||||
.hasRootCauseInstanceOf(IllegalArgumentException.class);
|
.hasRootCauseInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
for (String field : List.of("fleetEmail", "appointmentAccount", "appointmentNo")) {
|
for (String field : List.of("fleetEmail", "appointmentAccount")) {
|
||||||
int max = field.equals("fleetEmail") ? 254 : 128;
|
int max = field.equals("fleetEmail") ? 254 : 128;
|
||||||
assertThat(json.treeToValue(json.createObjectNode().put(field, "a".repeat(max)), Maintenance.class)).isNotNull();
|
assertThat(json.treeToValue(json.createObjectNode().put(field, "a".repeat(max)), Maintenance.class)).isNotNull();
|
||||||
assertThatThrownBy(() -> json.treeToValue(json.createObjectNode().put(field, "a".repeat(max + 1)), Maintenance.class))
|
assertThatThrownBy(() -> json.treeToValue(json.createObjectNode().put(field, "a".repeat(max + 1)), Maintenance.class))
|
||||||
@@ -110,7 +110,7 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
var f = new DispatchAggregatePersistenceTest.Fixture();
|
var f = new DispatchAggregatePersistenceTest.Fixture();
|
||||||
var input = f.configured("projection-maintenance-create", List.of());
|
var input = f.configured("projection-maintenance-create", List.of());
|
||||||
var created = f.tx.execute(t -> f.service.create(f.actor, input));
|
var created = f.tx.execute(t -> f.service.create(f.actor, input));
|
||||||
var maintenance = new Maintenance(LocalDate.of(2026, 11, 1), "外配", "一提一卸", "地板", null, "平板车", null, "AP-LOCAL");
|
var maintenance = new Maintenance(LocalDate.of(2026, 11, 1), "外配", "一提一卸", "地板", null, "平板车", null, List.of());
|
||||||
f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), new DispatchCommands.Update(created.recordVersion(),
|
f.tx.execute(t -> f.service.update(f.actor, created.dispatchNo(), new DispatchCommands.Update(created.recordVersion(),
|
||||||
"projection-maintenance-save", vehicle(f, "MASTER", List.of(301L)), input.driver(), input.plannedDepartureAt(), null, null, true, maintenance)));
|
"projection-maintenance-save", vehicle(f, "MASTER", List.of(301L)), input.driver(), input.plannedDepartureAt(), null, null, true, maintenance)));
|
||||||
var projection = new com.baiyue.lastleg.dispatch.transport.TransportTaskProjection(f.repository,
|
var projection = new com.baiyue.lastleg.dispatch.transport.TransportTaskProjection(f.repository,
|
||||||
@@ -147,7 +147,8 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
assertThat(fields.size()).isEqualTo(Maintenance.class.getRecordComponents().length);
|
assertThat(fields.size()).isEqualTo(Maintenance.class.getRecordComponents().length);
|
||||||
assertThat(schema.path("required").isMissingNode()).isTrue();
|
assertThat(schema.path("required").isMissingNode()).isTrue();
|
||||||
for (var field : Maintenance.class.getRecordComponents()) {
|
for (var field : Maintenance.class.getRecordComponents()) {
|
||||||
assertThat(fields.path(field.getName()).path("nullable").asBoolean()).isTrue();
|
if(field.getName().equals("destinationAppointments")) assertThat(fields.path(field.getName()).path("type").asText()).isEqualTo("array");
|
||||||
|
else assertThat(fields.path(field.getName()).path("nullable").asBoolean()).isTrue();
|
||||||
for (var value : fields.path(field.getName()).path("enum")) {
|
for (var value : fields.path(field.getName()).path("enum")) {
|
||||||
assertThat(json.treeToValue(json.createObjectNode().put(field.getName(), value.asText()), Maintenance.class)).isNotNull();
|
assertThat(json.treeToValue(json.createObjectNode().put(field.getName(), value.asText()), Maintenance.class)).isNotNull();
|
||||||
}
|
}
|
||||||
@@ -155,7 +156,8 @@ class DispatchMaintenancePersistenceTest {
|
|||||||
assertThat(fields.path("plannedDeliveryDate").path("format").asText()).isEqualTo("date");
|
assertThat(fields.path("plannedDeliveryDate").path("format").asText()).isEqualTo("date");
|
||||||
assertThat(fields.path("fleetEmail").path("maxLength").asInt()).isEqualTo(254);
|
assertThat(fields.path("fleetEmail").path("maxLength").asInt()).isEqualTo(254);
|
||||||
assertThat(fields.path("appointmentAccount").path("maxLength").asInt()).isEqualTo(128);
|
assertThat(fields.path("appointmentAccount").path("maxLength").asInt()).isEqualTo(128);
|
||||||
assertThat(fields.path("appointmentNo").path("maxLength").asInt()).isEqualTo(128);
|
assertThat(fields.path("destinationAppointments").path("items").path("$ref").asText()).isEqualTo("#/components/schemas/DispatchDestinationAppointment");
|
||||||
|
assertThat(schemas.path("DispatchDestinationAppointment").path("properties").path("appointmentNo").path("maxLength").asInt()).isEqualTo(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 主档请求只携带身份与本趟照片,名称及容量必须仍取权威主档。 */
|
/** 主档请求只携带身份与本趟照片,名称及容量必须仍取权威主档。 */
|
||||||
|
|||||||
+1
@@ -142,6 +142,7 @@ class DispatchReviewWorkflowPersistenceTest {
|
|||||||
|
|
||||||
/** 每次提交以真实返回版本开始下一轮,不人工造审核状态。 */
|
/** 每次提交以真实返回版本开始下一轮,不人工造审核状态。 */
|
||||||
private static DispatchContracts.CommandResult submit(DispatchAggregatePersistenceTest.Fixture f,DispatchContracts.CommandResult prior,String key) {
|
private static DispatchContracts.CommandResult submit(DispatchAggregatePersistenceTest.Fixture f,DispatchContracts.CommandResult prior,String key) {
|
||||||
|
f.prepareAppointmentNumbers(prior.dispatchNo());
|
||||||
return f.tx.execute(s->f.service.submitReview(f.actor,prior.dispatchNo(),new DispatchCommands.SubmitReview(prior.recordVersion(),key,null)));
|
return f.tx.execute(s->f.service.submitReview(f.actor,prior.dispatchNo(),new DispatchCommands.SubmitReview(prior.recordVersion(),key,null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ class DispatchWholeSourcePersistenceTest {
|
|||||||
for(long id:List.of(1L,2L)) {
|
for(long id:List.of(1L,2L)) {
|
||||||
var row=f.candidates.get(id);f.db.update("INSERT INTO ll_order(id,customer_id,order_no)VALUES(?,?,?)",row.orderId(),row.customerId(),row.orderNo());
|
var row=f.candidates.get(id);f.db.update("INSERT INTO ll_order(id,customer_id,order_no)VALUES(?,?,?)",row.orderId(),row.customerId(),row.orderNo());
|
||||||
f.db.update("INSERT INTO ll_inbound_plan VALUES(?,?,?,?)",id,row.customerId(),"9",row.orderId());f.db.update("INSERT INTO ll_inbound_plan_pallet VALUES(?,?,?,?,?)",id,id,row.palletNo(),row.warehousePalletId(),row.customerId());
|
f.db.update("INSERT INTO ll_inbound_plan VALUES(?,?,?,?)",id,row.customerId(),"9",row.orderId());f.db.update("INSERT INTO ll_inbound_plan_pallet VALUES(?,?,?,?,?)",id,id,row.palletNo(),row.warehousePalletId(),row.customerId());
|
||||||
f.db.update("INSERT INTO ll_inbound_plan_line VALUES(?,?,?)",id,row.orderId(),row.customerId());f.db.update("INSERT INTO ll_inbound_plan_pallet_allocation VALUES(?,?)",id,id);
|
f.db.update("INSERT INTO ll_inbound_plan_line(id,order_id,customer_id) VALUES(?,?,?)",id,row.orderId(),row.customerId());f.db.update("INSERT INTO ll_inbound_plan_pallet_allocation(pallet_id,line_id) VALUES(?,?)",id,id);
|
||||||
f.db.update("INSERT INTO ll_inventory_position VALUES(?,?,?,?,?,?,?,0,0,0,1)",id,row.customerId(),id,row.warehousePalletId(),row.palletNo(),"9",row.packageCount());
|
f.db.update("INSERT INTO ll_inventory_position VALUES(?,?,?,?,?,?,?,0,0,0,1)",id,row.customerId(),id,row.warehousePalletId(),row.palletNo(),"9",row.packageCount());
|
||||||
f.db.update("INSERT INTO ll_inbound_stock_receipt VALUES(?,?,?,?,?,?,?)",id,row.customerId(),row.inboundCode(),row.orderId(),id,row.packageCount(),row.warehousePalletId());
|
f.db.update("INSERT INTO ll_inbound_stock_receipt VALUES(?,?,?,?,?,?,?)",id,row.customerId(),row.inboundCode(),row.orderId(),id,row.packageCount(),row.warehousePalletId());
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -65,11 +65,10 @@ class AppointmentWorkDispatchBindingTest {
|
|||||||
assertNull(service.reviewBlockReason("D-20",departure,arrival));
|
assertNull(service.reviewBlockReason("D-20",departure,arrival));
|
||||||
verify(mapper,never()).pickedPhysical(anyLong(),anyString());
|
verify(mapper,never()).pickedPhysical(anyLong(),anyString());
|
||||||
assertEquals(arrival,service.reviewEvidence("D-20").get(0).startAt(),"10点洛杉矶预约应按当地时区解释");
|
assertEquals(arrival,service.reviewEvidence("D-20").get(0).startAt(),"10点洛杉矶预约应按当地时区解释");
|
||||||
assertNotNull(service.reviewBlockReason("D-20",departure,null));
|
// 目的仓编号及时间由整车入口校验;此端口只核实真实来源分配。
|
||||||
assertNotNull(service.reviewBlockReason("D-20",arrival.plusSeconds(60),arrival.plusSeconds(120)));
|
assertNull(service.reviewBlockReason("D-20",departure,null));
|
||||||
assertNotNull(service.reviewBlockReason("D-20",departure,arrival.plusSeconds(60)));
|
when(item.packageCount()).thenReturn(4);when(mapper.allocated("FBA_APPOINTMENT:1","C","ORDER:1","FBA:ONT8",20)).thenReturn(1L);
|
||||||
when(item.packageCount()).thenReturn(5);when(mapper.allocated("FBA_APPOINTMENT:1","C","ORDER:1","FBA:ONT8",20)).thenReturn(1L);
|
assertTrue(service.departureBlockReason("D-20").contains("分配量"));
|
||||||
assertTrue(service.departureBlockReason("D-20").contains("收货确认未完整覆盖")); // Batch has 5, but the current agreement covers only 4 across every dispatch.
|
|
||||||
when(item.packageCount()).thenReturn(4);when(mapper.allocated("FBA_APPOINTMENT:1","C","ORDER:1","FBA:ONT8",20)).thenReturn(0L);
|
when(item.packageCount()).thenReturn(4);when(mapper.allocated("FBA_APPOINTMENT:1","C","ORDER:1","FBA:ONT8",20)).thenReturn(0L);
|
||||||
when(batch.appointmentStatus()).thenReturn("PENDING");
|
when(batch.appointmentStatus()).thenReturn("PENDING");
|
||||||
assertDoesNotThrow(()->service.requireDeparture("D-20")); // The current receiving agreement, not the old header, authorizes receipt.
|
assertDoesNotThrow(()->service.requireDeparture("D-20")); // The current receiving agreement, not the old header, authorizes receipt.
|
||||||
@@ -77,16 +76,16 @@ class AppointmentWorkDispatchBindingTest {
|
|||||||
assertDoesNotThrow(()->service.requireDeparture("D-20"));
|
assertDoesNotThrow(()->service.requireDeparture("D-20"));
|
||||||
when(receiving.hasPending("FBA_APPOINTMENT:1","C")).thenReturn(true);
|
when(receiving.hasPending("FBA_APPOINTMENT:1","C")).thenReturn(true);
|
||||||
clearInvocations(mapper);
|
clearInvocations(mapper);
|
||||||
assertTrue(service.departureBlockReason("D-20").contains("待仓库确认"));verify(mapper,never()).lockAppointment(anyLong());
|
assertNull(service.departureBlockReason("D-20"));verify(mapper,never()).lockAppointment(anyLong());
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-20"));
|
assertDoesNotThrow(()->service.requireDeparture("D-20"));
|
||||||
when(receiving.hasPending("FBA_APPOINTMENT:1","C")).thenReturn(false);
|
when(receiving.hasPending("FBA_APPOINTMENT:1","C")).thenReturn(false);
|
||||||
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(agreement("OTHER",4));
|
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(agreement("OTHER",4));
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-20"));
|
assertTrue(service.reviewEvidence("D-20").isEmpty());
|
||||||
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(agreement("C",3));
|
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(agreement("C",3));
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-20"));
|
assertDoesNotThrow(()->service.requireDeparture("D-20"));
|
||||||
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(null);
|
when(receiving.currentAgreement("FBA_APPOINTMENT:1","C")).thenReturn(null);
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-20"));
|
assertDoesNotThrow(()->service.requireDeparture("D-20"));
|
||||||
assertTrue(service.reviewBlockReason("D-20",departure,arrival).contains("尚无有效收货确认"));
|
assertNull(service.reviewBlockReason("D-20",departure,arrival));
|
||||||
verifyNoInteractions(changes);
|
verifyNoInteractions(changes);
|
||||||
}
|
}
|
||||||
private com.baiyue.lastleg.inboundplan.receiving.FbaReceivingContracts.Agreement agreement(String customer,int packages) {
|
private com.baiyue.lastleg.inboundplan.receiving.FbaReceivingContracts.Agreement agreement(String customer,int packages) {
|
||||||
@@ -133,7 +132,7 @@ class AppointmentWorkDispatchBindingTest {
|
|||||||
assertEquals("BOOKING:X",AppointmentWorkPhysicalSources.ref(refs,one).sourceKey());
|
assertEquals("BOOKING:X",AppointmentWorkPhysicalSources.ref(refs,one).sourceKey());
|
||||||
assertEquals("BOOKING:X",AppointmentWorkPhysicalSources.ref(refs,two).sourceKey());
|
assertEquals("BOOKING:X",AppointmentWorkPhysicalSources.ref(refs,two).sourceKey());
|
||||||
}
|
}
|
||||||
@Test void emptyAllocationCannotBypassAnExistingBatchAtArrangeOrDeparture() {
|
@Test void prearrangementBuildsRealSourceRowsWithoutMandatoryAppointmentBatches() {
|
||||||
var mapper=mock(AppointmentWorkDispatchMapper.class); var appointments=mock(InboundFbaAppointmentService.class);
|
var mapper=mock(AppointmentWorkDispatchMapper.class); var appointments=mock(InboundFbaAppointmentService.class);
|
||||||
var sources=mock(AppointmentSourceService.class); var changes=mock(AppointmentWorkChanges.class);
|
var sources=mock(AppointmentSourceService.class); var changes=mock(AppointmentWorkChanges.class);
|
||||||
var service=new AppointmentWorkDispatchBinding(mapper,appointments,sources,changes,mock(com.baiyue.lastleg.inboundplan.receiving.FbaReceivingStore.class),mock(AppointmentWorkDispatchCandidates.class));
|
var service=new AppointmentWorkDispatchBinding(mapper,appointments,sources,changes,mock(com.baiyue.lastleg.inboundplan.receiving.FbaReceivingStore.class),mock(AppointmentWorkDispatchCandidates.class));
|
||||||
@@ -147,9 +146,10 @@ class AppointmentWorkDispatchBindingTest {
|
|||||||
when(mapper.dispatchPhysicalById(20)).thenReturn(List.of(new AppointmentWorkDispatchMapper.DispatchPhysical(30,10L,"C","RECEIVED",4)));
|
when(mapper.dispatchPhysicalById(20)).thenReturn(List.of(new AppointmentWorkDispatchMapper.DispatchPhysical(30,10L,"C","RECEIVED",4)));
|
||||||
for(var status:List.of("SUCCESS","CANCELLED","FAILED")) {
|
for(var status:List.of("SUCCESS","CANCELLED","FAILED")) {
|
||||||
when(batch.appointmentStatus()).thenReturn(status);
|
when(batch.appointmentStatus()).thenReturn(status);
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.bindItems(20,List.of(new AppointmentWorkDispatchPort.PhysicalItem(30L,"C",10L,"RECEIVED",4)),List.of()));
|
assertDoesNotThrow(()->service.bindItems(20,List.of(new AppointmentWorkDispatchPort.PhysicalItem(30L,"C",10L,"RECEIVED",4)),List.of()));
|
||||||
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-1"));
|
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service.requireDeparture("D-1"));
|
||||||
}
|
}
|
||||||
verify(mapper,never()).insert(any()); verifyNoInteractions(changes);
|
verify(mapper,times(3)).insert(new AppointmentWorkDispatchMapper.Bound(20,30,10,"DISPATCH:20","C","ORDER:1","FBA:ONT8",4));
|
||||||
|
verify(changes,times(3)).requirementsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-5
@@ -182,13 +182,22 @@ class AppointmentWorkDispatchPersistenceTest {
|
|||||||
assertEquals(80,jdbc.queryForObject("SELECT SUM(package_count) FROM ll_dispatch_appointment_allocation",Integer.class));
|
assertEquals(80,jdbc.queryForObject("SELECT SUM(package_count) FROM ll_dispatch_appointment_allocation",Integer.class));
|
||||||
assertEquals(original,jdbc.queryForList("SELECT * FROM ll_dispatch_item ORDER BY id"));
|
assertEquals(original,jdbc.queryForList("SELECT * FROM ll_dispatch_item ORDER BY id"));
|
||||||
}
|
}
|
||||||
/** 正式确认未完成时,候选和写入都阻止提前排车,不留下部分分配。 */
|
/** 正式确认未完成也允许先排车;不自动带入尚未确认的预约引用。 */
|
||||||
@Test void unconfirmedAppointmentBlocksBothCandidateAndBindingBeforeReview() {
|
@Test void unconfirmedAppointmentAllowsPrearrangementWithoutAutomaticConfirmedNumber() {
|
||||||
when(receiving.currentAgreement(batch,"101")).thenReturn(null);
|
when(receiving.currentAgreement(batch,"101")).thenReturn(null);
|
||||||
when(receiving.snapshots(anyList())).thenReturn(List.of());
|
when(receiving.snapshots(anyList())).thenReturn(List.of());
|
||||||
assertFalse(candidates.batchReferences(List.of(new CandidatePhysical("101",111L))).get(new CandidatePhysical("101",111L)).blockReasons().isEmpty());
|
var candidate=candidates.batchReferences(List.of(new CandidatePhysical("101",111L))).get(new CandidatePhysical("101",111L));
|
||||||
assertThrows(ResponseStatusException.class,()->tx.executeWithoutResult(s->bind(11)));
|
assertTrue(candidate.blockReasons().isEmpty());assertTrue(candidate.appointmentBatches().isEmpty());
|
||||||
assertEquals(0,jdbc.queryForObject("SELECT COUNT(*) FROM ll_dispatch_appointment_allocation",Integer.class));
|
assertDoesNotThrow(()->tx.executeWithoutResult(s->bind(11)));
|
||||||
|
assertEquals(1,jdbc.queryForObject("SELECT COUNT(*) FROM ll_dispatch_appointment_allocation",Integer.class));
|
||||||
|
}
|
||||||
|
/** 先排后约沿本车真实来源记账,不能省略客户或箱数,也不占用尚未确认的预约批次。 */
|
||||||
|
@Test void fbaPrearrangementKeepsWholePhysicalSourcesWithoutBatchSelection() {
|
||||||
|
var physical=mapper.dispatchPhysicalById(1).stream().filter(p->p.itemId()==11).findFirst().orElseThrow();
|
||||||
|
tx.executeWithoutResult(s->{binding.lockBatches(Map.of());binding.bindItems(1,List.of(new PhysicalItem(physical.itemId(),physical.customerId(),physical.planPalletId(),physical.sourceStage(),physical.packages())),List.of());});
|
||||||
|
var rows=jdbc.queryForList("SELECT batch_key,customer_id,package_count FROM ll_dispatch_appointment_allocation WHERE dispatch_item_id=11");
|
||||||
|
assertEquals(1,rows.size());assertEquals("DISPATCH:1",rows.get(0).get("BATCH_KEY"));
|
||||||
|
assertEquals("101",rows.get(0).get("CUSTOMER_ID"));assertEquals(physical.packages(),rows.get(0).get("PACKAGE_COUNT"));
|
||||||
}
|
}
|
||||||
/** 查询本车重分配量排除本车原占用,保留其他车占用及真实业务标识。 */
|
/** 查询本车重分配量排除本车原占用,保留其他车占用及真实业务标识。 */
|
||||||
@Test void ownedAllocationOptionsExcludeOnlyThisDispatchAndKeepOtherCarsQuota() {
|
@Test void ownedAllocationOptionsExcludeOnlyThisDispatchAndKeepOtherCarsQuota() {
|
||||||
|
|||||||
+13
@@ -27,6 +27,19 @@ class VehicleApplicationServiceTest {
|
|||||||
service = new VehicleApplicationService(repository, mock(VehicleAssignmentGuard.class));
|
service = new VehicleApplicationService(repository, mock(VehicleAssignmentGuard.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 可用性排除集传入仓储查询,分页不先取再过滤。 */
|
||||||
|
@Test void availabilityIsAppliedBeforePaging() {
|
||||||
|
var assignments=mock(VehicleAssignmentGuard.class);
|
||||||
|
service=new VehicleApplicationService(repository,assignments);
|
||||||
|
when(assignments.unavailableForDispatch("PC-1")).thenReturn(java.util.List.of(12L));
|
||||||
|
when(repository.page(org.mockito.ArgumentMatchers.any())).thenReturn(new VehicleRepository.PageSlice(java.util.List.of(),1,20,0,0));
|
||||||
|
service.page(new VehicleModels.Query(1,20,null,null,"OVERSEAS","IN_SERVICE","PC-1"));
|
||||||
|
var criteria=org.mockito.ArgumentCaptor.forClass(VehicleRepository.SearchCriteria.class);
|
||||||
|
org.mockito.Mockito.verify(repository).page(criteria.capture());
|
||||||
|
assertThat(criteria.getValue().excludedIds()).containsExactly(12L);
|
||||||
|
assertThat(criteria.getValue().status()).isEqualTo("IN_SERVICE");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void rejectsStaleVersionBeforeUpdating() {
|
void rejectsStaleVersionBeforeUpdating() {
|
||||||
when(repository.lockById(1L)).thenReturn(Optional.of(vehicle(3L, 1000L)));
|
when(repository.lockById(1L)).thenReturn(Optional.of(vehicle(3L, 1000L)));
|
||||||
|
|||||||
+9
-4
@@ -32,6 +32,10 @@ class ReturnRelabelPackingServiceTest {
|
|||||||
var app = new RelabelApplication(); app.setId(1L); app.setCustomerId("2"); app.setRelabelNo("RL1");
|
var app = new RelabelApplication(); app.setId(1L); app.setCustomerId("2"); app.setRelabelNo("RL1");
|
||||||
var first = item(10L, 20L, "A"); var second = item(11L, 21L, "B");
|
var first = item(10L, 20L, "A"); var second = item(11L, 21L, "B");
|
||||||
var a = carton(20L, "A"); var b = carton(21L, "B"); var target = carton(22L, "NEW");
|
var a = carton(20L, "A"); var b = carton(21L, "B"); var target = carton(22L, "NEW");
|
||||||
|
var physical = mock(ReturnInventoryCartonItemMapper.class);
|
||||||
|
var stock = new ReturnInventoryCartonItem(); stock.setSkuCode("SKU"); stock.setQuantity(6L);
|
||||||
|
when(physical.lockCarton(anyLong())).thenReturn(List.of(stock));
|
||||||
|
ReflectionTestUtils.setField(service, "cartonItems", physical);
|
||||||
var history = mock(com.baiyue.lastleg.relabel.pda.mapper.PdaRelabelHistoryMapper.class);
|
var history = mock(com.baiyue.lastleg.relabel.pda.mapper.PdaRelabelHistoryMapper.class);
|
||||||
ReflectionTestUtils.setField(service, "histories", history);
|
ReflectionTestUtils.setField(service, "histories", history);
|
||||||
if (inheritedCompletion) {
|
if (inheritedCompletion) {
|
||||||
@@ -42,7 +46,6 @@ class ReturnRelabelPackingServiceTest {
|
|||||||
var fact = new com.baiyue.lastleg.relabel.pda.entity.PdaRelabelUnitFact(); fact.setItemId(9L); fact.setQuantity(1);
|
var fact = new com.baiyue.lastleg.relabel.pda.entity.PdaRelabelUnitFact(); fact.setItemId(9L); fact.setQuantity(1);
|
||||||
when(facts.selectList(any())).thenReturn(List.of(fact));
|
when(facts.selectList(any())).thenReturn(List.of(fact));
|
||||||
ReflectionTestUtils.setField(service, "facts", facts);
|
ReflectionTestUtils.setField(service, "facts", facts);
|
||||||
var physical = mock(ReturnInventoryCartonItemMapper.class);
|
|
||||||
var line = new ReturnInventoryCartonItem(); line.setSkuCode("SKU"); line.setQuantity(6L);
|
var line = new ReturnInventoryCartonItem(); line.setSkuCode("SKU"); line.setQuantity(6L);
|
||||||
when(physical.lockCarton(20L)).thenReturn(List.of(line));
|
when(physical.lockCarton(20L)).thenReturn(List.of(line));
|
||||||
ReflectionTestUtils.setField(service, "cartonItems", physical);
|
ReflectionTestUtils.setField(service, "cartonItems", physical);
|
||||||
@@ -57,13 +60,15 @@ class ReturnRelabelPackingServiceTest {
|
|||||||
var request = (ReturnInventoryRequests.BoxMerge)call.getArgument(1);
|
var request = (ReturnInventoryRequests.BoxMerge)call.getArgument(1);
|
||||||
assertEquals(List.of("A", "B"), request.sourceCartonMarks());
|
assertEquals(List.of("A", "B"), request.sourceCartonMarks());
|
||||||
assertNull(request.targetCartonMark());
|
assertNull(request.targetCartonMark());
|
||||||
|
assertEquals(List.of(new ReturnInventoryRequests.SourceQuantity("A", "SKU", 6),
|
||||||
|
new ReturnInventoryRequests.SourceQuantity("B", "SKU", 6)), request.expectedSourceQuantities());
|
||||||
assertEquals(List.of(new ReturnInventoryRequests.SourceDeduction("A", "SKU", 3),
|
assertEquals(List.of(new ReturnInventoryRequests.SourceDeduction("A", "SKU", 3),
|
||||||
new ReturnInventoryRequests.SourceDeduction("B", "SKU", 3)), request.sourceDeductions());
|
new ReturnInventoryRequests.SourceDeduction("B", "SKU", 3)), request.sourceDeductions());
|
||||||
return new ReturnInventoryResponses.MergeResult("NEW", "SKU", 6, null);
|
return new ReturnInventoryResponses.MergeResult("NEW", "SKU", 6, null);
|
||||||
});
|
});
|
||||||
var result = service.pack(new PdaWarehouseIdentity("op", "picker", 42L), app, List.of(first, second),
|
var result = service.pack(new PdaWarehouseIdentity("op", "picker", 42L), app, List.of(first, second),
|
||||||
new ReturnInventoryRequests.BoxMerge(List.of("A", "B"), null, "key", null,
|
new ReturnInventoryRequests.BoxMerge(List.of("A", "B"), null, "key", null,
|
||||||
BigDecimal.TEN, BigDecimal.TEN, BigDecimal.TEN, BigDecimal.ONE));
|
BigDecimal.TEN, BigDecimal.TEN, BigDecimal.TEN, BigDecimal.ONE, null));
|
||||||
assertEquals("NEW", result.cartonMark());
|
assertEquals("NEW", result.cartonMark());
|
||||||
assertEquals(22L, first.getReturnCartonId()); assertEquals(22L, second.getReturnCartonId());
|
assertEquals(22L, first.getReturnCartonId()); assertEquals(22L, second.getReturnCartonId());
|
||||||
assertEquals("A", first.getSourceCartonMark()); assertEquals("B", second.getSourceCartonMark());
|
assertEquals("A", first.getSourceCartonMark()); assertEquals("B", second.getSourceCartonMark());
|
||||||
@@ -87,9 +92,9 @@ class ReturnRelabelPackingServiceTest {
|
|||||||
var app = new RelabelApplication();
|
var app = new RelabelApplication();
|
||||||
var a = item(10L, 20L, "A"); var b = item(11L, 21L, "B"); b.setDestinationFbaWarehouseCode("OTHER");
|
var a = item(10L, 20L, "A"); var b = item(11L, 21L, "B"); b.setDestinationFbaWarehouseCode("OTHER");
|
||||||
assertThrows(ResponseStatusException.class, () -> service.pack(new PdaWarehouseIdentity("op", "name", 42L), app,
|
assertThrows(ResponseStatusException.class, () -> service.pack(new PdaWarehouseIdentity("op", "name", 42L), app,
|
||||||
List.of(a), new ReturnInventoryRequests.BoxMerge(List.of("OTHER"), null, "wrong")));
|
List.of(a), new ReturnInventoryRequests.BoxMerge(List.of("OTHER"), null, "wrong", null, null, null, null, null, null)));
|
||||||
assertThrows(ResponseStatusException.class, () -> service.pack(new PdaWarehouseIdentity("op", "name", 42L), app,
|
assertThrows(ResponseStatusException.class, () -> service.pack(new PdaWarehouseIdentity("op", "name", 42L), app,
|
||||||
List.of(a, b), new ReturnInventoryRequests.BoxMerge(List.of("A", "B"), null, "dest")));
|
List.of(a, b), new ReturnInventoryRequests.BoxMerge(List.of("A", "B"), null, "dest", null, null, null, null, null, null)));
|
||||||
verifyNoInteractions(inventory);
|
verifyNoInteractions(inventory);
|
||||||
}
|
}
|
||||||
private RelabelItem item(long id, long cartonId, String mark) {
|
private RelabelItem item(long id, long cartonId, String mark) {
|
||||||
|
|||||||
+47
-1
@@ -647,13 +647,59 @@ class ReturnInventoryServiceTest {
|
|||||||
when(cartons.lockMark("RC-SOURCE")).thenReturn(source);
|
when(cartons.lockMark("RC-SOURCE")).thenReturn(source);
|
||||||
when(cartonItems.lockCarton(31L)).thenReturn(List.of(item(41L, "SKU-A", 5)));
|
when(cartonItems.lockCarton(31L)).thenReturn(List.of(item(41L, "SKU-A", 5)));
|
||||||
var request = new ReturnInventoryRequests.BoxMerge(List.of("RC-SOURCE"), "RC-TARGET", "partial-existing",
|
var request = new ReturnInventoryRequests.BoxMerge(List.of("RC-SOURCE"), "RC-TARGET", "partial-existing",
|
||||||
List.of(new ReturnInventoryRequests.SourceDeduction("RC-SOURCE", "SKU-A", 1)), null, null, null, null);
|
List.of(new ReturnInventoryRequests.SourceDeduction("RC-SOURCE", "SKU-A", 1)), null, null, null, null,
|
||||||
|
List.of(new ReturnInventoryRequests.SourceQuantity("RC-SOURCE", "SKU-A", 5)));
|
||||||
var error = assertThrows(ResponseStatusException.class, () -> service.mergeBoxes(new PdaWarehouseIdentity("operator-1", "作业员", 42L), request));
|
var error = assertThrows(ResponseStatusException.class, () -> service.mergeBoxes(new PdaWarehouseIdentity("operator-1", "作业员", 42L), request));
|
||||||
assertThat(error.getReason()).contains("独立新箱");
|
assertThat(error.getReason()).contains("独立新箱");
|
||||||
verify(cartonItems, never()).updateById(any(ReturnInventoryCartonItem.class));
|
verify(cartonItems, never()).updateById(any(ReturnInventoryCartonItem.class));
|
||||||
verify(cartons, never()).insert(any(ReturnInventoryCarton.class));
|
verify(cartons, never()).insert(any(ReturnInventoryCarton.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void freshKeyCannotRepeatPartialMergeFromAStaleSourceSnapshot() {
|
||||||
|
var source = prepareConcurrentSource(); source.setTotalQuantity(10L);
|
||||||
|
var line = item(41L, "SKU-A", 10L);
|
||||||
|
when(cartonItems.lockCarton(31L)).thenReturn(List.of(line));
|
||||||
|
when(balances.adjustCartonQuantity(anyString(), anyString(), anyString(), anyLong())).thenReturn(1);
|
||||||
|
var saved = new java.util.HashMap<String, ReturnInventoryOperation>();
|
||||||
|
org.mockito.Mockito.doAnswer(call -> {
|
||||||
|
ReturnInventoryOperation operation = call.getArgument(0); saved.put(operation.getIdempotencyKey(), operation); return 1;
|
||||||
|
}).when(operations).insert(any(ReturnInventoryOperation.class));
|
||||||
|
when(operations.lockKey(anyString(), anyString())).thenAnswer(call -> saved.get(call.getArgument(1)));
|
||||||
|
var identity = new PdaWarehouseIdentity("worker", "作业员", 42L);
|
||||||
|
var first = boxMerge("first-click", 10L);
|
||||||
|
service.mergeBoxes(identity, first);
|
||||||
|
assertThat(line.getQuantity()).isEqualTo(7L);
|
||||||
|
|
||||||
|
var error = assertThrows(ResponseStatusException.class, () -> service.mergeBoxes(identity, boxMerge("next-click", 10L)));
|
||||||
|
assertThat(error.getStatusCode().value()).isEqualTo(409);
|
||||||
|
assertThat(error.getReason()).contains("库存已变化");
|
||||||
|
assertThat(line.getQuantity()).isEqualTo(7L);
|
||||||
|
verify(cartons, org.mockito.Mockito.times(1)).insert(any(ReturnInventoryCarton.class));
|
||||||
|
verify(operations, org.mockito.Mockito.times(1)).insert(any(ReturnInventoryOperation.class));
|
||||||
|
|
||||||
|
service.mergeBoxes(identity, boxMerge("rescanned", 7L));
|
||||||
|
assertThat(line.getQuantity()).isEqualTo(4L);
|
||||||
|
verify(cartons, org.mockito.Mockito.times(2)).insert(any(ReturnInventoryCarton.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void boxMergeRejectsMissingSnapshotBeforeInventoryAccess() {
|
||||||
|
var request = new ReturnInventoryRequests.BoxMerge(List.of("RC-SOURCE"), null, "missing", null,
|
||||||
|
BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, null);
|
||||||
|
var error = assertThrows(ResponseStatusException.class, () -> service.mergeBoxes(new PdaWarehouseIdentity("worker", "作业员", 42L), request));
|
||||||
|
assertThat(error.getStatusCode().value()).isEqualTo(400);
|
||||||
|
verifyNoInteractions(cartons, cartonItems, balances);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建同一实物扣三件的请求,快照与请求键按场景独立变化。 */
|
||||||
|
private ReturnInventoryRequests.BoxMerge boxMerge(String key, long expectedQuantity) {
|
||||||
|
return new ReturnInventoryRequests.BoxMerge(List.of("RC-SOURCE"), null, key,
|
||||||
|
List.of(new ReturnInventoryRequests.SourceDeduction("RC-SOURCE", "SKU-A", 3L)),
|
||||||
|
BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE,
|
||||||
|
List.of(new ReturnInventoryRequests.SourceQuantity("RC-SOURCE", "SKU-A", expectedQuantity)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void confirmingPhysicalLabelIsIdempotentAndBoundToWarehouse() {
|
void confirmingPhysicalLabelIsIdempotentAndBoundToWarehouse() {
|
||||||
var source = new ReturnInventoryCarton(); source.setId(31L); source.setCartonMark("RC-SOURCE");
|
var source = new ReturnInventoryCarton(); source.setId(31L); source.setCartonMark("RC-SOURCE");
|
||||||
|
|||||||
+36
-14
@@ -60,7 +60,7 @@ class ReturnReceiptServiceTest {
|
|||||||
for (String code : List.of("中文包裹", "PK-中文")) {
|
for (String code : List.of("中文包裹", "PK-中文")) {
|
||||||
var request = new PdaReturnReceiptRequests.Confirm("RT-1", null, "RETURN_NO", null,
|
var request = new PdaReturnReceiptRequests.Confirm("RT-1", null, "RETURN_NO", null,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU1", 1)), "INVALID-CODE", "PARCEL", code,
|
List.of(new PdaReturnReceiptRequests.Item("SKU1", 1)), "INVALID-CODE", "PARCEL", code,
|
||||||
java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, null, true);
|
java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, null, true, 0L);
|
||||||
assertThat(assertThrows(ResponseStatusException.class, () -> service.confirm(identity, request)).getReason())
|
assertThat(assertThrows(ResponseStatusException.class, () -> service.confirm(identity, request)).getReason())
|
||||||
.contains("实物编码无法生成条码");
|
.contains("实物编码无法生成条码");
|
||||||
}
|
}
|
||||||
@@ -435,7 +435,7 @@ class ReturnReceiptServiceTest {
|
|||||||
ReturnOrderItem second = item(12L, "SKU-B", 2, 0);
|
ReturnOrderItem second = item(12L, "SKU-B", 2, 0);
|
||||||
stubNewReceipt(order, List.of(first, second), "RC-1");
|
stubNewReceipt(order, List.of(first, second), "RC-1");
|
||||||
|
|
||||||
var result = service.confirm(identity, confirm("RETURN_NO", "TRACK-1", "RC-1", "key-1",
|
var result = service.confirm(identity, confirm("RETURN_NO", "TRACK-1", "RC-1", "key-1", 1,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1))));
|
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1))));
|
||||||
|
|
||||||
assertFalse(result.fullyMatched());
|
assertFalse(result.fullyMatched());
|
||||||
@@ -464,7 +464,7 @@ class ReturnReceiptServiceTest {
|
|||||||
ReturnOrder order = order("RT-1", "10", ReturnReceiptService.PARTIALLY_RECEIVED, 2, 1);
|
ReturnOrder order = order("RT-1", "10", ReturnReceiptService.PARTIALLY_RECEIVED, 2, 1);
|
||||||
ReturnOrderItem line = item(11L, "SKU-A", 2, 1);
|
ReturnOrderItem line = item(11L, "SKU-A", 2, 1);
|
||||||
stubNewReceipt(order, List.of(line), "RC-AUTO");
|
stubNewReceipt(order, List.of(line), "RC-AUTO");
|
||||||
var request = confirm("SKU", null, "RC-AUTO", "key-final",
|
var request = confirm("SKU", null, "RC-AUTO", "key-final", 1,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
||||||
|
|
||||||
var first = service.confirm(identity, request);
|
var first = service.confirm(identity, request);
|
||||||
@@ -489,7 +489,7 @@ class ReturnReceiptServiceTest {
|
|||||||
stubNewReceipt(order, List.of(line), "SP-SOURCE");
|
stubNewReceipt(order, List.of(line), "SP-SOURCE");
|
||||||
var request = new PdaReturnReceiptRequests.Confirm("RT-1", null, "SKU", null,
|
var request = new PdaReturnReceiptRequests.Confirm("RT-1", null, "SKU", null,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)), "parcel-key",
|
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)), "parcel-key",
|
||||||
"PARCEL", null, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, null, true);
|
"PARCEL", null, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, null, true, 0L);
|
||||||
var result = service.confirm(identity, request);
|
var result = service.confirm(identity, request);
|
||||||
var capture = ArgumentCaptor.forClass(ReturnReceipt.class);
|
var capture = ArgumentCaptor.forClass(ReturnReceipt.class);
|
||||||
verify(receipts).insert(capture.capture());
|
verify(receipts).insert(capture.capture());
|
||||||
@@ -514,7 +514,7 @@ class ReturnReceiptServiceTest {
|
|||||||
when(orderItems.lockOrder(1L)).thenReturn(List.of(line));
|
when(orderItems.lockOrder(1L)).thenReturn(List.of(line));
|
||||||
|
|
||||||
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
||||||
confirm("RETURN_NO", null, null, "key-over", List.of(new PdaReturnReceiptRequests.Item("SKU-A", 2)))));
|
confirm("RETURN_NO", null, null, "key-over", 1, List.of(new PdaReturnReceiptRequests.Item("SKU-A", 2)))));
|
||||||
|
|
||||||
assertEquals(409, error.getStatusCode().value());
|
assertEquals(409, error.getStatusCode().value());
|
||||||
verify(receipts, never()).insert(any(ReturnReceipt.class));
|
verify(receipts, never()).insert(any(ReturnReceipt.class));
|
||||||
@@ -527,7 +527,7 @@ class ReturnReceiptServiceTest {
|
|||||||
when(orders.lockNo("RT-1")).thenReturn(order);
|
when(orders.lockNo("RT-1")).thenReturn(order);
|
||||||
|
|
||||||
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
||||||
confirm("RETURN_NO", null, null, "key-cross", List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
confirm("RETURN_NO", null, null, "key-cross", 0, List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
||||||
|
|
||||||
assertEquals(404, error.getStatusCode().value());
|
assertEquals(404, error.getStatusCode().value());
|
||||||
verify(orderItems, never()).lockOrder(any());
|
verify(orderItems, never()).lockOrder(any());
|
||||||
@@ -539,7 +539,7 @@ class ReturnReceiptServiceTest {
|
|||||||
ReturnOrder order = order("RT-1", "10", ReturnReceiptService.PENDING_RECEIPT, 2, 0);
|
ReturnOrder order = order("RT-1", "10", ReturnReceiptService.PENDING_RECEIPT, 2, 0);
|
||||||
ReturnOrderItem line = item(11L, "SKU-A", 2, 0);
|
ReturnOrderItem line = item(11L, "SKU-A", 2, 0);
|
||||||
stubNewReceipt(order, List.of(line), "RC-1");
|
stubNewReceipt(order, List.of(line), "RC-1");
|
||||||
var original = confirm("RETURN_NO", "TRACK-1", "RC-1", "key-1",
|
var original = confirm("RETURN_NO", "TRACK-1", "RC-1", "key-1", 0,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
||||||
service.confirm(identity, original);
|
service.confirm(identity, original);
|
||||||
ArgumentCaptor<ReturnReceipt> savedReceipt = ArgumentCaptor.forClass(ReturnReceipt.class);
|
ArgumentCaptor<ReturnReceipt> savedReceipt = ArgumentCaptor.forClass(ReturnReceipt.class);
|
||||||
@@ -547,7 +547,7 @@ class ReturnReceiptServiceTest {
|
|||||||
when(receipts.lockKey("operator-1", "key-1")).thenReturn(savedReceipt.getValue());
|
when(receipts.lockKey("operator-1", "key-1")).thenReturn(savedReceipt.getValue());
|
||||||
|
|
||||||
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
||||||
confirm("RETURN_NO", "TRACK-CHANGED", "RC-1", "key-1",
|
confirm("RETURN_NO", "TRACK-CHANGED", "RC-1", "key-1", 0,
|
||||||
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
||||||
|
|
||||||
assertEquals(409, error.getStatusCode().value());
|
assertEquals(409, error.getStatusCode().value());
|
||||||
@@ -555,6 +555,29 @@ class ReturnReceiptServiceTest {
|
|||||||
verify(batches, times(1)).insert(any(ReturnReceiptBatch.class));
|
verify(batches, times(1)).insert(any(ReturnReceiptBatch.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void freshKeyAfterLostResponseCannotCountTheSameSnapshotTwice() {
|
||||||
|
ReturnOrder order = order("RT-1", "10", ReturnReceiptService.PENDING_RECEIPT, 10, 0);
|
||||||
|
ReturnOrderItem line = item(11L, "SKU-A", 10, 0);
|
||||||
|
stubNewReceipt(order, List.of(line), "RC-1");
|
||||||
|
var items = List.of(new PdaReturnReceiptRequests.Item("SKU-A", 2));
|
||||||
|
|
||||||
|
service.confirm(identity, confirm("SKU", null, null, "first-click", 0, items));
|
||||||
|
var stale = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
||||||
|
confirm("SKU", null, null, "new-click", 0, items)));
|
||||||
|
|
||||||
|
assertEquals(409, stale.getStatusCode().value());
|
||||||
|
assertThat(stale.getReason()).contains("实收数量已变化");
|
||||||
|
assertEquals(2, line.getReceivedQuantity());
|
||||||
|
verify(inventory, times(1)).createReceiptCarton(any(), any(), any(), any());
|
||||||
|
verify(receipts, times(1)).insert(any(ReturnReceipt.class));
|
||||||
|
verify(batches, times(1)).insert(any(ReturnReceiptBatch.class));
|
||||||
|
|
||||||
|
var next = service.confirm(identity, confirm("SKU", null, null, "after-refresh", 2, items));
|
||||||
|
assertEquals(4, next.receivedQuantity());
|
||||||
|
verify(inventory, times(2)).createReceiptCarton(any(), any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
private void stubNewReceipt(ReturnOrder order, List<ReturnOrderItem> items, String cartonMark) {
|
private void stubNewReceipt(ReturnOrder order, List<ReturnOrderItem> items, String cartonMark) {
|
||||||
when(orders.lockNo("RT-1")).thenReturn(order);
|
when(orders.lockNo("RT-1")).thenReturn(order);
|
||||||
when(orderItems.lockOrder(1L)).thenReturn(items);
|
when(orderItems.lockOrder(1L)).thenReturn(items);
|
||||||
@@ -568,7 +591,7 @@ class ReturnReceiptServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sameKeyCommittedWhileWaitingForOrderLockReplaysCompletedReceipt() throws Exception {
|
void sameKeyCommittedWhileWaitingForOrderLockReplaysCompletedReceipt() throws Exception {
|
||||||
var request = confirm("RETURN_NO", null, null, "concurrent-key", List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
var request = confirm("RETURN_NO", null, null, "concurrent-key", 0, List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)));
|
||||||
ReturnOrder completed = order("RT-1", "10", ReturnReceiptService.COMPLETED, 1, 1);
|
ReturnOrder completed = order("RT-1", "10", ReturnReceiptService.COMPLETED, 1, 1);
|
||||||
ReturnReceipt committed = new ReturnReceipt();
|
ReturnReceipt committed = new ReturnReceipt();
|
||||||
committed.setReceiptNo("RR-COMMITTED"); committed.setReceiptBatchNo("RB-COMMITTED"); committed.setPalletCode("RC-COMMITTED");
|
committed.setReceiptNo("RR-COMMITTED"); committed.setReceiptBatchNo("RB-COMMITTED"); committed.setPalletCode("RC-COMMITTED");
|
||||||
@@ -597,7 +620,7 @@ class ReturnReceiptServiceTest {
|
|||||||
ReturnReceipt committed = new ReturnReceipt(); committed.setRequestHash("different-content");
|
ReturnReceipt committed = new ReturnReceipt(); committed.setRequestHash("different-content");
|
||||||
when(receipts.lockKey("operator-1", "concurrent-key")).thenReturn(committed);
|
when(receipts.lockKey("operator-1", "concurrent-key")).thenReturn(committed);
|
||||||
var error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
var error = assertThrows(ResponseStatusException.class, () -> service.confirm(identity,
|
||||||
confirm("RETURN_NO", null, null, "concurrent-key", List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
confirm("RETURN_NO", null, null, "concurrent-key", 0, List.of(new PdaReturnReceiptRequests.Item("SKU-A", 1)))));
|
||||||
assertEquals(409, error.getStatusCode().value());
|
assertEquals(409, error.getStatusCode().value());
|
||||||
verifyNoInteractions(inventory, batches, orderItems);
|
verifyNoInteractions(inventory, batches, orderItems);
|
||||||
}
|
}
|
||||||
@@ -640,13 +663,12 @@ class ReturnReceiptServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static PdaReturnReceiptRequests.Confirm confirm(String startedBy, String trackingNo, String palletCode,
|
private static PdaReturnReceiptRequests.Confirm confirm(String startedBy, String trackingNo, String palletCode,
|
||||||
String key, List<PdaReturnReceiptRequests.Item> items) {
|
String key, long expectedReceivedQuantity, List<PdaReturnReceiptRequests.Item> items) {
|
||||||
List<PdaReturnReceiptRequests.Item> boxed = items.stream()
|
List<PdaReturnReceiptRequests.Item> boxed = items.stream()
|
||||||
.map(item -> new PdaReturnReceiptRequests.Item(item.skuCode(), item.receivedQuantity(), 1L)).toList();
|
.map(item -> new PdaReturnReceiptRequests.Item(item.skuCode(), item.receivedQuantity(), 1L)).toList();
|
||||||
// These focused tests exercise receipt/idempotency behavior at the
|
// 本组测试验证单箱签收和幂等行为;托盘多箱由独立合同覆盖。
|
||||||
// carton level. Pallet receipts have a separate multi-carton contract.
|
|
||||||
return new PdaReturnReceiptRequests.Confirm("RT-1", trackingNo, startedBy, palletCode, boxed, key,
|
return new PdaReturnReceiptRequests.Confirm("RT-1", trackingNo, startedBy, palletCode, boxed, key,
|
||||||
"BOX", palletCode, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, 1L, true);
|
"BOX", palletCode, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, java.math.BigDecimal.ONE, 1L, true, expectedReceivedQuantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,6 +226,10 @@ PDA 待复核通过后,`manual-loading-complete-fixture.mjs` 冻结无证据
|
|||||||
|
|
||||||
`fee-items` 需要同一 marker 的客户订单和入库单。执行 `--modules fee-items` 时,入口自动扩展为 `merchant-qualification-fixture,orders,fee-items`,无需手工补齐前置模块。
|
`fee-items` 需要同一 marker 的客户订单和入库单。执行 `--modules fee-items` 时,入口自动扩展为 `merchant-qualification-fixture,orders,fee-items`,无需手工补齐前置模块。
|
||||||
|
|
||||||
|
固定客户模式下 `fee-items` 只查询现有费用目录、核对112条正式基线及客户权限,不新增、编辑或删除费用主档,增删改生命周期单独记录为未覆盖。所有模式均不自动删除历史 `ACPT_` 项目;非固定模式的隔离写入仅清理本轮返回的项目和明细 ID。
|
||||||
|
|
||||||
|
`finance-full-fixtures` 在固定客户模式下只复用已有不包税计费规则:唯一规则或唯一默认规则必须属于当前客户并匹配所需计费方式;缺失、不匹配或默认规则有歧义即停止,不自动创建规则版本或切换默认规则。供应商同样复用既有启用记录;下述创建隔离供应商的说明仅适用于非固定客户模式。
|
||||||
|
|
||||||
模块只需导出:
|
模块只需导出:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
|
|||||||
import test from 'node:test'
|
import test from 'node:test'
|
||||||
|
|
||||||
import { normalizeModuleOrder, parseArguments } from '../admin-test-env-acceptance.mjs'
|
import { normalizeModuleOrder, parseArguments } from '../admin-test-env-acceptance.mjs'
|
||||||
import { cleanupSucceeded, isAcceptanceFeeItem, formalFeeItems } from './fee-items.mjs'
|
import { cleanupSucceeded, formalFeeItems, run } from './fee-items.mjs'
|
||||||
|
|
||||||
const source = readFileSync(new URL('./fee-items.mjs', import.meta.url), 'utf8')
|
const source = readFileSync(new URL('./fee-items.mjs', import.meta.url), 'utf8')
|
||||||
|
|
||||||
@@ -23,15 +23,44 @@ test('cleanup treats successful deletion and an already absent resource as clean
|
|||||||
assert.equal(cleanupSucceeded({ http: 200, body: { code: 'A0422' } }), false)
|
assert.equal(cleanupSucceeded({ http: 200, body: { code: 'A0422' } }), false)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('stale cleanup only recognizes the acceptance-owned code and name pair', () => {
|
test('no automatic historical fee-item cleanup remains', () => {
|
||||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'ACPT_813083345572', feeTypeName: '全量验收费用-813083345572-已编辑' }), true)
|
assert.doesNotMatch(source, /cleanupStaleAcceptanceItems|isAcceptanceFeeItem/)
|
||||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'FEE_TYPE_001', feeTypeName: '全量验收费用-001' }), false)
|
|
||||||
assert.equal(isAcceptanceFeeItem({ feeCode: 'ACPT_813083345572', feeTypeName: '正式费用项目' }), false)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('baseline checks run only after stale acceptance cleanup', () => {
|
for (const missingBaseline of [false, true]) test(`fixed fee catalogue preserves old test items and performs no master writes; missing=${missingBaseline}`, async () => {
|
||||||
assert.ok(source.indexOf('cleanupStaleAcceptanceItems(context)')
|
const codes = ['FBA_HEAD_FREIGHT', 'PRIVATE_LAST_MILE_DELIVERY', ...Array.from({ length: 110 }, (_, i) => `FEE_TYPE_${String(i + 1).padStart(3, '0')}`)]
|
||||||
< source.indexOf("'全部目录默认20条分页与完整列表一致'"))
|
const catalogue = codes.map((feeCode, i) => ({ id: String(i + 1), feeCode, tenantId: '0', status: 'ACTIVE',
|
||||||
|
tradeScope: i < 84 ? 'DOMESTIC' : 'INTERNATIONAL', category: '标准', feeTypeName: `费用${i}` }))
|
||||||
|
catalogue.push({ id: '999', feeCode: 'ACPT_123456', feeTypeName: '全量验收费用-123456', tenantId: '0', status: 'DISABLED', category: '临时', tradeScope: 'DOMESTIC' })
|
||||||
|
if (missingBaseline) catalogue.splice(3, 1)
|
||||||
|
const calls = [], gaps = []
|
||||||
|
const context = { options: { fixedCustomerId: '101' }, marker: 'TEST', createdResources: {},
|
||||||
|
async request(method, path, body, token) {
|
||||||
|
calls.push({ method, path })
|
||||||
|
const response = data => ({ http: 200, path, body: { code: '200', data } })
|
||||||
|
if (path === '/api/auth/login') return response({ accessToken: 'client', refreshToken: 'refresh' })
|
||||||
|
if (path === '/api/auth/logout') return response({})
|
||||||
|
assert.equal(method, 'GET')
|
||||||
|
if (token === 'client') return { http: 403, body: { code: 'A0403' } }
|
||||||
|
const params = new URL(path, 'https://test.invalid').searchParams
|
||||||
|
const selected = catalogue.filter(row => ['category', 'tradeScope', 'status'].every(key => !params.has(key) || row[key] === params.get(key))
|
||||||
|
&& (!params.has('keyword') || row.feeTypeName.includes(params.get('keyword'))))
|
||||||
|
const size = Number(params.get('size')), page = Number(params.get('page'))
|
||||||
|
return response({ records: selected.slice((page - 1) * size, page * size), total: selected.length, page, size, pages: Math.ceil(selected.length / size) })
|
||||||
|
}, apiSuccess(_m, _n, response) { return response.body.data },
|
||||||
|
assert(_m, name, _r, passed) { assert.ok(passed, name) },
|
||||||
|
addCoverageGap(...args) { gaps.push(args) },
|
||||||
|
}
|
||||||
|
const before = structuredClone(catalogue)
|
||||||
|
if (missingBaseline) await assert.rejects(run(context), /112条/)
|
||||||
|
else {
|
||||||
|
await run(context)
|
||||||
|
assert.equal(context.createdResources.feeItems.mode, 'READ_ONLY')
|
||||||
|
assert.equal(gaps.length, 1)
|
||||||
|
assert.equal(calls.filter(row => row.path === '/api/auth/logout').length, 1)
|
||||||
|
}
|
||||||
|
assert.deepEqual(catalogue, before)
|
||||||
|
assert.ok(calls.every(row => row.method === 'GET' || row.path.startsWith('/api/auth/')))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('正式费用按编码识别,扩展停用项目保留且不掩盖缺失正式编码', () => {
|
test('正式费用按编码识别,扩展停用项目保留且不掩盖缺失正式编码', () => {
|
||||||
|
|||||||
@@ -56,10 +56,6 @@ export function formalFeeItems(rows) {
|
|||||||
const codes = new Set(expectedCodes())
|
const codes = new Set(expectedCodes())
|
||||||
return rows.filter(row => codes.has(row.feeCode))
|
return rows.filter(row => codes.has(row.feeCode))
|
||||||
}
|
}
|
||||||
export function isAcceptanceFeeItem(row) {
|
|
||||||
return /^ACPT_\d+$/.test(String(row?.feeCode || ''))
|
|
||||||
&& String(row?.feeTypeName || '').startsWith('全量验收费用-')
|
|
||||||
}
|
|
||||||
function fixture(context) {
|
function fixture(context) {
|
||||||
const candidates = [context.createdResources?.orders, context.createdResources?.testInbound,
|
const candidates = [context.createdResources?.orders, context.createdResources?.testInbound,
|
||||||
context.createdResources?.inboundMeasurement, context.context?.testInbound]
|
context.createdResources?.inboundMeasurement, context.context?.testInbound]
|
||||||
@@ -73,26 +69,7 @@ async function listAll(context) {
|
|||||||
return { response, page, rows: records(page) }
|
return { response, page, rows: records(page) }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanupStaleAcceptanceItems(context) {
|
|
||||||
const listed = await listAll(context)
|
|
||||||
const stale = listed.rows.filter(isAcceptanceFeeItem)
|
|
||||||
const failed = []
|
|
||||||
for (const row of stale) {
|
|
||||||
const response = await context.request('DELETE', `${BASE}/${encodeURIComponent(id(row.id))}`)
|
|
||||||
if (!cleanupSucceeded(response)) failed.push({ row, response })
|
|
||||||
}
|
|
||||||
const response = failed[0]?.response || listed.response
|
|
||||||
context.assert(MODULE, '前置清理历史验收临时费用项目', response, failed.length === 0,
|
|
||||||
failed.length === 0
|
|
||||||
? `stale=${stale.length}, cleaned=${stale.length}`
|
|
||||||
: `failed=${failed.map(({ row, response: failure }) => `${row.feeCode}:${failure.body?.code || failure.http}`).join(',')}`,
|
|
||||||
OPTIONS)
|
|
||||||
return failed.length === 0
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function run(context) {
|
export async function run(context) {
|
||||||
if (!await cleanupStaleAcceptanceItems(context)) return
|
|
||||||
|
|
||||||
const initialPageResponse = await context.request('GET', query({ page: 1, size: 20 }))
|
const initialPageResponse = await context.request('GET', query({ page: 1, size: 20 }))
|
||||||
const initialPage = context.apiSuccess(MODULE, '费用项目查看权限与分页查询', initialPageResponse,
|
const initialPage = context.apiSuccess(MODULE, '费用项目查看权限与分页查询', initialPageResponse,
|
||||||
'page=1,size=20', OPTIONS)
|
'page=1,size=20', OPTIONS)
|
||||||
@@ -158,12 +135,26 @@ export async function run(context) {
|
|||||||
}, '')
|
}, '')
|
||||||
const merchantLogin = success(merchantLoginResponse) ? merchantLoginResponse.body?.data : null
|
const merchantLogin = success(merchantLoginResponse) ? merchantLoginResponse.body?.data : null
|
||||||
const merchantToken = merchantLogin?.accessToken
|
const merchantToken = merchantLogin?.accessToken
|
||||||
|
try {
|
||||||
const forbiddenResponse = merchantToken
|
const forbiddenResponse = merchantToken
|
||||||
? await context.request('GET', query({ page: 1, size: 20 }), undefined, merchantToken)
|
? await context.request('GET', query({ page: 1, size: 20 }), undefined, merchantToken)
|
||||||
: merchantLoginResponse
|
: merchantLoginResponse
|
||||||
context.assert(MODULE, '无费用项目平台权限的客户账号被拒绝', forbiddenResponse,
|
context.assert(MODULE, '无费用项目平台权限的客户账号被拒绝', forbiddenResponse,
|
||||||
Boolean(merchantToken) && forbidden(forbiddenResponse),
|
Boolean(merchantToken) && forbidden(forbiddenResponse),
|
||||||
`HTTP=${forbiddenResponse.http}, code=${forbiddenResponse.body?.code ?? 'missing'}`, OPTIONS)
|
`HTTP=${forbiddenResponse.http}, code=${forbiddenResponse.body?.code ?? 'missing'}`, OPTIONS)
|
||||||
|
} finally {
|
||||||
|
if (merchantToken && merchantLogin.refreshToken) {
|
||||||
|
const logout = await context.request('POST', '/api/auth/logout', { refreshToken: merchantLogin.refreshToken }, merchantToken)
|
||||||
|
context.assert(MODULE, '退出费用目录权限核验会话', logout, success(logout), '', OPTIONS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.options?.fixedCustomerId) {
|
||||||
|
context.createdResources.feeItems = { marker: context.marker, mode: 'READ_ONLY', baselineCount: initialRows.length }
|
||||||
|
context.addCoverageGap(MODULE, 'fixed-fee-item-lifecycle', '费用项目增删改生命周期',
|
||||||
|
'固定客户模式只读核对现有费用目录,不创建、修改或删除公共主档及历史测试项目', 'not-implemented', { blocking: false })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const suffix = context.marker.replace(/\D/g, '').slice(-12)
|
const suffix = context.marker.replace(/\D/g, '').slice(-12)
|
||||||
const createPayload = payload(suffix)
|
const createPayload = payload(suffix)
|
||||||
|
|||||||
@@ -4,7 +4,33 @@ import fs from 'node:fs'
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import { buildContainerCostBody, buildSupplierBody, normalizeFinanceFixtureSources, run,
|
import { buildContainerCostBody, buildSupplierBody, normalizeFinanceFixtureSources, run,
|
||||||
supplierCategoryForFeeItem, loadSupplier } from './finance-full-fixtures.mjs'
|
supplierCategoryForFeeItem, loadSupplier, ensureCustomerChargeRule } from './finance-full-fixtures.mjs'
|
||||||
|
|
||||||
|
for (const mode of ['single', 'default', 'missing', 'wrong mode', 'foreign customer', 'ambiguous', 'two defaults']) {
|
||||||
|
test(`fixed customer charge rules are read-only and fail closed: ${mode}`, async () => {
|
||||||
|
const good = { id: '701', customerId: '456', status: 'ACTIVE', businessType: 'FBA', taxMode: 'TAX_EXCLUDED', chargeMode: 'CBM', defaultRule: false }
|
||||||
|
let rules = [good]
|
||||||
|
if (mode === 'default') rules = [{ ...good, defaultRule: true }, { ...good, id: '702', chargeMode: 'KG' }]
|
||||||
|
if (mode === 'missing') rules = []
|
||||||
|
if (mode === 'wrong mode') rules = [{ ...good, chargeMode: 'KG' }]
|
||||||
|
if (mode === 'foreign customer') rules = [{ ...good, customerId: '999' }]
|
||||||
|
if (mode === 'ambiguous') rules = [good, { ...good, id: '702', chargeMode: 'KG' }]
|
||||||
|
if (mode === 'two defaults') rules = [{ ...good, defaultRule: true }, { ...good, id: '702', defaultRule: true }]
|
||||||
|
const calls = [], checks = [], before = structuredClone(rules)
|
||||||
|
const context = { options: { fixedCustomerId: '456' },
|
||||||
|
async request(method, path) { calls.push({ method, path }); assert.equal(method, 'GET');
|
||||||
|
return { body: { data: path.includes('/inbounds/') ? { summary: { businessType: 'FBA' } } : rules } } },
|
||||||
|
apiSuccess(_m, _n, response) { return response.body.data },
|
||||||
|
assert(_m, _n, _r, passed) { checks.push(passed) },
|
||||||
|
}
|
||||||
|
const invoke = () => ensureCustomerChargeRule(context, { tenantId: '456', inboundId: '100' }, { pricingTaxMode: 'TAX_EXCLUDED', chargeUnit: 'CBM' })
|
||||||
|
if (['single', 'default'].includes(mode)) assert.equal((await invoke()).id, '701')
|
||||||
|
else await assert.rejects(invoke(), /禁止自动创建或切换/)
|
||||||
|
assert.deepEqual(rules, before)
|
||||||
|
assert.equal(calls.length, 2)
|
||||||
|
assert.equal(checks.at(-1), ['single', 'default'].includes(mode))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
test('fixed customer supplier selection paginates and never creates a fallback', async () => {
|
test('fixed customer supplier selection paginates and never creates a fallback', async () => {
|
||||||
const calls = [], failures = []
|
const calls = [], failures = []
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ async function loadPricingEvidence(context) {
|
|||||||
return { activeVersionIds: active.map((item) => id(item.id)).filter(Boolean), profiles }
|
return { activeVersionIds: active.map((item) => id(item.id)).filter(Boolean), profiles }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureCustomerChargeRule(context, resource, profile) {
|
export async function ensureCustomerChargeRule(context, resource, profile) {
|
||||||
if (context.financeFixtureHooks?.ensureCustomerChargeRule) {
|
if (context.financeFixtureHooks?.ensureCustomerChargeRule) {
|
||||||
return context.financeFixtureHooks.ensureCustomerChargeRule(context, resource, profile)
|
return context.financeFixtureHooks.ensureCustomerChargeRule(context, resource, profile)
|
||||||
}
|
}
|
||||||
@@ -389,6 +389,15 @@ async function ensureCustomerChargeRule(context, resource, profile) {
|
|||||||
const applicable = rows(listed).filter((rule) => rule?.status === 'ACTIVE'
|
const applicable = rows(listed).filter((rule) => rule?.status === 'ACTIVE'
|
||||||
&& rule?.businessType === businessType && rule?.taxMode === 'TAX_EXCLUDED')
|
&& rule?.businessType === businessType && rule?.taxMode === 'TAX_EXCLUDED')
|
||||||
let desired = applicable.find((rule) => rule?.chargeMode === profile.chargeUnit)
|
let desired = applicable.find((rule) => rule?.chargeMode === profile.chargeUnit)
|
||||||
|
if (context.options?.fixedCustomerId) {
|
||||||
|
const defaults = applicable.filter(rule => rule.defaultRule === true)
|
||||||
|
const selected = applicable.length === 1 ? applicable[0] : defaults.length === 1 ? defaults[0] : null
|
||||||
|
const valid = selected?.id && id(selected.customerId) === tenantId && selected.chargeMode === profile.chargeUnit
|
||||||
|
context.assert(MODULE, '固定客户复用现有有效默认计费方式', listResponse, Boolean(valid),
|
||||||
|
`customerId=${tenantId}, chargeMode=${profile.chargeUnit}`, OPTIONS)
|
||||||
|
if (!valid) throw new Error('固定客户缺少匹配且无歧义的计费规则,禁止自动创建或切换默认规则')
|
||||||
|
return selected
|
||||||
|
}
|
||||||
if (!desired) {
|
if (!desired) {
|
||||||
const effectiveFrom = new Date(Date.now() - 86_400_000).toISOString().slice(0, 19)
|
const effectiveFrom = new Date(Date.now() - 86_400_000).toISOString().slice(0, 19)
|
||||||
const body = {
|
const body = {
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ const acceptanceUrl = new URL('../admin-test-env-acceptance.mjs', import.meta.ur
|
|||||||
|
|
||||||
test('both pallet receipt batches supply SKU box counts and measured pallet fields', () => {
|
test('both pallet receipt batches supply SKU box counts and measured pallet fields', () => {
|
||||||
for (const [sku, quantity, startedBy] of [['A', 3, 'RETURN_NO'], ['B', 2, 'SKU']]) {
|
for (const [sku, quantity, startedBy] of [['A', 3, 'RETURN_NO'], ['B', 2, 'SKU']]) {
|
||||||
const body = palletReceiptBody('RT-1', `P-${sku}`, sku, quantity, `KEY-${sku}`, startedBy)
|
const body = palletReceiptBody('RT-1', `P-${sku}`, sku, quantity, `KEY-${sku}`, startedBy, sku === 'A' ? 0 : 3)
|
||||||
assert.equal(body.unitType, 'PALLET')
|
assert.equal(body.unitType, 'PALLET')
|
||||||
assert.equal(body.unitCode, `P-${sku}`)
|
assert.equal(body.unitCode, `P-${sku}`)
|
||||||
assert.equal(body.palletCode, body.unitCode)
|
assert.equal(body.palletCode, body.unitCode)
|
||||||
assert.equal(body.startedBy, startedBy)
|
assert.equal(body.startedBy, startedBy)
|
||||||
|
assert.equal(body.expectedReceivedQuantity, sku === 'A' ? 0 : 3)
|
||||||
assert.deepEqual(body.items, [{ skuCode: sku, receivedQuantity: quantity, boxCount: 1 }])
|
assert.deepEqual(body.items, [{ skuCode: sku, receivedQuantity: quantity, boxCount: 1 }])
|
||||||
for (const field of ['length', 'width', 'height', 'weight']) assert.ok(body[field] > 0)
|
for (const field of ['length', 'width', 'height', 'weight']) assert.ok(body[field] > 0)
|
||||||
assert.equal(body.totalBoxCount, undefined, 'server derives the total from SKU box counts')
|
assert.equal(body.totalBoxCount, undefined, 'server derives the total from SKU box counts')
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
|| !success(palletB.response) || !nonBlank(palletB.data?.palletCode)) throw new Error('签收托盘准备失败')
|
|| !success(palletB.response) || !nonBlank(palletB.data?.palletCode)) throw new Error('签收托盘准备失败')
|
||||||
const palletCodeA = palletA.data.palletCode
|
const palletCodeA = palletA.data.palletCode
|
||||||
const firstBody = {
|
const firstBody = {
|
||||||
...palletReceiptBody(returnNo, palletCodeA, skuA, 3, key(context, 'RECEIPT-1'), 'RETURN_NO'),
|
...palletReceiptBody(returnNo, palletCodeA, skuA, 3, key(context, 'RECEIPT-1'), 'RETURN_NO', 0),
|
||||||
trackingNo: `TRACK-${suffix}`,
|
trackingNo: `TRACK-${suffix}`,
|
||||||
}
|
}
|
||||||
const first = await overseas(context, picker.token, 'POST', 'PDA首次单SKU签收甲3件', `${PDA_RECEIPTS}/confirm`, firstBody)
|
const first = await overseas(context, picker.token, 'POST', 'PDA首次单SKU签收甲3件', `${PDA_RECEIPTS}/confirm`, firstBody)
|
||||||
@@ -291,7 +291,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
|
|
||||||
await reject('超收被拒绝且不得生成费用批次', conflict, async () => {
|
await reject('超收被拒绝且不得生成费用批次', conflict, async () => {
|
||||||
const body = {
|
const body = {
|
||||||
...palletReceiptBody(returnNo, palletCodeA, skuA, 2, key(context, 'OVER-RECEIPT'), 'SKU'),
|
...palletReceiptBody(returnNo, palletCodeA, skuA, 2, key(context, 'OVER-RECEIPT'), 'SKU', 3),
|
||||||
}
|
}
|
||||||
let response = null
|
let response = null
|
||||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||||
@@ -310,7 +310,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
['非法签收方式', { startedBy: 'INVALID' }, validationFailure],
|
['非法签收方式', { startedBy: 'INVALID' }, validationFailure],
|
||||||
['未预报SKU', { items: [{ skuCode: `UNKNOWN-${suffix}`, receivedQuantity: 1, boxCount: 1 }] }, conflict],
|
['未预报SKU', { items: [{ skuCode: `UNKNOWN-${suffix}`, receivedQuantity: 1, boxCount: 1 }] }, conflict],
|
||||||
]) {
|
]) {
|
||||||
await reject(`拒绝${name}`, expected, () => context.request('POST', `${PDA_RECEIPTS}/confirm`, { ...firstBody, ...changes, idempotencyKey: key(context, `INVALID-RECEIPT-${encodeURIComponent(name)}`) }, picker.token, {}))
|
await reject(`拒绝${name}`, expected, () => context.request('POST', `${PDA_RECEIPTS}/confirm`, { ...firstBody, expectedReceivedQuantity: 3, ...changes, idempotencyKey: key(context, `INVALID-RECEIPT-${encodeURIComponent(name)}`) }, picker.token, {}))
|
||||||
}
|
}
|
||||||
await reject('部分签收退货单禁止合箱', conflict, () => context.request('POST', '/api/pda/v1/last-leg/return-inventory/cartons/merge', {
|
await reject('部分签收退货单禁止合箱', conflict, () => context.request('POST', '/api/pda/v1/last-leg/return-inventory/cartons/merge', {
|
||||||
returnNos: [returnNo], items: [{ skuCode: skuA, quantity: 1 }], length: 30, width: 20, height: 10,
|
returnNos: [returnNo], items: [{ skuCode: skuA, quantity: 1 }], length: 30, width: 20, height: 10,
|
||||||
@@ -327,7 +327,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
`receipts=${afterPartial.data?.receipts?.length ?? 'missing'}`, OPTIONS)
|
`receipts=${afterPartial.data?.receipts?.length ?? 'missing'}`, OPTIONS)
|
||||||
|
|
||||||
const secondBody = {
|
const secondBody = {
|
||||||
...palletReceiptBody(returnNo, palletB.data.palletCode, skuB, 2, key(context, 'RECEIPT-2'), 'SKU'),
|
...palletReceiptBody(returnNo, palletB.data.palletCode, skuB, 2, key(context, 'RECEIPT-2'), 'SKU', 3),
|
||||||
}
|
}
|
||||||
const second = await overseas(context, picker.token, 'POST', 'PDA无照片按单SKU完成乙2件签收', `${PDA_RECEIPTS}/confirm`, secondBody)
|
const second = await overseas(context, picker.token, 'POST', 'PDA无照片按单SKU完成乙2件签收', `${PDA_RECEIPTS}/confirm`, secondBody)
|
||||||
if (!success(second.response)) throw new Error('最终签收失败,停止合箱和换标后续')
|
if (!success(second.response)) throw new Error('最终签收失败,停止合箱和换标后续')
|
||||||
@@ -419,6 +419,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
|
|
||||||
const mergeBody = {
|
const mergeBody = {
|
||||||
sourceCartonMarks: [cartonA, cartonB],
|
sourceCartonMarks: [cartonA, cartonB],
|
||||||
|
expectedSourceQuantities: [{ cartonMark: cartonA, skuCode: skuA, quantity: 3 }, { cartonMark: cartonB, skuCode: skuB, quantity: 2 }],
|
||||||
sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 1 }, { cartonMark: cartonB, skuCode: skuB, quantity: 1 }],
|
sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 1 }, { cartonMark: cartonB, skuCode: skuB, quantity: 1 }],
|
||||||
length: 30, width: 20, height: 10, weight: 2, idempotencyKey: key(context, 'MERGE'),
|
length: 30, width: 20, height: 10, weight: 2, idempotencyKey: key(context, 'MERGE'),
|
||||||
}
|
}
|
||||||
@@ -469,7 +470,7 @@ async function runWithSession(context, merchantToken) {
|
|||||||
['空来源箱', { sourceCartonMarks: [] }, validationFailure],
|
['空来源箱', { sourceCartonMarks: [] }, validationFailure],
|
||||||
['零合箱数量', { sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 0 }] }, validationFailure],
|
['零合箱数量', { sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 0 }] }, validationFailure],
|
||||||
['超可用库存', { sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 999 }] }, conflict],
|
['超可用库存', { sourceDeductions: [{ cartonMark: cartonA, skuCode: skuA, quantity: 999 }] }, conflict],
|
||||||
['不存在来源箱', { sourceCartonMarks: [`MISSING-${suffix}`] }, conflict],
|
['不存在来源箱', { sourceCartonMarks: [`MISSING-${suffix}`], expectedSourceQuantities: [{ cartonMark: `MISSING-${suffix}`, skuCode: skuA, quantity: 1 }] }, conflict],
|
||||||
]) {
|
]) {
|
||||||
await reject(`合箱拒绝${name}`, expected, () => context.request('POST', '/api/pda/v1/last-leg/return-inventory/cartons/merge-boxes', { ...mergeBody, ...changes, idempotencyKey: key(context, `INVALID-MERGE-${encodeURIComponent(name)}`) }, picker.token, {}))
|
await reject(`合箱拒绝${name}`, expected, () => context.request('POST', '/api/pda/v1/last-leg/return-inventory/cartons/merge-boxes', { ...mergeBody, ...changes, idempotencyKey: key(context, `INVALID-MERGE-${encodeURIComponent(name)}`) }, picker.token, {}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ export function exactReceiptLedger(data, expected) {
|
|||||||
&& JSON.stringify(stableState(rows(data).map(project))) === JSON.stringify(stableState(expected.map(project)))
|
&& JSON.stringify(stableState(rows(data).map(project))) === JSON.stringify(stableState(expected.map(project)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function palletReceiptBody(returnNo, palletCode, skuCode, receivedQuantity, idempotencyKey, startedBy) {
|
export function palletReceiptBody(returnNo, palletCode, skuCode, receivedQuantity, idempotencyKey, startedBy, expectedReceivedQuantity) {
|
||||||
return {
|
return {
|
||||||
returnNo, palletCode, unitType: 'PALLET', unitCode: palletCode, startedBy,
|
returnNo, palletCode, unitType: 'PALLET', unitCode: palletCode, startedBy, expectedReceivedQuantity,
|
||||||
length: 120, width: 100, height: 80, weight: 10,
|
length: 120, width: 100, height: 80, weight: 10,
|
||||||
items: [{ skuCode, receivedQuantity, boxCount: 1 }], idempotencyKey,
|
items: [{ skuCode, receivedQuantity, boxCount: 1 }], idempotencyKey,
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ export async function runReturnBoundaries(context, { merchantToken, warehouse, p
|
|||||||
}
|
}
|
||||||
function receiptBody(order, quantity = order.quantity, idempotencyKey = key('RECEIPT')) {
|
function receiptBody(order, quantity = order.quantity, idempotencyKey = key('RECEIPT')) {
|
||||||
// 合成包裹明确原包装选择与实测输入,使边界场景进入待验证的库存/并发规则。
|
// 合成包裹明确原包装选择与实测输入,使边界场景进入待验证的库存/并发规则。
|
||||||
return { returnNo: order.returnNo, startedBy: 'RETURN_NO', unitType: 'PARCEL', unitCode: order.unitCode,
|
return { returnNo: order.returnNo, expectedReceivedQuantity: 0, startedBy: 'RETURN_NO', unitType: 'PARCEL', unitCode: order.unitCode,
|
||||||
originalPackaging: true, length: 30, width: 20, height: 10, weight: 2,
|
originalPackaging: true, length: 30, width: 20, height: 10, weight: 2,
|
||||||
items: [{ skuCode: order.sku, receivedQuantity: quantity }], idempotencyKey }
|
items: [{ skuCode: order.sku, receivedQuantity: quantity }], idempotencyKey }
|
||||||
}
|
}
|
||||||
@@ -399,9 +399,9 @@ export async function runReturnBoundaries(context, { merchantToken, warehouse, p
|
|||||||
const withLedger = async () => ({ inventory: await snapshot([order]), ledger: await ledger() })
|
const withLedger = async () => ({ inventory: await snapshot([order]), ledger: await ledger() })
|
||||||
await verifyNoMutation({ snapshot: withLedger, action: () => request(picker.token, 'POST', `${RECEIPTS}/confirm`, body),
|
await verifyNoMutation({ snapshot: withLedger, action: () => request(picker.token, 'POST', `${RECEIPTS}/confirm`, body),
|
||||||
check, name: '签收重放不重复产生流水', expected: result => ok(result) && result.body.data?.receiptNo === signed.receiptNo })
|
check, name: '签收重放不重复产生流水', expected: result => ok(result) && result.body.data?.receiptNo === signed.receiptNo })
|
||||||
await verifyNoMutation({ snapshot: withLedger, action: () => request(picker.token, 'POST', `${RECEIPTS}/confirm`, receiptBody(order, 2)),
|
await verifyNoMutation({ snapshot: withLedger, action: () => request(picker.token, 'POST', `${RECEIPTS}/confirm`, { ...receiptBody(order, 2), expectedReceivedQuantity: 2 }),
|
||||||
check, name: '超收失败不留下流水', expected: result => rejected(result, [409]) })
|
check, name: '超收失败不留下流水', expected: result => rejected(result, [409]) })
|
||||||
const final = await good(picker.token, 'POST', '流水场景第二批实收一件', `${RECEIPTS}/confirm`, { ...receiptBody(order, 1), unitCode: `${order.unitCode}-SECOND` })
|
const final = await good(picker.token, 'POST', '流水场景第二批实收一件', `${RECEIPTS}/confirm`, { ...receiptBody(order, 1), expectedReceivedQuantity: 2, unitCode: `${order.unitCode}-SECOND` })
|
||||||
const data = await ledger()
|
const data = await ledger()
|
||||||
check('两批签收流水业务引用唯一且分别两件一件', null, exactReceiptLedger(data,
|
check('两批签收流水业务引用唯一且分别两件一件', null, exactReceiptLedger(data,
|
||||||
[entry, { ...entry, referenceNo: final.receiptNo, totalDelta: 1, availableDelta: 1 }]) && signed.receiptNo !== final.receiptNo)
|
[entry, { ...entry, referenceNo: final.receiptNo, totalDelta: 1, availableDelta: 1 }]) && signed.receiptNo !== final.receiptNo)
|
||||||
|
|||||||
@@ -1296,7 +1296,7 @@ $criticalPaths = @(
|
|||||||
'apps/pda-uniapp/tests/app-update.test.mjs',
|
'apps/pda-uniapp/tests/app-update.test.mjs',
|
||||||
'apps/pda-uniapp/tests/page-contract.test.mjs',
|
'apps/pda-uniapp/tests/page-contract.test.mjs',
|
||||||
'apps/pda-uniapp/tests/pda-loading-api.test.mjs',
|
'apps/pda-uniapp/tests/pda-loading-api.test.mjs',
|
||||||
'apps/pda-uniapp/utils/evidence-upload-queue.js',
|
'apps/pda-uniapp/tests/picking-failure-recovery.test.mjs',
|
||||||
'apps/pda-overseas-uniapp/package.json',
|
'apps/pda-overseas-uniapp/package.json',
|
||||||
'apps/pda-overseas-uniapp/src/pages.json',
|
'apps/pda-overseas-uniapp/src/pages.json',
|
||||||
'apps/pda-overseas-uniapp/src/data/overseas-workbench.js',
|
'apps/pda-overseas-uniapp/src/data/overseas-workbench.js',
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ try {
|
|||||||
const pallet = await command('os', picker.token, 'POST', `${receipts}/pallets`, { returnNo, skuCode })
|
const pallet = await command('os', picker.token, 'POST', `${receipts}/pallets`, { returnNo, skuCode })
|
||||||
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aWQAAAABJRU5ErkJggg==', 'base64')
|
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aWQAAAABJRU5ErkJggg==', 'base64')
|
||||||
await upload(picker.token, `${receipts}/${returnNo}/photos/files`, png, 'synthetic-receipt.png', 'image/png')
|
await upload(picker.token, `${receipts}/${returnNo}/photos/files`, png, 'synthetic-receipt.png', 'image/png')
|
||||||
const receiptBody = { returnNo, startedBy: 'RETURN_NO', palletCode: pallet.palletCode, items: [{ skuCode, receivedQuantity: receiptQuantity }], idempotencyKey: `${context.marker}-RECEIPT` }
|
const receiptBody = { returnNo, expectedReceivedQuantity: 0, startedBy: 'RETURN_NO', palletCode: pallet.palletCode, items: [{ skuCode, receivedQuantity: receiptQuantity }], idempotencyKey: `${context.marker}-RECEIPT` }
|
||||||
const received = await command('os', picker.token, 'POST', `${receipts}/confirm`, receiptBody)
|
const received = await command('os', picker.token, 'POST', `${receipts}/confirm`, receiptBody)
|
||||||
const replay = await command('os', picker.token, 'POST', `${receipts}/confirm`, receiptBody)
|
const replay = await command('os', picker.token, 'POST', `${receipts}/confirm`, receiptBody)
|
||||||
check('Receipt completed once with one stock and fee batch', received.orderStatus === 'COMPLETED' && Number(received.receivedQuantity) === receiptQuantity && received.receiptNo === replay.receiptNo && received.receiptBatchNo === replay.receiptBatchNo)
|
check('Receipt completed once with one stock and fee batch', received.orderStatus === 'COMPLETED' && Number(received.receivedQuantity) === receiptQuantity && received.receiptNo === replay.receiptNo && received.receiptBatchNo === replay.receiptBatchNo)
|
||||||
|
|||||||
Reference in New Issue
Block a user