distributor.go 2.6 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. return err
  23. }
  24. rsp.Data = g.Map{"list": list, "total": total}
  25. return nil
  26. }
  27. // 创建
  28. func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
  29. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  30. return err
  31. }
  32. distributorServer, err := server.NewDistributorService(ctx)
  33. if err != nil {
  34. g.Log().Error(err)
  35. return err
  36. }
  37. distributorServer.Create(req)
  38. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  39. if err != nil {
  40. g.Log().Error(err)
  41. return err
  42. }
  43. return nil
  44. }
  45. //详情
  46. func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  47. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  48. return err
  49. }
  50. distributorServer, err := server.NewDistributorService(ctx)
  51. if err != nil {
  52. g.Log().Error(err)
  53. return err
  54. }
  55. list, err := distributorServer.GetEntityById(req.Id)
  56. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  57. if err != nil {
  58. g.Log().Error(err)
  59. return err
  60. }
  61. rsp.Data = g.Map{"list": list}
  62. return nil
  63. }
  64. //删掉
  65. // 编辑
  66. func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
  67. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  68. return err
  69. }
  70. distributorServer, err := server.NewDistributorService(ctx)
  71. if err != nil {
  72. g.Log().Error(err)
  73. return err
  74. }
  75. distributorServer.UpdateById(req)
  76. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  77. if err != nil {
  78. g.Log().Error(err)
  79. return err
  80. }
  81. return nil
  82. }
  83. //删掉
  84. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  85. distributorServer, err := server.NewDistributorService(ctx)
  86. if err != nil {
  87. g.Log().Error(err)
  88. return err
  89. }
  90. err = distributorServer.DeleteByIds(req.Ids)
  91. g.Log().Info("req", req)
  92. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  93. if err != nil {
  94. g.Log().Error(err)
  95. return err
  96. }
  97. return nil
  98. }