notice.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. artmdl "go-common/app/interface/openplatform/article/model"
  6. )
  7. const (
  8. _platAll = 0
  9. _platAndroid = 1
  10. _platIOS = 2
  11. _equal = 0
  12. _greaterThanOrEqual = 1
  13. _lessThanOrEqual = 2
  14. )
  15. func (s *Service) loadNoticeproc() {
  16. for {
  17. if notices, err := s.dao.Notices(context.TODO(), time.Now()); err == nil {
  18. s.notices = notices
  19. }
  20. time.Sleep(time.Minute)
  21. }
  22. }
  23. // Notice get notice
  24. func (s *Service) Notice(platform string, build int) (res *artmdl.Notice) {
  25. var plat int
  26. if platform == "android" {
  27. plat = _platAndroid
  28. }
  29. if platform == "ios" {
  30. plat = _platIOS
  31. }
  32. for _, notice := range s.notices {
  33. var ok bool
  34. if (notice.Plat == _platAll) || (notice.Plat == plat) {
  35. switch notice.Condition {
  36. case _equal:
  37. ok = build == notice.Build
  38. case _greaterThanOrEqual:
  39. ok = build >= notice.Build
  40. case _lessThanOrEqual:
  41. ok = build <= notice.Build
  42. }
  43. }
  44. if ok {
  45. notice.Content = notice.Title
  46. return notice
  47. }
  48. }
  49. return nil
  50. }