sys_dept.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import (
  3. model2 "cold-delivery/common/model"
  4. "errors"
  5. log "gogs.baozhida.cn/zoie/OAuth-core/logger"
  6. "gogs.baozhida.cn/zoie/OAuth-core/sdk"
  7. "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
  8. "gorm.io/gorm"
  9. )
  10. var GetCompanyKeyErr = errors.New("获取公司秘钥失败")
  11. type SysDept struct {
  12. model2.Model
  13. ParentId int `json:"parentId" gorm:""` // 上级部门
  14. Path string `json:"-" gorm:"size:255;" swaggerignore:"true"` // 路径
  15. Name string `json:"name" gorm:"size:128;"` // 部门名称
  16. Sort int `json:"-" gorm:"size:4;"` // 排序
  17. Status int `json:"-" gorm:"size:4;"` // 状态 1-停用 2-正常
  18. Remark string `json:"remark" gorm:"size:1024;"` // 备注
  19. ColdKey string `json:"coldKey" gorm:"size:128;"` // 冷链3.0key
  20. ColdPid int `json:"coldPid" gorm:"size:128;"` // 冷链3.0公司id
  21. Children []SysDept `json:"children" gorm:"-"`
  22. model2.ControlBy
  23. model2.ModelTime
  24. }
  25. func (SysDept) TableName() string {
  26. return "sys_dept"
  27. }
  28. type SysDeptOmit struct {
  29. Id int `json:"id,omitempty"`
  30. Path string `json:"path,omitempty"` // 路径
  31. Name string `json:"name,omitempty"` // 部门名称
  32. }
  33. func (SysDeptOmit) TableName() string {
  34. return "sys_dept"
  35. }
  36. func (e *SysDept) Generate() model2.ActiveRecord {
  37. o := *e
  38. return &o
  39. }
  40. func (e *SysDept) GetId() interface{} {
  41. return e.Id
  42. }
  43. func (e *SysDept) BeforeDelete(_ *gorm.DB) (err error) {
  44. if e.Id == 1 {
  45. return errors.New("禁止删除系统部门")
  46. }
  47. return
  48. }
  49. func GetCompanyById(id int) (SysDept, error) {
  50. var err error
  51. var deptModel SysDept
  52. //准备db
  53. db := sdk.Runtime.GetDbByKey(config.ApplicationConfig.Host)
  54. if db == nil {
  55. err = errors.New("db not exist")
  56. log.Errorf("host[%s]'s %s", err.Error())
  57. return deptModel, err
  58. }
  59. err = db.First(&deptModel, id).Error
  60. if err != nil {
  61. log.Errorf("db error: %s", err)
  62. err = errors.New("获取企业信息失败")
  63. return deptModel, err
  64. }
  65. return deptModel, nil
  66. }