group.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package handler
  2. import (
  3. "context"
  4. "dashoo.cn/opms_libary/myerrors"
  5. "dashoo.cn/common_definition/comm_def"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/util/gvalid"
  8. "dashoo.cn/micro/app/model"
  9. "dashoo.cn/micro/app/service"
  10. )
  11. type GroupHandler struct{}
  12. // GetList 获取列表
  13. func (h *GroupHandler) GetList(ctx context.Context, req *model.SysGroupSearchParams, rsp *comm_def.CommonMsg) error {
  14. groupService, err := service.NewGroupService(ctx)
  15. if err != nil {
  16. return err
  17. }
  18. total, list, err := groupService.GetList(req)
  19. if err != nil {
  20. return err
  21. }
  22. rsp.Data = g.Map{"list": list, "total": total}
  23. return nil
  24. }
  25. // GetEntityById 详情
  26. func (o *GroupHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  27. // 参数校验
  28. if req.Id == 0 {
  29. return myerrors.TipsError("请求参数不存在。")
  30. }
  31. groupService, err := service.NewGroupService(ctx)
  32. if err != nil {
  33. return err
  34. }
  35. entity, err := groupService.GetEntity(req.Id)
  36. if err != nil {
  37. return err
  38. }
  39. rsp.Data = entity
  40. return nil
  41. }
  42. // Create 添加
  43. func (h *GroupHandler) Create(ctx context.Context, req *model.SysGroupReq, rsp *comm_def.CommonMsg) error {
  44. // 检查请求参数
  45. if v := gvalid.CheckStruct(ctx, req, nil); v != nil {
  46. return v
  47. }
  48. groupService, err := service.NewGroupService(ctx)
  49. if err != nil {
  50. return err
  51. }
  52. err = groupService.Create(req)
  53. return err
  54. }
  55. // UpdateById 编辑
  56. func (h *GroupHandler) UpdateById(ctx context.Context, req *model.UpdateSysGroupReq, rsp *comm_def.CommonMsg) error {
  57. // 检查请求参数
  58. if v := gvalid.CheckStruct(ctx, req, nil); v != nil {
  59. return v
  60. }
  61. groupService, err := service.NewGroupService(ctx)
  62. if err != nil {
  63. return err
  64. }
  65. err = groupService.UpdateById(req)
  66. return err
  67. }
  68. // DeleteByIds 删除菜单
  69. func (h *GroupHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
  70. groupService, err := service.NewGroupService(ctx)
  71. if err != nil {
  72. return err
  73. }
  74. err = groupService.DeleteByIds(req.Ids)
  75. return err
  76. }