feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图
This commit is contained in:
@@ -13,10 +13,12 @@ import (
|
||||
"bj_power_mes/ent/materialrequest"
|
||||
"bj_power_mes/ent/plcsendlog"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stationstate"
|
||||
"bj_power_mes/ent/torquerecord"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/ent/workpiece"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
"bj_power_mes/internal/plc"
|
||||
)
|
||||
|
||||
const dashboardTTL = 60 // 秒,看板缓存
|
||||
@@ -509,6 +511,9 @@ func (s *Service) buildEquipment(ctx context.Context, today time.Time) []Station
|
||||
v.CurrentSn = r.Sn
|
||||
v.CurrentOperator = r.Operator
|
||||
v.CurrentFlowId = r.FlowId
|
||||
if v.CurrentProcess == "" {
|
||||
v.CurrentProcess = r.ProcessName
|
||||
}
|
||||
}
|
||||
if v.Status != "alarm" {
|
||||
if strings.EqualFold(r.Result, "NG") {
|
||||
@@ -521,6 +526,19 @@ func (s *Service) buildEquipment(ctx context.Context, today time.Time) []Station
|
||||
}
|
||||
}
|
||||
|
||||
// 当天停单(station_state):paused=true 时前端仅以图标提示,不渲染刺眼文字
|
||||
if pauses, err := s.ctx.EntClient.StationState.Query().
|
||||
Where(stationstate.Date(today.Format("2006-01-02")), stationstate.Paused(true)).
|
||||
All(ctx); err == nil {
|
||||
for _, p := range pauses {
|
||||
if v, ok := stMap[p.StationNo]; ok {
|
||||
v.Paused = true
|
||||
v.PauseReason = p.Reason
|
||||
stMap[p.StationNo] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当日累计:每个工位的完成数与 NG 数
|
||||
if steps, err := s.ctx.EntClient.WorkpieceProcess.Query().
|
||||
Where(workpieceprocess.EndedAtGTE(today)).All(ctx); err == nil {
|
||||
@@ -602,6 +620,65 @@ func agvStatusFromRequest(status string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 看板点位态(主线 C1~C15 / 接驳台 G1L..G10R + JBT21 / 在途路径指令)
|
||||
// ============================================================
|
||||
|
||||
// dockCodeToLabel PLC/Dock 表编码(DOCK01..21)→ 布局说明命名(G1L..G10R / JBT21)。
|
||||
// 顺序即 PLC M900.0~M902.3:DOCK01=G1L(左侧)、DOCK02=G1R(右侧)、DOCK03=G2L … DOCK20=G10R;DOCK21=JBT21。
|
||||
func dockCodeToLabel(code string) string {
|
||||
c := strings.ToUpper(strings.TrimSpace(code))
|
||||
if c == "DOCK21" || c == "JBT21" {
|
||||
return "JBT21"
|
||||
}
|
||||
if !strings.HasPrefix(c, "DOCK") {
|
||||
return c
|
||||
}
|
||||
n, err := strconv.Atoi(strings.TrimPrefix(c, "DOCK"))
|
||||
if err != nil || n < 1 || n > 20 {
|
||||
return c
|
||||
}
|
||||
// 奇数=左侧 L、偶数=右侧 R(产线布局说明.md 命名规则)
|
||||
suffix := "R"
|
||||
if n%2 == 1 {
|
||||
suffix = "L"
|
||||
}
|
||||
return fmt.Sprintf("G%d%s", (n+1)/2, suffix)
|
||||
}
|
||||
|
||||
// buildPoints 看板点位态:主线 15 位 + 接驳台 21 位(PLC 一次位块读)+ 在途路径指令(MW 一次块读)。
|
||||
// PLC 读取失败只降级本块(返回 Mock=true 空态),不影响整屏快照。
|
||||
func (s *Service) buildPoints(ctx context.Context) FrontPoints {
|
||||
out := FrontPoints{Mock: s.ctx.PLC.IsMock(), Main: []FrontPoint{}, Dock: []FrontPoint{}, Transit: []InTransit{}}
|
||||
bits, err := s.ctx.PLC.ReadBits(ctx)
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
for i := 0; i < 15; i++ {
|
||||
out.Main = append(out.Main, FrontPoint{Code: fmt.Sprintf("C%d", i+1), Has: bitAt(bits, 12+i)})
|
||||
}
|
||||
for i := 0; i < 20; i++ {
|
||||
out.Dock = append(out.Dock, FrontPoint{Code: dockCodeToLabel(fmt.Sprintf("DOCK%02d", i+1)), Has: bitAt(bits, 27+i)})
|
||||
}
|
||||
out.Dock = append(out.Dock, FrontPoint{Code: "JBT21", Has: bitAt(bits, 47)})
|
||||
// 在途路径指令:一次批量读 MW800..MW887(44 个路由寄存器),非 0 即在途
|
||||
if vals, err := s.ctx.PLC.ReadMWBlock(ctx, 800, 88); err == nil {
|
||||
for _, addr := range plc.AllRouteAddrs() {
|
||||
idx := addr - 800
|
||||
if idx < 0 || idx >= len(vals) || vals[idx] == 0 {
|
||||
continue
|
||||
}
|
||||
if srcType, tgtType, src, tgt, ok := plc.ParseMW(addr, vals[idx]); ok {
|
||||
out.Transit = append(out.Transit, InTransit{
|
||||
Src: string(srcType) + strconv.Itoa(src),
|
||||
Tgt: string(tgtType) + strconv.Itoa(tgt),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 屏6:人员绩效
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user