新增部门列表
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/constants"
|
||||
"context"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"math"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/ldap-admin/internal/svc"
|
||||
"fusenapi/server/ldap-admin/internal/types"
|
||||
@@ -32,39 +29,42 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||
// func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *GetDepartmentsLogic) GetDepartments(req *types.GetDepartmentsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//todo 鉴权 。。。。
|
||||
if req.CurrentPage <= 0{
|
||||
req.CurrentPage = constants.DEFAULT_PAGE
|
||||
}
|
||||
if req.Limit <= 0{
|
||||
req.Limit = constants.DEFAULT_PAGE_SIZE
|
||||
}
|
||||
departList,total,err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx,req.CurrentPage,req.Limit,"")
|
||||
departList,_,err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx,"")
|
||||
if err != nil{
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
|
||||
}
|
||||
list := make([]types.DepartmentsItem,0,len(departList))
|
||||
mapDepartment := make(map[int64]*types.DepartmentsItem)
|
||||
for _,v := range departList{
|
||||
list = append(list,types.DepartmentsItem{
|
||||
Id: v.Id,
|
||||
Name: *v.Name,
|
||||
Remark: *v.Remark,
|
||||
Type: *v.Type,
|
||||
ParentId: *v.ParentId,
|
||||
Dn: *v.Dn,
|
||||
mapDepartment[v.Id] = &types.DepartmentsItem{
|
||||
Id: v.Id,
|
||||
Name: *v.Name,
|
||||
Remark: *v.Remark,
|
||||
Type: *v.Type,
|
||||
ParentId: *v.ParentId,
|
||||
Dn: *v.Dn,
|
||||
SyncState: *v.SyncState,
|
||||
})
|
||||
Child: make([]*types.DepartmentsItem,0,50),
|
||||
}
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK,"success",types.GetDepartmentsRsp{
|
||||
//组织树形关系
|
||||
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)
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"success",types.GetDepartmentsRsp{
|
||||
List: list,
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(req.Limit))),
|
||||
CurrentPage: req.CurrentPage,
|
||||
PerPage: req.Limit,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user