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.
55 lines
1.0 KiB
55 lines
1.0 KiB
package service |
|
|
|
import ( |
|
"context" |
|
"time" |
|
|
|
artmdl "go-common/app/interface/openplatform/article/model" |
|
) |
|
|
|
const ( |
|
_platAll = 0 |
|
_platAndroid = 1 |
|
_platIOS = 2 |
|
_equal = 0 |
|
_greaterThanOrEqual = 1 |
|
_lessThanOrEqual = 2 |
|
) |
|
|
|
func (s *Service) loadNoticeproc() { |
|
for { |
|
if notices, err := s.dao.Notices(context.TODO(), time.Now()); err == nil { |
|
s.notices = notices |
|
} |
|
time.Sleep(time.Minute) |
|
} |
|
} |
|
|
|
// Notice get notice |
|
func (s *Service) Notice(platform string, build int) (res *artmdl.Notice) { |
|
var plat int |
|
if platform == "android" { |
|
plat = _platAndroid |
|
} |
|
if platform == "ios" { |
|
plat = _platIOS |
|
} |
|
for _, notice := range s.notices { |
|
var ok bool |
|
if (notice.Plat == _platAll) || (notice.Plat == plat) { |
|
switch notice.Condition { |
|
case _equal: |
|
ok = build == notice.Build |
|
case _greaterThanOrEqual: |
|
ok = build >= notice.Build |
|
case _lessThanOrEqual: |
|
ok = build <= notice.Build |
|
} |
|
} |
|
if ok { |
|
notice.Content = notice.Title |
|
return notice |
|
} |
|
} |
|
return nil |
|
}
|
|
|