40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
sysModel "sundynix-micro-go/app/system/model"
|
|
"sundynix-micro-go/app/system/rpc/internal/svc"
|
|
"sundynix-micro-go/app/system/rpc/system"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type DeleteRoleLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic {
|
|
return &DeleteRoleLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *DeleteRoleLogic) DeleteRole(in *system.IdsReq) (*system.CommonResp, error) {
|
|
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
|
|
if err := tx.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixRole{}).Error; err != nil {
|
|
return fmt.Errorf("删除角色失败: %w", err)
|
|
}
|
|
if err := tx.Where("role_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{}).Error; err != nil {
|
|
return fmt.Errorf("清除菜单关联失败: %w", err)
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
|
}
|