distributor.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, 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. distributorServer.UpdateById(req)
  57. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  58. if err != nil {
  59. g.Log().Error(err)
  60. return err
  61. }
  62. return nil
  63. }
  64. //删掉
  65. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  66. distributorServer, err := server.NewDistributorService(ctx)
  67. if err != nil {
  68. g.Log().Error(err)
  69. return err
  70. }
  71. err = distributorServer.DeleteByIds(req.Ids)
  72. g.Log().Info("req", req)
  73. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  74. if err != nil {
  75. g.Log().Error(err)
  76. return err
  77. }
  78. return nil
  79. }