...
|
...
|
@@ -14,8 +14,9 @@ import ( |
|
|
func GetDeviceDailyRunningRecord(t time.Time, deviceCode string) (*domain.DeviceDailyRunningRecord, error) {
|
|
|
client := GetRedis()
|
|
|
key := DeviceDailyRunningRecordKey(t, deviceCode)
|
|
|
log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v", deviceCode, key))
|
|
|
return getDeviceDailyRunningRecord(client, key)
|
|
|
record, err := getDeviceDailyRunningRecord(client, key)
|
|
|
log.Logger.Debug(fmt.Sprintf("Redis Device:%v GET Key:%v Value:%v", deviceCode, key, record))
|
|
|
return record, err
|
|
|
}
|
|
|
|
|
|
func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.DeviceDailyRunningRecord, error) {
|
...
|
...
|
@@ -25,6 +26,7 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi |
|
|
return nil, domain.ErrorNotFound
|
|
|
}
|
|
|
var record = &domain.DeviceDailyRunningRecord{}
|
|
|
record.RedisKey = key
|
|
|
if err = json.Unmarshal(data, record); err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -35,13 +37,25 @@ func getDeviceDailyRunningRecord(client *redis.Client, key string) (*domain.Devi |
|
|
func SaveDeviceDailyRunningRecord(t time.Time, record *domain.DeviceDailyRunningRecord) error {
|
|
|
client := GetRedis()
|
|
|
key := DeviceDailyRunningRecordKey(t, record.DeviceCode)
|
|
|
log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Count:%v", record.DeviceCode, key, record.DeviceRunningRecordInfo.Count))
|
|
|
recordData, err := json.Marshal(record)
|
|
|
result := client.Set(key, recordData, time.Hour*24*5)
|
|
|
_, err = result.Result()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 保存每日设备运行数据 - 按键值
|
|
|
func SaveDeviceDailyRunningRecordByKey(key string, record *domain.DeviceDailyRunningRecord) error {
|
|
|
client := GetRedis()
|
|
|
recordData, err := json.Marshal(record)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
log.Logger.Debug(fmt.Sprintf("Redis Device:%v SET Key:%v Value:%v", record.DeviceCode, key, record))
|
|
|
result := client.Set(key, recordData, time.Hour*24*5)
|
|
|
_, err = result.Result()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 保存每日设备运行数据
|
|
|
func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error {
|
|
|
client := GetRedis()
|
...
|
...
|
@@ -51,11 +65,25 @@ func RemoveDeviceDailyRunningRecord(t time.Time, deviceCode string) error { |
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 保存每日设备运行数据
|
|
|
func RemoveDeviceDailyRunningRecordByKey(key string) error {
|
|
|
client := GetRedis()
|
|
|
//key := DeviceDailyRunningRecordKey(t, deviceCode)
|
|
|
result := client.Del(key)
|
|
|
_, err := result.Result()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func DeviceDailyRunningRecordKey(t time.Time, deviceCode string) string {
|
|
|
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, t.Local().Format("2006-01-02"), deviceCode)
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
func DeviceDailyRunningRecordKeyByTimeStr(timeStr string, deviceCode string) string {
|
|
|
str := fmt.Sprintf("%v:device-daily-record:%v-%v:%v:%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID, timeStr, deviceCode)
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
// 获取设备每日所有数据记录
|
|
|
func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, error) {
|
|
|
client := GetRedis()
|
...
|
...
|
@@ -70,6 +98,7 @@ func GetDeviceDailyAllRecord(t time.Time) ([]*domain.DeviceDailyRunningRecord, e |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
record.RedisKey = v
|
|
|
records = append(records, record)
|
|
|
}
|
|
|
return records, nil
|
...
|
...
|
|