From efec800478214f3a412f879d2b51c2968515995d Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 25 十一月 2023 17:04:25 +0800 Subject: [PATCH] plc断开连接时获取工序最后一次报工数量作为加工数 --- service/progress.go | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/service/progress.go b/service/progress.go index 9f19ae6..0f18fb9 100644 --- a/service/progress.go +++ b/service/progress.go @@ -3,7 +3,7 @@ import ( "apsClient/model" "errors" - "gorm.io/gorm" + "github.com/jinzhu/gorm" ) type ProgressService struct { @@ -22,20 +22,20 @@ ProcedureID: procedure.ProceduresInfo.ProcedureID, DeviceID: procedure.DeviceID, TotalQuantity: order.Amount.IntPart(), - Position: procedure.Position, + Channel: procedure.Channel, } err := model.NewProductionProgressSearch(db).Create(progress) if err != nil { return err } - ProgressCacheSet(procedure.Position, progress) + ProgressCacheSet(procedure.DeviceID, procedure.Channel, progress) } return nil } -func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) { - progressCache, err := slf.GetCurrentProgress(position) +func (slf ProgressService) UpdateProgress(deviceID string, channel int32, finishedQuantity int64) (err error) { + progressCache, err := slf.GetCurrentProgress(deviceID, channel) if err != nil { return err } @@ -44,17 +44,17 @@ } if finishedQuantity > progressCache.FinishedQuantity { //褰撴湁鍙樺寲鏃舵墠鏇存柊 progressCache.FinishedQuantity = finishedQuantity - ProgressCacheSet(position, progressCache) + ProgressCacheSet(deviceID, channel, progressCache) return model.NewProductionProgressSearch(nil).SetId(progressCache.ID).Save(progressCache) } return nil } -func (slf ProgressService) GetCurrentProgress(position int) (progressCache *model.ProductionProgress, err error) { +func (slf ProgressService) GetCurrentProgress(deviceID string, channel int32) (progressCache *model.ProductionProgress, err error) { var ok bool - progressCache, ok = ProgressCacheGet(position) + progressCache, ok = ProgressCacheGet(deviceID, channel) if !ok { - progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First() + progressCache, err = model.NewProductionProgressSearch(nil).SetDeviceId(deviceID).SetChannel(channel).SetOrder("id asc").First() if err == gorm.ErrRecordNotFound { return nil, errors.New("progress not found") } @@ -66,8 +66,14 @@ progressCache = nil } if progressCache != nil { - ProgressCacheSet(position, progressCache) + ProgressCacheSet(deviceID, channel, progressCache) } } return } + +// GetProgressList 鑾峰彇寰呭悓姝ヨ繘搴﹀伐搴� +func (slf ProgressService) GetProgressList() (progressList []*model.ProductionProgress, err error) { + progressList, err = model.NewProductionProgressSearch(nil).SetUnFinished().SetOrder("id desc").SetPage(1, 100).FindNotTotal() + return +} -- Gitblit v1.8.0