From 7ebd578c8ad476579fcbb4350eaa42971b9da9bb Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Sat, 11 Oct 2025 18:47:43 +0800 Subject: [PATCH] fix --- .../internal/logic/agent/getlinkdatalogic.go | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/app/main/api/internal/logic/agent/getlinkdatalogic.go b/app/main/api/internal/logic/agent/getlinkdatalogic.go index ec609d0..690edf5 100644 --- a/app/main/api/internal/logic/agent/getlinkdatalogic.go +++ b/app/main/api/internal/logic/agent/getlinkdatalogic.go @@ -2,10 +2,13 @@ package agent import ( "context" + "hm-server/app/main/model" "hm-server/common/xerr" + "github.com/Masterminds/squirrel" "github.com/jinzhu/copier" "github.com/pkg/errors" + "github.com/zeromicro/go-zero/core/mr" "hm-server/app/main/api/internal/svc" "hm-server/app/main/api/internal/types" @@ -37,9 +40,47 @@ func (l *GetLinkDataLogic) GetLinkData(req *types.GetLinkDataReq) (resp *types.G if err != nil { return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取代理链接数据, %v", err) } + + // 查询产品关联的 feature + build := l.svcCtx.ProductFeatureModel.SelectBuilder().Where(squirrel.Eq{ + "product_id": productModel.Id, + }) + productFeatureAll, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, build, "") + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取代理链接数据, 查找产品关联错误: %v", err) + } + var product types.Product - copier.Copy(&product, productModel) + err = copier.Copy(&product, productModel) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理链接数据, 产品信息结构体复制失败, %v", err) + } product.SellPrice = agentLinkModel.Price + + // 并发查询所有 feature 详情 + mr.MapReduceVoid(func(source chan<- interface{}) { + for _, productFeature := range productFeatureAll { + source <- productFeature.FeatureId + } + }, func(item interface{}, writer mr.Writer[*model.Feature], cancel func(error)) { + id := item.(int64) + + feature, findFeatureErr := l.svcCtx.FeatureModel.FindOne(l.ctx, id) + if findFeatureErr != nil { + logx.WithContext(l.ctx).Errorf("获取代理链接数据, 查找关联feature错误: %d, err:%v", id, findFeatureErr) + return + } + if feature != nil && feature.Id > 0 { + writer.Write(feature) + } + }, func(pipe <-chan *model.Feature, cancel func(error)) { + for item := range pipe { + var feature types.Feature + _ = copier.Copy(&feature, item) + product.Features = append(product.Features, feature) + } + }) + return &types.GetLinkDataResp{ Product: product, }, nil