sys_dept.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package model
  2. import (
  3. model2 "Medical_OAuth/common/model"
  4. "errors"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  8. "gorm.io/gorm"
  9. "strings"
  10. )
  11. type SysDept struct {
  12. model2.Model
  13. ParentId int `json:"parentId" gorm:""` //上级部门
  14. DeptPath string `json:"deptPath" gorm:"size:255;" swaggerignore:"true"` //
  15. DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
  16. Sort int `json:"sort" gorm:"size:4;"` //排序
  17. Status int `json:"status" gorm:"size:4;"` //状态 1-停用 2-正常
  18. Children []SysDept `json:"children" gorm:"-"`
  19. model2.ControlBy
  20. model2.ModelTime
  21. }
  22. func (SysDept) TableName() string {
  23. return "sys_dept"
  24. }
  25. func (e *SysDept) Generate() model2.ActiveRecord {
  26. o := *e
  27. return &o
  28. }
  29. func (e *SysDept) GetId() interface{} {
  30. return e.Id
  31. }
  32. func (e *SysDept) BeforeDelete(_ *gorm.DB) (err error) {
  33. if e.Id == 1 {
  34. return errors.New("禁止删除系统部门")
  35. }
  36. return
  37. }
  38. func GetEnterDeptCacheKey(c *gin.Context) string {
  39. userId := user.GetUserId(c)
  40. tokenId := ""
  41. list := strings.Split(c.Request.Header.Get("Authorization"), ".")
  42. if len(list) > 0 {
  43. tokenId = list[len(list)-1]
  44. }
  45. return fmt.Sprintf("enter-dept-%s-%d", tokenId, userId)
  46. }
  47. func GetEnterDeptNameCacheKey(c *gin.Context) string {
  48. userId := user.GetUserId(c)
  49. tokenId := ""
  50. list := strings.Split(c.Request.Header.Get("Authorization"), ".")
  51. if len(list) > 0 {
  52. tokenId = list[len(list)-1]
  53. }
  54. return fmt.Sprintf("enter-dept-name-%s-%d", tokenId, userId)
  55. }