feat: 大屏新增虚拟工位滚动栏与多订单轮播,附件表增加删除原因及彻底清除留痕字段
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/alert"
|
||||
"bj_power_mes/ent/backuprecord"
|
||||
)
|
||||
|
||||
// 备份超期预警(backup_overdue):
|
||||
// 顶栏「数据归档清理提醒」角标已移除,提醒统一由预警中心承载。
|
||||
// 事件驱动(无定时器):跟随看板快照等高频入口做惰性检查,每日最多落一条未读预警;
|
||||
// 预警去重=同类型存在 UNREAD 即不再落(内存 lastCreatedDay 双保险,避免用户标记已读后被反复轰炸)。
|
||||
const AlertTypeBackupOverdue = "backup_overdue"
|
||||
|
||||
// backupOverdueLastDay 最近一次落 backup_overdue 预警的日期(进程内,重启后允许当天再落一次)
|
||||
var backupOverdueLastDay string
|
||||
|
||||
// CheckBackupOverdueAlert 惰性检查备份超期:超期则落预警,已恢复则自动关闭未读预警。
|
||||
// 由 DashboardSnapshot 等高频路径调用;内部自带去重与天级节流,重复调用无副作用。
|
||||
func (s *Service) CheckBackupOverdueAlert(ctx context.Context) {
|
||||
days := s.CfgInt(ctx, CfgArchiveRemindDays, 7)
|
||||
if days <= 0 {
|
||||
return // 提醒周期=0:用户已关闭提醒
|
||||
}
|
||||
last, err := s.ctx.EntClient.BackupRecord.Query().
|
||||
Where(backuprecord.StatusEQ("success")).
|
||||
Order(ent.Desc(backuprecord.FieldExecutedAt)).
|
||||
First(ctx)
|
||||
if err != nil {
|
||||
return // 从未成功备份过(初始化阶段)或查询失败:不提醒
|
||||
}
|
||||
due := last.ExecutedAt + int64(days)*86400
|
||||
if time.Now().Unix() < due {
|
||||
// 已在周期内:自动关闭历史遗留的未读超期预警(备份完成后自愈)
|
||||
_, _ = s.ctx.EntClient.Alert.Update().
|
||||
Where(alert.TypeEQ(AlertTypeBackupOverdue), alert.StatusEQ("UNREAD")).
|
||||
SetStatus("READ").Save(ctx)
|
||||
return
|
||||
}
|
||||
// 超期:存在未读预警则不重复落;当日已落过(被处置后)也不再落
|
||||
n, _ := s.ctx.EntClient.Alert.Query().
|
||||
Where(alert.TypeEQ(AlertTypeBackupOverdue), alert.StatusEQ("UNREAD")).Count(ctx)
|
||||
if n > 0 {
|
||||
return
|
||||
}
|
||||
today := time.Now().Format("2006-01-02")
|
||||
if backupOverdueLastDay == today {
|
||||
return
|
||||
}
|
||||
backupOverdueLastDay = today
|
||||
msg := fmt.Sprintf("距上次成功备份已超过 %d 天(最近成功备份:%s)。请先在「数据归档」页确认 U 盘备份完整,再手动清理旧数据(仅提醒,不自动删除)。",
|
||||
days, time.Unix(last.ExecutedAt, 0).Format("2006-01-02 15:04"))
|
||||
_ = s.CreateAlert(ctx, AlertTypeBackupOverdue, "警告", "数据归档", msg)
|
||||
}
|
||||
@@ -43,12 +43,14 @@ func (s *Service) DashboardSnapshot(ctx context.Context) (*DashboardSnapshot, er
|
||||
snap.Quality = s.buildQuality(ctx, today)
|
||||
snap.Trace = s.buildTrace(ctx)
|
||||
snap.Warehouse = s.buildWarehouse(ctx)
|
||||
snap.Equipment = s.buildEquipment(ctx, today)
|
||||
snap.Equipment = s.buildEquipment(ctx, today, false)
|
||||
snap.VirtualEquipment = s.buildEquipment(ctx, today, true) // 虚拟工位(OFFLINE,不连PLC)单独下发
|
||||
snap.Agv = s.buildAgv(ctx)
|
||||
snap.Performance = s.buildPerformance(ctx, today)
|
||||
snap.Alarms = s.buildAlarms(ctx, today)
|
||||
snap.Trends = s.buildTrends(ctx)
|
||||
snap.Events = s.buildEvents(ctx)
|
||||
s.CheckBackupOverdueAlert(ctx) // 备份超期→预警中心(惰性检查,天级节流,无定时器)
|
||||
return snap, nil
|
||||
})
|
||||
}
|
||||
@@ -457,10 +459,17 @@ func (s *Service) buildWarehouse(ctx context.Context) WarehouseStats {
|
||||
// 屏1:工位实时状态(3D 场景与工位矩阵共用)
|
||||
// ============================================================
|
||||
|
||||
func (s *Service) buildEquipment(ctx context.Context, today time.Time) []StationState {
|
||||
// buildEquipment 工位实时状态聚合。
|
||||
// offlineOnly=false → 常规工位(连 PLC,前端地图 12 槽位);
|
||||
// offlineOnly=true → 虚拟工位(station_type=OFFLINE,不连 PLC、仅记录,供地图"虚拟工位"滚动栏展示)。
|
||||
func (s *Service) buildEquipment(ctx context.Context, today time.Time, offlineOnly bool) []StationState {
|
||||
typePred := station.StationTypeNEQ("OFFLINE")
|
||||
if offlineOnly {
|
||||
typePred = station.StationTypeEQ("OFFLINE")
|
||||
}
|
||||
// 工位主数据
|
||||
stMap := map[int]StationState{}
|
||||
if sts, err := s.ctx.EntClient.Station.Query().Where(station.StationTypeNEQ("OFFLINE")).All(ctx); err == nil {
|
||||
if sts, err := s.ctx.EntClient.Station.Query().Where(typePred).All(ctx); err == nil {
|
||||
for _, st := range sts {
|
||||
stMap[st.StationNo] = StationState{
|
||||
StationNo: st.StationNo,
|
||||
@@ -474,8 +483,8 @@ func (s *Service) buildEquipment(ctx context.Context, today time.Time) []Station
|
||||
}
|
||||
}
|
||||
}
|
||||
// 工位主数据缺失时兜底:按 DB 非线下位工位生成;DB 完全空时回退 1~12
|
||||
if len(stMap) == 0 {
|
||||
// 工位主数据缺失时兜底:常规工位按 DB 非线下位工位生成;DB 完全空时回退 1~12(虚拟工位无兜底)
|
||||
if len(stMap) == 0 && !offlineOnly {
|
||||
if dbStations, e := s.ctx.EntClient.Station.Query().
|
||||
Where(station.StationTypeNEQ("OFFLINE")).All(ctx); e == nil && len(dbStations) > 0 {
|
||||
for _, st := range dbStations {
|
||||
|
||||
@@ -108,7 +108,12 @@ type FrontDashboard struct {
|
||||
Production FrontProduction `json:"production"`
|
||||
Warehouse FrontWarehouse `json:"warehouse"`
|
||||
Equipment []FrontStation `json:"equipment"`
|
||||
// VirtualStations 虚拟工位(OFFLINE,不连PLC):地图"虚拟工位"滚动栏展示,不混入 equipment(12 工位映射口径不变)
|
||||
VirtualStations []FrontStation `json:"virtualStations"`
|
||||
Progress FrontProgress `json:"progress"`
|
||||
// ProgressList 当前在产订单列表(多订单轮播):进行中的工单排前,最多 6 条;
|
||||
// 首条与 Progress 一致(老消费方可继续只用 progress)。
|
||||
ProgressList []FrontProgress `json:"progressList"`
|
||||
Traces []TraceItem `json:"traces"`
|
||||
Trends FrontTrends `json:"trends"`
|
||||
// Points 产线点位态(主线 15 位 / 接驳台 21 位 / 在途路径指令),驱动 2D 地图真实亮灭与流光
|
||||
@@ -179,6 +184,34 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
})
|
||||
}
|
||||
f.Equipment = equipment
|
||||
|
||||
// -------- 虚拟工位(OFFLINE):同构映射,但不计入设备在线/总数口径 --------
|
||||
f.VirtualStations = make([]FrontStation, 0, len(r.VirtualEquipment))
|
||||
for _, st := range r.VirtualEquipment {
|
||||
tool := "online"
|
||||
switch st.Status {
|
||||
case "running":
|
||||
tool = "busy"
|
||||
case "alarm":
|
||||
tool = "alarm"
|
||||
case "offline":
|
||||
tool = "offline"
|
||||
}
|
||||
f.VirtualStations = append(f.VirtualStations, FrontStation{
|
||||
ID: st.StationNo,
|
||||
Name: st.Name,
|
||||
Status: st.Status,
|
||||
ScanGun: FrontToolState{Status: tool, ProcessedCount: st.DoneToday},
|
||||
TighteningGun: FrontToolState{Status: tool, CurrentSn: st.CurrentSn, ProcessedCount: st.DoneToday},
|
||||
CurrentSn: st.CurrentSn,
|
||||
CurrentOperator: st.CurrentOperator,
|
||||
CurrentProcess: st.CurrentProcess,
|
||||
DoneCount: st.DoneToday,
|
||||
Paused: st.Paused,
|
||||
PauseReason: st.PauseReason,
|
||||
})
|
||||
}
|
||||
|
||||
f.Production = FrontProduction{
|
||||
OutputToday: r.Production.OutputToday,
|
||||
TargetToday: r.Production.TargetToday,
|
||||
@@ -241,6 +274,29 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
pr.Traceable = stepCount > 0 && allOk
|
||||
f.Progress = pr
|
||||
|
||||
// -------- 多订单列表(轮播):进行中工单排前,最多 6 条,首条与 progress 一致 --------
|
||||
f.ProgressList = make([]FrontProgress, 0, len(r.Production.WorkOrders))
|
||||
for i, wo := range r.Production.WorkOrders {
|
||||
if i >= 6 {
|
||||
break
|
||||
}
|
||||
f.ProgressList = append(f.ProgressList, FrontProgress{
|
||||
OrderNo: wo.OrderNo,
|
||||
ProductName: wo.ProductName,
|
||||
TotalQty: wo.TotalQty,
|
||||
DoneQty: wo.DoneQty,
|
||||
Progress: wo.Progress,
|
||||
Status: wo.Status,
|
||||
CurrentProcess: wo.CurrentProcess,
|
||||
PlanStart: shortDate(wo.PlanStart),
|
||||
PlanEnd: shortDate(wo.PlanEnd),
|
||||
RemainDays: remainDays(wo.PlanEnd),
|
||||
ProcessTotal: 12,
|
||||
TraceStepCount: stepCount,
|
||||
Traceable: stepCount > 0 && allOk,
|
||||
})
|
||||
}
|
||||
|
||||
// -------- traces / trends / points / agv / events --------
|
||||
f.Traces = r.Trace.Recent
|
||||
if f.Traces == nil {
|
||||
|
||||
@@ -275,6 +275,9 @@ type DashboardSnapshot struct {
|
||||
Trace TraceStats `json:"trace"`
|
||||
Warehouse WarehouseStats `json:"warehouse"`
|
||||
Equipment []StationState `json:"equipment"`
|
||||
// VirtualEquipment 虚拟工位(station_type=OFFLINE,不连 PLC、仅记录)。
|
||||
// 不混入 Equipment:12 工位地图映射与设备总数口径均按常规工位计算。
|
||||
VirtualEquipment []StationState `json:"virtualEquipment"`
|
||||
Agv AgvStats `json:"agv"`
|
||||
Performance []RankItem `json:"performance"`
|
||||
Alarms []AlarmItem `json:"alarms"`
|
||||
|
||||
@@ -338,6 +338,12 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
|
||||
st, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(req.StationNo)).First(ctx)
|
||||
if err != nil {
|
||||
// 新增工位:工位号不存在即创建(字段错误收集式列出)
|
||||
// 物理产线工位(1~12)为内置硬件锁定(G1~G12 各连 PLC、须按工位号顺序流转),
|
||||
// 禁止通过本接口新增或占用,避免与内置物理工位冲突、或绕过前端改物理工位号。
|
||||
// 物理工位号只能由种子/初始化数据产生;页面新增请使用虚拟工位(0)或扩展工位号(≥13)。
|
||||
if req.StationNo >= 1 && req.StationNo <= 12 {
|
||||
return errors.New("工位号 1~12 为内置物理产线工位(硬件锁定),不可通过本接口新增或占用;新增工位请使用虚拟工位(0)或扩展工位号(≥13)")
|
||||
}
|
||||
ve := verr.New()
|
||||
if req.Name == "" {
|
||||
ve.Add("name", "请填写工位名称", "在「工位名称」输入框填写名称后保存")
|
||||
|
||||
@@ -41,6 +41,8 @@ const (
|
||||
CfgDashboardVoice = "dashboard.board.voice"
|
||||
// CfgArchiveRemindDays 数据归档提醒周期(天):距上次成功备份超过该天数时提醒清理(默认 7,0=关闭)
|
||||
CfgArchiveRemindDays = "archive.remind.days"
|
||||
// CfgArchiveProtectDays 数据保护期(天):仅允许删除该天数之前的数据(默认 180)
|
||||
CfgArchiveProtectDays = "archive.protect.days"
|
||||
)
|
||||
|
||||
// startedAt 服务启动时刻(本机信息展示用)
|
||||
@@ -97,7 +99,8 @@ var settingsDefaults = map[string]int{
|
||||
CfgAllowCrossDay: 1,
|
||||
CfgTorqueNgAlert: 1, // B2.1 默认开启拧紧不合格报警
|
||||
CfgDashboardRefreshSeconds: 5, // 看板轮询兜底刷新间隔(秒)
|
||||
CfgArchiveRemindDays: 7, // 数据归档提醒周期(天)
|
||||
CfgArchiveRemindDays: 7, // 数据归档提醒周期(天)
|
||||
CfgArchiveProtectDays: 180, // 数据保护期(天)
|
||||
}
|
||||
|
||||
// GetSettings 读取基础设置 + 本机信息。DB 读失败时按默认值返回(设置页必须能打开)。
|
||||
|
||||
Reference in New Issue
Block a user