docquerylogic.go 1.6 KB

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