You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.5 KiB
67 lines
1.5 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package role
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateRoleLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 更新角色
|
|
func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleLogic {
|
|
return &UpdateRoleLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateRoleLogic) UpdateRole(req *types.UpdateRoleRequest) (resp *types.RoleInfo, err error) {
|
|
role, err := model.RoleFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("角色不存在: %v", err)
|
|
}
|
|
|
|
if req.Name != "" {
|
|
role.Name = req.Name
|
|
}
|
|
if req.Description != "" {
|
|
role.Description = req.Description
|
|
}
|
|
if req.SortOrder != nil {
|
|
role.SortOrder = *req.SortOrder
|
|
}
|
|
if req.Status != nil {
|
|
role.Status = *req.Status
|
|
}
|
|
|
|
err = model.RoleUpdate(l.ctx, l.svcCtx.DB, role)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("更新角色失败: %v", err)
|
|
}
|
|
|
|
return &types.RoleInfo{
|
|
Id: role.Id,
|
|
Name: role.Name,
|
|
Code: role.Code,
|
|
Description: role.Description,
|
|
IsSystem: role.IsSystem,
|
|
SortOrder: role.SortOrder,
|
|
Status: role.Status,
|
|
CreatedAt: role.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: role.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}, nil
|
|
}
|
|
|