f
This commit is contained in:
@@ -3,10 +3,12 @@ package query
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"sim-server/app/main/api/internal/svc"
|
||||
"sim-server/app/main/api/internal/types"
|
||||
"sim-server/common/xerr"
|
||||
"sim-server/pkg/lzkit/crypto"
|
||||
"strings"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/pkg/errors"
|
||||
@@ -14,6 +16,14 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// comboExampleDataItem 组合包示例 Content 解密后的单条结构,与 APIResponseData 一致,便于按模块展开
|
||||
type comboExampleDataItem struct {
|
||||
ApiID string `json:"apiID"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
type QueryExampleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
@@ -68,14 +78,49 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp strin
|
||||
// 根据特性ID查找示例数据
|
||||
example, err := l.svcCtx.ExampleModel.FindOneByFeatureId(l.ctx, pf.FeatureId)
|
||||
if err != nil {
|
||||
logx.Infof("示例报告, 特性ID %d 无示例数据: %v", pf.FeatureId, err)
|
||||
logx.Infof("示例报告, 特性ID %s 无示例数据: %v", pf.FeatureId, err)
|
||||
continue // 如果没有示例数据就跳过
|
||||
}
|
||||
|
||||
// 获取对应的Feature信息
|
||||
feature, err := l.svcCtx.FeatureModel.FindOne(l.ctx, pf.FeatureId)
|
||||
if err != nil {
|
||||
logx.Infof("示例报告, 无法获取特性ID %d 的信息: %v", pf.FeatureId, err)
|
||||
logx.Infof("示例报告, 无法获取特性ID %s 的信息: %v", pf.FeatureId, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// 组合包(api_id 前四位为 COMB):示例 Content 为多条 APIResponseData 的 JSON 数组,按子模块展开为多个 Tab
|
||||
if strings.HasPrefix(feature.ApiId, "COMB") {
|
||||
if example.Content == "000" {
|
||||
continue
|
||||
}
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(example.Content, key)
|
||||
if decryptErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 组合包解密失败: %v", decryptErr)
|
||||
}
|
||||
var comboItems []comboExampleDataItem
|
||||
if err := sonic.Unmarshal([]byte(decryptedData), &comboItems); err != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 组合包示例解析失败: %v", err)
|
||||
}
|
||||
for i, item := range comboItems {
|
||||
subFeature, subErr := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, item.ApiID)
|
||||
featureName := item.ApiID
|
||||
if subErr == nil && subFeature != nil {
|
||||
featureName = subFeature.Name
|
||||
}
|
||||
query.QueryData = append(query.QueryData, types.QueryItem{
|
||||
Feature: map[string]interface{}{
|
||||
"featureName": featureName,
|
||||
"sort": pf.Sort*1000 + int64(i), // 保持组合包整体顺序,子项按索引排
|
||||
},
|
||||
Data: map[string]interface{}{
|
||||
"apiID": item.ApiID,
|
||||
"data": item.Data,
|
||||
"success": item.Success,
|
||||
"timestamp": item.Timestamp,
|
||||
},
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user