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,85 @@
|
||||
package pallet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/common/errorx"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/job"
|
||||
"bj_power_mes/ent/pallet"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPalletLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取托盘详情
|
||||
func NewGetPalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPalletLogic {
|
||||
return &GetPalletLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPalletLogic) GetPallet(req *types.PathId) (resp *types.PalletDetailReply, err error) {
|
||||
p, err := l.svcCtx.EntClient.Pallet.Query().
|
||||
Where(pallet.IDEQ(req.Id)).
|
||||
Only(l.ctx)
|
||||
if ent.IsNotFound(err) {
|
||||
return nil, errorx.NewDirectError("托盘不存在")
|
||||
} else if err != nil {
|
||||
l.Errorf("查询托盘失败: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reply := types.PalletReply{
|
||||
Id: p.ID,
|
||||
PalletCode: p.PalletCode,
|
||||
WorkOrderId: p.WorkOrderId,
|
||||
DockNo: p.DockNo,
|
||||
Status: string(p.Status),
|
||||
PassQty: p.PassQty,
|
||||
NgQty: p.NgQty,
|
||||
}
|
||||
if p.ArrivedAt != nil {
|
||||
reply.ArrivedAt = p.ArrivedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if p.CompletedAt != nil && !p.CompletedAt.IsZero() {
|
||||
reply.CompletedAt = p.CompletedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if p.ReportedAt != nil && !p.ReportedAt.IsZero() {
|
||||
reply.ReportedAt = p.ReportedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// 查询托盘下的工件
|
||||
jobs, err := l.svcCtx.EntClient.Job.Query().
|
||||
Where(job.HasPalletWith(pallet.IDEQ(p.ID))).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorf("查询托盘工件失败: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
jobList := make([]types.PalletJobReply, 0, len(jobs))
|
||||
for _, jb := range jobs {
|
||||
jobList = append(jobList, types.PalletJobReply{
|
||||
Id: jb.ID,
|
||||
WorkpieceNo: jb.WorkpieceNo,
|
||||
Status: string(jb.Status),
|
||||
CurrentStepId: jb.CurrentStepId,
|
||||
PositionType: string(jb.PositionType),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.PalletDetailReply{
|
||||
PalletReply: reply,
|
||||
Jobs: jobList,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package pallet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/common/errorx"
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/pallet"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryPalletsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 查询托盘列表
|
||||
func NewQueryPalletsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryPalletsLogic {
|
||||
return &QueryPalletsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QueryPalletsLogic) QueryPallets(req *types.QueryPalletsReq) (resp *types.QueryPalletsReply, err error) {
|
||||
query := l.svcCtx.EntClient.Pallet.Query()
|
||||
|
||||
if req.WorkOrderId > 0 {
|
||||
query = query.Where(pallet.WorkOrderIdEQ(req.WorkOrderId))
|
||||
}
|
||||
if req.DockNo > 0 {
|
||||
query = query.Where(pallet.DockNoEQ(req.DockNo))
|
||||
}
|
||||
if req.Status != "" {
|
||||
validStatus := false
|
||||
for _, s := range constants.PalletStatus("").Values() {
|
||||
if s == req.Status {
|
||||
validStatus = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !validStatus {
|
||||
return nil, errorx.NewDirectError("无效的状态值")
|
||||
}
|
||||
query = query.Where(pallet.StatusEQ(constants.PalletStatus(req.Status)))
|
||||
}
|
||||
|
||||
// 默认按 ID 倒序
|
||||
query = query.Order(ent.Desc(pallet.FieldID))
|
||||
|
||||
total, err := query.Count(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorf("查询托盘总数失败: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pallets, err := query.
|
||||
Offset((req.Page - 1) * req.Limit).
|
||||
Limit(req.Limit).
|
||||
Order(ent.Asc(pallet.FieldID)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorf("查询托盘列表失败: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := make([]types.PalletReply, 0, len(pallets))
|
||||
for _, p := range pallets {
|
||||
item := types.PalletReply{
|
||||
Id: p.ID,
|
||||
PalletCode: p.PalletCode,
|
||||
WorkOrderId: p.WorkOrderId,
|
||||
DockNo: p.DockNo,
|
||||
Status: string(p.Status),
|
||||
PassQty: p.PassQty,
|
||||
NgQty: p.NgQty,
|
||||
}
|
||||
item.TotalQty = p.TotalQty
|
||||
if p.ArrivedAt != nil {
|
||||
item.ArrivedAt = p.ArrivedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if p.CompletedAt != nil && !p.CompletedAt.IsZero() {
|
||||
item.CompletedAt = p.CompletedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if p.ReportedAt != nil && !p.ReportedAt.IsZero() {
|
||||
item.ReportedAt = p.ReportedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
data = append(data, item)
|
||||
}
|
||||
|
||||
return &types.QueryPalletsReply{
|
||||
PageReply: types.PageReply{
|
||||
Total: total,
|
||||
Page: req.Page,
|
||||
Limit: req.Limit,
|
||||
},
|
||||
Data: data,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package pallet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/common/errorx"
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent/dockslot"
|
||||
"bj_power_mes/ent/pallet"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ReportPalletLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 托盘报工
|
||||
func NewReportPalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReportPalletLogic {
|
||||
return &ReportPalletLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ReportPalletLogic) ReportPallet(req *types.PathId) (*types.ReportPalletReply, error) {
|
||||
p, err := l.svcCtx.EntClient.Pallet.Query().
|
||||
Where(pallet.IDEQ(req.Id)).
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errorx.NewDirectError("托盘不存在")
|
||||
}
|
||||
|
||||
// 校验前置条件:Pallet 必须已 COMPLETED
|
||||
if p.Status != constants.PalletStatus_Completed {
|
||||
return nil, errorx.NewDirectError(fmt.Sprintf("托盘尚未全部完工,当前状态: %s", p.Status))
|
||||
}
|
||||
|
||||
// 开启事务:清除 dock_slot + 更新托盘状态
|
||||
tx, err := l.svcCtx.EntClient.Tx(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorf("开启事务失败: %v", err)
|
||||
return nil, errorx.NewDirectError("系统错误")
|
||||
}
|
||||
|
||||
// 清除该托盘对应的 dock_slot:按 dockNo + workOrderId + 非空槽位 匹配
|
||||
_, err = tx.DockSlot.Update().
|
||||
Where(
|
||||
dockslot.DockNoEQ(p.DockNo),
|
||||
dockslot.WorkOrderIdEQ(p.WorkOrderId),
|
||||
dockslot.StatusNEQ(0),
|
||||
).
|
||||
SetStatus(0).
|
||||
ClearCurrentJobId().
|
||||
ClearWorkpieceTypeId().
|
||||
ClearWorkOrderId().
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
l.Errorf("清除 dock_slot 失败: %v", err)
|
||||
return nil, errorx.NewDirectError("清除 dock_slot 失败")
|
||||
}
|
||||
|
||||
// 状态转换:COMPLETED → REPORTED
|
||||
_, err = tx.Pallet.UpdateOneID(p.ID).
|
||||
SetStatus(constants.PalletStatus_Reported).
|
||||
SetReportedAt(time.Now()).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
l.Errorf("更新托盘报工状态失败: %v", err)
|
||||
return nil, errorx.NewDirectError("更新报工状态失败")
|
||||
}
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
l.Errorf("提交事务失败: %v", err)
|
||||
return nil, errorx.NewDirectError("提交事务失败")
|
||||
}
|
||||
|
||||
// 通知前端接驳台刷新
|
||||
if l.svcCtx.SSEHandler != nil {
|
||||
l.svcCtx.SSEHandler.Emit("dock_data_update", "{}")
|
||||
}
|
||||
|
||||
return &types.ReportPalletReply{
|
||||
Id: p.ID,
|
||||
Status: string(constants.PalletStatus_Reported),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user