69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
// reconcile/settle-check S2-D5:三方对账子命令——明细直查 vs 日汇总 vs
|
|
// 结算单(diff=0 为 S2 泳道出口判据)。
|
|
//
|
|
// 用法(仓库根目录):go run ./cmd/reconcile/settle-check -period 2026-11 [-json]
|
|
// 退出码:0=三方差异全零;1=存在差异(明细见输出);2=运行错误。
|
|
// 注意:金额不在比对范围(结算单金额=出账时点价/阶梯快照,事后调价重算必生
|
|
// 噪音,口径见 settle/reconcile.go 头注);账单未生成=流程状态,计入
|
|
// bill_missing 但不影响 AllZero 判定。
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go-sms/internal/app"
|
|
"go-sms/internal/service/settle"
|
|
)
|
|
|
|
func main() {
|
|
period := flag.String("period", time.Now().Format("2006-01"), "对账账期 YYYY-MM(缺省=当前月)")
|
|
asJSON := flag.Bool("json", false, "输出完整 JSON 报告(缺省=人类可读摘要+异常行)")
|
|
flag.Parse()
|
|
|
|
a, err := app.New(app.Options{ServiceName: "reconcile-settle-check"})
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "app init:", err)
|
|
os.Exit(2)
|
|
}
|
|
rep, err := settle.NewService(a.DB()).ReconcilePeriod(context.Background(), *period)
|
|
if err != nil {
|
|
a.Lg().Error("settle_check_failed", zap.String("period", *period), zap.Error(err))
|
|
fmt.Fprintln(os.Stderr, "reconcile:", err)
|
|
os.Exit(2)
|
|
}
|
|
|
|
if *asJSON {
|
|
out, _ := json.MarshalIndent(rep, "", " ")
|
|
fmt.Println(string(out))
|
|
} else {
|
|
s := rep.Summary
|
|
fmt.Printf("settle-check period=%s as_of=%s\n", rep.Period, rep.AsOf.Format(time.RFC3339))
|
|
fmt.Printf("accounts: checked=%d diffs=%d bill_missing=%d\n", s.AccountsChecked, s.AccountDiffs, s.BillMissing)
|
|
fmt.Printf("channels: checked=%d diffs=%d\n", s.ChannelsChecked, s.ChannelDiffs)
|
|
fmt.Printf("upstreams: checked=%d diffs=%d\n", s.UpstreamsChecked, s.UpstreamDiffs)
|
|
for _, r := range rep.Accounts {
|
|
fmt.Printf(" [DIFF] account=%d detail=%d consume=%d bill=%v\n",
|
|
r.AccountID, r.DetailSuccess, r.ConsumeSuccess, r.BillSuccess)
|
|
}
|
|
for _, r := range rep.Channels {
|
|
fmt.Printf(" [DIFF] channel=%d detail=%d daily=%d\n",
|
|
r.ChannelID, r.DetailSuccess, r.DailySuccess)
|
|
}
|
|
for _, r := range rep.Upstreams {
|
|
fmt.Printf(" [DIFF] upstream=%d daily=%d bill=%v\n",
|
|
r.UpstreamID, r.DailyCount, r.BillSuccess)
|
|
}
|
|
fmt.Printf("all_zero=%v\n", s.AllZero)
|
|
}
|
|
if !rep.Summary.AllZero {
|
|
os.Exit(1)
|
|
}
|
|
}
|