lishihai
2024-06-24 9effa1fd02fcfb17a2726415efa830575ef45822
report物料导入BUG
2个文件已修改
18 ■■■■ 已修改文件
controllers/product_controller.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/material.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/product_controller.go
@@ -912,6 +912,11 @@
//
//    @Tags        物料管理
//    @Summary    导入物料
//
// @Accept multipart/form-data
// @Param file formData file true "file"
// @Param     Authorization    header string true "token"
//
//    @Produce    application/xlsx
//    @Success    200        {object}    util.Response     "成功"
//    @Router        /api-wms/v1/product/inputProduct [post]
service/material.go
@@ -190,11 +190,11 @@
                    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]],
@@ -203,12 +203,17 @@
        }
    }
    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
    })