distributor.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package base
  2. import (
  3. "context"
  4. "dashoo.cn/common_definition/comm_def"
  5. "dashoo.cn/opms_libary/myerrors"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/util/gvalid"
  8. model "dashoo.cn/micro/app/model/base"
  9. server "dashoo.cn/micro/app/service/base"
  10. )
  11. type DistributorHandler struct{}
  12. // GetList 获取列表
  13. func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error {
  14. distributorServer, err := server.NewDistributorService(ctx)
  15. if err != nil {
  16. g.Log().Error(err)
  17. return err
  18. }
  19. total, list, err := distributorServer.GetList(req)
  20. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  21. if err != nil {
  22. g.Log().Error(err)
  23. return err
  24. }
  25. rsp.Data = g.Map{"list": list, "total": total}
  26. return nil
  27. }
  28. // 创建
  29. func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
  30. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  31. return err
  32. }
  33. distributorServer, err := server.NewDistributorService(ctx)
  34. if err != nil {
  35. g.Log().Error(err)
  36. return err
  37. }
  38. distributorServer.Create(req)
  39. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  40. if err != nil {
  41. g.Log().Error(err)
  42. return err
  43. }
  44. return nil
  45. }
  46. //详情
  47. func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  48. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  49. return err
  50. }
  51. distributorServer, err := server.NewDistributorService(ctx)
  52. if err != nil {
  53. g.Log().Error(err)
  54. return err
  55. }
  56. list, err := distributorServer.GetEntityById(req.Id)
  57. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  58. if err != nil {
  59. g.Log().Error(err)
  60. return err
  61. }
  62. rsp.Data = g.Map{"list": list}
  63. return nil
  64. }
  65. //删掉
  66. // 编辑
  67. func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
  68. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  69. return err
  70. }
  71. distributorServer, err := server.NewDistributorService(ctx)
  72. if err != nil {
  73. g.Log().Error(err)
  74. return err
  75. }
  76. distributorServer.UpdateById(req)
  77. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  78. if err != nil {
  79. g.Log().Error(err)
  80. return err
  81. }
  82. return nil
  83. }
  84. //删掉
  85. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  86. distributorServer, err := server.NewDistributorService(ctx)
  87. if err != nil {
  88. g.Log().Error(err)
  89. return err
  90. }
  91. err = distributorServer.DeleteByIds(req.Ids)
  92. g.Log().Info("req", req)
  93. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  94. if err != nil {
  95. g.Log().Error(err)
  96. return err
  97. }
  98. return nil
  99. }