chore(lastleg): instrument appointment latency from restored 662dead baseline

This commit is contained in:
2026-10-18 11:43:10 +08:00
parent b0acbfbb34
commit 5cd108b39a
35 changed files with 951 additions and 780 deletions
@@ -28,28 +28,6 @@ public interface InboundFbaAppointmentQueryMapper {
" ORDER BY appointment_id DESC LIMIT 1001</script>"})
List<Long> relatedBatchIds(@Param("sources") List<com.baiyue.lastleg.appointmentplanning.AppointmentCoverageService.SourceRef> sources);
record RequirementSource(int groupOrdinal,String customerId,String sourceKey,String destinationKey) { }
record RequirementBatch(int groupOrdinal,long appointmentId) { }
/** 按原需求组返回历史归属,失活明细也保留;每组第1001条用于检测超限。 */
@Select("""
<script>
SELECT group_ordinal,appointment_id FROM (
SELECT matched.*,ROW_NUMBER() OVER(PARTITION BY group_ordinal ORDER BY appointment_id DESC) work_row FROM (
SELECT DISTINCT requested.group_ordinal,i.appointment_id
FROM ll_inbound_fba_appointment_item i JOIN (
<foreach collection='sources' item='s' separator=' UNION ALL '>
SELECT CAST(#{s.groupOrdinal} AS SIGNED) group_ordinal,
CAST(#{s.customerId} AS CHAR(128)) customer_id,CAST(#{s.sourceKey} AS CHAR(160)) source_key,
CAST(#{s.destinationKey} AS CHAR(160)) destination_key
</foreach>
) requested ON requested.customer_id=i.customer_id AND requested.source_key=i.source_key
AND requested.destination_key=CONCAT('FBA:',i.fba_warehouse_code)
) matched
) ranked WHERE work_row &lt;= 1001 ORDER BY group_ordinal,appointment_id DESC
</script>
""")
List<RequirementBatch> requirementBatches(@Param("sources") List<RequirementSource> sources);
@Select("<script>SELECT COUNT(*) FROM ll_order o "+com.baiyue.lastleg.appointmentplanning.AppointmentCoverageMapper.TRANSFER_JOIN+
" WHERE o.id IN <foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach> AND ("+
com.baiyue.lastleg.appointmentplanning.AppointmentCoverageMapper.SHIPMENT_MISSING+") </script>")
@@ -34,7 +34,6 @@ public class InboundFbaAppointmentService {
@Resource private com.baiyue.lastleg.inboundplan.receiving.FbaReceivingStore receiving;
@Resource private com.baiyue.lastleg.inboundplan.receiving.FbaAppointmentWorkPort receivingWork;
@Resource private com.baiyue.lastleg.inboundplan.work.AppointmentWorkAppointmentChanges workChanges;
@Resource private com.baiyue.lastleg.inboundplan.work.AppointmentRequirementReadRepository requirementReads;
@Transactional(readOnly=true)
public List<FbaAppointmentResponse> calendar(LocalDate from,LocalDate to) {
@@ -112,42 +111,6 @@ public class InboundFbaAppointmentService {
if(ids.size()>1000) throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE,"关联批次超过读取范围,请缩小原来源范围后继续核对");
return ids.isEmpty()?List.of():responses(appointmentMapper.selectBatchIds(ids));
}
/** 同页原料只读一次,历史归属按原需求组保留;响应解析延后至原访问顺序。 */
public java.util.function.IntFunction<List<FbaAppointmentResponse>> prepareRelatedBatchSnapshots(List<List<AppointmentCoverageService.SourceRef>> groups) {
var errors=new HashMap<Integer,RuntimeException>();
var requested=new ArrayList<InboundFbaAppointmentQueryMapper.RequirementSource>();
for(int i=0;i<groups.size();i++) {
var refs=groups.get(i);
if(refs==null || refs.isEmpty()) continue;
if(refs.size()>100 || refs.stream().anyMatch(ref->ref==null || clean(ref.customerId())==null || clean(ref.sourceKey())==null || clean(ref.destinationKey())==null)) {
errors.put(i,bad("每次最多读取100个完整原来源的关联批次"));continue;
}
final int group=i;
refs.stream().distinct().forEach(ref->requested.add(new InboundFbaAppointmentQueryMapper.RequirementSource(group,ref.customerId(),ref.sourceKey(),ref.destinationKey())));
}
var groupIds=new HashMap<Integer,Set<Long>>();
for(int start=0;start<requested.size();start+=100) {
for(var match:requirementReads.history(requested.subList(start,Math.min(start+100,requested.size())))) {
if(match.groupOrdinal()<0 || match.groupOrdinal()>=groups.size()) throw new IllegalStateException("历史关联返回了请求外需求组");
groupIds.computeIfAbsent(match.groupOrdinal(),ignored->new TreeSet<>()).add(match.appointmentId());
}
}
groupIds.forEach((group,ids)->{if(ids.size()>1000) errors.put(group,new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE,"关联批次超过读取范围,请缩小原来源范围后继续核对"));});
var ids=groupIds.entrySet().stream().filter(e->!errors.containsKey(e.getKey())).flatMap(e->e.getValue().stream()).distinct().sorted().toList();
var rows=new LinkedHashMap<Long,InboundFbaAppointment>();
var items=new HashMap<Long,List<InboundFbaAppointmentItem>>();
for(int start=0;start<ids.size();start+=200) {
var batch=ids.subList(start,Math.min(start+200,ids.size()));
requirementReads.appointments(batch).forEach(row->rows.put(row.getId(),row));
requirementReads.items(batch).forEach(item->items.computeIfAbsent(item.getAppointmentId(),ignored->new ArrayList<>()).add(item));
}
return group->{
if(group<0 || group>=groups.size()) throw new IllegalArgumentException("需求组不属于本次读取范围");
if(errors.containsKey(group)) throw errors.get(group);
var selected=groupIds.getOrDefault(group,Set.of());
return rows.values().stream().filter(row->selected.contains(row.getId())).map(row->response(row,items.getOrDefault(row.getId(),List.of()))).toList();
};
}
@Transactional(readOnly=true)
public FbaAppointmentBatchContext batchContext(String key) {
final long id;
@@ -1,28 +0,0 @@
package com.baiyue.lastleg.inboundplan.work;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baiyue.lastleg.inboundplan.entity.*;
import com.baiyue.lastleg.inboundplan.mapper.*;
import org.springframework.stereotype.Repository;
import java.util.List;
/** 需求生成的本域原料读取,历史归属不能从活动响应明细反推。 */
@Repository
public class AppointmentRequirementReadRepository {
private final AppointmentWorkSourceMapper mapping;
private final InboundFbaAppointmentQueryMapper queries;
private final InboundFbaAppointmentMapper appointments;
private final InboundFbaAppointmentItemMapper items;
/** 保留本域 Mapper 与客户来源查询边界。 */
public AppointmentRequirementReadRepository(AppointmentWorkSourceMapper mapping,InboundFbaAppointmentQueryMapper queries,InboundFbaAppointmentMapper appointments,InboundFbaAppointmentItemMapper items) {
this.mapping=mapping;this.queries=queries;this.appointments=appointments;this.items=items;
}
/** 每柜独立上限由既有窗口查询保持。 */
public List<AppointmentWorkSourceMapper.ContainerSource> sources(List<String> containers) { return containers.isEmpty()?List.of():mapping.containerSourcesBatch(containers); }
/** 分块只控制单条 SQL 输入,业务服务仍按需求组完整合并及核对上限。 */
public List<InboundFbaAppointmentQueryMapper.RequirementBatch> history(List<InboundFbaAppointmentQueryMapper.RequirementSource> sources) { return sources.isEmpty()?List.of():queries.requirementBatches(sources); }
/** 读取已确认关联的预约主记录。 */
public List<InboundFbaAppointment> appointments(List<Long> ids) { return ids.isEmpty()?List.of():appointments.selectBatchIds(ids); }
/** 包括失活明细以维持取消与替代历史;响应过滤由业务服务执行。 */
public List<InboundFbaAppointmentItem> items(List<Long> ids) { return ids.isEmpty()?List.of():items.selectList(new LambdaQueryWrapper<InboundFbaAppointmentItem>().in(InboundFbaAppointmentItem::getAppointmentId,ids).orderByAsc(InboundFbaAppointmentItem::getId)); }
}
@@ -8,6 +8,7 @@ import com.baiyue.lastleg.inboundplan.receiving.FbaReceivingStore;
import com.baiyue.lastleg.inboundplan.receiving.FbaReceivingContracts.BatchReceiving;
import com.baiyue.lastleg.security.OverseasPermissions;
import org.springframework.stereotype.Component;
import static com.baiyue.lastleg.appointmentwork.diagnostics.AppointmentWorkDiagnostics.*;
import java.util.*;
import static com.baiyue.lastleg.appointmentwork.AppointmentWorkFactGateway.*;
import static com.baiyue.lastleg.appointmentwork.AppointmentWorkModels.*;
@@ -26,11 +27,12 @@ public class AppointmentWorkDeliveryProvider implements AppointmentWorkFactGatew
this.appointments=appointments; this.cargo=cargo; this.commitments=commitments; this.deliveries=deliveries; this.sourceMapping=sourceMapping;this.receiving=receiving;
}
public boolean supports(Type type,Flow flow) { return type==Type.DELIVERY && flow==Flow.TRANSFER; }
/** 按原批次顺序读取,仅对固定步骤附加耗时,不更改来源或失败语义。 */
public List<Fact> read(List<FactRequest> requests) {
var mapped=new HashMap<String,List<AppointmentWorkSourceMapper.Source>>();
var privateSources=new HashMap<String,List<AppointmentWorkSourceMapper.Source>>();
var containers=requests.stream().filter(r->r.batchKey()==null && r.requirementKey()!=null && r.requirementKey().startsWith("INBOUND:")).map(FactRequest::containerBookingId).distinct().toList();
if(!containers.isEmpty()) sourceMapping.containerSourcesBatch(containers).forEach(s->mapped.computeIfAbsent(s.containerBookingId(),ignored->new ArrayList<>()).add(s.source()));
if(!containers.isEmpty()) measure(Stage.DELIVERY_SOURCE_MAP,()->sourceMapping.containerSourcesBatch(containers)).forEach(s->mapped.computeIfAbsent(s.containerBookingId(),ignored->new ArrayList<>()).add(s.source()));
for(var request:requests) if(request.batchKey()==null && request.requirementKey()!=null && request.requirementKey().startsWith("INBOUND:")) {
var sources=mapped.getOrDefault(request.containerBookingId(),List.of());
if(sources.size()>1000) throw unavailable("柜次尾程来源超过完整读取上限");
@@ -40,20 +42,20 @@ public class AppointmentWorkDeliveryProvider implements AppointmentWorkFactGatew
var refs=requests.stream().filter(r->r.batchKey()==null && !privateSources.containsKey(r.workItemKey())).flatMap(r->r.sources().stream())
.map(s->new AppointmentCoverageService.SourceRef(s.customerId(),s.sourceKey(),s.destinationKey())).distinct().toList();
var inspections=new HashMap<AppointmentCoverageService.SourceRef,AppointmentCargoVerificationService.Inspection>();
if(!refs.isEmpty()) cargo.inspectBatch(refs).forEach(i->inspections.put(i.reference(),i));
if(!refs.isEmpty()) measure(Stage.DELIVERY_CARGO,()->cargo.inspectBatch(refs)).forEach(i->inspections.put(i.reference(),i));
var batches=requests.stream().map(FactRequest::batchKey).filter(k->k!=null && !k.startsWith("DISPATCH:")).distinct().toList();
var snapshots=new HashMap<String,FbaAppointmentResponse>();
var deliveryRows=new HashMap<String,List<AppointmentWorkDeliveryMapper.Delivery>>();
Map<String,String> impacts=Map.of();
var receivingSnapshots=new HashMap<String,BatchReceiving>();
if(!batches.isEmpty()) {
appointments.batchSnapshots(batches).forEach(a->snapshots.put(a.batchKey(),a));
deliveries.batches(batches).forEach(d->deliveryRows.computeIfAbsent(d.batchKey(),ignored->new ArrayList<>()).add(d.delivery()));
receiving.snapshots(batches).forEach(s->receivingSnapshots.put(s.batchKey(),s));
impacts=commitments.impactTokens(requests.stream().filter(r->r.batchKey()!=null && r.batchKey().startsWith("FBA_APPOINTMENT:")).map(r->customerRequirement(r.batchKey(),deliveryCustomer(r.sources()))).distinct().toList());
measure(Stage.DELIVERY_SNAPSHOTS,()->appointments.batchSnapshots(batches)).forEach(a->snapshots.put(a.batchKey(),a));
measure(Stage.DELIVERY_ROWS,()->deliveries.batches(batches)).forEach(d->deliveryRows.computeIfAbsent(d.batchKey(),ignored->new ArrayList<>()).add(d.delivery()));
measure(Stage.DELIVERY_RECEIVING,()->receiving.snapshots(batches)).forEach(s->receivingSnapshots.put(s.batchKey(),s));
impacts=measure(Stage.DELIVERY_IMPACTS,()->commitments.impactTokens(requests.stream().filter(r->r.batchKey()!=null && r.batchKey().startsWith("FBA_APPOINTMENT:")).map(r->customerRequirement(r.batchKey(),deliveryCustomer(r.sources()))).distinct().toList()));
}
var context=new BatchFacts(snapshots,deliveryRows,impacts,receivingSnapshots);
return requests.stream().map(r->read(r,privateSources.get(r.workItemKey()),inspections,context)).toList();
return measure(Stage.DELIVERY_ASSEMBLY,()->requests.stream().map(r->read(r,privateSources.get(r.workItemKey()),inspections,context)).toList());
}
private record BatchFacts(Map<String,FbaAppointmentResponse> appointments,Map<String,List<AppointmentWorkDeliveryMapper.Delivery>> deliveries,Map<String,String> impacts,Map<String,BatchReceiving> receiving) { }
private Fact read(FactRequest request,List<AppointmentWorkSourceMapper.Source> privateSources,Map<AppointmentCoverageService.SourceRef,AppointmentCargoVerificationService.Inspection> inspections,BatchFacts context) {
@@ -17,85 +17,29 @@ public class AppointmentWorkRequirementProvider implements AppointmentWorkFactGa
private final AppointmentCargoVerificationService cargo;
private final InboundFbaAppointmentService appointments;
private final AppointmentWorkSourceMapper sourceMapping;
@jakarta.annotation.Resource private AppointmentRequirementReadRepository reads;
public AppointmentWorkRequirementProvider(AppointmentSourceService sources,AppointmentCargoVerificationService cargo,InboundFbaAppointmentService appointments,AppointmentWorkSourceMapper sourceMapping) {
this.sources=sources; this.cargo=cargo; this.appointments=appointments; this.sourceMapping=sourceMapping;
}
/** 本次生成共享原料,实例不会跨同步页或独立命令保存。 */
public RequirementReader openRequirements(List<RequirementInput> inputs) {
/** 同次生成仅共享按需读取的目录;原业务数据继续逐需求核实。 */
public RequirementReader openRequirements() {
return new RequirementReader() {
private Prepared prepared;
/** 原料提示不替代实际路线判断;未提示的真实需求按同一实现即时读取。 */
private AppointmentSourceService.ReadScope scope;
/** 直送和未建立尾程来源的需求不创建目录读取依赖。 */
public List<Requirement> read(ContainerSource container,Flow flow) {
if(flow==Flow.DIRECT) return original(container);
if(flow!=Flow.TRANSFER) throw conflict("需求清单必须明确有效作业路线");
if(prepared==null) {
var requested=new ArrayList<>(inputs);requested.add(new RequirementInput(container,flow));
prepared=prepare(requested);
}
var data=prepared.containers.contains(container)?prepared:prepare(List.of(new RequirementInput(container,flow)));
return requirements(container,flow,data);
return requirements(container,flow,refs->{
if(scope==null) scope=sources.openReadScope();
return scope.resolveBatch(refs);
});
}
};
}
/** 私人地址仍以原客户仓需求表示,直送不增加尾程读取依赖。 */
private List<Requirement> original(ContainerSource container) {
return container.requirements().stream().map(r->"PRIVATE".equals(r.destinationKind())?new Requirement(r.requirementKey(),r.batchKey(),r.batchNo(),"CUSTOMER",r.originName(),r.destinationName(),r.timezone(),r.references(),r.replacesRequirementKeys(),r.sources()):r).toList();
}
private record Group(ContainerSource container,String requirementKey) { }
/** 只含本次原料及延后执行器,不缓存已经解析的业务响应。 */
private static final class Prepared {
private final Set<ContainerSource> containers=new LinkedHashSet<>();
private final Map<String,List<AppointmentWorkSourceMapper.Source>> mapped=new HashMap<>();
private final Map<Group,Integer> ordinals=new LinkedHashMap<>();
private List<AppointmentSourceService.OrderGroup> sources=List.of();
private RuntimeException mappingError,sourceError;
private java.util.function.IntFunction<List<FbaAppointmentResponse>> history;
private java.util.function.Function<AppointmentSourceService.Source,AppointmentCargoVerificationService.Context> inspection;
}
/** 先批量读取原料,组级业务错误在原需求访问位置抛出。 */
private Prepared prepare(List<RequirementInput> inputs) {
var data=new Prepared();
inputs.stream().filter(i->i.flow()==Flow.TRANSFER).map(RequirementInput::source).forEach(data.containers::add);
var ids=data.containers.stream().map(ContainerSource::containerBookingId).distinct().toList();
try {
for(int start=0;start<ids.size();start+=100) reads.sources(ids.subList(start,Math.min(start+100,ids.size())))
.forEach(row->data.mapped.computeIfAbsent(row.containerBookingId(),ignored->new ArrayList<>()).add(row.source()));
} catch(RuntimeException error) { data.mappingError=error;return data; }
var groups=new ArrayList<List<AppointmentExternalSourceGateway.OrderRef>>();
for(var container:data.containers) {
var mapped=data.mapped.getOrDefault(container.containerBookingId(),List.of());
if(mapped.size()>1000) continue;
for(var requirement:original(container)) {
if(!"FBA".equals(requirement.destinationKind())) continue;
var inbound=requirement.requirementKey().startsWith("INBOUND:")?requirement.requirementKey().substring(8):null;
var orders=mapped.stream().filter(row->Objects.equals(row.sourceInboundId(),inbound)).toList();
if(orders.isEmpty()) continue;
data.ordinals.put(new Group(container,requirement.requirementKey()),groups.size());
groups.add(orders.stream().map(row->new AppointmentExternalSourceGateway.OrderRef(row.customerId(),row.id())).toList());
}
}
if(groups.isEmpty()) return data;
try { data.sources=sources.openReadScope().resolveOrderGroups(groups); }
catch(RuntimeException error) { data.sourceError=error;return data; }
var historyGroups=data.sources.stream().map(group->group.error()==null?group.sources().stream().map(source->new AppointmentCoverageService.SourceRef(source.customerId(),source.sourceKey(),source.destinationKey())).toList():List.<AppointmentCoverageService.SourceRef>of()).toList();
var valid=data.sources.stream().filter(group->group.error()==null).flatMap(group->group.sources().stream()).toList();
if(valid.isEmpty()) return data;
try { data.history=appointments.prepareRelatedBatchSnapshots(historyGroups); }
catch(RuntimeException error) { data.history=ignored->{throw error;}; }
// 不提前解析货件,仍由原 history -> anyMatch 路径按实际访问顺序执行。
try { data.inspection=cargo.prepareInspection(valid); }
catch(RuntimeException error) { data.inspection=ignored->{throw error;}; }
return data;
}
/** 按当前实物分配生成客户需求,保留已撤销批次身份以退役旧事项。 */
private List<Requirement> requirements(ContainerSource container,Flow effectiveFlow,
Prepared data) {
var original=original(container);
java.util.function.Function<List<AppointmentCoverageService.SourceRef>,List<AppointmentSourceService.Source>> resolver) {
var original=container.requirements().stream().map(r->"PRIVATE".equals(r.destinationKind())?new Requirement(r.requirementKey(),r.batchKey(),r.batchNo(),"CUSTOMER",r.originName(),r.destinationName(),r.timezone(),r.references(),r.replacesRequirementKeys(),r.sources()):r).toList();
if(effectiveFlow==Flow.DIRECT) return original;
if(effectiveFlow!=Flow.TRANSFER) throw conflict("需求清单必须明确有效作业路线");
if(data.mappingError!=null) throw data.mappingError;
var mapped=data.mapped.getOrDefault(container.containerBookingId(),List.of());
var mapped=sourceMapping.containerSources(container.containerBookingId());
if(mapped.size()>1000) throw unavailable("柜次尾程来源超过完整读取上限");
var result=new LinkedHashMap<String,Requirement>();
var privateDispatches=original.stream().anyMatch(r->"CUSTOMER".equals(r.destinationKind()))?sourceMapping.privateDispatches(container.containerBookingId()):List.<AppointmentWorkSourceMapper.DispatchSource>of();
@@ -106,13 +50,9 @@ public class AppointmentWorkRequirementProvider implements AppointmentWorkFactGa
if(sourceOrders.isEmpty()) { result.put(requirement.requirementKey(),requirement); continue; }
if("CUSTOMER".equals(requirement.destinationKind())) { customer(requirement,sourceOrders,privateDispatches,result);continue; }
if(!"FBA".equals(requirement.destinationKind())) { result.put(requirement.requirementKey(),requirement); continue; }
if(sourceOrders.size()>100) throw unavailable("Firstleg需求缺少完整客户货源关系");
if(data.sourceError!=null) throw data.sourceError;
int ordinal=data.ordinals.get(new Group(container,requirement.requirementKey()));
var group=data.sources.get(ordinal);
var refs=group.references();
var refs=canonical(sourceOrders.stream().map(s->new SourceReference(s.customerId(),"ORDER:"+s.id(),null)).toList());
List<AppointmentSourceService.Source> resolved;
try { resolved=group.requireSources(); }
try { resolved=resolver.apply(refs); }
catch(org.springframework.web.server.ResponseStatusException error) {
if(!AppointmentWorkSourceAvailability.unresolved(error)) throw error;
// Keep the complete physical obligation and its canonical source identities. The fact
@@ -123,10 +63,10 @@ public class AppointmentWorkRequirementProvider implements AppointmentWorkFactGa
continue;
}
var complete=resolved.stream().map(s->new AppointmentCoverageService.SourceRef(s.customerId(),s.sourceKey(),s.destinationKey())).toList();
var history=data.history.apply(ordinal);
var history=appointments.relatedBatchSnapshots(complete);
var active=history.stream().filter(AppointmentWorkRequirementProvider::active).toList();
// Unknown remaining quantity is still work, never a zero or an absent requirement.
boolean remainder=resolved.stream().map(data.inspection).anyMatch(c->c.availablePackages()==null || c.availablePackages()>0);
boolean remainder=resolved.stream().map(cargo::inspect).anyMatch(c->c.availablePackages()==null || c.availablePackages()>0);
var replaced=history.stream().filter(a->!active(a)).map(FbaAppointmentResponse::batchKey).toList();
if(remainder) {
var restored=new LinkedHashSet<>(replaced);
@@ -188,6 +128,18 @@ public class AppointmentWorkRequirementProvider implements AppointmentWorkFactGa
result.put(batch,new Requirement(batch,batch,all.get(0).dispatchNo(),"CUSTOMER",requirement.originName(),requirement.destinationName(),requirement.timezone(),refs.stream().distinct().toList(),List.copyOf(replacements),all.stream().map(d->new SourceReference(d.customerId(),d.sourceKey(),d.destinationKey())).distinct().toList()));
}
}
private List<AppointmentCoverageService.SourceRef> canonical(List<SourceReference> input) {
if(input==null || input.isEmpty() || input.size()>100) throw unavailable("Firstleg需求缺少完整客户货源关系");
var orders=input.stream().filter(s->s.sourceKey()!=null && s.sourceKey().startsWith("ORDER:")).map(s->{
try { return new AppointmentExternalSourceGateway.OrderRef(s.customerId(),Long.parseLong(s.sourceKey().substring(6))); }
catch(RuntimeException error) { throw unavailable("Firstleg原订单关联无效",error); }
}).toList();
var result=new ArrayList<AppointmentCoverageService.SourceRef>();
if(!orders.isEmpty()) result.addAll(sources.canonicalOrders(orders));
input.stream().filter(s->s.sourceKey()!=null && s.sourceKey().startsWith("BOOKING:")).map(s->new AppointmentCoverageService.SourceRef(s.customerId(),s.sourceKey(),s.destinationKey())).forEach(result::add);
if(result.size()!=input.size()) throw unavailable("来源键必须明确为ORDER或BOOKING");
return result.stream().distinct().toList();
}
/** 已取消且没有当前实物分配的记录只属历史;取消但仍有货物的批次继续产生需求。 */
private static boolean active(FbaAppointmentResponse batch) {
if(batch.replacementBatchKeys()!=null && !batch.replacementBatchKeys().isEmpty()) return false;