docquerylogic.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package logic
  2. import (
  3. "context"
  4. "app.yhyue.com/moapp/jy_docs/rpc/stdlib/internal/svc"
  5. "app.yhyue.com/moapp/jy_docs/rpc/stdlib/stdlib"
  6. stdlibService "app.yhyue.com/moapp/jy_docs/services/stdlib"
  7. "app.yhyue.com/moapp/jybase/common"
  8. "github.com/tal-tech/go-zero/core/logx"
  9. )
  10. type DocQueryLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewDocQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocQueryLogic {
  16. return &DocQueryLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *DocQueryLogic) DocQuery(in *stdlib.DocQueryRequest) (*stdlib.DocQueryResponse, error) {
  23. if in.PageNum <= 0 {
  24. in.PageNum = 0
  25. }
  26. total, list := stdlibService.FindDocumentsByKeyWords(in.KeyWord, in.ClassLevelOne, in.ClassLevelTwo, in.Tag, in.UpdateDateSort, in.DownloadSort, in.ViewSort, in.PageNum, in.PageSize)
  27. docs := []*stdlib.Doc{}
  28. if list != nil {
  29. for _, v := range *list {
  30. docs = append(docs, &stdlib.Doc{
  31. DocId: common.ObjToString(v["id"]),
  32. DocName: common.ObjToString(v["docName"]),
  33. Price: common.Int64All(v["price"]),
  34. DocPageSize: common.Int64All(v["docPageSize"]),
  35. DocFileSize: common.Int64All(v["docFileSize"]),
  36. DownTimes: common.Int64All(v["downTimes"]),
  37. UploadDate: common.ObjToString(v["uploadDate"]),
  38. DocSummary: common.ObjToString(v["docSummary"]),
  39. })
  40. }
  41. }
  42. return &stdlib.DocQueryResponse{
  43. Total: total,
  44. Docs: docs,
  45. }, nil
  46. }