feat: 新增收集式校验错误弹窗及工位报警语音播报

新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
SunYF
2026-10-20 16:36:26 +08:00
parent f743cf21fb
commit b0c048d9aa
126 changed files with 4603 additions and 1639 deletions
+31 -83
View File
@@ -22,6 +22,7 @@ type PointBit struct {
// BitsGroup 三组点位(工位 / 主线 / 接驳台 + 库房接驳台)。
type BitsGroup struct {
Mock bool `json:"mock"` // 当前 PLC 为模拟模式(未连接真实 PLC,页面显示「模拟数据」标注)
Station []PointBit `json:"station"`
Main []PointBit `json:"main"`
Dock []PointBit `json:"dock"`
@@ -62,7 +63,7 @@ func (s *Service) PlcMonitorBits(ctx context.Context) (*BitsGroup, error) {
if err != nil {
return nil, err
}
g := &BitsGroup{}
g := &BitsGroup{Mock: s.ctx.PLC.IsMock()}
for i := 0; i < 12; i++ {
g.Station = append(g.Station, PointBit{Code: "G" + strconv.Itoa(i+1), Has: bitAt(bits, i)})
}
@@ -148,105 +149,52 @@ func (s *Service) PlcMonitorManualWrite(ctx context.Context, req ManualWriteReq,
return &MonitorPreview{Ok: true, MW: mw, Value: value, SrcCode: srcCode, TgtCode: tgtCode}, nil
}
// ---------- 强制写入(块 D:PLC 强制写,危险操作,需二次确认) ----------
// ---------- 在途指令强制清零(仅 §4.4 路由区 MW=0,不开放任意写) ----------
// ForceBitReq 强制写单个 M 位请求体。
type ForceBitReq struct {
MerkerByte int `json:"merkerByte"` // M 字节偏移(如 898 表示 MB898)
MerkerBit int `json:"merkerBit"` // 位 0..7
On bool `json:"on"` // true=置 1,false=清 0
Confirmed bool `json:"confirmed"` // 二次确认勾选,必须 true 才执行
// ClearInTransitReq 在途指令强制清零请求体:仅允许 §4.4 路由表覆盖的 MW 地址,写 0。
type ClearInTransitReq struct {
Addr int `json:"addr"` // MW 地址(必须是 §4.4 路由表覆盖的 MW)
}
// ForceResult 强制写 M 位结果。
type ForceResult struct {
Before bool `json:"before"` // 写前位值
After bool `json:"after"` // 写后即时回读位值(M 位可能被 PLC 程序覆盖,仅反映即时态)
// ClearInTransitResult 清零结果。
type ClearInTransitResult struct {
Addr int `json:"addr"` // 被清零的 MW 地址
Before int `json:"before"` // 清零前的值(非 0 即在途指令)
}
// ForceMWResult 强制写 MW 结果。
type ForceMWResult struct {
Before int `json:"before"` // 写前值
After int `json:"after"` // 写入值
}
// PlcMonitorForceBit 强制置/复位单个 M 位(停机/调试用)。
// 必须二次确认(confirmed=true)才执行;M 位可能被 PLC 程序循环覆盖,结果不保证持久。
func (s *Service) PlcMonitorForceBit(ctx context.Context, req ForceBitReq, operator string) (*ForceResult, error) {
if !req.Confirmed {
return nil, errors.New("未勾选「确认执行强制写」:操作已拒绝")
// PlcMonitorClearInTransit 强制清零在途指令:把 §4.4 路由区某 MW 写 0。
// 仅允许路由表覆盖的 MW 地址(MWCategory 命中),越界/控制区/无关寄存器一律拒绝;不开放任意写。
// 记操作日志(event_log,type=plc_in_transit_clear)。
func (s *Service) PlcMonitorClearInTransit(ctx context.Context, req ClearInTransitReq, operator string) (*ClearInTransitResult, error) {
if req.Addr <= 0 {
return nil, errors.New("缺少 MW 地址")
}
if !plc.IsWritableMerkerByte(req.MerkerByte) || req.MerkerBit < 0 || req.MerkerBit > 7 {
return nil, errors.New("非法的 M 位地址(MB" + strconv.Itoa(req.MerkerByte) + "." + strconv.Itoa(req.MerkerBit) + ")")
}
before, after, err := s.ctx.PLC.Get().WriteBit(ctx, req.MerkerByte, req.MerkerBit, req.On)
if err != nil {
return nil, err
}
obj := "M" + strconv.Itoa(req.MerkerByte) + "." + strconv.Itoa(req.MerkerBit)
desc := "强制写 " + obj + ":" + boolToZh(before) + " → " + boolToZh(after) + "(" + onZh(req.On) + ")"
s.ctx.EventLog.Write(ctx, "plc_manual_force", "", operator, "plc", obj,
desc,
map[string]any{
"object": obj,
"before": before,
"after": after,
"target": req.On,
"operator": operator,
"confirmTime": time.Now().Format(time.RFC3339),
})
return &ForceResult{Before: before, After: after}, nil
}
// ForceMWReq 强制写 MW 请求体。
type ForceMWReq struct {
Addr int `json:"addr"` // MW 地址
Value int `json:"value"` // 写入值
Confirmed bool `json:"confirmed"` // 二次确认勾选,必须 true 才执行
}
// PlcMonitorWriteMw 强制写 16 位寄存器(MW)。
// 必须二次确认(confirmed=true)才执行;仅白名单内地址(MW800~886 + 4096~4099)允许,越界拒绝。
func (s *Service) PlcMonitorWriteMw(ctx context.Context, req ForceMWReq, operator string) (*ForceMWResult, error) {
if !req.Confirmed {
return nil, errors.New("未勾选「确认执行强制写」:操作已拒绝")
}
if !plc.IsWritableMW(req.Addr) {
return nil, errors.New("MW" + strconv.Itoa(req.Addr) + " 不在可写白名单内(仅允许 MW800~886 与 MW4096~4099),操作已拒绝")
// 仅允许 §4.4 路由表覆盖的 MW(防止误清控制区/无关寄存器)
if _, ok := plc.MWCategory(req.Addr); !ok {
return nil, errors.New("MW" + strconv.Itoa(req.Addr) + " 不在 §4.4 路由表覆盖范围内,操作已拒绝")
}
before, err := s.ctx.PLC.Get().ReadMW(ctx, req.Addr)
if err != nil {
return nil, err
}
if err := s.ctx.PLC.Get().WriteMW(ctx, req.Addr, req.Value); err != nil {
if err := s.ctx.PLC.Get().WriteMW(ctx, req.Addr, 0); err != nil {
return nil, err
}
obj := "MW" + strconv.Itoa(req.Addr)
desc := "强制写 " + obj + ":" + strconv.Itoa(before) + " → " + strconv.Itoa(req.Value)
s.ctx.EventLog.Write(ctx, "plc_manual_force", "", operator, "plc", obj,
desc := "强制清零在途指令:" + obj + " " + strconv.Itoa(before) + " → 0"
if srcType, tgtType, src, tgt, ok := plc.ParseMW(req.Addr, before); ok {
desc += "(" + string(srcType) + strconv.Itoa(src) + " → " + string(tgtType) + strconv.Itoa(tgt) + ")"
}
s.ctx.EventLog.Write(ctx, "plc_in_transit_clear", "", operator, "plc", obj,
desc,
map[string]any{
"object": obj,
"before": before,
"after": req.Value,
"operator": operator,
"confirmTime": time.Now().Format(time.RFC3339),
"object": obj,
"before": before,
"after": 0,
"operator": operator,
"clearedAt": time.Now().Format(time.RFC3339),
})
return &ForceMWResult{Before: before, After: req.Value}, nil
}
func boolToZh(b bool) string {
if b {
return "1"
}
return "0"
}
func onZh(on bool) string {
if on {
return "置位"
}
return "复位"
return &ClearInTransitResult{Addr: req.Addr, Before: before}, nil
}
// ---------- 工件位置纠正(块 E:产线管理页 tab4) ----------