distributor.go 2.5 KB

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