This commit is contained in:
laodaming 2023-11-14 11:57:09 +08:00
parent 15671c02c3
commit cf06e4fc6a
4 changed files with 31 additions and 17 deletions
model/gmodel
server/ldap-admin/internal
server_api

View File

@ -15,6 +15,7 @@ type LdapDepartment struct {
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30 ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30
Dn *string `gorm:"default:'';" json:"dn"` // Dn *string `gorm:"default:'';" json:"dn"` //
SyncState *int64 `gorm:"default:1;" json:"sync_state"` // SyncState *int64 `gorm:"default:1;" json:"sync_state"` //
Sort *int64 `gorm:"default:999;" json:"sort"` // 排序
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
} }

View File

@ -31,13 +31,14 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
//todo 鉴权 。。。。 //todo 鉴权 。。。。
departList,_,err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx,"") departList, _, err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx, "sort ASC")
if err != nil{ if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
} }
//存入map
mapDepartment := make(map[int64]*types.DepartmentsItem) mapDepartment := make(map[int64]*types.DepartmentsItem)
for _,v := range departList{ for _, v := range departList {
mapDepartment[v.Id] = &types.DepartmentsItem{ mapDepartment[v.Id] = &types.DepartmentsItem{
Id: v.Id, Id: v.Id,
Name: *v.Name, Name: *v.Name,
@ -46,24 +47,34 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
ParentId: *v.ParentId, ParentId: *v.ParentId,
Dn: *v.Dn, Dn: *v.Dn,
SyncState: *v.SyncState, SyncState: *v.SyncState,
Child: make([]*types.DepartmentsItem,0,50), Sort: *v.Sort,
Child: make([]*types.DepartmentsItem, 0, 50),
} }
} }
//组织树形关系
for _,v := range mapDepartment{ for _,v := range mapDepartment{
//有父级,把他付给父级 for _,val := range departList{
if info,ok := mapDepartment[v.ParentId];ok{ if *val.ParentId != v.Id{
info.Child = append(info.Child,v) continue
} }
v.Child = append(v.Child,&types.DepartmentsItem{
} Id: val.Id,
list := make([]*types.DepartmentsItem,0,len(departList)) Name: *val.Name,
for _,v := range mapDepartment{ Remark: *val.Remark,
if v.ParentId == 0{ Type: *val.Type,
list = append(list,v) ParentId: *val.ParentId,
Dn: *val.Dn,
SyncState: *val.SyncState,
Sort: *val.Sort,
})
} }
} }
return resp.SetStatusWithMessage(basic.CodeOK,"success",types.GetDepartmentsRsp{ list := make([]*types.DepartmentsItem, 0, len(departList))
for _, v := range mapDepartment {
if v.ParentId == 0 {
list = append(list, v)
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{
List: list, List: list,
}) })
} }

View File

@ -17,6 +17,7 @@ type DepartmentsItem struct {
ParentId int64 `json:"parent_id"` ParentId int64 `json:"parent_id"`
Dn string `json:"dn"` Dn string `json:"dn"`
SyncState int64 `json:"sync_state"` SyncState int64 `json:"sync_state"`
Sort int64 `json:"sort"`
Child []*DepartmentsItem `json:"child"` Child []*DepartmentsItem `json:"child"`
} }

View File

@ -30,6 +30,7 @@ type DepartmentsItem {
ParentId int64 `json:"parent_id"` ParentId int64 `json:"parent_id"`
Dn string `json:"dn"` Dn string `json:"dn"`
SyncState int64 `json:"sync_state"` SyncState int64 `json:"sync_state"`
Sort int64 `json:"sort"`
Child []*DepartmentsItem `json:"child"` Child []*DepartmentsItem `json:"child"`
} }
//保存部门信息 //保存部门信息