1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package model
- import (
- model2 "cold-delivery/common/model"
- "errors"
- log "gogs.baozhida.cn/zoie/OAuth-core/logger"
- "gogs.baozhida.cn/zoie/OAuth-core/sdk"
- "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
- "gorm.io/gorm"
- )
- var GetCompanyKeyErr = errors.New("获取公司秘钥失败")
- type SysDept struct {
- model2.Model
- ParentId int `json:"parentId" gorm:""` // 上级部门
- Path string `json:"-" gorm:"size:255;" swaggerignore:"true"` // 路径
- Name string `json:"name" gorm:"size:128;"` // 部门名称
- Sort int `json:"-" gorm:"size:4;"` // 排序
- Status int `json:"-" gorm:"size:4;"` // 状态 1-停用 2-正常
- Remark string `json:"remark" gorm:"size:1024;"` // 备注
- ColdKey string `json:"coldKey" gorm:"size:128;"` // 冷链3.0key
- ColdPid int `json:"coldPid" gorm:"size:128;"` // 冷链3.0公司id
- Children []SysDept `json:"children" gorm:"-"`
- model2.ControlBy
- model2.ModelTime
- }
- func (SysDept) TableName() string {
- return "sys_dept"
- }
- type SysDeptOmit struct {
- Id int `json:"id,omitempty"`
- Path string `json:"path,omitempty"` // 路径
- Name string `json:"name,omitempty"` // 部门名称
- }
- func (SysDeptOmit) 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 GetCompanyById(id int) (SysDept, error) {
- var err error
- var deptModel SysDept
- //准备db
- db := sdk.Runtime.GetDbByKey(config.ApplicationConfig.Host)
- if db == nil {
- err = errors.New("db not exist")
- log.Errorf("host[%s]'s %s", err.Error())
- return deptModel, err
- }
- err = db.First(&deptModel, id).Error
- if err != nil {
- log.Errorf("db error: %s", err)
- err = errors.New("获取企业信息失败")
- return deptModel, err
- }
- return deptModel, nil
- }
|