6
0

question.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package learning
  2. import (
  3. "context"
  4. "encoding/base64"
  5. "lims_adapter/model"
  6. "lims_adapter/model/learning"
  7. learningSrv "lims_adapter/service/learning"
  8. "dashoo.cn/common_definition/comm_def"
  9. "dashoo.cn/micro_libary/myerrors"
  10. "github.com/gogf/gf/frame/g"
  11. )
  12. type LearningQuestion struct{}
  13. func (c *LearningQuestion) List(ctx context.Context, req *learning.LearningQuestionListReq, rsp *comm_def.CommonMsg) error {
  14. g.Log().Infof("LearningQuestion.List request %#v ", *req)
  15. s, err := learningSrv.NewLearningQuestionService(ctx)
  16. if err != nil {
  17. return err
  18. }
  19. total, ent, err := s.List(ctx, req)
  20. _, err, code, msg := myerrors.CheckError(err)
  21. if err != nil {
  22. return err
  23. }
  24. if ent == nil {
  25. ent = []*learning.LearningQuestionGetRsp{}
  26. }
  27. rsp.Code = code
  28. rsp.Msg = msg
  29. rsp.Data = map[string]interface{}{
  30. "total": total,
  31. "list": ent,
  32. }
  33. return nil
  34. }
  35. func (c *LearningQuestion) Get(ctx context.Context, req *learning.LearningQuestionGetReq, rsp *comm_def.CommonMsg) error {
  36. g.Log().Infof("LearningQuestion.Get request %#v ", *req)
  37. s, err := learningSrv.NewLearningQuestionService(ctx)
  38. if err != nil {
  39. return err
  40. }
  41. ent, err := s.Get(ctx, req)
  42. _, err, code, msg := myerrors.CheckError(err)
  43. if err != nil {
  44. return err
  45. }
  46. rsp.Code = code
  47. rsp.Msg = msg
  48. rsp.Data = ent
  49. return nil
  50. }
  51. func (c *LearningQuestion) Add(ctx context.Context, req *learning.LearningQuestionAddReq, rsp *comm_def.CommonMsg) error {
  52. g.Log().Infof("LearningQuestion.Add request %#v ", *req)
  53. s, err := learningSrv.NewLearningQuestionService(ctx)
  54. if err != nil {
  55. return err
  56. }
  57. id, err := s.Add(ctx, req)
  58. _, err, code, msg := myerrors.CheckError(err)
  59. if err != nil {
  60. return err
  61. }
  62. rsp.Code = code
  63. rsp.Msg = msg
  64. rsp.Data = id
  65. return nil
  66. }
  67. func (c *LearningQuestion) Update(ctx context.Context, req *learning.LearningQuestionUpdateReq, rsp *comm_def.CommonMsg) error {
  68. g.Log().Infof("LearningQuestion.Update request %#v ", *req)
  69. s, err := learningSrv.NewLearningQuestionService(ctx)
  70. if err != nil {
  71. return err
  72. }
  73. err = s.Update(ctx, req)
  74. _, err, code, msg := myerrors.CheckError(err)
  75. if err != nil {
  76. return err
  77. }
  78. rsp.Code = code
  79. rsp.Msg = msg
  80. return nil
  81. }
  82. func (c *LearningQuestion) Delete(ctx context.Context, req *learning.LearningQuestionDeleteReq, rsp *comm_def.CommonMsg) error {
  83. g.Log().Infof("LearningQuestion.Delete request %#v ", *req)
  84. s, err := learningSrv.NewLearningQuestionService(ctx)
  85. if err != nil {
  86. return err
  87. }
  88. err = s.Delete(ctx, req.Id)
  89. _, err, code, msg := myerrors.CheckError(err)
  90. if err != nil {
  91. return err
  92. }
  93. rsp.Code = code
  94. rsp.Msg = msg
  95. return nil
  96. }
  97. func (c *LearningQuestion) Template(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
  98. g.Log().Infof("LearningQuestion.Template request %#v ", *req)
  99. f, err := learningSrv.QuestionTemplate()
  100. if err != nil {
  101. return err
  102. }
  103. buf, err := f.WriteToBuffer()
  104. if err != nil {
  105. return err
  106. }
  107. rsp.Code = 200
  108. rsp.Data = base64.StdEncoding.EncodeToString(buf.Bytes())
  109. return nil
  110. }