f
This commit is contained in:
@@ -29,7 +29,7 @@ service main {
|
||||
|
||||
type (
|
||||
getHomeDynamicDataReq {
|
||||
LastId int64 `json:"lastId,optional"`
|
||||
LastId int64 `form:"lastId,optional"`
|
||||
}
|
||||
InquiryRecordItem {
|
||||
Id int64 `json:"id"`
|
||||
|
||||
@@ -26,6 +26,9 @@ func NewGetHomeDynamicDataLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
|
||||
func (l *GetHomeDynamicDataLogic) GetHomeDynamicData(req *types.GetHomeDynamicDataReq) (resp *types.GetHomeDynamicDataResp, err error) {
|
||||
// 1. 获取真实查询案例 (支持增量查询)
|
||||
// 增加日志输出,方便调试
|
||||
l.Infof("获取首页动态数据, lastId: %d", req.LastId)
|
||||
|
||||
builder := l.svcCtx.InquiryRecordModel.SelectBuilder().Where("status = ?", 1)
|
||||
|
||||
var records []*model.InquiryRecord
|
||||
@@ -37,8 +40,12 @@ func (l *GetHomeDynamicDataLogic) GetHomeDynamicData(req *types.GetHomeDynamicDa
|
||||
records, err = l.svcCtx.InquiryRecordModel.FindPageListByPage(l.ctx, builder, 1, 10, "id DESC")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l.Errorf("查询查询记录失败: %v", err)
|
||||
}
|
||||
|
||||
cases := make([]types.InquiryRecordItem, 0)
|
||||
if err == nil {
|
||||
if err == nil && len(records) > 0 {
|
||||
for _, r := range records {
|
||||
cases = append(cases, types.InquiryRecordItem{
|
||||
Id: r.Id,
|
||||
@@ -47,15 +54,35 @@ func (l *GetHomeDynamicDataLogic) GetHomeDynamicData(req *types.GetHomeDynamicDa
|
||||
Model: r.CarModel,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 如果数据库没有数据或查询失败,返回一些兜底的 Mock 数据,确保前端有展示
|
||||
if req.LastId == 0 {
|
||||
l.Info("使用兜底 Mock 案例数据")
|
||||
mockCases := []struct {
|
||||
Id int64
|
||||
Tag string
|
||||
Vin string
|
||||
Model string
|
||||
}{
|
||||
{1, "查询成功", "湘A·12345", "奔驰GLC"},
|
||||
{2, "查询成功", "粤B·67890", "丰田凯美瑞"},
|
||||
{3, "查询成功", "京A·00011", "特斯拉ModelY"},
|
||||
{4, "查询成功", "苏E·88888", "大众迈腾"},
|
||||
{5, "查询成功", "沪A·87654", "宝马325"},
|
||||
}
|
||||
for _, m := range mockCases {
|
||||
cases = append(cases, types.InquiryRecordItem{
|
||||
Id: m.Id,
|
||||
Tag: m.Tag,
|
||||
Vin: m.Vin,
|
||||
Model: m.Model,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 硬编码返回一些初始评价
|
||||
reviews := []types.ReviewItem{
|
||||
{Name: "王先生", Content: "查询速度非常快,报告里关于出险的描述非常详细,避坑神器!"},
|
||||
{Name: "李女士", Content: "买二手车之前查一下真的有必要,帮我发现了一台调表车。"},
|
||||
{Name: "张先生", Content: "数据更新很及时,4S店的维保记录全都能查到。"},
|
||||
{Name: "赵先生", Content: "操作简单,手机号绑定后报告一直保存着,随时可以查看。"},
|
||||
}
|
||||
// 2. 评价数据不再从后端返回,改为前端硬编码
|
||||
reviews := make([]types.ReviewItem, 0)
|
||||
|
||||
return &types.GetHomeDynamicDataResp{
|
||||
Cases: cases,
|
||||
|
||||
@@ -5,12 +5,10 @@ import (
|
||||
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/threading"
|
||||
)
|
||||
|
||||
type ToolboxQueryLogic struct {
|
||||
@@ -43,53 +41,8 @@ func (l *ToolboxQueryLogic) ToolboxQuery(req *types.ToolboxQueryReq) (*types.Too
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 记录免费工具查询到动态展示表
|
||||
l.recordFreeToolInquiry(req.ToolKey)
|
||||
|
||||
return &types.ToolboxQueryResp{
|
||||
ToolKey: req.ToolKey,
|
||||
Result: result,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// recordFreeToolInquiry 记录免费工具查询
|
||||
func (l *ToolboxQueryLogic) recordFreeToolInquiry(toolKey string) {
|
||||
// 异步记录,不影响主流程
|
||||
threading.GoSafe(func() {
|
||||
ctx := context.Background()
|
||||
// 1. 获取工具名称 (这里可以建立一个简单的映射,或者从前端传过来,或者查询配置)
|
||||
// 为了简单和解耦,我们这里仅记录 ToolKey,前端展示时再映射名称,或者在这里硬编码一些常用名称
|
||||
toolName := toolKey
|
||||
// 如果能访问到 toolboxRegistry 的逻辑最好,但后端通常不包含前端配置
|
||||
// 我们可以通过一个简单的 Switch 处理一些核心工具名
|
||||
switch toolKey {
|
||||
case "ip-location":
|
||||
toolName = "IP地址查询"
|
||||
case "idcard-info":
|
||||
toolName = "身份证归属地"
|
||||
case "oilprice":
|
||||
toolName = "实时油价"
|
||||
case "joke":
|
||||
toolName = "趣味笑话"
|
||||
case "dream":
|
||||
toolName = "周公解梦"
|
||||
case "constellation":
|
||||
toolName = "星座运势"
|
||||
case "garbage":
|
||||
toolName = "垃圾分类"
|
||||
default:
|
||||
// 其他的就直接用 key 或保持原样
|
||||
}
|
||||
|
||||
record := &model.InquiryRecord{
|
||||
UserPhoneTail: "系统",
|
||||
DisplayName: "游客用户",
|
||||
VinMasked: "******",
|
||||
CarModel: "免费工具查询",
|
||||
InquiryTag: toolName,
|
||||
Status: 1,
|
||||
}
|
||||
|
||||
_, _ = l.svcCtx.InquiryRecordModel.Insert(ctx, nil, record)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2438,7 +2438,7 @@ type SendSmsReq struct {
|
||||
}
|
||||
|
||||
type GetHomeDynamicDataReq struct {
|
||||
LastId int64 `json:"lastId,optional"`
|
||||
LastId int64 `form:"lastId,optional"`
|
||||
}
|
||||
|
||||
type InquiryRecordItem struct {
|
||||
|
||||
Reference in New Issue
Block a user