| | |
| | | package service |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/model" |
| | | "errors" |
| | | "github.com/jinzhu/gorm" |
| | |
| | | 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 |
| | | } |
| | |
| | | } |
| | | 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") |
| | | } |
| | |
| | | progressCache = nil |
| | | } |
| | | if progressCache != nil { |
| | | ProgressCacheSet(channel, progressCache) |
| | | ProgressCacheSet(deviceID, channel, progressCache) |
| | | } |
| | | } |
| | | return |