新增部门列表
This commit is contained in:
parent
561ce385a1
commit
15671c02c3
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//获取列表
|
//获取列表
|
||||||
func (d *LdapDepartmentModel)GetList(ctx context.Context,page,limit int,sort string)(resp []LdapDepartment,total int64,err error){
|
func (d *LdapDepartmentModel)GetAll(ctx context.Context,sort string)(resp []LdapDepartment,total int64,err error){
|
||||||
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
||||||
if sort != ""{
|
if sort != ""{
|
||||||
db = db.Order(sort)
|
db = db.Order(sort)
|
||||||
@ -15,8 +15,7 @@ func (d *LdapDepartmentModel)GetList(ctx context.Context,page,limit int,sort str
|
|||||||
if err = db.Count(&total).Error;err != nil{
|
if err = db.Count(&total).Error;err != nil{
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
offset := (page - 1) * limit
|
err = db.Find(&resp).Error
|
||||||
err = db.Offset(offset).Limit(limit).Find(&resp).Error
|
|
||||||
return resp, total, err
|
return resp, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/rest"
|
import (
|
||||||
|
"fusenapi/server/ldap-admin/internal/types"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.GetDepartmentsReq
|
var req types.Request
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -13,7 +13,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodGet,
|
||||||
Path: "/api/ldap-admin/get_departments",
|
Path: "/api/ldap-admin/get_departments",
|
||||||
Handler: GetDepartmentsHandler(serverCtx),
|
Handler: GetDepartmentsHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/constants"
|
"context"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"math"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
"fusenapi/server/ldap-admin/internal/svc"
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
"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) 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 鉴权 。。。。
|
//todo 鉴权 。。。。
|
||||||
if req.CurrentPage <= 0{
|
departList,_,err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx,"")
|
||||||
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,"")
|
|
||||||
if err != nil{
|
if err != nil{
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
|
||||||
}
|
}
|
||||||
list := make([]types.DepartmentsItem,0,len(departList))
|
mapDepartment := make(map[int64]*types.DepartmentsItem)
|
||||||
for _,v := range departList{
|
for _,v := range departList{
|
||||||
list = append(list,types.DepartmentsItem{
|
mapDepartment[v.Id] = &types.DepartmentsItem{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Name: *v.Name,
|
Name: *v.Name,
|
||||||
Remark: *v.Remark,
|
Remark: *v.Remark,
|
||||||
Type: *v.Type,
|
Type: *v.Type,
|
||||||
ParentId: *v.ParentId,
|
ParentId: *v.ParentId,
|
||||||
Dn: *v.Dn,
|
Dn: *v.Dn,
|
||||||
SyncState: *v.SyncState,
|
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,
|
List: list,
|
||||||
Meta: types.Meta{
|
|
||||||
TotalCount: total,
|
|
||||||
PageCount: int64(math.Ceil(float64(total) / float64(req.Limit))),
|
|
||||||
CurrentPage: req.CurrentPage,
|
|
||||||
PerPage: req.Limit,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,24 +5,19 @@ import (
|
|||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetDepartmentsReq struct {
|
|
||||||
CurrentPage int `form:"current_page"`
|
|
||||||
Limit int `form:"limit"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDepartmentsRsp struct {
|
type GetDepartmentsRsp struct {
|
||||||
List []DepartmentsItem `json:"list"`
|
List []*DepartmentsItem `json:"list"`
|
||||||
Meta Meta `json:"meta"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DepartmentsItem struct {
|
type DepartmentsItem struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
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"`
|
||||||
|
Child []*DepartmentsItem `json:"child"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveDepartmentReq struct {
|
type SaveDepartmentReq struct {
|
||||||
|
@ -12,29 +12,25 @@ import "basic.api"
|
|||||||
service ldap-admin {
|
service ldap-admin {
|
||||||
//获取部门列表
|
//获取部门列表
|
||||||
@handler GetDepartmentsHandler
|
@handler GetDepartmentsHandler
|
||||||
post /api/ldap-admin/get_departments(GetDepartmentsReq) returns (response);
|
get /api/ldap-admin/get_departments(request) returns (response);
|
||||||
//保存部门信息
|
//保存部门信息
|
||||||
@handler SaveDepartmentHandler
|
@handler SaveDepartmentHandler
|
||||||
post /api/ldap-admin/save_department(SaveDepartmentReq) returns (response);
|
post /api/ldap-admin/save_department(SaveDepartmentReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取部门列表
|
//获取部门列表
|
||||||
type GetDepartmentsReq {
|
|
||||||
CurrentPage int `form:"current_page"`
|
|
||||||
Limit int `form:"limit"`
|
|
||||||
}
|
|
||||||
type GetDepartmentsRsp {
|
type GetDepartmentsRsp {
|
||||||
List []DepartmentsItem `json:"list"`
|
List []*DepartmentsItem `json:"list"`
|
||||||
Meta Meta `json:"meta"`
|
|
||||||
}
|
}
|
||||||
type DepartmentsItem {
|
type DepartmentsItem {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
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"`
|
||||||
|
Child []*DepartmentsItem `json:"child"`
|
||||||
}
|
}
|
||||||
//保存部门信息
|
//保存部门信息
|
||||||
type SaveDepartmentReq {
|
type SaveDepartmentReq {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user