package controller import ( "Medical_OAuth/app/admin/model" "Medical_OAuth/app/admin/service" "Medical_OAuth/app/admin/service/dto" "Medical_OAuth/common/actions" "encoding/json" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "gogs.baozhida.cn/zoie/OAuth-core/api" "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user" _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response" ) type SysMenuController struct { api.Api } // GetPage 获取菜单列表 // @Summary 获取菜单列表 // @Description 获取菜单列表 // @Tags 菜单 // @Param menuName query string false "菜单名称" // @Param title query string false "显示名称" // @Param visible query string false "显示状态" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysMenu}} "{"code": 200, "data": [...]}" // @Router /api/menu [get] // @Security Bearer func (e SysMenuController) GetPage(c *gin.Context) { s := service.SysMenu{} req := dto.SysMenuGetPageReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.Form). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var list = make([]model.SysMenu, 0) if err = s.GetPage(&req, &list).Error; err != nil { e.Error(500, err, "查询失败") return } e.OK(list, "查询成功") } // Get 通过id获取菜单 // @Summary 通过id获取菜单 // @Description 通过id获取菜单 // @Tags 菜单 // @Param id path string true "菜单id" // @Success 200 {object} response.Response{data=model.SysMenu} "{"code": 200, "data": [...]}" // @Router /api/menu/{id} [get] // @Security Bearer func (e SysMenuController) Get(c *gin.Context) { req := dto.SysMenuGetReq{} s := service.SysMenu{} err := e.MakeContext(c). MakeOrm(). Bind(&req, nil). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var object = model.SysMenu{} err = s.Get(&req, &object).Error if err != nil { e.Error(500, err, "查询失败") return } e.OK(object, "查询成功") } // Insert 创建菜单 // @Summary 创建菜单 // @Description 创建菜单 // @Tags 菜单 // @Accept application/json // @Product application/json // @Param data body dto.SysMenuInsertReq true "data" // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/menu [post] // @Security Bearer func (e SysMenuController) Insert(c *gin.Context) { req := dto.SysMenuInsertReq{} s := service.SysMenu{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } // 设置创建人 req.SetCreateBy(user.GetUserId(c)) err = s.Insert(&req).Error if err != nil { e.Error(500, err, "创建失败") return } e.OK(req.GetId(), "创建成功") } // Update 修改菜单 // @Summary 修改菜单 // @Description 修改菜单 // @Tags 菜单 // @Accept application/json // @Product application/json // @Param id path string true "菜单id" // @Param data body dto.SysMenuUpdateReq true "body" // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/menu/{id} [put] // @Security Bearer func (e SysMenuController) Update(c *gin.Context) { s := service.SysMenu{} req := dto.SysMenuUpdateReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON, nil). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } req.SetUpdateBy(user.GetUserId(c)) err = s.Update(&req).Error if err != nil { e.Error(500, err, "更新失败") return } e.OK(req.GetId(), "更新成功") } // Delete 删除菜单 // @Summary 删除菜单 // @Description 删除菜单 // @Tags 菜单 // @Accept application/json // @Product application/json // @Param data body dto.SysMenuDeleteReq true "body" // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/menu [delete] // @Security Bearer func (e SysMenuController) Delete(c *gin.Context) { s := service.SysMenu{} req := dto.SysMenuDeleteReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } req.SetUpdateBy(user.GetUserId(c)) err = s.Remove(&req).Error if err != nil { e.Logger.Errorf("RemoveSysMenu error, %s", err) e.Error(500, err, "删除失败") return } e.OK(req.GetId(), "删除成功") } // GetMenuRole 根据登录角色名称获取菜单列表数据【左菜单使用】 // @Summary 根据登录角色名称获取菜单列表数据【左菜单使用】 // @Description 根据登录角色名称获取菜单列表数据【左菜单使用】 // @Tags 菜单 // @Success 200 {object} response.Response{data=[]model.SysMenu} "{"code": 200, "data": [...]}" // @Router /api/menu-role [get] // @Security Bearer func (e SysMenuController) GetMenuRole(c *gin.Context) { s := new(service.SysMenu) err := e.MakeContext(c). MakeOrm(). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } result, err := s.SetMenuRole(user.GetRoleName(c)) if err != nil { e.Error(500, err, err.Error()) return } e.OK(result, "") } func (e SysMenuController) List(c *gin.Context) { s := service.SysMenu{} req := dto.SysMenuGetPageReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.Form). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) if p.DeptId == 0 { data := make([]map[string]interface{}, 0) err = json.Unmarshal([]byte(model.NoDeptMenu), &data) if err != nil { e.Error(500, err, err.Error()) } e.OK(data, "查询成功") return } data := make([]map[string]interface{}, 0) err = json.Unmarshal([]byte(model.HaveDeptMenu), &data) if err != nil { e.Error(500, err, err.Error()) } e.OK(data, "查询成功") }