// Package common 跨场景通用业务口径(案例.md:538-625)。 // 只读核查:直连三库看真实数据分布,不发起写操作。 package common import ( "fmt" "bj_power_test/internal/assert" "bj_power_test/internal/db" "bj_power_test/internal/env" ) // Item 一条口径核查。 type Item struct { ID, Line, Name, Query string Target db.Target Expect string } // Items 七组口径的只读核查项。 var Items = []Item{ {"C-01", "案例.md:540-545", "叫料时接驳台非必填(允许空值行)", "select count(*) from material_request where target_dock is null or target_dock=''", db.MES, ">=0"}, {"C-02", "案例.md:543,601-611", "退料必须指定左/右接驳台(空值行应为 0)", "select count(*) from return_orders where return_dock is null or return_dock=''", db.WMS, "0"}, {"C-03", "案例.md:544,282", "叫料池按工位×物料聚合、不认工单", "select count(*) from call_pool", db.MES, ">=0"}, {"C-04", "案例.md:551-560", "AGV 任务按配送单驱动(biz_no 关联配送单)", "select count(*) from agv_tasks", db.MES, ">=0"}, {"C-05", "案例.md:613-617", "损耗原因在 WMS 确认收货时落账", "select count(*) from return_orders where loss_reason is not null and loss_reason<>''", db.WMS, ">=0"}, {"C-06", "案例.md:623-625", "MES 物料副本与 WMS 主数据源同源", "select count(*) from materials", db.MES, "同源"}, {"C-07", "案例.md:547-549", "设备失联降级动作有事件日志留痕", "select count(*) from event_log", db.MES, ">=0"}, {"C-08", "案例.md:449,547-549", "工位终端本地无离线队列/重试缓存表", "select count(*) from sqlite_master where type='table' and name in ('report_queue','torque_results')", db.WS, "0"}, } // Run 执行只读口径核查。 func Run(c *assert.Ctx) { for _, it := range Items { if !c.DB.Ready(it.Target) { c.L4(it.ID, it.Line, it.Name+"(期望 "+it.Expect+")", string(it.Target)+" 库未连接", false, "库不可用,无法核查") continue } got, err := c.DB.Scalar(c.C, it.Target, it.Query) if err != nil { c.L4(it.ID, it.Line, it.Name+"(期望 "+it.Expect+")", "SQL 失败:"+err.Error(), false, err.Error()) continue } pass := true reason := "" if it.Expect == "0" || it.Expect == "同源" { if it.Expect == "0" && got != "0" && got != "" { pass, reason = false, "期望 0,实际 "+got } } actual := fmt.Sprintf("%s → %q", it.Query, got) if it.ID == "C-06" { wmsCnt, werr := c.DB.Scalar(c.C, db.WMS, "select count(*) from materials") if werr == nil { actual = fmt.Sprintf("MES=%s / WMS=%s(差集需按 code 逐条核)", got, wmsCnt) pass = got == wmsCnt if !pass { reason = "两库物料行数不一致" } } } c.L4(it.ID, it.Line, it.Name+"(期望 "+it.Expect+")", actual, pass, reason) } // 看板口径:只展示正面指标(案例.md:619-621)。 resp, err := c.Client.Get(c.C, env.Board, "/") if err != nil { c.L4("C-09", "案例.md:619-621", "看板免登录可读、报喜不报忧", "看板不可达:"+err.Error(), false, "看板服务未启动") return } c.L4("C-09", "案例.md:619-621", "看板免登录可读、报喜不报忧", fmt.Sprintf("HTTP %d / 首页长度 %d 字节", resp.HTTPStatus, len(resp.Raw)), resp.HTTPStatus == 200, "若非 200:看板未就绪") }