Explorar o código

fix: add article publish path endpoint + product_skus table auto-init

- Add POST /api/admin/articles/{id}/publish for path-based article publish
- Add product_skus table creation to DatabaseInitializer (was manual-only)
Xiaogang Liao hai 2 meses
pai
achega
44c4917a37

+ 24 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -914,6 +914,30 @@ log.info("已添加template_id列到tasks表");
             log.warn("创建products表失败: {}", e.getMessage());
             log.warn("创建products表失败: {}", e.getMessage());
         }
         }
 
 
+        // 商品SKU表
+        try {
+            jdbcTemplate.execute(
+                "CREATE TABLE IF NOT EXISTS product_skus (" +
+                "  id INT NOT NULL AUTO_INCREMENT," +
+                "  product_id INT NOT NULL COMMENT '商品ID'," +
+                "  sku_code VARCHAR(64) NOT NULL COMMENT 'SKU编码'," +
+                "  specs JSON NOT NULL COMMENT '规格JSON'," +
+                "  price DECIMAL(10,2) NOT NULL COMMENT 'SKU价格'," +
+                "  stock INT NOT NULL DEFAULT 0 COMMENT '库存'," +
+                "  original_price DECIMAL(10,2) COMMENT '原价/划线价'," +
+                "  image VARCHAR(512) COMMENT 'SKU图片'," +
+                "  enabled TINYINT(1) NOT NULL DEFAULT 1," +
+                "  create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
+                "  update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
+                "  PRIMARY KEY (id)," +
+                "  KEY idx_product_id (product_id)" +
+                ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品SKU'"
+            );
+            log.info("已创建product_skus表");
+        } catch (Exception e) {
+            log.warn("创建product_skus表失败: {}", e.getMessage());
+        }
+
         // 订单表
         // 订单表
         try {
         try {
             jdbcTemplate.execute(
             jdbcTemplate.execute(

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminArticleController.java

@@ -97,6 +97,13 @@ public class AdminArticleController {
         return Result.success("删除成功");
         return Result.success("删除成功");
     }
     }
 
 
+    @PostMapping("/{id}/publish")
+    public Result<String> publishById(@PathVariable Long id, @RequestBody Map<String, Object> body) {
+        String status = (String) body.get("status");
+        articleService.toggleStatus(id, status);
+        return Result.success("操作成功");
+    }
+
     @PostMapping("/publish")
     @PostMapping("/publish")
     public Result<String> publish(@RequestBody Map<String, Object> body) {
     public Result<String> publish(@RequestBody Map<String, Object> body) {
         if (body.get("id") == null) {
         if (body.get("id") == null) {