12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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
- IsIceReleaseCold bool `json:"isIceReleaseCold" gorm:"type:boolean;default:false"` //冰排是否释冷
- IsCoolerReleaseCold bool `json:"isCoolerReleaseCold" gorm:"type:boolean;default:false"` //保温箱是否释冷
- IsCoolerShow bool `json:"isCoolerShow" gorm:"type:boolean;default:false"` //保温箱是否展示开始使用时间
- IsOutStorage bool `json:"isOutStorage" gorm:"type:boolean;default:false"` //是否可以出库
- Children []SysDept `json:"children" gorm:"-"`
- CompanyAddress string `json:"companyAddress"` //公司地址
- 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
- }
|