合并冲突
This commit is contained in:
commit
c19dbc1a41
@ -2,48 +2,46 @@ package gmodel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"errors"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *LdapDepartmentModel) GetOneById(ctx context.Context, id int64) (resp LdapDepartment, err error) {
|
// 获取列表
|
||||||
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
|
func (d *LdapDepartmentModel) GetAll(ctx context.Context, sort string) (resp []LdapDepartment, total int64, err error) {
|
||||||
return resp, db.Take(&resp).Error
|
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
||||||
}
|
|
||||||
|
|
||||||
func (d *LdapDepartmentModel) GetList(ctx context.Context, page, pageSize int, sort string) (resp []LdapDepartment, total int64, err error) {
|
|
||||||
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
|
|
||||||
if sort != "" {
|
if sort != "" {
|
||||||
db = db.Order(sort)
|
db = db.Order(sort)
|
||||||
}
|
}
|
||||||
//查询数量
|
if err = db.Count(&total).Error; err != nil {
|
||||||
if err = db.Limit(1).Count(&total).Error; err != nil {
|
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
offset := (page - 1) * pageSize
|
err = db.Find(&resp).Error
|
||||||
err = db.Offset(offset).Limit(pageSize).Find(&resp).Error
|
|
||||||
return resp, total, err
|
return resp, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertOne 单个插入
|
func (d *LdapDepartmentModel) FindOne(ctx context.Context, id int64) (resp *LdapDepartment, err error) {
|
||||||
func (d *LdapDepartmentModel) InsertOne(ctx context.Context, insertData LdapDepartment) error {
|
err = d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Take(&resp).Error
|
||||||
var nowTime = time.Now().UTC()
|
return resp, err
|
||||||
|
|
||||||
insertData.Ctime = &nowTime
|
|
||||||
insertData.Utime = &nowTime
|
|
||||||
result := d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&insertData)
|
|
||||||
if result.Error != nil {
|
|
||||||
return result.Error
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOne 单个更新
|
// 更新
|
||||||
func (d *LdapDepartmentModel) UpdateOne(ctx context.Context, Department LdapDepartment, updateData map[string]interface{}) error {
|
func (d *LdapDepartmentModel) Update(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||||
result := d.db.WithContext(ctx).Model(&Department).Updates(updateData)
|
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Updates(&data).Error
|
||||||
if result.Error != nil {
|
}
|
||||||
return result.Error
|
|
||||||
} else {
|
// 创建
|
||||||
return nil
|
func (d *LdapDepartmentModel) Create(ctx context.Context, data *LdapDepartment) error {
|
||||||
}
|
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *LdapDepartmentModel) CreateOrUpdate(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||||
|
_, err := d.FindOne(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return d.Create(ctx, data)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.Update(ctx, id, data)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ type LdapUsers struct {
|
|||||||
Password *string `gorm:"default:'';" json:"password"` //
|
Password *string `gorm:"default:'';" json:"password"` //
|
||||||
Nickname *string `gorm:"default:'';" json:"nickname"` //
|
Nickname *string `gorm:"default:'';" json:"nickname"` //
|
||||||
GivenName *string `gorm:"default:'';" json:"given_name"` //
|
GivenName *string `gorm:"default:'';" json:"given_name"` //
|
||||||
Email *string `gorm:"default:'';" json:"email"` //
|
Email *string `gorm:"unique_key;default:'';" json:"email"` //
|
||||||
JobNumber *string `gorm:"default:'';" json:"job_number"` //
|
JobNumber *string `gorm:"default:'';" json:"job_number"` //
|
||||||
Mobile *string `gorm:"unique_key;default:'';" json:"mobile"` //
|
Mobile *string `gorm:"unique_key;default:'';" json:"mobile"` //
|
||||||
Avatar *string `gorm:"default:'';" json:"avatar"` //
|
Avatar *string `gorm:"default:'';" json:"avatar"` //
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/logic"
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AddDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.AddDepartmentReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewAddDepartmentLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.AddDepartment(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/logic"
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AddMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.AddMenuHandler
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewAddMenuLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.AddMenu(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/logic"
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func DeleteDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.DeleteDepartmentReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewDeleteDepartmentLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.DeleteDepartment(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/logic"
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func EditMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.EditMenuHandler
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewEditMenuLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.EditMenu(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/logic"
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetMenusTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var req types.GetMenusTreeReq
|
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewGetMenusTreeLogic(r.Context(), svcCtx)
|
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
|
||||||
basic.BeforeLogic(w, r, rl)
|
|
||||||
|
|
||||||
resp := l.GetMenusTree(&req, userinfo)
|
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,39 +13,14 @@ 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),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/ldap-admin/add_department",
|
Path: "/api/ldap-admin/save_department",
|
||||||
Handler: AddDepartmentHandler(serverCtx),
|
Handler: SaveDepartmentHandler(serverCtx),
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/ldap-admin/edit_department",
|
|
||||||
Handler: EditDepartmentHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/ldap-admin/delete_department",
|
|
||||||
Handler: DeleteDepartmentHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/ldap-admin/get_menus_tree",
|
|
||||||
Handler: GetMenusTreeHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/ldap-admin/add_menu",
|
|
||||||
Handler: AddMenuHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/api/ldap-admin/edit_menu",
|
|
||||||
Handler: EditMenuHandler(serverCtx),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -11,22 +11,22 @@ import (
|
|||||||
"fusenapi/server/ldap-admin/internal/types"
|
"fusenapi/server/ldap-admin/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EditDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SaveDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var req types.EditDepartmentReq
|
var req types.SaveDepartmentReq
|
||||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewEditDepartmentLogic(r.Context(), svcCtx)
|
l := logic.NewSaveDepartmentLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
rl := reflect.ValueOf(l)
|
rl := reflect.ValueOf(l)
|
||||||
basic.BeforeLogic(w, r, rl)
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
resp := l.EditDepartment(&req, userinfo)
|
resp := l.SaveDepartment(&req, userinfo)
|
||||||
|
|
||||||
if !basic.AfterLogic(w, r, rl, resp) {
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
basic.NormalAfterLogic(w, r, resp)
|
basic.NormalAfterLogic(w, r, resp)
|
@ -1,62 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AddDepartmentLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAddDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDepartmentLogic {
|
|
||||||
return &AddDepartmentLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *AddDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *AddDepartmentLogic) AddDepartment(req *types.AddDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
if req.ParentId > 0 {
|
|
||||||
_, err := l.svcCtx.AllModels.LdapDepartment.GetOneById(l.ctx, req.ParentId)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
basic.CodeServiceErr.Message = "查询不到上级"
|
|
||||||
} else {
|
|
||||||
basic.CodeServiceErr.Message = "系统出错"
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeServiceErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := l.svcCtx.AllModels.LdapDepartment.InsertOne(l.ctx, gmodel.LdapDepartment{
|
|
||||||
Name: &req.Name,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return resp.SetStatus(basic.CodeServiceErr)
|
|
||||||
}
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *AddDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -1,43 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AddMenuLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAddMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMenuLogic {
|
|
||||||
return &AddMenuLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *AddMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *AddMenuLogic) AddMenu(req *types.AddMenuHandler, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *AddMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -1,43 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DeleteDepartmentLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDeleteDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDepartmentLogic {
|
|
||||||
return &DeleteDepartmentLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *DeleteDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *DeleteDepartmentLogic) DeleteDepartment(req *types.DeleteDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *DeleteDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -1,43 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EditMenuLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEditMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditMenuLogic {
|
|
||||||
return &EditMenuLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *EditMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *EditMenuLogic) EditMenu(req *types.EditMenuHandler, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *EditMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -1,10 +1,8 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/constants"
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"math"
|
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
@ -32,35 +30,11 @@ 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) {
|
||||||
if req.CurrentPage <= 0 {
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
req.CurrentPage = constants.DEFAULT_PAGE
|
// userinfo 传入值时, 一定不为null
|
||||||
}
|
|
||||||
if req.PageSize <= 0 {
|
|
||||||
req.PageSize = constants.DEFAULT_PAGE_SIZE
|
|
||||||
}
|
|
||||||
resList, resTotal, err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx, req.CurrentPage, req.PageSize, "")
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
|
|
||||||
}
|
|
||||||
var pageCount int64 = 1
|
|
||||||
if resTotal > int64(req.PageSize) {
|
|
||||||
var float64Count = float64(resTotal)
|
|
||||||
var float64PerPage = float64(req.PageSize)
|
|
||||||
pageCountFloat := math.Ceil(float64Count / float64PerPage)
|
|
||||||
pageCount = int64(pageCountFloat)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
return resp.SetStatus(basic.CodeOK)
|
||||||
"list": resList,
|
|
||||||
"meta": map[string]int64{
|
|
||||||
"total_count": resTotal,
|
|
||||||
"page_count": pageCount,
|
|
||||||
"current_page": int64(req.CurrentPage),
|
|
||||||
"per_page": int64(req.PageSize),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetMenusTreeLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGetMenusTreeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenusTreeLogic {
|
|
||||||
return &GetMenusTreeLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
|
||||||
// func (l *GetMenusTreeLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (l *GetMenusTreeLogic) GetMenusTree(req *types.GetMenusTreeReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
||||||
// func (l *GetMenusTreeLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
// }
|
|
@ -12,14 +12,14 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EditDepartmentLogic struct {
|
type SaveDepartmentLogic struct {
|
||||||
logx.Logger
|
logx.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEditDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDepartmentLogic {
|
func NewSaveDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveDepartmentLogic {
|
||||||
return &EditDepartmentLogic{
|
return &SaveDepartmentLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
svcCtx: svcCtx,
|
svcCtx: svcCtx,
|
||||||
@ -27,17 +27,15 @@ func NewEditDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理进入前逻辑w,r
|
// 处理进入前逻辑w,r
|
||||||
// func (l *EditDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
// func (l *SaveDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *EditDepartmentLogic) EditDepartment(req *types.EditDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *SaveDepartmentLogic) SaveDepartment(req *types.SaveDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
//todo 鉴权。。。
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
// func (l *EditDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
// func (l *SaveDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
// }
|
// }
|
@ -5,60 +5,28 @@ import (
|
|||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EditMenuHandler struct {
|
type GetDepartmentsRsp struct {
|
||||||
|
List []*DepartmentsItem `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DepartmentsItem struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Icon string `json:"icon"`
|
|
||||||
Path string `json:"path"`
|
|
||||||
Sort int64 `json:"sort"`
|
|
||||||
Status int64 `json:"status"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddMenuHandler struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Icon string `json:"icon"`
|
|
||||||
Path string `json:"path"`
|
|
||||||
Sort int64 `json:"sort"`
|
|
||||||
Status int64 `json:"status"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetMenusTreeReq struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddDepartmentReq struct {
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
Creator string `json:"creator"`
|
|
||||||
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 EditDepartmentReq struct {
|
type SaveDepartmentReq 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"`
|
||||||
Creator string `json:"creator"`
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteDepartmentReq struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDepartmentsReq struct {
|
|
||||||
CurrentPage int `form:"current_page"`
|
|
||||||
PageSize int `form:"page_size"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
@ -149,6 +149,11 @@ func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.Resp
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//灯下删掉
|
||||||
|
/*if userInfo.UserId != 127{
|
||||||
|
conn.Close()
|
||||||
|
return
|
||||||
|
}*/
|
||||||
//设置连接
|
//设置连接
|
||||||
ws, err := l.setConnPool(conn, userInfo, isFirefoxBrowser, userAgent, oldWid)
|
ws, err := l.setConnPool(conn, userInfo, isFirefoxBrowser, userAgent, oldWid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,90 +12,32 @@ 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 AddDepartmentHandler
|
post /api/ldap-admin/save_department(SaveDepartmentReq) returns (response);
|
||||||
post /api/ldap-admin/add_department(AddDepartmentReq) returns (response);
|
|
||||||
|
|
||||||
// 编辑部门
|
|
||||||
@handler EditDepartmentHandler
|
|
||||||
post /api/ldap-admin/edit_department(EditDepartmentReq) returns (response);
|
|
||||||
|
|
||||||
// 删除部门
|
|
||||||
@handler DeleteDepartmentHandler
|
|
||||||
post /api/ldap-admin/delete_department(DeleteDepartmentReq) returns (response);
|
|
||||||
|
|
||||||
//获取菜单列表--树形
|
|
||||||
@handler GetMenusTreeHandler
|
|
||||||
post /api/ldap-admin/get_menus_tree(GetMenusTreeReq) returns (response);
|
|
||||||
|
|
||||||
// 新增菜单
|
|
||||||
@handler AddMenuHandler
|
|
||||||
post /api/ldap-admin/add_menu(AddMenuHandler) returns (response);
|
|
||||||
|
|
||||||
// 编辑菜单
|
|
||||||
@handler EditMenuHandler
|
|
||||||
post /api/ldap-admin/edit_menu(EditMenuHandler) returns (response);
|
|
||||||
}
|
|
||||||
|
|
||||||
type EditMenuHandler {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Icon string `json:"icon"`
|
|
||||||
Path string `json:"path"`
|
|
||||||
Sort int64 `json:"sort"`
|
|
||||||
Status int64 `json:"status"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddMenuHandler {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Icon string `json:"icon"`
|
|
||||||
Path string `json:"path"`
|
|
||||||
Sort int64 `json:"sort"`
|
|
||||||
Status int64 `json:"status"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取菜单列表--树形
|
|
||||||
type GetMenusTreeReq {
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增部门
|
|
||||||
type AddDepartmentReq {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Remark string `json:"remark"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Dn string `json:"dn"`
|
|
||||||
SyncState int64 `json:"sync_state"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编辑部门
|
|
||||||
type EditDepartmentReq {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Remark string `json:"remark"`
|
|
||||||
Creator string `json:"creator"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
ParentId int64 `json:"parent_id"`
|
|
||||||
Dn string `json:"dn"`
|
|
||||||
SyncState int64 `json:"sync_state"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除部门
|
|
||||||
type DeleteDepartmentReq {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取部门列表
|
//获取部门列表
|
||||||
type GetDepartmentsReq {
|
type GetDepartmentsRsp {
|
||||||
CurrentPage int `form:"current_page"`
|
List []*DepartmentsItem `json:"list"`
|
||||||
PageSize int `form:"page_size"`
|
}
|
||||||
|
type DepartmentsItem {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ParentId int64 `json:"parent_id"`
|
||||||
|
Dn string `json:"dn"`
|
||||||
|
SyncState int64 `json:"sync_state"`
|
||||||
|
Child []*DepartmentsItem `json:"child"`
|
||||||
|
}
|
||||||
|
//保存部门信息
|
||||||
|
type SaveDepartmentReq {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ParentId int64 `json:"parent_id"`
|
||||||
|
Dn string `json:"dn"`
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user