From 82b0baaef5073989f1ee8910942e21bddb9582d4 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期六, 10 十月 2020 01:10:35 +0800
Subject: [PATCH] 优化保存目录代码

---
 service-goods/src/main/java/com/java110/goods/api/ProductCategoryApi.java |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/service-goods/src/main/java/com/java110/goods/api/ProductCategoryApi.java b/service-goods/src/main/java/com/java110/goods/api/ProductCategoryApi.java
index c6c1fda..9b32a9f 100644
--- a/service-goods/src/main/java/com/java110/goods/api/ProductCategoryApi.java
+++ b/service-goods/src/main/java/com/java110/goods/api/ProductCategoryApi.java
@@ -11,7 +11,12 @@
 import com.java110.utils.util.BeanConvertUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 
 @RestController
@@ -37,7 +42,8 @@
      * @path /app/productCategory/saveProductCategory
      */
     @RequestMapping(value = "/saveProductCategory", method = RequestMethod.POST)
-    public ResponseEntity<String> saveProductCategory(@RequestBody JSONObject reqJson) {
+    public ResponseEntity<String> saveProductCategory(@RequestBody JSONObject reqJson,
+                                                      @RequestHeader(value = "store-id") String storeId) {
 
         Assert.hasKeyAndValue(reqJson, "categoryName", "璇锋眰鎶ユ枃涓湭鍖呭惈categoryName");
         Assert.hasKeyAndValue(reqJson, "categoryLevel", "璇锋眰鎶ユ枃涓湭鍖呭惈categoryLevel");
@@ -46,6 +52,10 @@
 
 
         ProductCategoryPo productCategoryPo = BeanConvertUtil.covertBean(reqJson, ProductCategoryPo.class);
+        productCategoryPo.setStoreId(storeId);
+        if (!reqJson.containsKey("parentCategoryId")) {
+            productCategoryPo.setParentCategoryId("-1");
+        }
         return saveProductCategoryBMOImpl.save(productCategoryPo);
     }
 
@@ -58,7 +68,8 @@
      * @path /app/productCategory/updateProductCategory
      */
     @RequestMapping(value = "/updateProductCategory", method = RequestMethod.POST)
-    public ResponseEntity<String> updateProductCategory(@RequestBody JSONObject reqJson) {
+    public ResponseEntity<String> updateProductCategory(@RequestBody JSONObject reqJson,
+                                                        @RequestHeader(value = "store-id") String storeId) {
 
         Assert.hasKeyAndValue(reqJson, "categoryName", "璇锋眰鎶ユ枃涓湭鍖呭惈categoryName");
         Assert.hasKeyAndValue(reqJson, "categoryLevel", "璇锋眰鎶ユ枃涓湭鍖呭惈categoryLevel");
@@ -68,6 +79,7 @@
 
 
         ProductCategoryPo productCategoryPo = BeanConvertUtil.covertBean(reqJson, ProductCategoryPo.class);
+        productCategoryPo.setStoreId(storeId);
         return updateProductCategoryBMOImpl.update(productCategoryPo);
     }
 
@@ -80,13 +92,15 @@
      * @path /app/productCategory/deleteProductCategory
      */
     @RequestMapping(value = "/deleteProductCategory", method = RequestMethod.POST)
-    public ResponseEntity<String> deleteProductCategory(@RequestBody JSONObject reqJson) {
+    public ResponseEntity<String> deleteProductCategory(@RequestBody JSONObject reqJson,
+                                                        @RequestHeader(value = "store-id") String storeId) {
         Assert.hasKeyAndValue(reqJson, "communityId", "灏忓尯ID涓嶈兘涓虹┖");
 
         Assert.hasKeyAndValue(reqJson, "categoryId", "categoryId涓嶈兘涓虹┖");
 
 
         ProductCategoryPo productCategoryPo = BeanConvertUtil.covertBean(reqJson, ProductCategoryPo.class);
+        productCategoryPo.setStoreId(storeId);
         return deleteProductCategoryBMOImpl.delete(productCategoryPo);
     }
 

--
Gitblit v1.8.0