notice.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package dao
  2. import (
  3. "context"
  4. notice "go-common/app/service/bbq/notice-service/api/v1"
  5. msg "go-common/app/service/bbq/sys-msg/api/v1"
  6. "go-common/library/log"
  7. )
  8. // 通知的业务类型
  9. const (
  10. NoticeBizTypeSv = 1
  11. NoticeBizTypeComment = 2
  12. NoticeBizTypeUser = 3
  13. NoticeBizTypeSysMsg = 4
  14. )
  15. // 通知类型
  16. const (
  17. NoticeTypeLike = 1
  18. NoticeTypeComment = 2
  19. NoticeTypeFan = 3
  20. NoticeTypeSysMsg = 4
  21. )
  22. const (
  23. _selectSQL = "select id, type, sender, receiver, jump_url, text, ctime, state from sys_msg where id > ? order by id asc"
  24. )
  25. // CreateNotice 创建通知
  26. func (d *Dao) CreateNotice(ctx context.Context, notice *notice.NoticeBase) (err error) {
  27. _, err = d.noticeClient.CreateNotice(ctx, notice)
  28. if err != nil {
  29. log.Errorv(ctx, log.KV("log", "create notice fail: notice="+notice.String()))
  30. return
  31. }
  32. log.V(10).Infov(ctx, log.KV("log", "create notice: notice="+notice.String()))
  33. return
  34. }
  35. // GetNewSysMsg 获取未被推送的系统消息
  36. func (d *Dao) GetNewSysMsg(ctx context.Context, id int64) (list []*msg.SysMsg, err error) {
  37. rows, err := d.db.Query(ctx, _selectSQL, id)
  38. if err != nil {
  39. log.Errorv(ctx, log.KV("log", "query mysql sys msg fail"))
  40. return
  41. }
  42. defer rows.Close()
  43. for rows.Next() {
  44. var msg msg.SysMsg
  45. if err = rows.Scan(&msg.Id, &msg.Type, &msg.Sender, &msg.Receiver, &msg.JumpUrl, &msg.Text, &msg.Ctime, &msg.State); err != nil {
  46. log.Errorv(ctx, log.KV("log", "scan mysql sys msg fail"))
  47. return
  48. }
  49. list = append(list, &msg)
  50. }
  51. return
  52. }