@startuml

title  对账代码时序图-以支付宝对账为例

skinparam responseMessageBelowArrow true

actor       客户端       as Client
participant ReconcileService
participant ReconcileOrderService
participant ReconcileStrategy
participant AliPayReconcileService
participant ReconcileDiffService
participant ReconcileOrderManager
participant ReconcileContext
participant ReconcileDetailManager
participant ReconcileStrategyFactory
participant AliGateway as 支付宝网关

autonumber
Client -> ReconcileService: 发起对账请求

group 1. 创建对账订单
    autonumber 1
    ReconcileService -> ReconcileStrategyFactory: 构建对账策略
    ReconcileService <- ReconcileStrategyFactory: 返回对账策略对象
    ReconcileService -> ReconcileStrategy: 生成批次号
    ReconcileService <- ReconcileStrategy: 返回批次号
    ReconcileService -> ReconcileService: 创建对账订单
    ReconcileService -> ReconcileOrderManager: 保存对账订单
    ReconcileService <- ReconcileOrderManager: 返回对账订单
end

group 2. 下载对账单并进行保存
    autonumber 1
    ReconcileService -> ReconcileStrategyFactory: 构建对账策略
    ReconcileService <- ReconcileStrategyFactory: 返回对账策略对象
    ReconcileService -> ReconcileStrategy: 下载对账单, 并进行解析进行保存
    ReconcileStrategy -> AliPayReconcileService: 发起对账单下载请求，获取对账单下载地址
    AliPayReconcileService -> AliGateway: 发起对账单下载请求，获取对账单下载地址
    AliPayReconcileService <- AliGateway: 返回对账单下载地址
    AliPayReconcileService -> AliGateway: 下载对账单
    AliPayReconcileService <- AliGateway: 返回对账单内容
    AliPayReconcileService -> AliPayReconcileService: 解析对账单, 同时生成通用对账单记录
    AliPayReconcileService --> ReconcileContext: 将解析后的通用对账单记录放到到上下文
    ReconcileStrategy <- AliPayReconcileService: 处理结束
    ReconcileService <- ReconcileStrategy: 处理结束
    ReconcileService <- ReconcileContext: 获取通用对账单记录
    ReconcileService --> reconcileDetailManager: 保存明细记录
end

group 3. 对账单比对
    autonumber 1
    ReconcileService -> ReconcileStrategyFactory: 构建对账策略
    ReconcileService <- ReconcileStrategyFactory: 返回对账策略对象
    ReconcileService <--> ReconcileStrategy: 初始对账策略类
    ReconcileService <- ReconcileStrategy: 获取本地和网关订单数据
    ReconcileService -> ReconcileService: 比对本地和网关订单差异
    ReconcileService --> ReconcileDiffService: 保存差异记录

end
autonumber 2
Client <- ReconcileService: 返回对账结束

@enduml
