kobe6258 6 ماه پیش
والد
کامیت
4f9e014f56
3فایلهای تغییر یافته به همراه20 افزوده شده و 7 حذف شده
  1. 1 1
      controllers/sys_department.go
  2. 16 5
      models/sys_department.go
  3. 3 1
      services/sys_department.go

+ 1 - 1
controllers/sys_department.go

@@ -31,7 +31,7 @@ func (this *SysDepartmentController) List() {
 		br.ErrMsg = "获取部门列表失败,Err" + err.Error()
 		return
 	}
-	list := services.GetSysDepartmentTree(departmentList, 0)
+	list := services.GetSysDepartmentTree(departmentList, 0, 1)
 
 	resp := new(response.SysDepartmentListResp)
 	resp.List = list

+ 16 - 5
models/sys_department.go

@@ -8,12 +8,21 @@ import (
 	"github.com/beego/beego/v2/client/orm"
 )
 
+type DepartmentType string
+
+const (
+	SubCompany DepartmentType = "sub"
+	Department DepartmentType = "department"
+)
+
 type SysDepartment struct {
-	SysDepartmentId   int    `orm:"pk" description:"部门id"`
-	SysDepartmentName string `description:"部门名称"`
-	Sort              int    `description:"排序"`
-	Level             int    `description:"层级"`
-	ParentId          int    `description:"父目录id"`
+	SysDepartmentId   int            `orm:"pk" description:"部门id"`
+	SysDepartmentName string         `description:"部门名称"`
+	OutId             int            `gorm:"column:out_id;type:int(11);not null" json:"out_id"`
+	Type              DepartmentType `gorm:"column:type;type:varchar(50);not null" json:"type"`
+	Sort              int            `description:"排序"`
+	Level             int            `description:"层级"`
+	ParentId          int            `description:"父目录id"`
 }
 
 func (s *SysDepartment) Add() (err error) {
@@ -31,6 +40,8 @@ func (s *SysDepartment) Update(cols []string) (err error) {
 type SysDepartmentList struct {
 	SysDepartmentId   int                  `description:"部门id"`
 	SysDepartmentName string               `description:"部门名称"`
+	OutId             int                  `gorm:"column:out_id;type:int(11);not null" json:"out_id"`
+	Type              DepartmentType       `gorm:"column:type;type:varchar(50);not null" json:"type"`
 	Child             []*SysDepartmentList `description:"分组"`
 	Level             int                  `description:"1:部门, 2|3:分组"`
 	ParentId          int                  `description:"父目录id"`

+ 3 - 1
services/sys_department.go

@@ -14,9 +14,11 @@ func GetSysDepartmentTree(list []*models.SysDepartmentList, parentId int) []*mod
 			t := new(models.SysDepartmentList)
 			t.SysDepartmentId = v.SysDepartmentId
 			t.SysDepartmentName = v.SysDepartmentName
+			t.OutId = v.OutId
+			t.Type = v.Type
 			t.Level = v.Level
 			t.ParentId = v.ParentId
-			t.Child = GetSysDepartmentTree(list, v.SysDepartmentId)
+			t.Child = GetSysDepartmentTree(list, v.OutId)
 			res = append(res, t)
 		}
 	}