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,60 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/common/errorx"
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent/equipment"
|
||||
"bj_power_mes/ent/equipmenttype"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetMachineLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取机床详情
|
||||
func NewGetMachineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMachineLogic {
|
||||
return &GetMachineLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetMachineLogic) GetMachine(req *types.PathId) (resp *types.MachineReply, err error) {
|
||||
m, err := l.svcCtx.EntClient.Equipment.Query().
|
||||
Where(
|
||||
equipment.IDEQ(req.Id),
|
||||
equipment.HasEquipmentTypeWith(
|
||||
equipmenttype.CodeEQ(constants.EquipmentTypeCode_CNC),
|
||||
),
|
||||
).
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errorx.NewDirectError("机床不存在")
|
||||
}
|
||||
|
||||
resp = &types.MachineReply{
|
||||
Id: m.ID,
|
||||
Name: m.Name,
|
||||
IpAddress: m.IpAddress,
|
||||
Location: m.Location,
|
||||
Status: string(m.Status),
|
||||
Remark: m.Remark,
|
||||
SlotCount: m.SlotCount,
|
||||
}
|
||||
if m.CreatedAt != nil {
|
||||
resp.CreatedAt = m.CreatedAt.Unix()
|
||||
}
|
||||
if m.UpdatedAt != nil {
|
||||
resp.UpdatedAt = m.UpdatedAt.Unix()
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent/equipment"
|
||||
"bj_power_mes/ent/equipmenttype"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListMachinesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewListMachinesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListMachinesLogic {
|
||||
return &ListMachinesLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListMachinesLogic) ListMachines() (resp []types.MachineListReply, err error) {
|
||||
machines, err := l.svcCtx.EntClient.Equipment.Query().
|
||||
Where(equipment.HasEquipmentTypeWith(
|
||||
equipmenttype.CodeEQ(constants.EquipmentTypeCode_CNC),
|
||||
)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query cnc machines: %w", err)
|
||||
}
|
||||
|
||||
resp = make([]types.MachineListReply, 0, len(machines))
|
||||
for _, m := range machines {
|
||||
resp = append(resp, types.MachineListReply{
|
||||
Id: m.ID,
|
||||
No: m.ID,
|
||||
Name: m.Name,
|
||||
Enabled: m.Enabled,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/equipment"
|
||||
"bj_power_mes/ent/equipmenttype"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryMachinesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 分页查询机床列表
|
||||
func NewQueryMachinesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryMachinesLogic {
|
||||
return &QueryMachinesLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QueryMachinesLogic) QueryMachines(req *types.QueryMachinesReq) (resp *types.QueryMachinesReply, err error) {
|
||||
query := l.svcCtx.EntClient.Equipment.Query().
|
||||
Where(equipment.HasEquipmentTypeWith(
|
||||
equipmenttype.CodeEQ(constants.EquipmentTypeCode_CNC),
|
||||
))
|
||||
|
||||
if req.Keyword != "" {
|
||||
query = query.Where(equipment.NameContainsFold(req.Keyword))
|
||||
}
|
||||
|
||||
total, err := query.Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
machines, err := query.
|
||||
Offset((req.Page - 1) * req.Limit).
|
||||
Limit(req.Limit).
|
||||
Order(ent.Desc(equipment.FieldID)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := make([]types.MachineReply, 0, len(machines))
|
||||
for _, m := range machines {
|
||||
item := types.MachineReply{
|
||||
Id: m.ID,
|
||||
Name: m.Name,
|
||||
IpAddress: m.IpAddress,
|
||||
Location: m.Location,
|
||||
Status: string(m.Status),
|
||||
Remark: m.Remark,
|
||||
SlotCount: m.SlotCount,
|
||||
}
|
||||
if m.CreatedAt != nil {
|
||||
item.CreatedAt = m.CreatedAt.Unix()
|
||||
}
|
||||
if m.UpdatedAt != nil {
|
||||
item.UpdatedAt = m.UpdatedAt.Unix()
|
||||
}
|
||||
data = append(data, item)
|
||||
}
|
||||
|
||||
return &types.QueryMachinesReply{
|
||||
PageReply: types.PageReply{
|
||||
Page: req.Page,
|
||||
Limit: req.Limit,
|
||||
Total: total,
|
||||
},
|
||||
Data: data,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user