This commit is contained in:
laodaming 2023-08-14 10:51:39 +08:00
parent f8792a9c2b
commit 538d9ff4cf

View File

@ -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)
}