新增菜单详情,增加返回api。修改部门详情返回数据
This commit is contained in:
parent
2e6df8c974
commit
a22dd7c38c
@ -2,7 +2,6 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"hospital-admin-api/api/dao"
|
|
||||||
"hospital-admin-api/api/requests"
|
"hospital-admin-api/api/requests"
|
||||||
"hospital-admin-api/api/responses"
|
"hospital-admin-api/api/responses"
|
||||||
"hospital-admin-api/api/responses/menuResponse"
|
"hospital-admin-api/api/responses/menuResponse"
|
||||||
@ -138,8 +137,8 @@ func (r *Menu) PutMenu(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 业务处理
|
// 业务处理
|
||||||
MenuService := service.MenuService{}
|
menuService := service.MenuService{}
|
||||||
_, err = MenuService.PutMenu(menuId, MenuRequest.PutMenu)
|
_, err = menuService.PutMenu(menuId, MenuRequest.PutMenu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
@ -188,42 +187,28 @@ func (r *Menu) GetMenu(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
AdminMenuDao := dao.AdminMenuDao{}
|
menuService := service.MenuService{}
|
||||||
|
|
||||||
adminMenu, _ := AdminMenuDao.GetAdminMenuById(menuId)
|
// 获取菜单详情
|
||||||
if adminMenu == nil {
|
adminMenu, err := menuService.GetMenu(menuId)
|
||||||
responses.Fail(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换int64为string
|
|
||||||
MenuId := strconv.FormatInt(adminMenu.MenuId, 10)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.Fail(c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ParentId := strconv.FormatInt(adminMenu.ParentId, 10)
|
// 获取菜单api
|
||||||
|
getAdminMenuApis, err := menuService.GetAdminMenuApi(menuId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.Fail(c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMenuResponse := &menuResponse.GetMenu{
|
// 处理返回值
|
||||||
MenuId: MenuId,
|
getMenuResponse, err := menuResponse.GetMenuResponse(adminMenu, getAdminMenuApis)
|
||||||
MenuName: adminMenu.MenuName,
|
if err != nil {
|
||||||
MenuTitle: adminMenu.MenuTitle,
|
responses.FailWithMessage(err.Error(), c)
|
||||||
ParentId: ParentId,
|
return
|
||||||
MenuStatus: adminMenu.MenuStatus,
|
|
||||||
MenuType: adminMenu.MenuType,
|
|
||||||
Permission: adminMenu.Permission,
|
|
||||||
OrderNum: adminMenu.OrderNum,
|
|
||||||
Icon: adminMenu.Icon,
|
|
||||||
Path: adminMenu.Path,
|
|
||||||
Component: adminMenu.Component,
|
|
||||||
CreatedAt: adminMenu.CreatedAt,
|
|
||||||
UpdatedAt: adminMenu.UpdatedAt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responses.OkWithData(GetMenuResponse, c)
|
responses.OkWithData(getMenuResponse, c)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,15 @@ type AdminMenuApiDao struct {
|
|||||||
// GetAdminMenuApiListByMenuID 获取菜单api-菜单id
|
// GetAdminMenuApiListByMenuID 获取菜单api-菜单id
|
||||||
// menuId 菜单id
|
// menuId 菜单id
|
||||||
func (r *AdminMenuApiDao) GetAdminMenuApiListByMenuID(menuId int64) (m []*model.AdminMenuApi, err error) {
|
func (r *AdminMenuApiDao) GetAdminMenuApiListByMenuID(menuId int64) (m []*model.AdminMenuApi, err error) {
|
||||||
|
err = global.Db.Where("menu_id = ?", menuId).Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAdminMenuApiListWithAPIByMenuID 获取菜单api,关联api模型-菜单id
|
||||||
|
func (r *AdminMenuApiDao) GetAdminMenuApiListWithAPIByMenuID(menuId int64) (m []*model.AdminMenuApi, err error) {
|
||||||
err = global.Db.Where("menu_id = ?", menuId).Preload("API").Find(&m).Error
|
err = global.Db.Where("menu_id = ?", menuId).Preload("API").Find(&m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -34,3 +43,15 @@ func (r *AdminMenuApiDao) DeleteAdminMenuApiByMenuId(tx *gorm.DB, menuId int64)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAdminMenuApiApiIdByMenuId 获取菜单接口id-菜单id
|
||||||
|
func (r *AdminMenuApiDao) GetAdminMenuApiApiIdByMenuId(menuId int64) (m []int64, err error) {
|
||||||
|
err = global.Db.Model(&model.AdminRoleMenu{}).
|
||||||
|
Where("menu_id = ?", menuId).
|
||||||
|
Pluck("api_id", &m).
|
||||||
|
Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -130,7 +130,7 @@ func Auth() gin.HandlerFunc {
|
|||||||
// 获取菜单对应api
|
// 获取菜单对应api
|
||||||
adminMenuApiDao := dao.AdminMenuApiDao{}
|
adminMenuApiDao := dao.AdminMenuApiDao{}
|
||||||
for _, v := range adminRoleMenu {
|
for _, v := range adminRoleMenu {
|
||||||
AdminMenuApi, _ := adminMenuApiDao.GetAdminMenuApiListByMenuID(v.MenuID)
|
AdminMenuApi, _ := adminMenuApiDao.GetAdminMenuApiListWithAPIByMenuID(v.MenuID)
|
||||||
if AdminMenuApi == nil {
|
if AdminMenuApi == nil {
|
||||||
// 菜单无需权限
|
// 菜单无需权限
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
package menuResponse
|
package menuResponse
|
||||||
|
|
||||||
import "hospital-admin-api/api/model"
|
import (
|
||||||
|
"hospital-admin-api/api/model"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
// GetMenuList 获取菜单列表
|
// GetMenuList 获取菜单列表
|
||||||
type GetMenuList struct {
|
type GetMenuList struct {
|
||||||
@ -19,7 +22,7 @@ type GetMenuList struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMenu 菜单详情
|
// GetMenu 菜单详情
|
||||||
type GetMenu struct {
|
type getMenu struct {
|
||||||
MenuId string `json:"menu_id"`
|
MenuId string `json:"menu_id"`
|
||||||
MenuName string `json:"menu_name"` // 菜单名称
|
MenuName string `json:"menu_name"` // 菜单名称
|
||||||
MenuTitle string `json:"menu_title"` // 菜单名称
|
MenuTitle string `json:"menu_title"` // 菜单名称
|
||||||
@ -31,6 +34,54 @@ type GetMenu struct {
|
|||||||
Icon string `json:"icon"` // 图标地址
|
Icon string `json:"icon"` // 图标地址
|
||||||
Path string `json:"path"` // 页面地址(#表示当前页)
|
Path string `json:"path"` // 页面地址(#表示当前页)
|
||||||
Component string `json:"component"` // 组件名称
|
Component string `json:"component"` // 组件名称
|
||||||
|
Api []*getAdminMenuApi `json:"api"` // 接口数据
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 接口id
|
||||||
|
type getAdminMenuApi struct {
|
||||||
|
ApiId string `json:"api_id"` // 接口id
|
||||||
|
ApiName string `json:"api_name"` // 接口名称
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMenuResponse 菜单详情
|
||||||
|
func GetMenuResponse(adminMenu *model.AdminMenu, adminMenuApi []*model.AdminMenuApi) (*getMenu, error) {
|
||||||
|
var getMenuResponse *getMenu
|
||||||
|
|
||||||
|
getAdminMenuApis := make([]*getAdminMenuApi, len(adminMenuApi))
|
||||||
|
|
||||||
|
if adminMenu != nil {
|
||||||
|
getMenuResponse = &getMenu{
|
||||||
|
MenuId: strconv.Itoa(int(adminMenu.MenuId)),
|
||||||
|
MenuName: adminMenu.MenuName,
|
||||||
|
MenuTitle: adminMenu.MenuTitle,
|
||||||
|
ParentId: strconv.Itoa(int(adminMenu.ParentId)),
|
||||||
|
MenuStatus: adminMenu.MenuStatus,
|
||||||
|
MenuType: adminMenu.MenuType,
|
||||||
|
Permission: adminMenu.Permission,
|
||||||
|
OrderNum: adminMenu.OrderNum,
|
||||||
|
Icon: adminMenu.Icon,
|
||||||
|
Path: adminMenu.Path,
|
||||||
|
Component: adminMenu.Component,
|
||||||
|
CreatedAt: adminMenu.CreatedAt,
|
||||||
|
UpdatedAt: adminMenu.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if getMenuResponse != nil && len(adminMenuApi) != 0 {
|
||||||
|
for i, v := range adminMenuApi {
|
||||||
|
result := &getAdminMenuApi{
|
||||||
|
ApiId: strconv.FormatInt(v.ApiId, 10),
|
||||||
|
ApiName: v.API.APIName,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将转换后的结构体添加到新切片中
|
||||||
|
getAdminMenuApis[i] = result
|
||||||
|
}
|
||||||
|
|
||||||
|
getMenuResponse.Api = getAdminMenuApis
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMenuResponse, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
type getPostPage struct {
|
type getPostPage struct {
|
||||||
PostId string `json:"post_id"` // 主键id
|
PostId string `json:"post_id"` // 主键id
|
||||||
PostName string `json:"post_name"` // 岗位名称
|
PostName string `json:"post_name"` // 岗位名称
|
||||||
DeptStatus int `json:"dept_status"` // 岗位状态(1:正常 2:删除)
|
PostStatus int `json:"post_status"` // 岗位状态(1:正常 2:删除)
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ type getPostPage struct {
|
|||||||
type GetPost struct {
|
type GetPost struct {
|
||||||
PostId string `json:"post_id"` // 主键id
|
PostId string `json:"post_id"` // 主键id
|
||||||
PostName string `json:"post_name"` // 岗位名称
|
PostName string `json:"post_name"` // 岗位名称
|
||||||
DeptStatus int `json:"dept_status"` // 岗位状态(1:正常 2:删除)
|
PostStatus int `json:"post_status"` // 岗位状态(1:正常 2:删除)
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func GetPostPageResponse(adminPost []*model.AdminPost) []getPostPage {
|
|||||||
getPostPageResponse := getPostPage{
|
getPostPageResponse := getPostPage{
|
||||||
PostId: strconv.Itoa(int(v.PostId)),
|
PostId: strconv.Itoa(int(v.PostId)),
|
||||||
PostName: v.PostName,
|
PostName: v.PostName,
|
||||||
DeptStatus: v.PostStatus,
|
PostStatus: v.PostStatus,
|
||||||
CreatedAt: v.CreatedAt,
|
CreatedAt: v.CreatedAt,
|
||||||
UpdatedAt: v.UpdatedAt,
|
UpdatedAt: v.UpdatedAt,
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func GetPostResponse(adminPost *model.AdminPost) *GetPost {
|
|||||||
return &GetPost{
|
return &GetPost{
|
||||||
PostId: strconv.Itoa(int(adminPost.PostId)),
|
PostId: strconv.Itoa(int(adminPost.PostId)),
|
||||||
PostName: adminPost.PostName,
|
PostName: adminPost.PostName,
|
||||||
DeptStatus: adminPost.PostStatus,
|
PostStatus: adminPost.PostStatus,
|
||||||
CreatedAt: adminPost.CreatedAt,
|
CreatedAt: adminPost.CreatedAt,
|
||||||
UpdatedAt: adminPost.UpdatedAt,
|
UpdatedAt: adminPost.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -304,3 +304,25 @@ func (r *MenuService) DeleteMenu(c *gin.Context, DeleteMenuRequest requests.Dele
|
|||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMenu 菜单详情
|
||||||
|
func (r *MenuService) GetMenu(menuId int64) (*model.AdminMenu, error) {
|
||||||
|
adminMenuDao := dao.AdminMenuDao{}
|
||||||
|
|
||||||
|
adminMenu, _ := adminMenuDao.GetAdminMenuById(menuId)
|
||||||
|
if adminMenu == nil {
|
||||||
|
return nil, errors.New("数据错误")
|
||||||
|
}
|
||||||
|
return adminMenu, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAdminMenuApi 获取菜单关联api-菜单id
|
||||||
|
func (r *MenuService) GetAdminMenuApi(menuId int64) ([]*model.AdminMenuApi, error) {
|
||||||
|
adminMenuApiDao := dao.AdminMenuApiDao{}
|
||||||
|
adminMenuApis, err := adminMenuApiDao.GetAdminMenuApiListWithAPIByMenuID(menuId)
|
||||||
|
if err != nil {
|
||||||
|
return adminMenuApis, errors.New("数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
return adminMenuApis, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user