fusenapi/server/ldap-admin/internal/logic/deletemenulogic.go

66 lines
1.7 KiB
Go
Raw Normal View History

2023-11-15 07:50:18 +00:00
package logic
import (
2023-11-15 08:32:07 +00:00
"fusenapi/model/gmodel"
2023-11-15 07:50:18 +00:00
"fusenapi/utils/auth"
"fusenapi/utils/basic"
2023-11-15 08:32:07 +00:00
"gorm.io/gorm"
"time"
2023-11-15 07:50:18 +00:00
"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) {
2023-11-15 08:32:07 +00:00
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, "删除成功")
2023-11-15 07:50:18 +00:00
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *DeleteMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }