Parcourir la source

商品图片地址分割存库,拼接前缀返回页面

yzc il y a 2 ans
Parent
commit
24eeb47b22

+ 3 - 1
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsImageService.java

@@ -3,6 +3,7 @@ package com.sckw.product.service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.CollectionUtils;
 import com.sckw.product.dao.KwpGoodsImageMapper;
 import com.sckw.product.model.KwpGoodsImage;
 import lombok.RequiredArgsConstructor;
@@ -45,7 +46,8 @@ public class KwpGoodsImageService {
         LambdaQueryWrapper<KwpGoodsImage> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(KwpGoodsImage::getGoodsId, goodsId).eq(KwpGoodsImage::getDelFlag, Global.NO)
                 .orderByAsc(KwpGoodsImage::getSort);
-        return kwpGoodsImageMapper.selectList(wrapper);
+        List<KwpGoodsImage> list = kwpGoodsImageMapper.selectList(wrapper);
+        return CollectionUtils.emptyIfNull(list);
     }
 
     /**

+ 28 - 10
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -14,10 +14,7 @@ import com.sckw.core.model.page.PageResult;
 import com.sckw.core.model.vo.TableBottom;
 import com.sckw.core.model.vo.TableStatisticRes;
 import com.sckw.core.model.vo.TableTop;
-import com.sckw.core.utils.BeanUtils;
-import com.sckw.core.utils.CollectionUtils;
-import com.sckw.core.utils.NumberUtils;
-import com.sckw.core.utils.StringUtils;
+import com.sckw.core.utils.*;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.excel.utils.DateUtil;
@@ -105,7 +102,8 @@ public class KwpGoodsService {
         if (Objects.nonNull(address)) {
             goods.setAreaCode(address.getCityCode()).setAddressName(address.getName());
         }
-        goods.setEntId(LoginUserHolder.getEntId()).setStatus(GoodsStatusEnum.SAVED.getCode());
+        goods.setEntId(LoginUserHolder.getEntId()).setThumb(FileUtils.replaceAll(goods.getThumb()))
+                .setStatus(GoodsStatusEnum.SAVED.getCode());
         kwpGoodsMapper.insert(goods);
         //添加商品其他信息
         addGoodsOtherInfo(goods.getId(), BeanUtils.copyProperties(param, AddGoodsParam.class));
@@ -130,7 +128,8 @@ public class KwpGoodsService {
         KwpGoods goods = BeanUtils.copyProperties(param, KwpGoods.class);
         AddressInfo address = param.getAddressInfo();
         goods.setCode(NumberUtils.createRandomVcode()).setAreaCode(address.getCityCode()).setAddressName(address.getName())
-                .setEntId(LoginUserHolder.getEntId()).setAddedTime(new Date()).setStatus(GoodsStatusEnum.PUT_ON_SHELVES.getCode());
+                .setThumb(FileUtils.replaceAll(goods.getThumb())).setEntId(LoginUserHolder.getEntId())
+                .setAddedTime(new Date()).setStatus(GoodsStatusEnum.PUT_ON_SHELVES.getCode());
         kwpGoodsMapper.insert(goods);
         //添加商品其他信息
         addGoodsOtherInfo(goods.getId(), param);
@@ -168,6 +167,7 @@ public class KwpGoodsService {
             List<KwpGoodsImage> list = new ArrayList<>(images.size());
             images.forEach(e -> {
                 KwpGoodsImage image = BeanUtils.copyProperties(e, KwpGoodsImage.class);
+                image.setImage(FileUtils.replaceAll(e.getImage()));
                 image.setGoodsId(goodsId);
                 list.add(image);
             });
@@ -217,7 +217,8 @@ public class KwpGoodsService {
             RecommendGoods recommendGoods = BeanUtils.copyProperties(e, RecommendGoods.class);
             List<KwpGoodsPriceRange> prices = map.get(recommendGoods.getId());
             recommendGoods.setUnitLabel(CollectionUtils.isNotEmpty(unitMap) ? unitMap.get(recommendGoods.getUnit()) : null)
-                    .setPrice(CollectionUtils.isNotEmpty(prices) ? prices.get(0).getPrice() : null);
+                    .setPrice(CollectionUtils.isNotEmpty(prices) ? prices.get(0).getPrice() : null)
+                    .setThumb(FileUtils.splice(e.getThumb()));
             recommendGoodsList.add(recommendGoods);
         });
         detail.setRecommendGoodsList(recommendGoodsList);
@@ -271,7 +272,13 @@ public class KwpGoodsService {
                 .setStatusLabel(CollectionUtils.isNotEmpty(goodsStatusMap) ? goodsStatusMap.get(String.valueOf(detail.getStatus())) : null)
                 .setPrepaidLimitLabel(Objects.equals(detail.getPrepaidLimit(), 1) ? "是" : "否");
         //商品图片信息
+        if (Objects.nonNull(goods.getThumb())) {
+            detail.setThumb(FileUtils.splice(goods.getThumb()));
+        }
         List<KwpGoodsImage> goodsImages = kwpGoodsImageService.getByGoodsId(id);
+        goodsImages.forEach(e -> {
+            e.setImage(FileUtils.splice(e.getImage()));
+        });
         List<GoodsImagesDetail> images = BeanUtils.copyToList(goodsImages, GoodsImagesDetail.class);
         //商品价格段信息
         List<KwpGoodsPriceRange> priceRanges = kwpGoodsPriceRangeService.getByGoodsId(id);
@@ -337,7 +344,7 @@ public class KwpGoodsService {
                 .set(KwpGoods::getSupplyEntId, param.getSupplyEntId())
                 .set(KwpGoods::getManager, param.getManager())
                 .set(KwpGoods::getRemark, param.getRemark())
-                .set(KwpGoods::getThumb, param.getThumb())
+                .set(KwpGoods::getThumb, FileUtils.replaceAll(param.getThumb()))
                 .set(KwpGoods::getAreaCode, areaCode)
                 .set(KwpGoods::getAddressName, addressName)
                 .eq(KwpGoods::getId, param.getId());
@@ -380,7 +387,7 @@ public class KwpGoodsService {
             List<KwpGoodsImage> list = new ArrayList<>(param.getImages().size());
             param.getImages().forEach(e -> {
                 KwpGoodsImage image = BeanUtils.copyProperties(e, KwpGoodsImage.class);
-                image.setGoodsId(goodsId);
+                image.setGoodsId(goodsId).setImage(FileUtils.replaceAll(image.getImage()));
                 list.add(image);
             });
             kwpGoodsImageService.insertBatch(list);
@@ -705,6 +712,7 @@ public class KwpGoodsService {
                     .setAddress(addressMap.get(id)).setSupplyEnt(entMap.get(e.getSupplyEntId()))
                     .setManageName(Objects.nonNull(manager) ? manager.getName() : null)
                     .setPhone(Objects.nonNull(manager) ? manager.getPhone() : null)
+                    .setThumb(FileUtils.splice(e.getThumb()))
                     .setCreateByName(Objects.nonNull(createUser) ? createUser.getName() : null);
             List<KwpGoodsPriceRange> priceRanges = priceRangeMap.get(id);
             if (CollectionUtils.isNotEmpty(priceRanges)) {
@@ -912,6 +920,7 @@ public class KwpGoodsService {
                     .setAddressName(Objects.isNull(address) ? null : address.getCityName())
                     .setDetailAddress(Objects.isNull(address) ? null : address.getDetailAddress())
                     .setPrice(CollectionUtils.isEmpty(priceRanges) ? null : priceRanges.get(0).getPrice())
+                    .setThumb(FileUtils.splice(e.getThumb()))
                     .setSupplyEnt(entMap.get(e.getSupplyEntId()));
             result.add(materials);
         });
@@ -989,7 +998,11 @@ public class KwpGoodsService {
      * @return: java.util.List<com.sckw.product.model.KwpGoods>
      */
     public KwpGoods selectById(Long id) {
-        return kwpGoodsMapper.selectById(id);
+        KwpGoods goods = kwpGoodsMapper.selectById(id);
+        if (Objects.nonNull(goods)) {
+            goods.setThumb(FileUtils.splice(goods.getThumb()));
+        }
+        return goods;
     }
 
 
@@ -1002,6 +1015,11 @@ public class KwpGoodsService {
      */
     public List<KwpGoods> selectByIds(List<Long> ids) {
         List<KwpGoods> list = kwpGoodsMapper.selectBatchIds(ids);
+        if (CollectionUtils.isNotEmpty(list)) {
+            list.forEach(e -> {
+                e.setThumb(FileUtils.splice(e.getThumb()));
+            });
+        }
         return CollectionUtils.emptyIfNull(list);
     }