learning_record.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package learning
  2. import (
  3. "context"
  4. "fmt"
  5. "lims_adapter/model/learning"
  6. learningSrv "lims_adapter/service/learning"
  7. "dashoo.cn/common_definition/comm_def"
  8. "dashoo.cn/micro_libary/micro_srv"
  9. "dashoo.cn/micro_libary/myerrors"
  10. "github.com/gogf/gf/frame/g"
  11. )
  12. type LearningLearningRecord struct{}
  13. func (c *LearningLearningRecord) List(ctx context.Context, req *learning.LearningLearningRecordListReq, rsp *comm_def.CommonMsg) error {
  14. g.Log().Infof("LearningLearningRecord.List request %#v ", *req)
  15. s, err := learningSrv.NewLearningLearningRecordService(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.LearningLearningRecordGetRsp{}
  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 *LearningLearningRecord) ListMy(ctx context.Context, req *learning.LearningLearningRecordListReq, rsp *comm_def.CommonMsg) error {
  36. g.Log().Infof("LearningLearningRecord.ListMy request %#v ", *req)
  37. s, err := learningSrv.NewLearningLearningRecordService(ctx)
  38. if err != nil {
  39. return err
  40. }
  41. userInfo, err := micro_srv.GetUserInfo(ctx)
  42. if err != nil {
  43. return fmt.Errorf("获取用户信息异常:%s", err.Error())
  44. }
  45. req.UserId = int(userInfo.Id)
  46. total, ent, err := s.List(ctx, req)
  47. _, err, code, msg := myerrors.CheckError(err)
  48. if err != nil {
  49. return err
  50. }
  51. if ent == nil {
  52. ent = []*learning.LearningLearningRecordGetRsp{}
  53. }
  54. rsp.Code = code
  55. rsp.Msg = msg
  56. rsp.Data = map[string]interface{}{
  57. "total": total,
  58. "list": ent,
  59. }
  60. return nil
  61. }
  62. func (c *LearningLearningRecord) AddToMy(ctx context.Context, req *learning.LearningLearningRecordAddReq, rsp *comm_def.CommonMsg) error {
  63. g.Log().Infof("LearningLearningRecord.AddToMy request %#v ", *req)
  64. s, err := learningSrv.NewLearningLearningRecordService(ctx)
  65. if err != nil {
  66. return err
  67. }
  68. userInfo, err := micro_srv.GetUserInfo(ctx)
  69. if err != nil {
  70. return fmt.Errorf("获取用户信息异常:%s", err.Error())
  71. }
  72. req.UserId = int(userInfo.Id)
  73. id, err := s.Add(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. rsp.Data = id
  81. return nil
  82. }