66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/ldap-admin/internal/svc"
|
|
"fusenapi/server/ldap-admin/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type DeleteMenuLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
|
|
return &DeleteMenuLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// 处理进入前逻辑w,r
|
|
// func (l *DeleteMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
// }
|
|
|
|
func (l *DeleteMenuLogic) DeleteMenu(req *types.DeleteMenuReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
if req.Id <= 0 {
|
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数id无效")
|
|
}
|
|
err := l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
|
menusModel := gmodel.NewLdapMenusModel(tx)
|
|
status := int64(0)
|
|
now := time.Now().UTC()
|
|
err := menusModel.Update(l.ctx, req.Id, &gmodel.LdapMenus{
|
|
Status: &status,
|
|
Utime: &now,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
//删除分组绑定的菜单
|
|
groupMenusModel := gmodel.NewLdapGroupMenusModel(tx)
|
|
return groupMenusModel.DeleteByMenuId(l.ctx, req.Id)
|
|
})
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "删除菜单失败")
|
|
}
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "删除成功")
|
|
}
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
// func (l *DeleteMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
// }
|