feat: 新增收集式校验错误弹窗及工位报警语音播报
新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
@@ -2,6 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -50,6 +51,20 @@ func (s *Service) DashboardSnapshot(ctx context.Context) (*DashboardSnapshot, er
|
||||
})
|
||||
}
|
||||
|
||||
// DashboardMaterialQuery 看板物料追溯查询:直接转发 WMS 物料档案 + 库存(C7)。
|
||||
// WMS 不可达时返回 available=false,看板前端降级提示。
|
||||
func (s *Service) DashboardMaterialQuery(ctx context.Context, code, batch string) (map[string]any, error) {
|
||||
if s.ctx.Wms == nil {
|
||||
return map[string]any{"available": false, "found": false, "material": nil, "inventory": []map[string]any{}}, nil
|
||||
}
|
||||
res, err := s.ctx.Wms.MaterialQuery(ctx, code, batch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res["available"] = true
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 屏1/屏2:生产统计
|
||||
// ============================================================
|
||||
@@ -94,6 +109,9 @@ func (s *Service) buildProduction(ctx context.Context, today time.Time) Producti
|
||||
out.TorqueTotal = n
|
||||
}
|
||||
|
||||
// 实际生产节拍:相邻完工时间间隔均值(分钟)。口径可调(见 buildCycleTime)。
|
||||
out.CycleTimeMin = s.buildCycleTime(ctx)
|
||||
|
||||
out.WorkOrders = s.buildWorkOrderProgress(ctx, today)
|
||||
if len(out.WorkOrders) > 0 {
|
||||
cur := out.WorkOrders[0]
|
||||
@@ -141,6 +159,35 @@ func (s *Service) buildWorkOrderProgress(ctx context.Context, today time.Time) [
|
||||
return list
|
||||
}
|
||||
|
||||
// buildCycleTime 实际生产节拍:最近 N 条完工工件相邻 DoneAt 间隔的均值(分钟)。
|
||||
// 口径:节拍 = 相邻完工时间间隔均值(现场可按需替换为理论节拍/设计节拍)。
|
||||
// 样本不足(<2 条有效间隔)时返回 0,前端显示「—」。
|
||||
func (s *Service) buildCycleTime(ctx context.Context) float64 {
|
||||
recent, err := s.ctx.EntClient.Workpiece.Query().
|
||||
Where(workpiece.DoneAtNotNil()).
|
||||
Order(ent.Desc(workpiece.FieldDoneAt)).Limit(30).All(ctx)
|
||||
if err != nil || len(recent) < 2 {
|
||||
return 0
|
||||
}
|
||||
var sum float64
|
||||
cnt := 0
|
||||
for i := 0; i < len(recent)-1; i++ {
|
||||
if recent[i].DoneAt == nil || recent[i+1].DoneAt == nil {
|
||||
continue
|
||||
}
|
||||
gap := recent[i].DoneAt.Sub(*recent[i+1].DoneAt).Minutes()
|
||||
if gap <= 0 {
|
||||
continue
|
||||
}
|
||||
sum += gap
|
||||
cnt++
|
||||
}
|
||||
if cnt == 0 {
|
||||
return 0
|
||||
}
|
||||
return sum / float64(cnt)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 屏3:质量分析
|
||||
// ============================================================
|
||||
@@ -365,6 +412,21 @@ func (s *Service) buildWarehouse(ctx context.Context) WarehouseStats {
|
||||
out.OutToday = toInt(data["outToday"])
|
||||
out.LockedQty = toInt(data["lockedQty"])
|
||||
out.MaterialTypes = toInt(data["materialTypes"])
|
||||
out.LocationUsed = toInt(data["locationUsed"])
|
||||
out.LocationTotal = toInt(data["locationTotal"])
|
||||
out.PendingInbound = toInt(data["pendingInbound"])
|
||||
out.PendingOutbound = toInt(data["pendingOutbound"])
|
||||
if mv, ok := data["movements"].([]any); ok {
|
||||
for _, x := range mv {
|
||||
if m, ok := x.(map[string]any); ok {
|
||||
out.Movements = append(out.Movements, WmsMovement{
|
||||
ID: toStr(m["id"]), Time: toStr(m["time"]), Type: toStr(m["type"]),
|
||||
Material: toStr(m["material"]), Qty: toInt(m["qty"]),
|
||||
Operator: toStr(m["operator"]), Batch: toStr(m["batch"]),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if t, ok := data["time"].(string); ok {
|
||||
out.UpdatedAt = t
|
||||
}
|
||||
@@ -734,6 +796,20 @@ func toInt(v any) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func toStr(v any) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
return x
|
||||
case fmt.Stringer:
|
||||
return x.String()
|
||||
default:
|
||||
return fmt.Sprintf("%v", x)
|
||||
}
|
||||
}
|
||||
|
||||
// rankFromMap 把 map 排行化,按数量降序;prefix 用于生成展示名(如「工位」)
|
||||
func rankFromMap(m map[string]int, prefix string) []RankItem {
|
||||
out := make([]RankItem, 0, len(m))
|
||||
@@ -756,7 +832,7 @@ func rankOrderStatus(status string) int {
|
||||
case "IN_PROGRESS":
|
||||
return 0
|
||||
case "RELEASED":
|
||||
return 0 // 存量兼容:旧 RELEASED 等同已下发并开工
|
||||
return 0 // 存量兼容:旧 RELEASED 等同已开工(IN_PROGRESS)
|
||||
case "CREATED":
|
||||
return 2
|
||||
case "COMPLETED":
|
||||
@@ -810,7 +886,7 @@ func (s *Service) countWorkpieceDoneByOrder(ctx context.Context, today time.Time
|
||||
|
||||
// loadTorqueCriterion 取工艺指标中的扭矩规格(上下限/目标值/单位),用于绘制控制图规格线。
|
||||
// 取不到时返回 ok=false,前端不画控制线(不臆造规格值)。
|
||||
// 与 evaluateTorqueCriterion 统一口径:取「isTorque 步骤 + RANGE 逻辑」的标准,不依赖指标名(如「扭矩」)。
|
||||
// 与 evaluateTorqueCriterion 统一口径:取「采集方式=拧紧枪自动(AUTO)步骤 + RANGE 逻辑」的标准,不依赖指标名(如「扭矩」)。
|
||||
func (s *Service) loadTorqueCriterion(ctx context.Context) (lo, hi, target float64, unit string, ok bool) {
|
||||
crits, err := s.torqueRangeCriteria(ctx, 0)
|
||||
if err != nil || len(crits) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user