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,67 @@
|
||||
package inspection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"bj_power_mes/constants"
|
||||
"bj_power_mes/ent/equipment"
|
||||
"bj_power_mes/ent/equipmentslot"
|
||||
"bj_power_mes/ent/equipmenttype"
|
||||
"bj_power_mes/ent/job"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetInspectionInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取当前检测信息
|
||||
func NewGetInspectionInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInspectionInfoLogic {
|
||||
return &GetInspectionInfoLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetInspectionInfoLogic) GetInspectionInfo() (resp *types.InspectionInfoReply, err error) {
|
||||
// 查找内窥镜检测设备上正在检测的工件
|
||||
slot, err := l.svcCtx.EntClient.EquipmentSlot.Query().
|
||||
Where(
|
||||
equipmentslot.StatusEQ(constants.SlotStatus_Occupied),
|
||||
equipmentslot.HasEquipmentWith(
|
||||
equipment.HasEquipmentTypeWith(
|
||||
equipmenttype.CodeEQ(constants.EquipmentTypeCode_Inspection),
|
||||
),
|
||||
),
|
||||
).
|
||||
WithEquipment().
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
// 无正在检测的工件
|
||||
return &types.InspectionInfoReply{}, nil
|
||||
}
|
||||
|
||||
resp = &types.InspectionInfoReply{}
|
||||
|
||||
// 通过 currentJobId 查找工件信息
|
||||
if slot.CurrentJobId != nil && *slot.CurrentJobId > 0 {
|
||||
j, err := l.svcCtx.EntClient.Job.Query().
|
||||
Where(job.IDEQ(*slot.CurrentJobId)).
|
||||
WithWorkOrder().
|
||||
Only(l.ctx)
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
resp.JobId = j.ID
|
||||
resp.WorkpieceType = j.ProductTypeId
|
||||
resp.ScanCode = j.WorkpieceNo
|
||||
if j.Edges.WorkOrder != nil {
|
||||
resp.OrderId = j.Edges.WorkOrder.ID
|
||||
resp.OrderNo = fmt.Sprintf("WO-%d", j.Edges.WorkOrder.ID)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package inspection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/inspectionimage"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type QueryInspectionImagesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewQueryInspectionImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryInspectionImagesLogic {
|
||||
return &QueryInspectionImagesLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *QueryInspectionImagesLogic) QueryInspectionImages(req *types.QueryInspectionImagesReq) (resp *types.QueryInspectionImagesReply, err error) {
|
||||
query := l.svcCtx.EntClient.InspectionImage.Query()
|
||||
|
||||
if req.JobId > 0 {
|
||||
query = query.Where(inspectionimage.JobIdEQ(req.JobId))
|
||||
}
|
||||
if req.StartDate != "" {
|
||||
if t, err := time.ParseInLocation("2006-01-02", req.StartDate, time.Local); err == nil {
|
||||
query = query.Where(inspectionimage.CapturedAtGTE(t))
|
||||
}
|
||||
}
|
||||
if req.EndDate != "" {
|
||||
if t, err := time.ParseInLocation("2006-01-02", req.EndDate, time.Local); err == nil {
|
||||
query = query.Where(inspectionimage.CapturedAtLTE(t.Add(24 * time.Hour)))
|
||||
}
|
||||
}
|
||||
if req.WorkpieceNo != "" {
|
||||
query = query.Where(inspectionimage.WorkpieceNoContains(req.WorkpieceNo))
|
||||
}
|
||||
|
||||
// 工单号搜索
|
||||
if req.WorkOrderNo != "" {
|
||||
ids, err := l.svcCtx.EntClient.WorkOrder.Query().
|
||||
Where(workorder.WorkOrderNoContains(req.WorkOrderNo)).
|
||||
IDs(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return &types.QueryInspectionImagesReply{Data: []types.InspectionImageReply{}, Total: 0}, nil
|
||||
}
|
||||
query = query.Where(inspectionimage.WorkOrderIdIn(ids...))
|
||||
}
|
||||
|
||||
if req.PalletCode != "" {
|
||||
query = query.Where(inspectionimage.PalletCodeContains(req.PalletCode))
|
||||
}
|
||||
|
||||
total, err := query.Count(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
limit := req.Limit
|
||||
if limit <= 0 || limit > 100 {
|
||||
limit = 20
|
||||
}
|
||||
offset := (req.Page - 1) * limit
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
images, err := query.
|
||||
Order(ent.Desc(inspectionimage.FieldCapturedAt)).
|
||||
Offset(offset).
|
||||
Limit(limit).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := make([]types.InspectionImageReply, 0, len(images))
|
||||
for _, img := range images {
|
||||
item := types.InspectionImageReply{
|
||||
Id: img.ID,
|
||||
JobId: img.JobId,
|
||||
WorkpieceNo: img.WorkpieceNo,
|
||||
WorkOrderNo: img.WorkOrderNo,
|
||||
PalletCode: img.PalletCode,
|
||||
FileName: img.FileName,
|
||||
FilePath: img.FilePath,
|
||||
FileSize: img.FileSize,
|
||||
}
|
||||
if img.CapturedAt != nil {
|
||||
item.CapturedAt = img.CapturedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
data = append(data, item)
|
||||
}
|
||||
|
||||
return &types.QueryInspectionImagesReply{Data: data, Total: total}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user