zhangqian
2024-06-20 0b7036989cbbe1073e5338dc57b395c6d10ee0d1
物料导入保存动态属性代码逻辑修正
1个文件已修改
119 ■■■■■ 已修改文件
service/material.go 119 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/material.go
@@ -45,7 +45,14 @@
        return 0, errors.New("改文件没有数据内容")
    }
    inserts := rows[1:len(rows)]
    inserts := rows[1:]
    headers := rows[0]
    attributesColumns := make([]int, 0)
    for i, header := range headers {
        if mapAttribute[header] != 0 {
            attributesColumns = append(attributesColumns, i)
        }
    }
    for index, insert := range inserts {
        errMsg := ""
@@ -132,53 +139,73 @@
        if len(insert) > 8 && insert[7] != "" {
            material.Type = insert[7] //型号
        }
        if len(insert) > 9 && insert[8] != "" {
            if mapAttribute[insert[8]] == 0 {
                errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别材质属性,请先添加该属性"
                return 0, errors.New(errMsg)
            }
            //material.Quality = insert[8] //材质
            attributeValue1 := new(models.AttributeValue)
            attributeValue1.EntityID = material.ID
            attributeValue1.AttributeID = mapAttribute[insert[8]]
            attributeValue1.Value = insert[8]
            attributeValueList = append(attributeValueList, attributeValue1)
        {
            /*
                if len(insert) > 9 && insert[8] != "" {
                    if mapAttribute[insert[8]] == 0 {
                        errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别材质属性,请先添加该属性"
                        return 0, errors.New(errMsg)
                    }
                    //material.Quality = insert[8] //材质
                    attributeValue1 := new(models.AttributeValue)
                    attributeValue1.EntityID = material.ID
                    attributeValue1.AttributeID = mapAttribute[insert[8]]
                    attributeValue1.Value = insert[8]
                    attributeValueList = append(attributeValueList, attributeValue1)
                }
                if len(insert) > 10 && insert[9] != "" {
                    if mapAttribute[insert[9]] == 0 {
                        errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别品牌属性,请先添加该属性"
                        return 0, errors.New(errMsg)
                    }
                    //material.Brand = insert[9]   //品牌
                    attributeValue2 := new(models.AttributeValue)
                    attributeValue2.EntityID = material.ID
                    attributeValue2.AttributeID = mapAttribute[insert[9]]
                    attributeValue2.Value = insert[9]
                    attributeValueList = append(attributeValueList, attributeValue2)
                }
                if len(insert) > 11 && insert[10] != "" {
                    if mapAttribute[insert[10]] == 0 {
                        errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别等级属性,请先添加该属性"
                        return 0, errors.New(errMsg)
                    }
                    //material.Level = insert[10]  //等级
                    attributeValue3 := new(models.AttributeValue)
                    attributeValue3.EntityID = material.ID
                    attributeValue3.AttributeID = mapAttribute[insert[10]]
                    attributeValue3.Value = insert[10]
                    attributeValueList = append(attributeValueList, attributeValue3)
                }
                if len(insert) > 12 && insert[11] != "" {
                    if mapAttribute[insert[11]] == 0 {
                        errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别庄口属性,请先添加该属性"
                        return 0, errors.New(errMsg)
                    }
                    //material.From = insert[11]   //庄口
                    attributeValue4 := new(models.AttributeValue)
                    attributeValue4.EntityID = material.ID
                    attributeValue4.AttributeID = mapAttribute[insert[11]]
                    attributeValue4.Value = insert[11]
                    attributeValueList = append(attributeValueList, attributeValue4)
                }
            */
        }
        if len(insert) > 10 && insert[9] != "" {
            if mapAttribute[insert[9]] == 0 {
                errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别品牌属性,请先添加该属性"
                return 0, errors.New(errMsg)
        //保存动态属性
        for attributesColumn := range attributesColumns {
            if mapAttribute[insert[attributesColumn]] != 0 {
                attributeValue2 := new(models.AttributeValue)
                attributeValue2.EntityID = material.ID
                attributeValue2.AttributeID = mapAttribute[insert[9]]
                attributeValue2.Value = insert[9]
                attributeValueList = append(attributeValueList, &models.AttributeValue{
                    EntityID:    material.ID,
                    AttributeID: mapAttribute[insert[attributesColumn]],
                    Value:       insert[attributesColumn],
                })
            }
            //material.Brand = insert[9]   //品牌
            attributeValue2 := new(models.AttributeValue)
            attributeValue2.EntityID = material.ID
            attributeValue2.AttributeID = mapAttribute[insert[9]]
            attributeValue2.Value = insert[9]
            attributeValueList = append(attributeValueList, attributeValue2)
        }
        if len(insert) > 11 && insert[10] != "" {
            if mapAttribute[insert[10]] == 0 {
                errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别等级属性,请先添加该属性"
                return 0, errors.New(errMsg)
            }
            //material.Level = insert[10]  //等级
            attributeValue3 := new(models.AttributeValue)
            attributeValue3.EntityID = material.ID
            attributeValue3.AttributeID = mapAttribute[insert[10]]
            attributeValue3.Value = insert[10]
            attributeValueList = append(attributeValueList, attributeValue3)
        }
        if len(insert) > 12 && insert[11] != "" {
            if mapAttribute[insert[11]] == 0 {
                errMsg = "第" + strconv.Itoa(index+2) + "行,产品编码:" + insert[0] + ",未能识别庄口属性,请先添加该属性"
                return 0, errors.New(errMsg)
            }
            //material.From = insert[11]   //庄口
            attributeValue4 := new(models.AttributeValue)
            attributeValue4.EntityID = material.ID
            attributeValue4.AttributeID = mapAttribute[insert[11]]
            attributeValue4.Value = insert[11]
            attributeValueList = append(attributeValueList, attributeValue4)
        }
    }