123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package model
- import (
- model2 "Medical_OAuth/common/model"
- "errors"
- "fmt"
- "github.com/gin-gonic/gin"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
- "gorm.io/gorm"
- "strings"
- )
- type SysDept struct {
- model2.Model
- ParentId int `json:"parentId" gorm:""` //上级部门
- DeptPath string `json:"deptPath" gorm:"size:255;" swaggerignore:"true"` //
- DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
- Sort int `json:"sort" gorm:"size:4;"` //排序
- Status int `json:"status" gorm:"size:4;"` //状态 1-停用 2-正常
- Children []SysDept `json:"children" gorm:"-"`
- model2.ControlBy
- model2.ModelTime
- }
- func (SysDept) TableName() string {
- return "sys_dept"
- }
- func (e *SysDept) Generate() model2.ActiveRecord {
- o := *e
- return &o
- }
- func (e *SysDept) GetId() interface{} {
- return e.Id
- }
- func (e *SysDept) BeforeDelete(_ *gorm.DB) (err error) {
- if e.Id == 1 {
- return errors.New("禁止删除系统部门")
- }
- return
- }
- func GetEnterDeptCacheKey(c *gin.Context) string {
- userId := user.GetUserId(c)
- tokenId := ""
- list := strings.Split(c.Request.Header.Get("Authorization"), ".")
- if len(list) > 0 {
- tokenId = list[len(list)-1]
- }
- return fmt.Sprintf("enter-dept-%s-%d", tokenId, userId)
- }
- func GetEnterDeptNameCacheKey(c *gin.Context) string {
- userId := user.GetUserId(c)
- tokenId := ""
- list := strings.Split(c.Request.Header.Get("Authorization"), ".")
- if len(list) > 0 {
- tokenId = list[len(list)-1]
- }
- return fmt.Sprintf("enter-dept-name-%s-%d", tokenId, userId)
- }
|