|
@@ -3,13 +3,13 @@ package dao
|
|
|
import "server/global"
|
|
|
|
|
|
type Department struct {
|
|
|
- Id int `gorm:"primarykey" from:"id" json:"ID"`
|
|
|
- Name string `json:"name" from:"name" gorm:"comment:部门名称"`
|
|
|
- Desc string `json:"desc" from:"desc" gorm:"comment:部门描述"`
|
|
|
- PrincipalId int `json:"principalId" from:"principal_id" gorm:"comment:负责人id"`
|
|
|
- PrincipalName string `json:"principalName" from:"principal_name" gorm:"comment:负责人姓名"`
|
|
|
- Users []SysUser `json:"users" gorm:"-"`
|
|
|
- IsStart bool `json:"isStart" from:"is_start" gorm:"comment:是否启用"`
|
|
|
+ Id int `gorm:"primarykey" from:"id" json:"ID"`
|
|
|
+ Name string `json:"name" from:"name" gorm:"comment:部门名称"`
|
|
|
+ Desc string `json:"desc" from:"desc" gorm:"comment:部门描述"`
|
|
|
+ PrincipalId int `json:"principalId" from:"principal_id" gorm:"comment:负责人id"`
|
|
|
+ Principal SysUser `json:"principal" from:"principal" gorm:"foreignKey:PrincipalId;references:id;"`
|
|
|
+ Users []SysUser `json:"users" gorm:"-"`
|
|
|
+ IsStart bool `json:"isStart" from:"is_start" gorm:"comment:是否启用"`
|
|
|
}
|
|
|
|
|
|
func (Department) TableName() string {
|
|
@@ -20,7 +20,7 @@ func (Department) TableName() string {
|
|
|
|
|
|
// QueryAllDep 查询所有部门
|
|
|
func QueryAllDep() (deps []Department, err error) {
|
|
|
- err = global.GVA_DB.Model(&Department{}).Find(&deps).Error
|
|
|
+ err = global.GVA_DB.Model(&Department{}).Preload("Principal").Find(&deps).Error
|
|
|
return deps, err
|
|
|
}
|
|
|
|
|
@@ -37,7 +37,7 @@ func QueryUsersByDepId(depId int) (users []SysUser, err error) {
|
|
|
}
|
|
|
|
|
|
func QueryDepById(id int) (dep Department, err error) {
|
|
|
- err = global.GVA_DB.Model(&Department{}).Where("id = ?", id).First(&dep).Error
|
|
|
+ err = global.GVA_DB.Model(&Department{}).Where("id = ?", id).Preload("Principal").First(&dep).Error
|
|
|
return dep, err
|
|
|
}
|
|
|
|