zhangqian
2023-09-14 040cd381f2e8475e9b4eb336b704ad878f56f4fa
service/progress.go
@@ -20,17 +20,18 @@
      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) {
   progressCache, err := slf.GetCurrentProgress()
func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(position)
   if err != nil {
      return err
   }
@@ -39,17 +40,17 @@
   }
   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() (progressCache *model.ProductionProgress, err error) {
func (slf ProgressService) GetCurrentProgress(position int) (progressCache *model.ProductionProgress, err error) {
   var ok bool
   progressCache, ok = ProgressCacheGet()
   progressCache, ok = ProgressCacheGet(position)
   if !ok {
      progressCache, err = model.NewProductionProgressSearch(nil).SetOrder("id desc").First()
      progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First()
      if err == gorm.ErrRecordNotFound {
         return nil, errors.New("progress not found")
      }
@@ -61,7 +62,7 @@
         progressCache = nil
      }
      if progressCache != nil {
         ProgressCacheSet(progressCache)
         ProgressCacheSet(position, progressCache)
      }
   }
   return