From cdbda5e3895814b688bcc0e6b34b6067b0b9b773 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 21 九月 2023 20:17:08 +0800
Subject: [PATCH] fix
---
service/cache_store.go | 46 ++++++++++++++++++++++++++++++++++------------
1 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/service/cache_store.go b/service/cache_store.go
index 4c3148b..9b7b74d 100644
--- a/service/cache_store.go
+++ b/service/cache_store.go
@@ -1,10 +1,13 @@
package service
import (
+ "apsClient/constvar"
"apsClient/model"
"apsClient/model/response"
"fmt"
+ "github.com/spf13/cast"
"sync"
+ "time"
)
type CacheStore struct {
@@ -44,17 +47,36 @@
}
const (
- PlcCacheKey = "plc:%v"
+ PlcCacheKey = "plc:%v:%v" //plc:position:key
CurrentTaskCacheKey = "current_task"
- CurrentProgressCacheKey = "current_progress"
+ CurrentProgressCacheKey = "current_progress:%v" //current_progress:position
+ PlcCacheKeyUpdateTime = "finish_number_update_time:%v" //finish_number_update_time:position
)
-func PlcCacheGet(key string) (interface{}, bool) {
- return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, key))
+func PlcCacheGet(position int, key string) (interface{}, bool) {
+ return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, position, key))
}
-func PlcCacheSet(key string, value interface{}) {
- defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, key), value)
+func PlcCacheSet(position int, key string, value interface{}) {
+ if key == constvar.PlcCacheKeyFinishNumber {
+ oldFinishNumber, exists := PlcCacheGet(position, key)
+ if !exists || cast.ToInt(oldFinishNumber) != cast.ToInt(value) { //finishNumber鏈変簡鍙樺寲锛岃缃洿鏂版椂闂寸紦瀛�
+ FinishUpdateTimeSet(position, time.Now().Unix())
+ }
+ }
+ defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, position, key), value)
+}
+
+func FinishUpdateTimeGet(position int) interface{} {
+ val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, position))
+ if ok {
+ return val
+ }
+ return 0
+}
+
+func FinishUpdateTimeSet(position int, value interface{}) {
+ defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, position), value)
}
func TaskCacheSet(value *response.TaskData) {
@@ -72,17 +94,17 @@
return nil, false
}
-func ProgressCacheGet() (*model.ProductionProgress, bool) {
- if v, ok := defaultCacheStore.Get(CurrentProgressCacheKey); ok {
+func ProgressCacheGet(position int) (*model.ProductionProgress, bool) {
+ if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, position)); ok {
return v.(*model.ProductionProgress), ok
}
return nil, false
}
-func ProgressCacheSet(value *model.ProductionProgress) {
- defaultCacheStore.Add(CurrentProgressCacheKey, value)
+func ProgressCacheSet(position int, value *model.ProductionProgress) {
+ defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, position), value)
}
-func ProgressCacheUnset() {
- defaultCacheStore.Remove(CurrentProgressCacheKey)
+func ProgressCacheUnset(position int) {
+ defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, position))
}
--
Gitblit v1.8.0