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,49 @@
|
||||
package dock
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/internal/types"
|
||||
)
|
||||
|
||||
func statusToString(s int) string {
|
||||
switch s {
|
||||
case 0:
|
||||
return "EMPTY"
|
||||
case 1:
|
||||
return "FILL"
|
||||
case 2:
|
||||
return "PROCESSING"
|
||||
case 3:
|
||||
return "DONE"
|
||||
default:
|
||||
return fmt.Sprintf("UNKNOWN_%d", s)
|
||||
}
|
||||
}
|
||||
|
||||
func determineDockSlotStatus(slot *ent.DockSlot, job *ent.Job) int {
|
||||
if slot.CurrentJobId == nil || *slot.CurrentJobId == 0 {
|
||||
return 0 // EMPTY
|
||||
}
|
||||
if job.Status == constants.JobStatus_Created {
|
||||
return 1 // FILL
|
||||
}
|
||||
if job.Status == constants.JobStatus_Completed {
|
||||
return 3 // DONE
|
||||
}
|
||||
return 2 // PROCESSING
|
||||
}
|
||||
|
||||
func toJobBrief(j *ent.Job) *types.JobBrief {
|
||||
brief := &types.JobBrief{
|
||||
Id: j.ID,
|
||||
WorkOrderId: j.WorkOrderId,
|
||||
WorkpieceNo: j.WorkpieceNo,
|
||||
ProductTypeId: j.ProductTypeId,
|
||||
Status: string(j.Status),
|
||||
CurrentStepId: j.CurrentStepId,
|
||||
}
|
||||
return brief
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package dock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/dockslot"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListDockSlotsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListDockSlotsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDockSlotsLogic {
|
||||
return &ListDockSlotsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListDockSlotsLogic) ListDockSlots() (*types.DockSlotsReply, error) {
|
||||
slots, err := l.svcCtx.EntClient.DockSlot.Query().
|
||||
WithCurrentJob(func(q *ent.JobQuery) {
|
||||
q.WithWorkOrder(func(wq *ent.WorkOrderQuery) {
|
||||
wq.WithProductType()
|
||||
})
|
||||
}).
|
||||
Order(ent.Asc(dockslot.FieldDockNo), ent.Asc(dockslot.FieldSlotNo)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
l.Logger.Errorf("query dock slots failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dockMap := make(map[int][]types.DockSlotReply)
|
||||
for _, s := range slots {
|
||||
status := determineDockSlotStatus(s, s.Edges.CurrentJob)
|
||||
dr := types.DockSlotReply{
|
||||
SlotNo: s.SlotNo,
|
||||
Status: statusToString(status),
|
||||
}
|
||||
if s.Edges.CurrentJob != nil {
|
||||
dr.Job = toJobBrief(s.Edges.CurrentJob)
|
||||
}
|
||||
dockMap[s.DockNo] = append(dockMap[s.DockNo], dr)
|
||||
}
|
||||
|
||||
docks := make([]types.DockReply, 0, len(dockMap))
|
||||
for dockNo, slotList := range dockMap {
|
||||
docks = append(docks, types.DockReply{
|
||||
DockNo: dockNo,
|
||||
Slots: slotList,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.DockSlotsReply{Docks: docks}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user