You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

package common_models
import (
"encoding/json"
"gitea.anxinyun.cn/container/common_models/constant/iotaScheme"
"time"
)
type IotaScheme struct {
Id string `json:"id"`
Name string `json:"name"`
Mode string `json:"mode"`
Interval int `json:"interval"`
Unit string `json:"unit"`
BeginTime *time.Time `json:"beginTime"`
EndTime *time.Time `json:"endTime,omitempty"`
Dimension Dimension `json:"dimension"`
}
type Dimension struct {
Id string `json:"id"`
ThingId string `json:"thingId"`
Name string `json:"name"`
}
// SimpleEquals 调度模式一致(模式 & 间隔 & 时间单位)
func (s *IotaScheme) SimpleEquals(other *IotaScheme) bool {
return s.Mode == other.Mode && s.Interval == other.Interval && s.Unit == other.Unit
}
// SimpleEqualsInt 周期调度的分钟数相等(周期 & 间隔 & 分钟)
func (s *IotaScheme) SimpleEqualsInt(iv int) bool {
return s.Mode == iotaScheme.ModeResponse && s.Interval == iv && s.Unit == iotaScheme.UnitMinute
}
// IntervalSecs 间隔秒
func (s *IotaScheme) IntervalSecs() int {
switch s.Unit {
case iotaScheme.UnitSecond:
return s.Interval
case iotaScheme.UnitMinute:
return s.Interval * 60
case iotaScheme.UnitHour:
return s.Interval * 60 * 60
case iotaScheme.UnitDay:
return s.Interval * 60 * 60 * 24
case iotaScheme.UnitWeek:
return s.Interval * 60 * 60 * 24 * 7
case iotaScheme.UnitMonth:
return s.Interval * 60 * 60 * 24 * 30
default:
return s.Interval
}
}
// redis序列化
func (s *IotaScheme) MarshalBinary() (data []byte, err error) {
return json.Marshal(s)
}
// redis序列化
func (s *IotaScheme) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, s)
}