推送
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

4 years ago
  1. package hasaki_push
  2. import (
  3. "git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
  4. "git.ouxuan.net/hasaki-service/hasaki-sdk/hskutils"
  5. )
  6. type MessageStatus int
  7. // 未发送
  8. // 已发送
  9. // 发送成功
  10. // 发送失败
  11. const (
  12. NotSend MessageStatus = 0
  13. Sending MessageStatus = 1
  14. SendSuccess MessageStatus = 2
  15. SendFailure MessageStatus = 3
  16. )
  17. // 发送方
  18. // 推送消息
  19. type PushMessage struct {
  20. Model `xorm:"extends"`
  21. UniqueId string `json:"unique_id" xorm:"not null default '' comment('消息唯一值')"`
  22. Type string `json:"type" xorm:"not null default '' comment('消息类型') VARCHAR(128)"`
  23. Content interface{} `json:"content" xorm:"json comment('消息内容')"`
  24. Sender int `json:"-" xorm:"not null default 0 comment('发送方') INT(11)"`
  25. Receiver int `json:"-" xorm:"not null default 0 comment('接收方') INT(11)"`
  26. RetryNumber int `json:"-" xorm:"not null default 0 comment('尝试次数') INT(11)"`
  27. SpanSecond int `json:"-" xorm:"not null default 0 comment('间隔秒') INT(11)"`
  28. Status MessageStatus `json:"-" xorm:"not null default 0 comment('消息状态') INT(11)"`
  29. }
  30. func add(message *PushMessage) error {
  31. if message.UniqueId == "" {
  32. message.UniqueId = hskutils.CreateUUID()
  33. }
  34. _, err := hskdb.GetXormAuto().InsertOne(message)
  35. return err
  36. }
  37. func setStatus(uniqueId string, status MessageStatus) error {
  38. _, err := hskdb.GetXormAuto().Where("unique_id=?", uniqueId).Cols("status").Update(&PushMessage{Status: status})
  39. return err
  40. }