fix
zhangqian
2023-10-19 cab6eea89a0d82710369604ecb51f1cdb122e433
service/cache_store.go
@@ -1,10 +1,11 @@
package service
import (
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/model"
   "apsClient/model/response"
   "fmt"
   "github.com/jinzhu/gorm"
   "github.com/spf13/cast"
   "sync"
   "time"
@@ -47,8 +48,8 @@
}
const (
   PlcCacheKey             = "plc:%v:%v" //plc:channel:key
   CurrentTaskCacheKey     = "current_task"
   PlcCacheKey             = "plc:%v:%v"                    //plc:channel:key
   CurrentTaskCacheKey     = "current_task:%v"              //current_task:channel
   CurrentProgressCacheKey = "current_progress:%v"          //current_progress:channel
   PlcCacheKeyUpdateTime   = "finish_number_update_time:%v" //finish_number_update_time:channel
)
@@ -79,19 +80,26 @@
   defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, channel), value)
}
func TaskCacheSet(value *response.TaskData) {
   defaultCacheStore.Add(CurrentTaskCacheKey, value)
func TaskFlagSet(channel int32) {
   defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), true)
}
func TaskCacheUnset() {
   defaultCacheStore.Remove(CurrentTaskCacheKey)
func TaskFlagUnset(channel int32) {
   defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false)
}
func TaskCacheGet() (*response.TaskData, bool) {
   if v, ok := defaultCacheStore.Get(CurrentTaskCacheKey); ok {
      return v.(*response.TaskData), ok
func TaskFlagGet(channel int32) bool {
   if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentTaskCacheKey, channel)); ok {
      return v.(bool)
   }
   return nil, false
   _, err := model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.System.DeviceId).SetStatus(model.ProcedureStatusProcessing).SetChannels([]int32{channel}).First()
   if err == gorm.ErrRecordNotFound {
      defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false)
      return false
   } else {
      defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), true)
      return true
   }
}
func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) {