Kaynağa Gözat

修改图片保存逻辑

tianboguang 3 yıl önce
ebeveyn
işleme
1d4a2d0dc2

+ 19 - 31
platform-shop/src/main/java/com/platform/service/impl/GoodsServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
 
 import java.util.*;
 
@@ -185,6 +186,15 @@ public class GoodsServiceImpl implements GoodsService {
                 galleryEntity.setGoodsId(id);
                 goodsGalleryDao.save(galleryEntity);
             }
+        }else if(ObjectUtils.isEmpty(goods.getGoodsImgList()) && !ObjectUtils.isEmpty(goods.getListPicUrl())){
+            String[] images = goods.getListPicUrl().split("#\\$#");
+            for (int i = 0; i < images.length; i++) {
+                GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
+                galleryEntity.setGoodsId(goods.getId());
+                galleryEntity.setImgUrl(images[i]);
+                galleryEntity.setSortOrder(i);
+                goodsGalleryDao.save(galleryEntity);
+            }
         }
 
         //保存商品详情页面显示的属性
@@ -283,41 +293,19 @@ public class GoodsServiceImpl implements GoodsService {
                 galleryEntity.setGoodsId(goods.getId());
                 goodsGalleryDao.save(galleryEntity);
             }
+        }else if(ObjectUtils.isEmpty(goods.getGoodsImgList()) && !ObjectUtils.isEmpty(goods.getListPicUrl())){
+            String[] images = goods.getListPicUrl().split("#\\$#");
+            for (int i = 0; i < images.length; i++) {
+                GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
+                galleryEntity.setGoodsId(goods.getId());
+                galleryEntity.setImgUrl(images[i]);
+                galleryEntity.setSortOrder(i);
+                goodsGalleryDao.save(galleryEntity);
+            }
         }
         return goods.getId();
     }
 
-//    @Override
-//    @Transactional
-//    public int update(GoodsEntity goods) {
-//        SysUserEntity user = ShiroUtils.getUserEntity();
-//        List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
-//        if (null != attributeEntityList && attributeEntityList.size() > 0) {
-//            for (GoodsAttributeEntity goodsAttributeEntity : attributeEntityList) {
-//                int result = goodsAttributeDao.updateByGoodsIdAttributeId(goodsAttributeEntity);
-//                if (result == 0) {
-//                    goodsAttributeDao.save(goodsAttributeEntity);
-//                }
-//            }
-//        }
-//        goods.setUpdateUserId(user.getUserId());
-//        goods.setUpdateTime(new Date());
-//        //商品轮播图
-//        //修改时全删全插
-//        List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
-//        Map<String, Integer> map = new HashMap<String, Integer>();
-//        map.put("goodsId", goods.getId());
-//        goodsGalleryDao.deleteByGoodsId(map);
-//
-//        if (null != galleryEntityList && galleryEntityList.size() > 0) {
-//            for (GoodsGalleryEntity galleryEntity : galleryEntityList) {
-//                galleryEntity.setGoodsId(goods.getId());
-//                goodsGalleryDao.save(galleryEntity);
-//            }
-//        }
-//        return goodsDao.update(goods);
-//    }
-
     @Override
     public int delete(Integer id) {
         CurrentUserLoginVo user = ShiroUtils.getUserEntity();