55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.10.1
|
|
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"sundynix-micro-go/app/system/api/internal/svc"
|
|
"sundynix-micro-go/app/system/api/internal/types"
|
|
sysModel "sundynix-micro-go/app/system/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateClientLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClientLogic {
|
|
return &UpdateClientLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateClientLogic) UpdateClient(req *types.ClientUpdateReq) error {
|
|
updates := map[string]interface{}{}
|
|
if req.ClientId != "" {
|
|
updates["client_id"] = req.ClientId
|
|
}
|
|
if req.Name != "" {
|
|
updates["name"] = req.Name
|
|
}
|
|
if req.GrantType != "" {
|
|
updates["grant_type"] = req.GrantType
|
|
}
|
|
if req.AdditionalInfo != "" {
|
|
updates["additional_info"] = req.AdditionalInfo
|
|
}
|
|
if req.ActiveTimeout > 0 {
|
|
updates["active_timeout"] = req.ActiveTimeout
|
|
}
|
|
|
|
if err := l.svcCtx.DB.Model(&sysModel.SundynixClient{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
|
l.Errorf("更新客户端失败: %v", err)
|
|
return fmt.Errorf("更新客户端失败")
|
|
}
|
|
return nil
|
|
}
|