feat: 全端体验与稳定性整改(帮助文档清理/收集式报错/操作列统一/托盘与WS通知/物料同步重推)
- 移除 bj_power_dashboard 旧 React 大屏源码(迁移至 2D SVG 方案) - MES/WMS/工位终端前端:清理 help.js 与 PageHelp 帮助文档,统一操作列与布局,接入请求拦截器 - 新增收集式校验错误弹窗(ErrorListDialog 统一拦截 3015,逐条列现象+建议) - 新增托盘程序(tray)与 WebSocket(ws) 实时通知模块(三端共用) - MES/WMS 物料档案新增同步状态字段,补齐双向失败重推与默认角色 seed - 工单/产能/产品工艺/日排产逻辑调整;拧紧枪按工位配置 - 新增迁移 SQL:扭矩按工位、sysconfig 序列修复 - 更新 技术约束/案例/部署手册/项目说明 等文档
This commit is contained in:
@@ -2,6 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -37,7 +38,7 @@ const (
|
||||
CfgTorqueNgAlert = "torque.ng.alert.enabled"
|
||||
// CfgDashboardRefreshSeconds 看板大屏轮询兜底刷新间隔(秒,1~10):仅影响 SSE 实时通道不可用时的 HTTP 轮询周期(默认 5)
|
||||
CfgDashboardRefreshSeconds = "dashboard.refresh.seconds"
|
||||
// CfgDashboardTitle 门口看板(项目A)标题文字:空=默认「总装产线实时看板」(默认空);看板端每分钟拉取跟随
|
||||
// CfgDashboardTitle 门口看板(MES /board 页)标题文字:空=默认「总装产线实时看板」(默认空);看板端每分钟拉取跟随
|
||||
CfgDashboardTitle = "dashboard.board.title"
|
||||
// CfgDashboardVoice 门口看板语音播报开关:1=开启(默认,报警语音播报),0=关闭
|
||||
CfgDashboardVoice = "dashboard.board.voice"
|
||||
@@ -49,6 +50,12 @@ const (
|
||||
CfgAgvUnloadTimeoutMinutes = "agv.unload.timeout.minutes"
|
||||
// CfgMultiOrderCachePolicy 多工单缓存策略:physical=物理优先(目标点位实际空闲即可放);strict=严格隔离(多工单物料禁共位);默认 physical
|
||||
CfgMultiOrderCachePolicy = "cache.multi.order.policy"
|
||||
// CfgDashboardKpiVisible 门口看板 KPI 显示项(JSON 数组字符串,15 个白名单 key,见 SaveSettings;默认 [])
|
||||
CfgDashboardKpiVisible = "dashboard.kpi.visible"
|
||||
// CfgDashboardAnimationLevel 门口看板动画级别(full 完整/simple 简洁/off 关闭;默认 full)
|
||||
CfgDashboardAnimationLevel = "dashboard.animation.level"
|
||||
// CfgDashboardBoardTitleScroll 门口看板标题滚动开关(0 不滚动/1 滚动;默认 0)
|
||||
CfgDashboardBoardTitleScroll = "dashboard.board.title.scroll"
|
||||
// 2026-11-09:全局 torque.manual.input 开关已废弃;「允许手填」改由拧紧枪配置页按工位维护,见 torque_gun_config.go。
|
||||
)
|
||||
|
||||
@@ -73,6 +80,9 @@ type SettingsVO struct {
|
||||
DashboardVoice bool `json:"dashboardVoice"` // 门口看板语音播报开关
|
||||
AgvUnloadTimeoutMinutes int `json:"agvUnloadTimeoutMinutes"` // AGV 卸货超时报警(分钟,默认 5)
|
||||
MultiOrderCachePolicy string `json:"multiOrderCachePolicy"` // 多工单缓存策略:physical/strict
|
||||
DashboardKpiVisible string `json:"dashboardKpiVisible"` // 门口看板 KPI 显示项(JSON 数组字符串,默认 [])
|
||||
DashboardAnimationLevel string `json:"dashboardAnimationLevel"` // 门口看板动画级别 full/simple/off(默认 full)
|
||||
DashboardBoardTitleScroll int `json:"dashboardBoardTitleScroll"` // 门口看板标题滚动 0/1(默认 0)
|
||||
|
||||
// 本机基础信息(只读)
|
||||
LocalIPs []string `json:"localIPs"` // 本机内网 IPv4 列表
|
||||
@@ -100,6 +110,9 @@ type SettingsReq struct {
|
||||
DashboardVoice *bool `json:"dashboardVoice"` // 门口看板语音播报开关(nil=不改)
|
||||
AgvUnloadTimeoutMinutes *int `json:"agvUnloadTimeoutMinutes"` // AGV 卸货超时报警(分钟,nil=不改)
|
||||
MultiOrderCachePolicy *string `json:"multiOrderCachePolicy"` // 多工单缓存策略(nil=不改)
|
||||
DashboardKpiVisible *string `json:"dashboardKpiVisible"` // 门口看板 KPI 显示项(JSON 数组字符串,nil=不改)
|
||||
DashboardAnimationLevel *string `json:"dashboardAnimationLevel"` // 门口看板动画级别 full/simple/off(nil=不改)
|
||||
DashboardBoardTitleScroll *int `json:"dashboardBoardTitleScroll"` // 门口看板标题滚动 0/1(nil=不改)
|
||||
}
|
||||
|
||||
// defaults 建议默认值(未配置时生效)
|
||||
@@ -116,6 +129,7 @@ var settingsDefaults = map[string]int{
|
||||
CfgArchiveRemindDays: 7, // 数据归档提醒周期(天)
|
||||
CfgArchiveProtectDays: 180, // 数据保护期(天)
|
||||
CfgAgvUnloadTimeoutMinutes: 5, // AGV 卸货超时报警(分钟)
|
||||
CfgDashboardBoardTitleScroll: 0, // 门口看板标题滚动(默认 0=不滚动)
|
||||
}
|
||||
|
||||
// GetSettings 读取基础设置 + 本机信息。DB 读失败时按默认值返回(设置页必须能打开)。
|
||||
@@ -142,6 +156,9 @@ func (s *Service) GetSettings(ctx context.Context) (*SettingsVO, error) {
|
||||
DashboardVoice: s.CfgInt(ctx, CfgDashboardVoice, 1) == 1,
|
||||
AgvUnloadTimeoutMinutes: cfgIntFrom(kv, CfgAgvUnloadTimeoutMinutes),
|
||||
MultiOrderCachePolicy: cfgStrFrom(kv, CfgMultiOrderCachePolicy, "physical"),
|
||||
DashboardKpiVisible: cfgStrFrom(kv, CfgDashboardKpiVisible, "[]"),
|
||||
DashboardAnimationLevel: cfgStrFrom(kv, CfgDashboardAnimationLevel, "full"),
|
||||
DashboardBoardTitleScroll: cfgIntFrom(kv, CfgDashboardBoardTitleScroll),
|
||||
LocalIPs: localIPv4s(),
|
||||
ListenAddr: fmt.Sprintf("%s:%d", s.ctx.Config.Host, s.ctx.Config.Port),
|
||||
DBInfo: fmt.Sprintf("%s:%d/%s", s.ctx.Config.Database.Host, s.ctx.Config.Database.Port, s.ctx.Config.Database.Dbname),
|
||||
@@ -202,8 +219,9 @@ func (s *Service) SaveSettings(ctx context.Context, req SettingsReq, operator st
|
||||
}
|
||||
if req.DashboardTitle != nil {
|
||||
t := strings.TrimSpace(*req.DashboardTitle)
|
||||
if len(t) > 30 {
|
||||
return errors.New("门口看板标题需 0~30 字(空=不显示标题)")
|
||||
// 按字符数(中文 1 字=1 rune),放宽到 100 字
|
||||
if len([]rune(t)) > 100 {
|
||||
return errors.New("门口看板标题需 0~100 字(空=不显示标题)")
|
||||
}
|
||||
if err := s.upsertConfig(ctx, CfgDashboardTitle, t, "门口看板标题文字(空=不显示)"); err != nil {
|
||||
return err
|
||||
@@ -235,6 +253,49 @@ func (s *Service) SaveSettings(ctx context.Context, req SettingsReq, operator st
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 门口看板 KPI 显示项:合法 JSON 数组 + 元素在 15 个白名单 key(禁正则,用 encoding/json)
|
||||
if req.DashboardKpiVisible != nil {
|
||||
v := strings.TrimSpace(*req.DashboardKpiVisible)
|
||||
var arr []string
|
||||
if err := json.Unmarshal([]byte(v), &arr); err != nil {
|
||||
return errors.New("看板 KPI 显示项需为合法的 JSON 数组")
|
||||
}
|
||||
allowed := map[string]bool{
|
||||
"output": true, "rate": true, "wip": true, "cycle": true,
|
||||
"pass": true, "online": true, "location": true,
|
||||
"yield": true, "onlineRate": true, "doneRate": true,
|
||||
"wipOrders": true, "materialReady": true, "torque": true,
|
||||
"inbound": true, "outbound": true,
|
||||
}
|
||||
for _, k := range arr {
|
||||
if !allowed[k] {
|
||||
return fmt.Errorf("看板 KPI 显示项「%s」不在允许范围(output/rate/wip/cycle/pass/online/location/yield/onlineRate/doneRate/wipOrders/materialReady/torque/inbound/outbound)", k)
|
||||
}
|
||||
}
|
||||
if err := s.upsertConfig(ctx, CfgDashboardKpiVisible, v, "门口看板 KPI 显示项(JSON 数组字符串)"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 门口看板动画级别:full/simple/off
|
||||
if req.DashboardAnimationLevel != nil {
|
||||
v := strings.TrimSpace(*req.DashboardAnimationLevel)
|
||||
if v != "full" && v != "simple" && v != "off" {
|
||||
return errors.New("看板动画级别仅支持 full(完整)/simple(简洁)/off(关闭)")
|
||||
}
|
||||
if err := s.upsertConfig(ctx, CfgDashboardAnimationLevel, v, "门口看板动画级别(full/simple/off)"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 门口看板标题滚动:0/1
|
||||
if req.DashboardBoardTitleScroll != nil {
|
||||
v := *req.DashboardBoardTitleScroll
|
||||
if v != 0 && v != 1 {
|
||||
return errors.New("看板标题滚动开关仅支持 0(不滚动)/1(滚动)")
|
||||
}
|
||||
if err := s.upsertConfig(ctx, CfgDashboardBoardTitleScroll, strconv.Itoa(v), "门口看板标题滚动(0/1)"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 2026-11-09:「允许手填」改由「拧紧枪配置」页按工位维护(关闭时校验本工位控制器地址),
|
||||
// 基础设置页不再保存该全局开关。
|
||||
payload := map[string]any{"req": req}
|
||||
@@ -283,13 +344,16 @@ func (s *Service) CfgStr(ctx context.Context, key, def string) string {
|
||||
return strings.TrimSpace(v.Value)
|
||||
}
|
||||
|
||||
// upsertConfig 幂等写入配置
|
||||
// upsertConfig 幂等写入配置(原子 upsert)。
|
||||
// 2026-11-10 根治 SQLSTATE 23505:原实现「先查后插」在并发/重复提交下两个请求会同时走到
|
||||
// Create(),撞 sys_config_pkey 或 sys_config_key_key。改为单条 INSERT ... ON CONFLICT (key)
|
||||
// DO UPDATE,由数据库保证串行收敛;id 交给序列,不再手工赋主键。
|
||||
func (s *Service) upsertConfig(ctx context.Context, key, value, remark string) error {
|
||||
exist, err := s.ctx.EntClient.SysConfig.Query().Where(sysconfig.Key(key)).Only(ctx)
|
||||
if err == nil && exist != nil {
|
||||
return exist.Update().SetValue(value).SetRemark(remark).Exec(ctx)
|
||||
}
|
||||
return s.ctx.EntClient.SysConfig.Create().SetKey(key).SetValue(value).SetRemark(remark).Exec(ctx)
|
||||
_, err := s.ctx.SQLDB.ExecContext(ctx,
|
||||
`INSERT INTO sys_config (key, value, remark) VALUES ($1, $2, $3)
|
||||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, remark = EXCLUDED.remark`,
|
||||
key, value, remark)
|
||||
return err
|
||||
}
|
||||
|
||||
// cfgIntFrom 从已加载的 kv map 解析整型(非法/未配置回退默认值)
|
||||
|
||||
Reference in New Issue
Block a user