feat✨: 添加修改角色状态接口
This commit is contained in:
1 parent
91d902389a
commit
1b579fb814
5 files changed
+103
-19
No files matched your search
@@ -34,7 +34,6 @@ func (m *SysRoleSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
// SysConfigControl 增、改使用的结构体
|
||||
type SysRoleControl struct {
|
||||
RoleId int `uri:"id" comment:"角色编码"` // 角色编码
|
||||
RoleName string `form:"roleName" comment:"角色名称"` // 角色名称
|
||||
@@ -80,7 +79,25 @@ func (s *SysRoleControl) GetId() interface{} {
|
||||
return s.RoleId
|
||||
}
|
||||
|
||||
// SysConfigById 获取单个或者删除的结构体
|
||||
type UpdateStatusReq struct {
|
||||
RoleId int `form:"roleId" comment:"角色编码"` // 角色编码
|
||||
Status string `form:"status" comment:"状态"` // 状态
|
||||
common.ControlBy
|
||||
}
|
||||
|
||||
func (s *UpdateStatusReq) Generate(model *models.SysRole) {
|
||||
if s.RoleId != 0 {
|
||||
model.RoleId = s.RoleId
|
||||
}
|
||||
model.Status = s.Status
|
||||
}
|
||||
|
||||
func (s *UpdateStatusReq) GetId() interface{} {
|
||||
return s.RoleId
|
||||
}
|
||||
|
||||
|
||||
// SysRoleById 获取单个或者删除的结构体
|
||||
type SysRoleById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
@@ -236,4 +236,32 @@ func (e *SysRole) UpdateDataScope(c *models.SysRole) (err error) {
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateStatus 修改SysRole对象status
|
||||
func (e *SysRole) UpdateStatus(c *dto.UpdateStatusReq) error {
|
||||
var err error
|
||||
|
||||
tx := e.Orm.Debug().Begin()
|
||||
defer func() {
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
} else {
|
||||
tx.Commit()
|
||||
}
|
||||
}()
|
||||
var model = models.SysRole{}
|
||||
tx.First(&model, c.GetId())
|
||||
c.Generate(&model)
|
||||
db := tx.Session(&gorm.Session{FullSaveAssociations: true}).Debug().Save(&model)
|
||||
|
||||
if db.Error != nil {
|
||||
e.Log.Errorf("db error:%s", err)
|
||||
return err
|
||||
}
|
||||
if db.RowsAffected == 0 {
|
||||
return errors.New("无权更新该数据")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user