| | |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | progressCache, err := slf.GetCurrentProgress() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if progressCache == nil { |
| | | return errors.New("progress cache not found") |
| | |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (slf ProgressService) GetCurrentProgress() (progressCache *model.ProductionProgress, err error) { |
| | | var ok bool |
| | | progressCache, ok = ProgressCacheGet() |
| | | if !ok { |
| | | progressCache, err = model.NewProductionProgressSearch(nil).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(progressCache) |
| | | } |
| | | } |
| | | return |
| | | } |