diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 51432f3d..e036fa15 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -67,8 +67,8 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, } else { //指定物料 sizeIds = append(sizeIds, req.ProductSizeId) } - //根据尺寸id获取模型id - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id") + //根据尺寸id获取模型 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") @@ -77,8 +77,10 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty") } modelIds := make([]int64, 0, len(modelList)) - for _, v := range modelList { + mapModel := make(map[int64]int) + for k, v := range modelList { modelIds = append(modelIds, v.Id) + mapModel[v.Id] = k } //查询模型ids下对应tag标签的模板 templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "") @@ -86,25 +88,38 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") } - rspList := make([]interface{}, 0, len(templateList)) + rsp := make(map[string][]interface{}) for _, templateInfo := range templateList { //没有设置模板据不要 if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { continue } + modelIndex, ok := mapModel[*templateInfo.ModelId] + if !ok { + continue + } //基础模板信息 - var info interface{} + var info map[string]map[string]interface{} if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json product template info:", templateInfo.Id) + return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id)) } //后台隐藏/显示信息 var switchInfo interface{} if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" { _ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo) } - // todo 继续下周 - rspList = append(rspList, map[string]interface{}{}) + modelInfo := modelList[modelIndex] + var material interface{} + if info["module_data"] != nil && info["module_data"]["material"] != nil { + material = info["module_data"]["material"] + } + mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) + rsp[mapKey] = append(rsp[mapKey], map[string]interface{}{ + "id": templateInfo.Id, + "material": material, + "material_data": switchInfo, + }) } - return nil + return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) }