You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. package sysModel
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "github.com/pkg/errors"
  5. "main/controller/servers"
  6. "main/init/qmsql"
  7. "main/model/modelInterface"
  8. )
  9. type SysAuthority struct {
  10. gorm.Model
  11. AuthorityId string `json:"authorityId" gorm:"not null;unique"`
  12. AuthorityName string `json:"authorityName"`
  13. }
  14. // 创建角色
  15. func (a *SysAuthority) CreateAuthority() (err error, authority *SysAuthority) {
  16. err = qmsql.DEFAULTDB.Create(a).Error
  17. return err, a
  18. }
  19. // 删除角色
  20. func (a *SysAuthority) DeleteAuthority() (err error) {
  21. err = qmsql.DEFAULTDB.Where("authority_id = ?", a.AuthorityId).Find(&SysUser{}).Error
  22. if err != nil {
  23. err = qmsql.DEFAULTDB.Where("authority_id = ?", a.AuthorityId).First(a).Delete(a).Error
  24. new(CasbinModel).clearCasbin(0,a.AuthorityId)
  25. } else {
  26. err = errors.New("此角色有用户正在使用禁止删除")
  27. }
  28. return err
  29. }
  30. // 分页获取数据 需要分页实现这个接口即可
  31. func (a *SysAuthority) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
  32. // 封装分页方法 调用即可 传入 当前的结构体和分页信息
  33. err, db, total := servers.PagingServer(a, info)
  34. if err != nil {
  35. return
  36. } else {
  37. var authority []SysAuthority
  38. err = db.Find(&authority).Error
  39. return err, authority, total
  40. }
  41. }