sys_role.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package model
  2. import (
  3. "ulink-admin/pkg/base"
  4. )
  5. type SysRole struct {
  6. base.BaseModel `xorm:"extends"`
  7. RoleName string `excel:"name=角色名称" xorm:"varchar(64)" json:"roleName" binding:"required"` //角色名称
  8. RoleKey string `excel:"name=角色权限" xorm:"varchar(64)" json:"roleKey" binding:"required"` //角色权限标识
  9. RoleSort int `excel:"name=角色排序" xorm:"int" json:"roleSort" ` //角色顺序
  10. DataScope string `excel:"-" json:"dataScope"` //数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
  11. MenuCheckStrictly bool `excel:"-" json:"menuCheckStrictly"` //菜单树选择项是否关联显示
  12. DeptCheckStrictly bool `excel:"-" json:"deptCheckStrictly"` //部门树选择项是否关联显示
  13. Status string `excel:"name=角色状态,format=0=正常,1=停用" xorm:"char(1)" json:"status"` //角色状态 0正常1停用
  14. DelFlag string `excel:"" xorm:"char(1)" json:"delFlag"` //删除标记0正常1删除
  15. Remark string `excel:"" json:"remark" binding:"required" msg:"备注不能为空"` //备注
  16. Rights []string `xorm:"longtext json" excel:"" json:"rights" ` //控制权限
  17. CompanyId int64 `excel:"name=公司Id" xorm:"bigint(20)" json:"companyId" ` //公司Id
  18. MenuIds []int64 `xorm:"-" json:"menuIds"` //菜单组
  19. DeptIds []int64 `xorm:"-" json:"deptIds"` //部门组
  20. }
  21. func (r SysRole) TableName() string {
  22. return "sys_role"
  23. }
  24. func (r *SysRole) Key() int64 {
  25. return r.Id
  26. }
  27. func (r *SysRole) BeforeUpdate() {
  28. user := base.GetCurUser()
  29. if user != nil {
  30. r.UpdateBy = user.Name
  31. }
  32. if user.ComponyId > 0 {
  33. r.CompanyId = user.ComponyId
  34. }
  35. }
  36. func (r *SysRole) BeforeInsert() {
  37. user := base.GetCurUser()
  38. if user != nil {
  39. r.CreateBy = user.Name
  40. r.UpdateBy = user.Name
  41. }
  42. if user != nil && user.ComponyId > 0 {
  43. r.CompanyId = user.ComponyId
  44. }
  45. }
  46. func (r *SysRole) Model() interface{} {
  47. return r
  48. }