help.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/main/web/model"
  5. "go-common/library/log"
  6. "go-common/library/net/metadata"
  7. )
  8. const _firstPage = 1
  9. var _emptyHelpList = make([]*model.HelpList, 0)
  10. // HelpList get help menu list
  11. func (s *Service) HelpList(c context.Context, pTypeID string) (res []*model.HelpList, err error) {
  12. if res, err = s.dao.HlCache(c, pTypeID); err != nil || len(res) == 0 {
  13. if res, err = s.dao.HelpList(context.Background(), pTypeID); err != nil {
  14. log.Error("s.do.HelpList(%s) error(%v)", pTypeID, err)
  15. return
  16. }
  17. if len(res) > 0 {
  18. s.cache.Do(c, func(c context.Context) {
  19. s.dao.SetHlCache(c, pTypeID, res)
  20. })
  21. }
  22. }
  23. return
  24. }
  25. // HelpDetail get help detail
  26. func (s *Service) HelpDetail(c context.Context, fID, qTypeID string, keyFlag, pn, ps int) (resD []*model.HelpDeatil, resL []*model.HelpList, total int, err error) {
  27. remoteIP := metadata.String(c, metadata.RemoteIP)
  28. if resD, total, err = s.dao.DetailCache(c, qTypeID, keyFlag, pn, ps); err != nil || len(resD) == 0 {
  29. if resD, total, err = s.dao.HelpDetail(context.Background(), qTypeID, keyFlag, pn, ps, remoteIP); err != nil {
  30. log.Error("s.do.HelpDetail(%s,%d,%d,%d) error(%v)", qTypeID, keyFlag, pn, ps, err)
  31. }
  32. if pn == _firstPage && len(resD) > 0 {
  33. s.cache.Do(c, func(c context.Context) {
  34. s.dao.SetDetailCache(c, qTypeID, keyFlag, pn, ps, total, resD)
  35. })
  36. }
  37. }
  38. if fID == "" {
  39. resL = _emptyHelpList
  40. } else {
  41. if resL, err = s.HelpList(c, fID); err != nil {
  42. log.Error("s.HelpList(%s) error(%v)", fID, err)
  43. }
  44. }
  45. return
  46. }
  47. // HelpSearch get help search
  48. func (s *Service) HelpSearch(c context.Context, pTypeID, keyWords string, keyFlag, pn, ps int) (res []*model.HelpDeatil, total int, err error) {
  49. if res, total, err = s.dao.HelpSearch(context.Background(), pTypeID, keyWords, keyFlag, pn, ps); err != nil {
  50. log.Error("s.do.HelpDetail(%s,%d,%d,%d) error(%v)", keyWords, keyFlag, pn, ps, err)
  51. }
  52. return
  53. }