From e57e32fc43da31917912eebb4e47d4e50df1a9e9 Mon Sep 17 00:00:00 2001
From: shiyj1101 <1098226878@qq.com>
Date: 星期四, 05 八月 2021 22:56:15 +0800
Subject: [PATCH] 完善格式化功能

---
 service-goods/src/main/java/com/java110/goods/api/ProductApi.java |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/service-goods/src/main/java/com/java110/goods/api/ProductApi.java b/service-goods/src/main/java/com/java110/goods/api/ProductApi.java
old mode 100644
new mode 100755
index 40a2c4b..1e210cf
--- a/service-goods/src/main/java/com/java110/goods/api/ProductApi.java
+++ b/service-goods/src/main/java/com/java110/goods/api/ProductApi.java
@@ -169,9 +169,19 @@
 
         JSONObject spec = null;
         List<ProductSpecValuePo> productSpecValuePos = new ArrayList<>();
+        boolean hasDefault = false;
+        ProductSpecValuePo productSpecValuePo = null;
         for (int specIndex = 0; specIndex < productSpecs.size(); specIndex++) {
             spec = productSpecs.getJSONObject(specIndex);
-            productSpecValuePos.add(BeanConvertUtil.covertBean(spec, ProductSpecValuePo.class));
+            productSpecValuePo = BeanConvertUtil.covertBean(spec, ProductSpecValuePo.class);
+            productSpecValuePos.add(productSpecValuePo);
+            if("T".equals(productSpecValuePo.getIsDefault())){
+                hasDefault = true;
+            }
+        }
+
+        if(!hasDefault){
+            throw new IllegalArgumentException("璇锋眰鎶ユ枃涓湭鍖呭惈榛樿瑙勬牸");
         }
 
         ProductPo productPo = BeanConvertUtil.covertBean(reqJson, ProductPo.class);
@@ -209,15 +219,25 @@
 
         JSONObject spec = null;
         List<ProductSpecValuePo> productSpecValuePos = null;
-        ;
+
+        boolean hasDefault = false;
+        ProductSpecValuePo productSpecValuePo = null;
         if (productSpecs != null) {
             productSpecValuePos = new ArrayList<>();
             for (int specIndex = 0; specIndex < productSpecs.size(); specIndex++) {
                 spec = productSpecs.getJSONObject(specIndex);
-                productSpecValuePos.add(BeanConvertUtil.covertBean(spec, ProductSpecValuePo.class));
+                productSpecValuePo = BeanConvertUtil.covertBean(spec, ProductSpecValuePo.class);
+                productSpecValuePos.add(productSpecValuePo);
+                if("T".equals(productSpecValuePo.getIsDefault())){
+                    hasDefault = true;
+                }
             }
         }
 
+        if(!hasDefault){
+            throw new IllegalArgumentException("璇锋眰鎶ユ枃涓湭鍖呭惈榛樿瑙勬牸");
+        }
+
         ProductPo productPo = BeanConvertUtil.covertBean(reqJson, ProductPo.class);
         productPo.setStoreId(storeId);
 

--
Gitblit v1.8.0