| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package handler
- import (
- "context"
- "dashoo.cn/opms_libary/myerrors"
- "dashoo.cn/common_definition/comm_def"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gvalid"
- "dashoo.cn/micro/app/model"
- "dashoo.cn/micro/app/service"
- )
- type GroupHandler struct{}
- // GetList 获取列表
- func (h *GroupHandler) GetList(ctx context.Context, req *model.SysGroupSearchParams, rsp *comm_def.CommonMsg) error {
- groupService, err := service.NewGroupService(ctx)
- if err != nil {
- return err
- }
- total, list, err := groupService.GetList(req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // GetEntityById 详情
- func (o *GroupHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- // 参数校验
- if req.Id == 0 {
- return myerrors.TipsError("请求参数不存在。")
- }
- groupService, err := service.NewGroupService(ctx)
- if err != nil {
- return err
- }
- entity, err := groupService.GetEntity(req.Id)
- if err != nil {
- return err
- }
- rsp.Data = entity
- return nil
- }
- // Create 添加
- func (h *GroupHandler) Create(ctx context.Context, req *model.SysGroupReq, rsp *comm_def.CommonMsg) error {
- // 检查请求参数
- if v := gvalid.CheckStruct(ctx, req, nil); v != nil {
- return v
- }
- groupService, err := service.NewGroupService(ctx)
- if err != nil {
- return err
- }
- err = groupService.Create(req)
- return err
- }
- // UpdateById 编辑
- func (h *GroupHandler) UpdateById(ctx context.Context, req *model.UpdateSysGroupReq, rsp *comm_def.CommonMsg) error {
- // 检查请求参数
- if v := gvalid.CheckStruct(ctx, req, nil); v != nil {
- return v
- }
- groupService, err := service.NewGroupService(ctx)
- if err != nil {
- return err
- }
- err = groupService.UpdateById(req)
- return err
- }
- // DeleteByIds 删除菜单
- func (h *GroupHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
- groupService, err := service.NewGroupService(ctx)
- if err != nil {
- return err
- }
- err = groupService.DeleteByIds(req.Ids)
- return err
- }
|