sys_dept.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package model
  2. import (
  3. model2 "Medical_OAuth/common/model"
  4. "errors"
  5. "fmt"
  6. "gorm.io/gorm"
  7. )
  8. type SysDept struct {
  9. model2.Model
  10. ParentId int `json:"parentId" gorm:""` //上级部门
  11. DeptPath string `json:"deptPath" gorm:"size:255;" swaggerignore:"true"` //
  12. DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
  13. Sort int `json:"sort" gorm:"size:4;"` //排序
  14. Status int `json:"status" gorm:"size:4;"` //状态 1-停用 2-正常
  15. Children []SysDept `json:"children" gorm:"-"`
  16. model2.ControlBy
  17. model2.ModelTime
  18. }
  19. func (SysDept) TableName() string {
  20. return "sys_dept"
  21. }
  22. func (e *SysDept) Generate() model2.ActiveRecord {
  23. o := *e
  24. return &o
  25. }
  26. func (e *SysDept) GetId() interface{} {
  27. return e.Id
  28. }
  29. func (e *SysDept) BeforeDelete(_ *gorm.DB) (err error) {
  30. if e.Id == 1 {
  31. return errors.New("禁止删除系统部门")
  32. }
  33. return
  34. }
  35. func GetEnterDeptCacheKey(userId int) string {
  36. return fmt.Sprintf("enter-dept-%d", userId)
  37. }
  38. func GetEnterDeptNameCacheKey(userId int) string {
  39. return fmt.Sprintf("enter-dept-name-%d", userId)
  40. }