Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"sort"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -37,9 +39,17 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
|
||||
}
|
||||
//变成树形结构
|
||||
list := l.DepartmentListToTree(departList)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{
|
||||
List: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (l *GetDepartmentsLogic)DepartmentListToTree(deps []gmodel.LdapDepartment)[]*types.DepartmentsItem{
|
||||
//存入map
|
||||
mapDepartment := make(map[int64]*types.DepartmentsItem)
|
||||
for _, v := range departList {
|
||||
for _, v := range deps {
|
||||
mapDepartment[v.Id] = &types.DepartmentsItem{
|
||||
Id: v.Id,
|
||||
Name: *v.Name,
|
||||
@@ -52,35 +62,23 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
|
||||
Child: make([]*types.DepartmentsItem, 0, 50),
|
||||
}
|
||||
}
|
||||
//组织从属关系
|
||||
for _,v := range mapDepartment{
|
||||
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,
|
||||
//如果有父级
|
||||
if parent,ok := mapDepartment[v.ParentId];ok{
|
||||
parent.Child = append(parent.Child,v)
|
||||
sort.Slice(parent.Child, func(i, j int) bool {
|
||||
return parent.Child[i].Sort < parent.Child[j].Sort //升序
|
||||
})
|
||||
}
|
||||
}
|
||||
list := make([]*types.DepartmentsItem, 0, len(departList))
|
||||
for _, v := range mapDepartment {
|
||||
if v.ParentId == 0 {
|
||||
list = append(list, v)
|
||||
//排序
|
||||
list := make([]*types.DepartmentsItem, 0, len(deps))
|
||||
for _, v := range deps {
|
||||
if *v.ParentId == 0 {
|
||||
list = append(list, mapDepartment[v.Id])
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{
|
||||
List: list,
|
||||
})
|
||||
return list
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetDepartmentsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -31,8 +33,30 @@ func NewSaveDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
|
||||
// }
|
||||
|
||||
func (l *SaveDepartmentLogic) SaveDepartment(req *types.SaveDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//todo 鉴权。。。
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
now := time.Now().UTC()
|
||||
data := &gmodel.LdapDepartment{
|
||||
Name: &req.Name,
|
||||
Remark: &req.Remark,
|
||||
Type: &req.Type,
|
||||
ParentId: &req.ParentId,
|
||||
Dn: &req.Dn,
|
||||
Sort: &req.Sort,
|
||||
Utime: &now,
|
||||
}
|
||||
if req.Id > 0{//更新
|
||||
if err := l.svcCtx.AllModels.LdapDepartment.Update(l.ctx,req.Id,data);err != nil{
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"更新失败")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"更新成功")
|
||||
}
|
||||
//添加
|
||||
data.Ctime = &now
|
||||
if err := l.svcCtx.AllModels.LdapDepartment.Create(l.ctx,data);err != nil{
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"添加失败")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"添加成功")
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
||||
Reference in New Issue
Block a user