zhangqian
2023-09-23 14fc2f577e2c0b7b146c1a430e9438f317ad5b0c
service/progress.go
@@ -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.Channel, progress)
   }
   return nil
}
func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(position)
func (slf ProgressService) UpdateProgress(channel int32, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(channel)
   if err != nil {
      return err
   }
@@ -44,17 +44,17 @@
   }
   if finishedQuantity > progressCache.FinishedQuantity { //当有变化时才更新
      progressCache.FinishedQuantity = finishedQuantity
      ProgressCacheSet(position, progressCache)
      ProgressCacheSet(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(channel int32) (progressCache *model.ProductionProgress, err error) {
   var ok bool
   progressCache, ok = ProgressCacheGet(position)
   progressCache, ok = ProgressCacheGet(channel)
   if !ok {
      progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First()
      progressCache, err = model.NewProductionProgressSearch(nil).SetChannel(channel).SetOrder("id desc").First()
      if err == gorm.ErrRecordNotFound {
         return nil, errors.New("progress not found")
      }
@@ -66,7 +66,7 @@
         progressCache = nil
      }
      if progressCache != nil {
         ProgressCacheSet(position, progressCache)
         ProgressCacheSet(channel, progressCache)
      }
   }
   return