zhangqian
2023-11-23 948bfeb2e8abd2ec80e282bd1b17975b89d3eb74
service/progress.go
@@ -1,7 +1,6 @@
package service
import (
   "apsClient/conf"
   "apsClient/model"
   "errors"
   "github.com/jinzhu/gorm"
@@ -29,14 +28,14 @@
      if err != nil {
         return err
      }
      ProgressCacheSet(procedure.Channel, progress)
      ProgressCacheSet(procedure.DeviceID, procedure.Channel, progress)
   }
   return nil
}
func (slf ProgressService) UpdateProgress(channel int32, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(channel)
func (slf ProgressService) UpdateProgress(deviceID string, channel int32, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(deviceID, channel)
   if err != nil {
      return err
   }
@@ -45,17 +44,17 @@
   }
   if finishedQuantity > progressCache.FinishedQuantity { //当有变化时才更新
      progressCache.FinishedQuantity = finishedQuantity
      ProgressCacheSet(channel, progressCache)
      ProgressCacheSet(deviceID, channel, progressCache)
      return model.NewProductionProgressSearch(nil).SetId(progressCache.ID).Save(progressCache)
   }
   return nil
}
func (slf ProgressService) GetCurrentProgress(channel int32) (progressCache *model.ProductionProgress, err error) {
func (slf ProgressService) GetCurrentProgress(deviceID string, channel int32) (progressCache *model.ProductionProgress, err error) {
   var ok bool
   progressCache, ok = ProgressCacheGet(channel)
   progressCache, ok = ProgressCacheGet(deviceID, channel)
   if !ok {
      progressCache, err = model.NewProductionProgressSearch(nil).SetDeviceId(conf.Conf.CurrentDeviceID).SetChannel(channel).SetOrder("id asc").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")
      }
@@ -67,7 +66,7 @@
         progressCache = nil
      }
      if progressCache != nil {
         ProgressCacheSet(channel, progressCache)
         ProgressCacheSet(deviceID, channel, progressCache)
      }
   }
   return