From 83b652cd2f1be2375d33a67366a7c359cf6e22c0 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 18 九月 2023 14:56:09 +0800 Subject: [PATCH] 支持几个配置,支持按配置选择plc驱动包 --- service/progress.go | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-) diff --git a/service/progress.go b/service/progress.go index 972a248..7d39cfa 100644 --- a/service/progress.go +++ b/service/progress.go @@ -13,20 +13,24 @@ return &ProgressService{} } -func (slf ProgressService) AddProgress(db *gorm.DB, procedure *model.Procedures, order *model.Order) error { - progress := &model.ProductionProgress{ - WorkOrderID: procedure.WorkOrderID, - OrderID: procedure.OrderID, - ProcedureID: procedure.ProceduresInfo.ProcedureID, - DeviceID: procedure.DeviceID, - TotalQuantity: order.Amount.IntPart(), - Position: procedure.Position, +func (slf ProgressService) Upsert(db *gorm.DB, procedure *model.Procedures, order *model.Order) error { + _, err := model.NewProductionProgressSearch(db).SetProcedureId(procedure.ProcedureID).SetWorkOrderId(procedure.WorkOrderID).First() + if err == gorm.ErrRecordNotFound { + progress := &model.ProductionProgress{ + WorkOrderID: procedure.WorkOrderID, + OrderID: procedure.OrderID, + ProcedureID: procedure.ProceduresInfo.ProcedureID, + DeviceID: procedure.DeviceID, + TotalQuantity: order.Amount.IntPart(), + Position: procedure.Position, + } + err := model.NewProductionProgressSearch(db).Create(progress) + if err != nil { + return err + } + ProgressCacheSet(procedure.Position, progress) } - err := model.NewProductionProgressSearch(db).Create(progress) - if err != nil { - return err - } - ProgressCacheSet(procedure.Position, progress) + return nil } -- Gitblit v1.8.0