fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent/alarm"
|
||||
"bj_power_mes/ent/equipmentslot"
|
||||
"bj_power_mes/ent/job"
|
||||
"bj_power_mes/ent/manualaction"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetSystemStatusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetSystemStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSystemStatusLogic {
|
||||
return &GetSystemStatusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSystemStatusLogic) GetSystemStatus() (resp *types.SystemStatusReply, err error) {
|
||||
plcConnected := l.svcCtx.PLCManager.IsConnected()
|
||||
robotConnected := l.svcCtx.RobotManager.IsConnected()
|
||||
|
||||
activeOrders, err := l.svcCtx.EntClient.WorkOrder.Query().
|
||||
Where(
|
||||
workorder.StatusEQ("IN_PROGRESS"),
|
||||
).
|
||||
Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询活跃工单失败: %w", err)
|
||||
}
|
||||
|
||||
pausedOrders, err := l.svcCtx.EntClient.WorkOrder.Query().
|
||||
Where(
|
||||
workorder.StatusEQ("PAUSED"),
|
||||
).
|
||||
Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询暂停工单失败: %w", err)
|
||||
}
|
||||
|
||||
activeJobs, err := l.svcCtx.EntClient.Job.Query().
|
||||
Where(
|
||||
job.StatusNEQ("COMPLETED"),
|
||||
job.StatusNEQ("SCRAPPED"),
|
||||
).
|
||||
Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询在制工件失败: %w", err)
|
||||
}
|
||||
|
||||
unackAlarms, err := l.svcCtx.EntClient.Alarm.Query().
|
||||
Where(
|
||||
alarm.Resolved(false),
|
||||
).
|
||||
Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询未确认报警失败: %w", err)
|
||||
}
|
||||
|
||||
// RecoverOnStartup 已将 PROCESSING 订单设为 PAUSED,列出所有 ON_BUFFER+ON_EQUIPMENT 非终态工件
|
||||
recoveryJobs, _ := l.svcCtx.EntClient.Job.Query().
|
||||
Where(
|
||||
job.StatusNotIn(constants.JobStatus_Completed, constants.JobStatus_Scrapped),
|
||||
job.PositionTypeIn(constants.PositionType_OnEquipment),
|
||||
job.HasWorkOrderWith(workorder.StatusEQ(constants.WorkOrderStatus_InProgress)),
|
||||
).
|
||||
Count(l.ctx)
|
||||
|
||||
stopPendingOrders, _ := l.svcCtx.EntClient.WorkOrder.Query().
|
||||
Where(
|
||||
workorder.StatusEQ(constants.WorkOrderStatus_Cancelling),
|
||||
).
|
||||
Count(l.ctx)
|
||||
pendingActions, err := l.svcCtx.EntClient.ManualAction.Query().
|
||||
Where(
|
||||
manualaction.StatusEQ("PENDING"),
|
||||
).
|
||||
Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询待处理操作失败: %w", err)
|
||||
}
|
||||
|
||||
emergencySlots, _ := l.svcCtx.EntClient.EquipmentSlot.Query().
|
||||
Where(
|
||||
equipmentslot.StatusEQ("EMERGENCY"),
|
||||
).
|
||||
Count(l.ctx)
|
||||
|
||||
lineStatus := "idle"
|
||||
if emergencySlots > 0 {
|
||||
lineStatus = "emergency"
|
||||
} else if unackAlarms > 0 {
|
||||
lineStatus = "paused"
|
||||
} else if pausedOrders > 0 {
|
||||
lineStatus = "paused"
|
||||
} else if activeOrders > 0 {
|
||||
lineStatus = "running"
|
||||
}
|
||||
|
||||
return &types.SystemStatusReply{
|
||||
PlcConnected: plcConnected,
|
||||
RobotConnected: robotConnected,
|
||||
LineStatus: lineStatus,
|
||||
ActiveWorkOrders: activeOrders + pausedOrders,
|
||||
ActiveJobs: activeJobs,
|
||||
UnacknowledgedAlarms: unackAlarms,
|
||||
RecoveryPending: recoveryJobs > 0,
|
||||
StopPending: stopPendingOrders > 0,
|
||||
PendingManualActions: pendingActions,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user