111 lines
2.7 KiB
Go
111 lines
2.7 KiB
Go
package system
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
"sundynix-go/model/commom/request"
|
|
"sundynix-go/model/commom/response"
|
|
"sundynix-go/model/system"
|
|
systemreq "sundynix-go/model/system/request"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type RoleApi struct {
|
|
}
|
|
|
|
func (a *RoleApi) SaveRole(context *gin.Context) {
|
|
var role system.Role
|
|
err := context.ShouldBindJSON(&role)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误"+err.Error(), context)
|
|
return
|
|
}
|
|
err = roleService.SaveRole(role)
|
|
if err != nil {
|
|
global.Logger.Error("保存角色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
response.OkWithMsg("保存角色成功!", context)
|
|
}
|
|
|
|
func (a *RoleApi) UpdateRole(context *gin.Context) {
|
|
var role system.Role
|
|
err := context.ShouldBindJSON(&role)
|
|
if err != nil {
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
err = roleService.UpdateRole(role)
|
|
if err != nil {
|
|
global.Logger.Error("更新角色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
response.OkWithMsg("更新角色成功!", context)
|
|
}
|
|
|
|
func (a *RoleApi) GetRoleList(c *gin.Context) {
|
|
var pageInfo systemreq.GetRoleList
|
|
err := c.ShouldBindJSON(&pageInfo)
|
|
if err != nil {
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
list, total, err := roleService.GetRoleList(pageInfo)
|
|
if err != nil {
|
|
global.Logger.Error("获取角色列表失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
}
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: pageInfo.Current,
|
|
PageSize: pageInfo.PageSize,
|
|
}, c)
|
|
}
|
|
|
|
func (a *RoleApi) Delete(context *gin.Context) {
|
|
var ids request.IdsReq
|
|
err := context.ShouldBindJSON(&ids)
|
|
if err != nil {
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
err = roleService.DeleteRoleByIds(ids)
|
|
if err != nil {
|
|
global.Logger.Error("删除角色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
response.OkWithMsg("删除角色成功!", context)
|
|
}
|
|
|
|
func (a *RoleApi) Detail(context *gin.Context) {
|
|
id := context.Query("id")
|
|
role, err := roleService.GetRoleById(id)
|
|
if err != nil {
|
|
global.Logger.Error("获取角色详情失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), context)
|
|
return
|
|
}
|
|
response.OkWithData(role, context)
|
|
}
|
|
|
|
func (a *RoleApi) GrantMenu(c *gin.Context) {
|
|
var grantMenu systemreq.GrantMenu
|
|
err := c.ShouldBindJSON(&grantMenu)
|
|
if err != nil {
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
err = roleService.GrantMenu(grantMenu.RoleId, grantMenu.MenuIds)
|
|
if err != nil {
|
|
global.Logger.Error("授权菜单失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMsg("授权菜单成功!", c)
|
|
}
|