Explorar el Código

fix: 商品SKU规格specs字段保存失败

根因: ProductSku.specs 声明为Object类型,数据库列为JSON,
MyBatis-Plus无TypeHandler导致updateById无法正确写入JSON列。
修复: specs改为String类型,service层校验空值默认设为{}
Xiaogang Liao hace 3 meses
padre
commit
b82c9ea1a8

+ 1 - 1
cfc-backend/src/main/java/com/etotem/cfc/entity/ProductSku.java

@@ -17,7 +17,7 @@ public class ProductSku implements Serializable {
 
     private Long productId;
     private String skuCode;
-    private Object specs;
+    private String specs;
     private BigDecimal price;
     private Integer stock;
     private Integer minQuantity; // 最小购买数量限制

+ 5 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/ProductSkuService.java

@@ -32,7 +32,9 @@ public class ProductSkuService {
 
     @Transactional
     public ProductSku create(ProductSku sku) {
-        sku.setSpecs(normalizeSpecsToJson(sku.getSpecs()));
+        if (sku.getSpecs() == null || sku.getSpecs().trim().isEmpty()) {
+            sku.setSpecs("{}");
+        }
         sku.setCreateTime(new Date());
         sku.setUpdateTime(new Date());
         if (sku.getEnabled() == null) {
@@ -47,8 +49,8 @@ public class ProductSkuService {
 
     @Transactional
     public void update(ProductSku sku) {
-        if (sku.getSpecs() != null) {
-            sku.setSpecs(normalizeSpecsToJson(sku.getSpecs()));
+        if (sku.getSpecs() == null || sku.getSpecs().trim().isEmpty()) {
+            sku.setSpecs("{}");
         }
         sku.setUpdateTime(new Date());
         skuMapper.updateById(sku);