subject.go 737 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/dm2/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. func (s *Service) subject(c context.Context, tp int32, oid int64) (sub *model.Subject, err error) {
  9. var cache = true
  10. if sub, err = s.dao.SubjectCache(c, tp, oid); err != nil {
  11. err = nil
  12. cache = false
  13. }
  14. if sub == nil {
  15. if sub, err = s.dao.Subject(c, tp, oid); err != nil {
  16. return
  17. }
  18. if sub == nil {
  19. sub = &model.Subject{
  20. Type: tp,
  21. Oid: oid,
  22. }
  23. }
  24. if cache {
  25. s.cache.Do(c, func(ctx context.Context) {
  26. s.dao.AddSubjectCache(ctx, sub)
  27. })
  28. }
  29. }
  30. if sub.ID == 0 {
  31. err = ecode.NothingFound
  32. log.Error("subject not exist,type:%d,oid:%d", tp, oid)
  33. return
  34. }
  35. return
  36. }