From d93d2bc56ed06b3c060ff48f49591e8c5d779230 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 14 九月 2023 22:33:45 +0800 Subject: [PATCH] 通讯方式字段转换 --- service/progress.go | 45 +++++++++++++++++++++++++++++---------------- 1 files changed, 29 insertions(+), 16 deletions(-) diff --git a/service/progress.go b/service/progress.go index bb0d859..972a248 100644 --- a/service/progress.go +++ b/service/progress.go @@ -20,37 +20,50 @@ 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(progress) + ProgressCacheSet(procedure.Position, progress) return nil } -func (slf ProgressService) UpdateProgress(finishedQuantity int64) (err error) { - var progressCache *model.ProductionProgress - progressCache, ok := ProgressCacheGet() - if !ok { - progressCache, err = model.NewProductionProgressSearch(nil).SetOrder("id desc").First() - if err == gorm.ErrRecordNotFound { - return errors.New("progress cache not found") - } - if err != nil { - return err - } - if progressCache.FinishedQuantity < progressCache.TotalQuantity { - ProgressCacheSet(progressCache) - } +func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) { + progressCache, err := slf.GetCurrentProgress(position) + if err != nil { + return err } if progressCache == nil { return errors.New("progress cache not found") } if finishedQuantity > progressCache.FinishedQuantity { //褰撴湁鍙樺寲鏃舵墠鏇存柊 progressCache.FinishedQuantity = finishedQuantity - ProgressCacheSet(progressCache) + ProgressCacheSet(position, progressCache) return model.NewProductionProgressSearch(nil).SetId(progressCache.ID).Save(progressCache) } return nil } + +func (slf ProgressService) GetCurrentProgress(position int) (progressCache *model.ProductionProgress, err error) { + var ok bool + progressCache, ok = ProgressCacheGet(position) + if !ok { + progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First() + if err == gorm.ErrRecordNotFound { + return nil, errors.New("progress not found") + } + if err != nil { + return nil, err + } + + if progressCache.FinishedQuantity >= progressCache.TotalQuantity { //濡傛灉瀹屾垚閲忓ぇ浜庣瓑浜庢�婚噺灏辫鏄庢槸涓婁竴涓凡瀹屾垚鐨勪换鍔★紝涓嶆槸褰撳墠杩涜涓殑浠诲姟銆� + progressCache = nil + } + if progressCache != nil { + ProgressCacheSet(position, progressCache) + } + } + return +} -- Gitblit v1.8.0