fix
This commit is contained in:
parent
15671c02c3
commit
cf06e4fc6a
|
@ -15,6 +15,7 @@ type LdapDepartment struct {
|
|||
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30
|
||||
Dn *string `gorm:"default:'';" json:"dn"` //
|
||||
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"` //
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
//todo 鉴权 。。。。
|
||||
departList,_,err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx,"")
|
||||
if err != nil{
|
||||
departList, _, err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx, "sort ASC")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
|
||||
}
|
||||
//存入map
|
||||
mapDepartment := make(map[int64]*types.DepartmentsItem)
|
||||
for _,v := range departList{
|
||||
for _, v := range departList {
|
||||
mapDepartment[v.Id] = &types.DepartmentsItem{
|
||||
Id: v.Id,
|
||||
Name: *v.Name,
|
||||
|
@ -46,24 +47,34 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
|
|||
ParentId: *v.ParentId,
|
||||
Dn: *v.Dn,
|
||||
SyncState: *v.SyncState,
|
||||
Child: make([]*types.DepartmentsItem,0,50),
|
||||
Sort: *v.Sort,
|
||||
Child: make([]*types.DepartmentsItem, 0, 50),
|
||||
}
|
||||
}
|
||||
//组织树形关系
|
||||
for _,v := range mapDepartment{
|
||||
//有父级,把他付给父级
|
||||
if info,ok := mapDepartment[v.ParentId];ok{
|
||||
info.Child = append(info.Child,v)
|
||||
}
|
||||
|
||||
}
|
||||
list := make([]*types.DepartmentsItem,0,len(departList))
|
||||
for _,v := range mapDepartment{
|
||||
if v.ParentId == 0{
|
||||
list = append(list,v)
|
||||
for _,val := range departList{
|
||||
if *val.ParentId != v.Id{
|
||||
continue
|
||||
}
|
||||
v.Child = append(v.Child,&types.DepartmentsItem{
|
||||
Id: val.Id,
|
||||
Name: *val.Name,
|
||||
Remark: *val.Remark,
|
||||
Type: *val.Type,
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ type DepartmentsItem struct {
|
|||
ParentId int64 `json:"parent_id"`
|
||||
Dn string `json:"dn"`
|
||||
SyncState int64 `json:"sync_state"`
|
||||
Sort int64 `json:"sort"`
|
||||
Child []*DepartmentsItem `json:"child"`
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ type DepartmentsItem {
|
|||
ParentId int64 `json:"parent_id"`
|
||||
Dn string `json:"dn"`
|
||||
SyncState int64 `json:"sync_state"`
|
||||
Sort int64 `json:"sort"`
|
||||
Child []*DepartmentsItem `json:"child"`
|
||||
}
|
||||
//保存部门信息
|
||||
|
|
Loading…
Reference in New Issue
Block a user