1 Star 0 Fork 0

liuliang/jpush-api-golang-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
schedule.go 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
liuliang 提交于 2022-11-09 13:44 +08:00 . init
package jpush
import (
"encoding/json"
"time"
)
type Schecule struct {
Cid string `json:"cid"` // 定时任务id
Name string `json:"name"` // 定时任务名称
Enabled bool `json:"enabled"` // 是否启用
Trigger map[string]interface{} `json:"trigger"` // 定时任务触发条件
Push *PayLoad `json:"push"` // 定时任务推送内容
}
const (
formatTime = "2006-01-02 15:04:05"
)
// NewSchedule 创建定时任务
func NewSchedule(cid, name string, enabled bool, push *PayLoad) *Schecule {
return &Schecule{
Cid: cid,
Name: name,
Enabled: enabled,
Push: push,
}
}
// SetCid 设置定时任务id
func (s *Schecule) SetCid(cid string) {
s.Cid = cid
}
// GetCid 获取定时任务id
func (s *Schecule) GetCid() string {
return s.Cid
}
// SetName 设置定时任务名称
func (s *Schecule) SetName(name string) {
s.Name = name
}
// GetName 获取定时任务名称
func (s *Schecule) GetName() string {
return s.Name
}
// SetEnabled 设置定时任务是否启用
func (s *Schecule) SetEnabled(enabled bool) {
s.Enabled = enabled
}
// GetEnabled 获取定时任务是否启用
func (s *Schecule) GetEnabled() bool {
return s.Enabled
}
// SetPayLoad 设置定时任务推送内容
func (s *Schecule) SetPayLoad(push *PayLoad) {
s.Push = push
}
// SingleTrigger 单次触发
func (s *Schecule) SingleTrigger(t time.Time) {
s.Trigger = map[string]interface{}{
"single": map[string]interface{}{
"time": t.Format(formatTime),
},
}
}
// PeriodicalTrigger 周期触发
func (s *Schecule) PeriodicalTrigger(start, end, t time.Time, timeUnit string, frequency int, point []string) {
s.Trigger = map[string]interface{}{
"periodical": map[string]interface{}{
"start": start.Format(formatTime),
"end": end.Format(formatTime),
"time": t.Format(formatTime),
"time_unit": timeUnit,
"frequency": frequency,
"point": point,
},
}
}
// Bytes 转换为字节数组
func (s *Schecule) Bytes() ([]byte, error) {
return json.Marshal(s)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dashiqiao/jpush-api-golang-client.git
git@gitee.com:dashiqiao/jpush-api-golang-client.git
dashiqiao
jpush-api-golang-client
jpush-api-golang-client
v1.0.1

搜索帮助