From 11168aeec504c395f656e22ea7e903582823c5fc Mon Sep 17 00:00:00 2001 From: lishihai <dslsh@dscom> Date: 星期一, 24 六月 2024 11:01:46 +0800 Subject: [PATCH] /api-wms/v1/product/getProductDetails/{id}->添加动态属性 --- controllers/product_controller.go | 35 +++++++++++++++++++++++++++++++++++ service/material.go | 5 +++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 1549251..86f4178 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -220,6 +220,7 @@ // @Tags 浜у搧 // @Summary 鑾峰彇浜у搧璇︽儏 // @Produce application/json +// @Param Authorization header string true "token" // @Param id path string true "id" "鏌ヨ鍙傛暟" // @Success 200 {object} util.Response{data=models.Material} "鎴愬姛" // @Router /api-wms/v1/product/getProductDetails/{id} [get] @@ -234,6 +235,40 @@ util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") return } + attributeValues, err := models.NewAttributeValueSearch().SetEntityID(material.ID).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") + return + } + aids := make([]uint, 0) + for _, v := range attributeValues { + aids = append(aids, v.AttributeID) + } + attributes, err := models.NewAttributeSearch().SetIDs(aids).FindNotTotal() + attributesMap := make(map[uint]*models.Attribute, len(attributes)) + for _, v := range attributes { + attributesMap[v.ID] = v + } + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏈煡鍔ㄦ�佸睘鎬�") + } + for _, v1 := range attributeValues { + attribute := attributesMap[v1.AttributeID] + if attribute == nil { + continue + } + //product.Attributes = append(product.Attributes,v1) + material.Attributes = append(material.Attributes, models.Attribute{ + Model: gorm.Model{ID: v1.ID, CreatedAt: v1.CreatedAt, UpdatedAt: v1.UpdatedAt, DeletedAt: v1.DeletedAt}, + Name: attribute.Name, + DataType: attribute.DataType, + EntityType: attribute.EntityType, + SelectValues: attribute.SelectValues, + SelectValue: attribute.SelectValue, + //Value: v1.Value, + Value: v1.Value, + }) + } util.ResponseFormat(c, code.Success, material) } diff --git a/service/material.go b/service/material.go index 1a32f8e..920fa36 100644 --- a/service/material.go +++ b/service/material.go @@ -196,8 +196,9 @@ //淇濆瓨鍔ㄦ�佸睘鎬� for _, attributesColumn := range attributesColumns { attributeValueList = append(attributeValueList, &models.AttributeValue{ - EntityID: material.ID, - AttributeID: mapAttribute[insert[attributesColumn]], + EntityID: material.ID, + //AttributeID: mapAttribute[insert[attributesColumn]], + AttributeID: mapAttribute[headers[attributesColumn]], Value: insert[attributesColumn], }) } -- Gitblit v1.8.0