bug修复

This commit is contained in:
张锐 committed 2026-11-25 17:45:10 +08:00
1 parent 6867194888
commit 4dfce9b521
3 files changed
+87 -5

No files matched your search

@@ -97,10 +97,15 @@ public class AdminProductService {
String attributeCode = item.attributeCode();
if (attributeCode == null || attributeCode.isBlank()) {
if (item.attributeName() == null || item.attributeName().isBlank()) throw new BusinessException("PRODUCT_ATTRIBUTE_NAME_REQUIRED", "自定义属性名称不能为空");
ProductAttributeEntity attribute = new ProductAttributeEntity(); attributeCode = codeUtils.generate(BusinessCodePrefixEnum.PRODUCT_ATTRIBUTE);
attribute.setAttributeCode(attributeCode); attribute.setSiteCode(entity.getSiteCode()); attribute.setAttributeName(item.attributeName());
attribute.setInputType("TEXT"); attribute.setUnit(item.unit()); attribute.setFilterableFlag(0); attribute.setRequiredFlag(0); attribute.setSortNo(item.sortNo()); attribute.setStatus("ENABLED");
if (attributeRepository.insert(attribute) != 1) throw new BusinessException("PRODUCT_ATTRIBUTE_SAVE_FAILED", "产品属性保存失败");
ProductAttributeEntity existingAttribute = attributeRepository.findByName(entity.getSiteCode(), item.attributeName()).orElse(null);
if (existingAttribute != null) {
attributeCode = existingAttribute.getAttributeCode();
} else {
ProductAttributeEntity attribute = new ProductAttributeEntity(); attributeCode = codeUtils.generate(BusinessCodePrefixEnum.PRODUCT_ATTRIBUTE);
attribute.setAttributeCode(attributeCode); attribute.setSiteCode(entity.getSiteCode()); attribute.setAttributeName(item.attributeName());
attribute.setInputType("TEXT"); attribute.setUnit(item.unit()); attribute.setFilterableFlag(0); attribute.setRequiredFlag(0); attribute.setSortNo(item.sortNo()); attribute.setStatus("ENABLED");
if (attributeRepository.insert(attribute) != 1) throw new BusinessException("PRODUCT_ATTRIBUTE_SAVE_FAILED", "产品属性保存失败");
}
} else attributeRepository.find(entity.getSiteCode(), attributeCode).orElseThrow(() -> new BusinessException("PRODUCT_ATTRIBUTE_NOT_FOUND", "产品属性不存在"));
ProductAttributeValueEntity value = new ProductAttributeValueEntity(); value.setValueCode(codeUtils.generate(BusinessCodePrefixEnum.PRODUCT_ATTRIBUTE_VALUE));
value.setSiteCode(entity.getSiteCode()); value.setProductCode(entity.getProductCode()); value.setAttributeCode(attributeCode); value.setOptionCode(""); value.setTextValue(item.value()); value.setSortNo(item.sortNo());