sys_dept.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. IsIceReleaseCold bool `json:"isIceReleaseCold" gorm:"type:boolean;default:false"` //冰排是否释冷
  22. IsCoolerReleaseCold bool `json:"isCoolerReleaseCold" gorm:"type:boolean;default:false"` //保温箱是否释冷
  23. IsCoolerShow bool `json:"isCoolerShow" gorm:"type:boolean;default:false"` //保温箱是否展示开始使用时间
  24. IsOutStorage bool `json:"isOutStorage" gorm:"type:boolean;default:false"` //是否可以出库
  25. Children []SysDept `json:"children" gorm:"-"`
  26. CompanyAddress string `json:"companyAddress"` //公司地址
  27. model2.ControlBy
  28. model2.ModelTime
  29. }
  30. func (SysDept) TableName() string {
  31. return "sys_dept"
  32. }
  33. type SysDeptOmit struct {
  34. Id int `json:"id,omitempty"`
  35. Path string `json:"path,omitempty"` // 路径
  36. Name string `json:"name,omitempty"` // 部门名称
  37. }
  38. func (SysDeptOmit) TableName() string {
  39. return "sys_dept"
  40. }
  41. func (e *SysDept) Generate() model2.ActiveRecord {
  42. o := *e
  43. return &o
  44. }
  45. func (e *SysDept) GetId() interface{} {
  46. return e.Id
  47. }
  48. func (e *SysDept) BeforeDelete(_ *gorm.DB) (err error) {
  49. if e.Id == 1 {
  50. return errors.New("禁止删除系统部门")
  51. }
  52. return
  53. }
  54. func GetCompanyById(id int) (SysDept, error) {
  55. var err error
  56. var deptModel SysDept
  57. //准备db
  58. db := sdk.Runtime.GetDbByKey(config.ApplicationConfig.Host)
  59. if db == nil {
  60. err = errors.New("db not exist")
  61. log.Errorf("host[%s]'s %s", err.Error())
  62. return deptModel, err
  63. }
  64. err = db.First(&deptModel, id).Error
  65. if err != nil {
  66. log.Errorf("db error: %s", err)
  67. err = errors.New("获取企业信息失败")
  68. return deptModel, err
  69. }
  70. return deptModel, nil
  71. }