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:
SunYF
2026-08-27 10:56:41 +08:00
parent 380715f8a9
commit 371b494c54
523 changed files with 67923 additions and 24758 deletions
@@ -0,0 +1,84 @@
package agv
import (
"context"
"fmt"
"time"
"bj_power_mes/internal/processor/eventloop"
"bj_power_mes/internal/svc"
"bj_power_mes/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AgvRequestEntryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAgvRequestEntryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AgvRequestEntryLogic {
return &AgvRequestEntryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// AgvRequestEntry MOM业务: AGV对自动线进出请求接口
// MOM文档必填字段: eventId, IsLoaded, palletid, stationCode, direction
// MOM文档可选字段: createdAt, BillNo
func (l *AgvRequestEntryLogic) AgvRequestEntry(req *types.AgvRequestEntryReq) (*types.AgvRequestEntryReply, error) {
// ── 必填字段校验 ──
if req.EventId == "" {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: "必填字段 eventId 为空"}, nil
}
if req.IsLoaded != "0" && req.IsLoaded != "1" {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: "必填字段 IsLoaded 必须为 0 或 1"}, nil
}
if req.PalletId == "" {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: "必填字段 palletid 为空"}, nil
}
if req.StationCode == "" {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: "必填字段 stationCode 为空"}, nil
}
if req.Direction != "ENTER" && req.Direction != "EXIT" {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: "必填字段 direction 必须为 ENTER 或 EXIT"}, nil
}
// ── stationCode → dockNo 映射 ──
// 从配置文件 StationDockMap 查找映射关系,避免硬编码解析
dockNo := l.svcCtx.Config.Mom.StationDockMap[req.StationCode]
if dockNo == 0 {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400",
Msg: fmt.Sprintf("未知的 stationCode: %s,请在配置 StationDockMap 中添加映射", req.StationCode)}, nil
}
l.Infof("AGV request entry: eventId=%s isLoaded=%s palletId=%s stationCode=%s dockNo=%d direction=%s billNo=%s",
req.EventId, req.IsLoaded, req.PalletId, req.StationCode, dockNo, req.Direction, req.BillNo)
if l.svcCtx.EventLoop == nil {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "500", Msg: "event loop not available"}, nil
}
result, err := l.svcCtx.EventLoop.SendSync(eventloop.EventLoopMessage{
ID: fmt.Sprintf("agv-req-%s-%d", req.EventId, time.Now().UnixNano()),
Type: eventloop.EvtAgvRequestEntry,
Payload: map[string]any{
"palletCode": req.PalletId,
"dockNo": dockNo,
"stationCode": req.StationCode,
"direction": req.Direction,
"billNo": req.BillNo,
},
}, 10*time.Second)
if err != nil {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "500", Msg: fmt.Sprintf("处理超时: %v", err)}, nil
}
if !result.Success {
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "400", Msg: result.Error}, nil
}
return &types.AgvRequestEntryReply{Id: req.EventId, Code: "200", Msg: "成功"}, nil
}