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}->添加动态属性 --- service/material.go | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/service/material.go b/service/material.go index 5ae63e5..920fa36 100644 --- a/service/material.go +++ b/service/material.go @@ -190,25 +190,31 @@ attributeValueList = append(attributeValueList, attributeValue4) } */ - + materialList = append(materialList, material) } //淇濆瓨鍔ㄦ�佸睘鎬� - for attributesColumn := range attributesColumns { + 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], }) } } + if len(materialList) == 0 { + return 0, errors.New("鐗╂枡鏁版嵁涓虹┖") + } err = models.WithTransaction(func(db *gorm.DB) error { if err := models.NewMaterialSearch().SetOrm(db).CreateBatch(materialList); err != nil { return err } - if err := models.NewAttributeValueSearch().SetOrm(db).CreateBatch(attributeValueList); err != nil { - return err + if len(attributeValueList) != 0 { + if err := models.NewAttributeValueSearch().SetOrm(db).CreateBatch(attributeValueList); err != nil { + return err + } } return nil }) -- Gitblit v1.8.0