history.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. hismdl "go-common/app/interface/main/history/model"
  7. "go-common/app/interface/openplatform/article/dao"
  8. "go-common/app/interface/openplatform/article/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. )
  12. const _historyArtType = 5
  13. const _historyListType = 7
  14. // AddHistory .
  15. func (s *Service) AddHistory(c context.Context, mid, cvid int64, listID int64, ip string, plat int8, from string) (err error) {
  16. if from == "articleSlide" {
  17. return
  18. }
  19. var client, typ int8
  20. client = model.HistoryClient(plat)
  21. var aid, cid int64
  22. if listID != 0 {
  23. typ = _historyListType
  24. aid = listID
  25. cid = cvid
  26. } else {
  27. typ = _historyArtType
  28. aid = cvid
  29. }
  30. arg := &hismdl.ArgHistory{
  31. Mid: mid,
  32. RealIP: ip,
  33. History: &hismdl.History{
  34. Mid: mid,
  35. Aid: aid,
  36. TP: typ,
  37. Cid: cid,
  38. DT: client,
  39. Unix: time.Now().Unix(),
  40. },
  41. }
  42. if err = s.hisRPC.Add(c, arg); err != nil {
  43. dao.PromError("rpc:添加历史记录")
  44. log.Error("s.historyRPC.Add(%+v +v) error(%v)", arg, arg.History, err)
  45. }
  46. return
  47. }
  48. func (s *Service) historyPosition(c context.Context, mid, listID int64) (cvid int64, err error) {
  49. arg := &hismdl.ArgPos{
  50. Mid: mid,
  51. Aid: listID,
  52. TP: _historyListType,
  53. }
  54. history, err := s.hisRPC.Position(c, arg)
  55. if err != nil {
  56. if ecode.NothingFound.Equal(err) {
  57. dao.PromError("history:获取历史记录")
  58. log.Warnv(c, log.KV("log", fmt.Sprintf("s.historyRPC.Position(%+v) error(%v)", arg, err)))
  59. } else {
  60. dao.PromError("history:获取历史记录")
  61. log.Errorv(c, log.KV("log", fmt.Sprintf("s.historyRPC.Position(%+v) error(%v)", arg, err)))
  62. }
  63. }
  64. if history != nil {
  65. cvid = history.Cid
  66. }
  67. return
  68. }