| | |
| | | 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 |
| | | TaskStartTimeCache = "task_start_time:%v" //task_start_time:channel |
| | | TaskEndTimeCache = "task_end_time:%v" //task_end_time:channel |
| | | ) |
| | | |
| | | func PlcCacheGet(channel int32, key string) (interface{}, bool) { |
| | |
| | | return 0 |
| | | } |
| | | |
| | | func TaskStartTimeSet(channel int32, ts int64) { |
| | | defaultCacheStore.Add(fmt.Sprintf(TaskStartTimeCache, channel), ts) |
| | | } |
| | | |
| | | func TaskStartTimeGet(channel int32) int64 { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(TaskStartTimeCache, channel)); ok { |
| | | return v.(int64) |
| | | } |
| | | procedure, err := model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.CurrentDeviceID).SetStatus(model.ProcedureStatusProcessing).SetChannels([]int32{channel}).First() //进行中任务 |
| | | if err == gorm.ErrRecordNotFound { |
| | | procedure, err = model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.CurrentDeviceID). |
| | | SetStatus(model.ProcedureStatusFinished).SetChannels([]int32{channel}).SetOrder("real_end_time desc").First() //上一个结束的任务 |
| | | if err == gorm.ErrRecordNotFound { //进行中和结束的都没有,开始时间和结束时间都设置0 |
| | | TaskStartTimeSet(channel, int64(0)) |
| | | TaskEndTimeSet(channel, int64(0)) |
| | | return 0 |
| | | } else { |
| | | TaskStartTimeSet(channel, procedure.RealStartTime) |
| | | TaskStartTimeSet(channel, procedure.RealEndTime) |
| | | return 0 |
| | | } |
| | | } else { |
| | | TaskStartTimeSet(channel, procedure.RealStartTime) |
| | | TaskStartTimeSet(channel, int64(0)) |
| | | return procedure.RealStartTime |
| | | } |
| | | } |
| | | |
| | | func TaskEndTimeSet(channel int32, ts int64) { |
| | | defaultCacheStore.Add(fmt.Sprintf(TaskEndTimeCache, channel), ts) |
| | | } |
| | | |
| | | func TaskEndTimeGet(channel int32) int64 { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(TaskEndTimeCache, channel)); ok { |
| | | return v.(int64) |
| | | } |
| | | 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), true) |
| | | func TaskFlagSet(channel int32, taskId int) { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), taskId) |
| | | } |
| | | |
| | | func TaskFlagUnset(channel int32) { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false) |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), 0) |
| | | } |
| | | |
| | | func TaskFlagGet(channel int32) bool { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentTaskCacheKey, channel)); ok { |
| | | return v.(bool) |
| | | return v.(int) > 0 |
| | | } |
| | | _, err := model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.CurrentDeviceID).SetStatus(model.ProcedureStatusProcessing).SetChannels([]int32{channel}).First() |
| | | procedure, err := model.NewProceduresSearch(nil).SetDeviceId(conf.Conf.CurrentDeviceID).SetStatus(model.ProcedureStatusProcessing).SetChannels([]int32{channel}).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false) |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), 0) |
| | | return false |
| | | } else { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), true) |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), int(procedure.ID)) |
| | | return true |
| | | } |
| | | } |