123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package system
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/fms_api/controller/resp"
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- "hongze/fms_api/models/system"
- systemService "hongze/fms_api/services/system"
- "hongze/fms_api/utils"
- )
- type SysRoleController struct {
- }
- // Add 添加角色
- func (s *SysRoleController) Add(c *gin.Context) {
- req := new(system.SysRoleAddReq)
- err := c.ShouldBind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- err, errMsg := systemService.AddRole(req)
- if err != nil {
- resp.FailMsg(errMsg, err.Error(), c)
- return
- }
- resp.Ok("保存成功", c)
- return
- }
- // Edit 编辑角色
- func (s *SysRoleController) Edit(c *gin.Context) {
- req := new(system.SysRoleEditReq)
- err := c.ShouldBind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- err, errMsg := systemService.EditRole(req)
- if err != nil {
- resp.FailMsg(errMsg, err.Error(), c)
- return
- }
- resp.Ok("保存成功", c)
- return
- }
- // 编辑角色菜单权限
- func (s *SysRoleController) EditMenu(c *gin.Context) {
- req := new(system.SysRoleMenuEditReq)
- err := c.ShouldBind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- err, errMsg := systemService.EditRoleMenu(req)
- if err != nil {
- resp.FailMsg(errMsg, err.Error(), c)
- return
- }
- resp.Ok("保存成功", c)
- return
- }
- func (s *SysRoleController) List(c *gin.Context) {
- req := new(system.SysRoleListReq)
- err := c.BindQuery(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- page := new(base.Page)
- page.SetPageSize(req.PageSize)
- page.SetCurrent(req.Current)
- item := new(system.SysRole)
- var condition string
- var pars []interface{}
- if req.RoleName != "" {
- roleName := "%" + req.RoleName + "%"
- condition += " role_name like ?"
- pars = append(pars, roleName)
- }
- page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
- total, roles, err := item.SelectPage(page, condition, pars)
- if err != nil {
- resp.FailMsg("获取失败", "获取失败,Err:"+err.Error(), c)
- return
- }
- list := make([]*system.SysRoleListItem, 0)
- for _, v := range roles {
- tmp := new(system.SysRoleListItem)
- tmp.RoleId = v.RoleId
- tmp.RoleName = v.RoleName
- tmp.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.CreateTime)
- tmp.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime)
- list = append(list, tmp)
- }
- page.SetTotal(total)
- baseData := new(base.BaseData)
- baseData.SetPage(page)
- baseData.SetList(list)
- resp.OkData("获取成功", baseData, c)
- }
- func (s *SysRoleController) MenuList(c *gin.Context) {
- req := new(system.SysRoleMenuListReq)
- err := c.BindQuery(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- list, err, errMsg := systemService.RoleMenuList(req)
- if err != nil {
- resp.FailMsg(errMsg, err.Error(), c)
- return
- }
- resp.OkData("获取成功", list, c)
- }
- // Delete 删除角色
- func (s *SysRoleController) Delete(c *gin.Context) {
- req := new(system.SysRoleDelReq)
- err := c.ShouldBind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- err, errMsg := systemService.DeleteRole(req)
- if err != nil {
- resp.FailMsg(errMsg, errMsg, c)
- return
- }
- resp.Ok("删除成功", c)
- return
- }
|