From b331c9990a0396301e934daffe095f99d62d1c89 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 27 九月 2023 15:58:49 +0800 Subject: [PATCH] 任务获取修改,状态2只返回已开始和已结束的 --- service/cache_store.go | 77 ++++++++++++++++++++++++-------------- 1 files changed, 49 insertions(+), 28 deletions(-) diff --git a/service/cache_store.go b/service/cache_store.go index 4c3148b..2f6c515 100644 --- a/service/cache_store.go +++ b/service/cache_store.go @@ -1,10 +1,12 @@ package service import ( + "apsClient/constvar" "apsClient/model" - "apsClient/model/response" "fmt" + "github.com/spf13/cast" "sync" + "time" ) type CacheStore struct { @@ -44,45 +46,64 @@ } const ( - PlcCacheKey = "plc:%v" - CurrentTaskCacheKey = "current_task" - CurrentProgressCacheKey = "current_progress" + 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 ) -func PlcCacheGet(key string) (interface{}, bool) { - return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, key)) +func PlcCacheGet(channel int32, key string) (interface{}, bool) { + return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, channel, key)) } -func PlcCacheSet(key string, value interface{}) { - defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, key), value) -} - -func TaskCacheSet(value *response.TaskData) { - defaultCacheStore.Add(CurrentTaskCacheKey, value) -} - -func TaskCacheUnset() { - defaultCacheStore.Remove(CurrentTaskCacheKey) -} - -func TaskCacheGet() (*response.TaskData, bool) { - if v, ok := defaultCacheStore.Get(CurrentTaskCacheKey); ok { - return v.(*response.TaskData), ok +func PlcCacheSet(channel int32, key string, value interface{}) { + if key == constvar.PlcCacheKeyFinishNumber { + oldFinishNumber, exists := PlcCacheGet(channel, key) + if !exists || cast.ToInt(oldFinishNumber) != cast.ToInt(value) { //finishNumber鏈変簡鍙樺寲锛岃缃洿鏂版椂闂寸紦瀛� + FinishUpdateTimeSet(channel, time.Now().Unix()) + } } - return nil, false + defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, channel, key), value) } -func ProgressCacheGet() (*model.ProductionProgress, bool) { - if v, ok := defaultCacheStore.Get(CurrentProgressCacheKey); ok { +func FinishUpdateTimeGet(channel int32) interface{} { + val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, channel)) + if ok { + return val + } + return 0 +} + +func FinishUpdateTimeSet(channel int32, value interface{}) { + defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, channel), value) +} + +func TaskFlagSet(channel int32) { + defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), struct{}{}) +} + +func TaskFlagUnset(channel int32) { + defaultCacheStore.Remove(fmt.Sprintf(CurrentTaskCacheKey, channel)) +} + +func TaskFlagGet(channel int32) bool { + if _, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentTaskCacheKey, channel)); ok { + return true + } + return false +} + +func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) { + if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, channel)); ok { return v.(*model.ProductionProgress), ok } return nil, false } -func ProgressCacheSet(value *model.ProductionProgress) { - defaultCacheStore.Add(CurrentProgressCacheKey, value) +func ProgressCacheSet(channel int32, value *model.ProductionProgress) { + defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, channel), value) } -func ProgressCacheUnset() { - defaultCacheStore.Remove(CurrentProgressCacheKey) +func ProgressCacheUnset(channel int32) { + defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, channel)) } -- Gitblit v1.8.0