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.

46 lines
1.2 KiB

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