tianboguang 3 лет назад
Родитель
Сommit
07f684784a

+ 32 - 15
platform-shop/src/main/java/com/platform/service/impl/GoodsServiceImpl.java

@@ -230,7 +230,6 @@ public class GoodsServiceImpl implements GoodsService {
         CurrentUserLoginVo user = ShiroUtils.getUserEntity();
         goods.setUpdateUserId(user.getId());
         goods.setUpdateTime(new Date());
-        goodsDao.update(goods);
 
         //先全部删除规格信息和设置信息
         goodsSpecificationService.deleteByGoodsId(goods.getId());
@@ -238,12 +237,29 @@ public class GoodsServiceImpl implements GoodsService {
 
         //保持产品规格信息
         List<GoodsSpecificationEntity> goodsSpecificationList = goods.getGoodsSpecificationList();
+        List<GoodsSpecificationEntity> latestGoodsSpecificationList = new ArrayList<>();
         for(GoodsSpecificationEntity goodsSpecificationEntity : goodsSpecificationList){
             goodsSpecificationEntity.setGoodsId(goods.getId());
-            goodsSpecificationService.save(goodsSpecificationEntity);
+            List<GoodsSpecificationValueVo> valueVoList = goodsSpecificationEntity.getVal();
+            if(!CollectionUtils.isEmpty(valueVoList)){
+                for (GoodsSpecificationValueVo valueVo : valueVoList){
+                    GoodsSpecificationEntity newEntity = new GoodsSpecificationEntity();
+                    BeanUtils.copyProperties(goodsSpecificationEntity , newEntity);
+                    newEntity.setPicUrl(valueVo.getPicUrl());
+                    newEntity.setValue(valueVo.getName());
+                    newEntity.setUuid(valueVo.getUuid());
+                    goodsSpecificationService.save(newEntity);
+                    latestGoodsSpecificationList.add(newEntity);
+                }
+            }else{
+                goodsSpecificationService.save(goodsSpecificationEntity);
+                latestGoodsSpecificationList.add(goodsSpecificationEntity);
+            }
+
         }
 
         //保存产品设置信息
+        int goodsNum = 0;
         List<ProductEntity> productList = goods.getProductList();
         String goodsSpecificationIds = "";
         String uuidLink = "";
@@ -252,29 +268,30 @@ public class GoodsServiceImpl implements GoodsService {
         GoodsSpecificationEntity goodsSpecificationEntity = null;
         if(productList != null || productList.size() > 0){
             for(ProductEntity productEntity : productList){
+                if(productEntity.getUuidLink() == null){
+                    throw new RRException("参数uuiLink为空");
+                }
                 goodsSpecificationIds = "";
                 uuidLink = productEntity.getUuidLink();
-                if(StringUtils.isNotBlank(uuidLink)){
-                    uuids = uuidLink.split("_");
-                    if(null != uuids){
-                        for(String uuid : uuids){
-                            param = new HashMap<>();
-                            param.put("uuid", uuid);
-                            param.put("goodsId", goods.getId());
-                            goodsSpecificationEntity = goodsSpecificationService.queryObjectBykeyAndGoodsId(param);
-                            if(goodsSpecificationEntity != null){
-                                goodsSpecificationIds = goodsSpecificationIds + "_" + goodsSpecificationEntity.getId();
-                            }
-                        }
+                uuids = uuidLink.split("_");
+                for(String uuid : uuids){
+                    goodsSpecificationEntity = findEntityByUuidAndGoodsId(uuid , goods.getId() , latestGoodsSpecificationList);
+                    if(goodsSpecificationEntity != null){
+                        goodsSpecificationIds = goodsSpecificationIds + "_" + goodsSpecificationEntity.getId();
                     }
-
                 }
                 productEntity.setGoodsSpecificationIds(goodsSpecificationIds);
                 productEntity.setGoodsId(goods.getId());
                 productEntity.setUuidLink(uuidLink);
                 productDao.save(productEntity);
+
+                if(productEntity.getGoodsNumber() != null){
+                    goodsNum += productEntity.getGoodsNumber();
+                }
             }
         }
+        goods.setGoodsNumber(goodsNum);
+        goodsDao.update(goods);
 
         List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
         if (null != attributeEntityList && attributeEntityList.size() > 0) {