2026-02-28 15:29:16 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"muyu-apiserver/model"
|
2026-03-30 02:53:55 +00:00
|
|
|
"muyu-apiserver/pkg/tenantctx"
|
2026-02-28 15:29:16 +08:00
|
|
|
"muyu-apiserver/rpc/system/internal/svc"
|
|
|
|
|
"muyu-apiserver/rpc/system/pb"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ListConfigLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
logx.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewListConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListConfigLogic {
|
|
|
|
|
return &ListConfigLogic{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ListConfigLogic) ListConfig(in *pb.ListConfigReq) (*pb.ListConfigResp, error) {
|
2026-03-30 02:53:55 +00:00
|
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
|
|
|
|
|
2026-02-28 15:29:16 +08:00
|
|
|
var err error
|
|
|
|
|
var configs []*model.SysConfig
|
|
|
|
|
|
|
|
|
|
if in.ConfigGroup != "" {
|
2026-03-30 02:53:55 +00:00
|
|
|
configs, err = l.svcCtx.ConfigModel.FindByGroup(l.ctx, tenantId, in.ConfigGroup)
|
2026-02-28 15:29:16 +08:00
|
|
|
} else {
|
2026-03-30 02:53:55 +00:00
|
|
|
configs, err = l.svcCtx.ConfigModel.FindAll(l.ctx, tenantId)
|
2026-02-28 15:29:16 +08:00
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list := make([]*pb.ConfigInfo, 0, len(configs))
|
|
|
|
|
for _, cfg := range configs {
|
|
|
|
|
var configValue, remark string
|
|
|
|
|
if cfg.ConfigValue.Valid {
|
|
|
|
|
configValue = cfg.ConfigValue.String
|
|
|
|
|
}
|
|
|
|
|
if cfg.Remark.Valid {
|
|
|
|
|
remark = cfg.Remark.String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list = append(list, &pb.ConfigInfo{
|
|
|
|
|
ConfigId: cfg.ConfigId,
|
|
|
|
|
ConfigKey: cfg.ConfigKey,
|
|
|
|
|
ConfigValue: configValue,
|
|
|
|
|
ConfigName: cfg.ConfigName,
|
|
|
|
|
ConfigGroup: cfg.ConfigGroup,
|
|
|
|
|
Remark: remark,
|
|
|
|
|
UpdatedAt: cfg.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &pb.ListConfigResp{List: list}, nil
|
|
|
|
|
}
|