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.
47 lines
1.5 KiB
47 lines
1.5 KiB
package hasaki_push
|
|
|
|
import (
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskutils"
|
|
)
|
|
|
|
type MessageStatus int
|
|
|
|
// 未发送
|
|
// 已发送
|
|
// 发送成功
|
|
// 发送失败
|
|
const (
|
|
NotSend MessageStatus = 0
|
|
Sending MessageStatus = 1
|
|
SendSuccess MessageStatus = 2
|
|
SendFailure MessageStatus = 3
|
|
)
|
|
|
|
// 发送方
|
|
// 推送消息
|
|
type PushMessage struct {
|
|
Model `xorm:"extends"`
|
|
|
|
UniqueId string `json:"unique_id" xorm:"not null default '' comment('消息唯一值')"`
|
|
Type string `json:"type" xorm:"not null default '' comment('消息类型') VARCHAR(128)"`
|
|
Content interface{} `json:"content" xorm:"json comment('消息内容')"`
|
|
Sender int `json:"-" xorm:"not null default 0 comment('发送方') INT(11)"`
|
|
Receiver int `json:"-" xorm:"not null default 0 comment('接收方') INT(11)"`
|
|
RetryNumber int `json:"-" xorm:"not null default 0 comment('尝试次数') INT(11)"`
|
|
SpanSecond int `json:"-" xorm:"not null default 0 comment('间隔秒') INT(11)"`
|
|
Status MessageStatus `json:"-" xorm:"not null default 0 comment('消息状态') INT(11)"`
|
|
}
|
|
|
|
func add(message *PushMessage) error {
|
|
if message.UniqueId == "" {
|
|
message.UniqueId = hskutils.CreateUUID()
|
|
}
|
|
_, err := hskdb.GetXormAuto().InsertOne(message)
|
|
return err
|
|
}
|
|
|
|
func setStatus(uniqueId string, status MessageStatus) error {
|
|
_, err := hskdb.GetXormAuto().Where("unique_id=?", uniqueId).Cols("status").Update(&PushMessage{Status: status})
|
|
return err
|
|
}
|