k3cloud_fetch_data.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package redis
import (
"fmt"
"github.com/go-redis/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
// 获取每日设备运行数据
func GetLastFetchTime(args ...string) (time.Time, error) {
client := GetRedis()
key := K3CloudFetchTimeKey()
result := client.Get(key)
t, err := result.Int()
if len(args) > 0 {
key = args[0]
}
if err == redis.Nil {
if _, err := client.Set(key, time.Now().Unix(), 0).Result(); err != nil {
return time.Time{}, err
}
}
fetchTime := time.Unix(int64(t), 0)
if fetchTime.IsZero() {
return time.Time{}, fmt.Errorf("zerotime retry")
}
if _, err := client.Set(key, time.Now().Unix(), 0).Result(); err != nil {
return time.Time{}, err
}
return fetchTime, nil
}
func K3CloudFetchTimeKey() string {
str := fmt.Sprintf("%v:k3clound-data:last-fetch:%v-%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID)
return str
}
func MaterialK3cloudFetchTimeKey() string {
str := fmt.Sprintf("%v:material-k3clound-data:last-fetch:%v-%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID)
return str
}