init: init refactor

This commit is contained in:
Blizzard
2026-04-27 00:02:18 +08:00
commit e515f6a287
360 changed files with 30713 additions and 0 deletions
@@ -0,0 +1,44 @@
// 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 CreateClientLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClientLogic {
return &CreateClientLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateClientLogic) CreateClient(req *types.ClientReq) error {
client := sysModel.SundynixClient{
ClientID: req.ClientId,
Name: req.Name,
GrantType: req.GrantType,
AdditionalInfo: req.AdditionalInfo,
ActiveTimeout: req.ActiveTimeout,
}
if err := l.svcCtx.DB.Create(&client).Error; err != nil {
l.Errorf("创建客户端失败: %v", err)
return fmt.Errorf("创建客户端失败")
}
return nil
}
@@ -0,0 +1,37 @@
// 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 DeleteClientLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClientLogic {
return &DeleteClientLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteClientLogic) DeleteClient(req *types.IdsReq) error {
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixClient{}).Error; err != nil {
l.Errorf("删除客户端失败: %v", err)
return fmt.Errorf("删除客户端失败")
}
return nil
}
@@ -0,0 +1,66 @@
// 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 GetClientListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetClientListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClientListLogic {
return &GetClientListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetClientListLogic) GetClientList(req *types.ClientListReq) (resp interface{}, err error) {
var clients []sysModel.SundynixClient
var total int64
db := l.svcCtx.DB.Model(&sysModel.SundynixClient{})
if req.Name != "" {
db = db.Where("name LIKE ?", "%"+req.Name+"%")
}
if err := db.Count(&total).Error; err != nil {
l.Errorf("查询客户端总数失败: %v", err)
return nil, fmt.Errorf("查询失败")
}
current := req.Current
pageSize := req.PageSize
if current <= 0 {
current = 1
}
if pageSize <= 0 {
pageSize = 10
}
offset := (current - 1) * pageSize
if err := db.Offset(offset).Limit(pageSize).Find(&clients).Error; err != nil {
l.Errorf("查询客户端列表失败: %v", err)
return nil, fmt.Errorf("查询失败")
}
return map[string]interface{}{
"list": clients,
"total": total,
"current": current,
"size": pageSize,
}, nil
}
@@ -0,0 +1,54 @@
// 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
}