From 0404b00b9cfecc8044d340ead52a30a5298c6c31 Mon Sep 17 00:00:00 2001 From: jiangqs <343695869@qq.com> Date: 星期日, 04 六月 2023 16:28:06 +0800 Subject: [PATCH] 优化部分代码 --- ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 43 insertions(+), 10 deletions(-) diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java index 29245d1..7604ed6 100644 --- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java +++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/goods/GoodsServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.uuid.IdUtils; import com.ruoyi.goods.domain.dto.*; import com.ruoyi.goods.domain.pojo.goods.GoodsTotal; @@ -27,6 +28,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -61,10 +63,12 @@ private GoodsTotalService goodsTotalService; /** - * 获取推荐商品列表 - * @param page - * @return - */ + * @description 获取推荐商品列表 + * @param page shopId + * @return List<AppSimpleGoodsVo> + * @author jqs34 + * @date 2023/6/4 16:27 + */ @Override public List<AppSimpleGoodsVo> pageRecommendGoods(Page page, Long shopId){ List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsMapper.pageRecommendGoods(page,shopId); @@ -266,14 +270,14 @@ * @date: 2023/6/4 15:37 */ @Override - public void editMgtGoods(MgtGoodsEditDto mgtGoodsEditDto){ + public void editMgtGoods(MgtGoodsEditDto mgtGoodsEditDto) { Goods goods; Boolean newGoods = false; String goodsId = mgtGoodsEditDto.getGoodsId(); // 判断是否有商品ID 没有则新建 - if(goodsId != null){ + if (goodsId != null) { goods = this.getById(goodsId); - }else{ + } else { goods = new Goods(); goodsId = IdUtils.simpleUUID(); goods.setGoodsId(goodsId); @@ -293,9 +297,9 @@ goods.setGoodsIntroduction(mgtGoodsEditDto.getGoodsIntroduction()); goods.setSalesPrice(mgtGoodsEditDto.getSalesPrice()); goods.setMininumPrice(mgtGoodsEditDto.getMininumPrice()); - if(mgtGoodsEditDto.getSubscription()!=null&&mgtGoodsEditDto.getSubscription().compareTo(BigDecimal.valueOf(0))>0){ + if (mgtGoodsEditDto.getSubscription() != null && mgtGoodsEditDto.getSubscription().compareTo(BigDecimal.valueOf(0)) > 0) { goods.setSubscriptionFlag(1); - }else{ + } else { goods.setSubscriptionFlag(0); } goods.setSubscription(mgtGoodsEditDto.getSubscription()); @@ -304,8 +308,13 @@ goods.setGoodsNurses(mgtGoodsEditDto.getGoodsNurses()); goods.setGoodsTags(mgtGoodsEditDto.getGoodsNurses()); this.saveOrUpdate(goods); + //商品图片视频处理 + final String goodsIdFinal = goodsId; + saveGoodsFiles(goodsIdFinal, mgtGoodsEditDto.getGoodsPicture(), 1); + saveGoodsFiles(goodsIdFinal, mgtGoodsEditDto.getGoodsVideo(), 2); + saveGoodsFiles(goodsIdFinal, mgtGoodsEditDto.getGoodsBanners(), 3); //如果是新建商品创建商品统计 - if(newGoods){ + if (newGoods) { GoodsTotal goodsTotal = new GoodsTotal(); goodsTotal.setGoodsId(goodsId); goodsTotal.setBuyCount(0); @@ -315,4 +324,28 @@ goodsTotalService.saveOrUpdate(goodsTotal); } } + + /** + * @description: 处理商品文件 + * @param: goodsId fileUrls fileType + * @return: void + * @author jqs34 + * @date: 2023/6/4 16:25 + */ + private void saveGoodsFiles(String goodsId, String fileUrls, int fileType) { + if (StringUtils.isNotEmpty(fileUrls)) { + List<GoodsFile> files = Arrays.stream(fileUrls.split(",")) + .map(str -> { + GoodsFile goodsFile = new GoodsFile(); + goodsFile.setDelFlag(0); + goodsFile.setGoodsId(goodsId); + goodsFile.setFileType(fileType); + goodsFile.setFileUrl(str); + return goodsFile; + }) + .collect(Collectors.toList()); + // 保存文件列表 + goodsFileService.saveBatch(files); + } + } } -- Gitblit v1.7.1