package com.gzzn.omms.msgexchange.delivery import com.gzzn.omms.msgexchange.domain.MsgEvent import com.gzzn.omms.msgexchange.domain.SchdPush /** * ACMA-8 流程 3 flushSchd 聚合(纯函数,可单测): * 按 PARTITION_KEY(=FLID) 分组、组内取 EVENT_ID 最大——v4 显式 max(EVENT_ID), * 不依赖集合遍历序(FIX:现役 buffer 无去重会重复投递旧值)。 */ object SchdAggregation { fun latestPerFlight(pending: List): List = pending .groupBy { it.partitionKey ?: "" } .map { (_, evs) -> evs.maxBy { it.eventId ?: 0 }.payloadJson } /** 由 Decision 直接构造时的等价聚合(测试与 dispatcher 共用语义)。 */ fun latestPerFlightOfPush(pushes: List): List = pushes .groupBy { it.flid } .map { (_, ps) -> ps.maxBy { it.eventSeq }.payloadJson } }