From 92c873eda099b869e15108a79bf5223d3f0264a6 Mon Sep 17 00:00:00 2001 From: peng <peng.com> Date: 星期三, 06 八月 2025 09:40:44 +0800 Subject: [PATCH] 调整商品可以进行排序 --- framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 3 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index 6909add..8fb237a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -18,6 +18,7 @@ import cn.lili.modules.goods.entity.dto.GoodsOperationDTO; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; +import cn.lili.modules.goods.entity.dto.GoodsSortDTO; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.vos.GoodsSkuVO; @@ -41,6 +42,7 @@ import cn.lili.mybatis.util.PageUtil; import cn.lili.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.rocketmq.tags.GoodsTagsEnum; +import cn.lili.utils.COSUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -121,6 +123,9 @@ @Autowired private Cache<GoodsVO> cache; + @Autowired + private COSUtil cosUtil; + @Override public List<Goods> getByBrandIds(List<String> brandIds) { LambdaQueryWrapper<Goods> lambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -172,7 +177,7 @@ //妫�鏌ュ晢鍝� this.checkGoods(goods); //鍚慻oods鍔犲叆鍥剧墖 - if (goodsOperationDTO.getGoodsGalleryList().size() > 0) { + if (goodsOperationDTO.getGoodsGalleryList()!=null&& !goodsOperationDTO.getGoodsGalleryList().isEmpty()) { this.setGoodsGalleryParam(goodsOperationDTO.getGoodsGalleryList().get(0), goods); } //娣诲姞鍟嗗搧鍙傛暟 @@ -201,15 +206,23 @@ //妫�鏌ュ晢鍝佷俊鎭� this.checkGoods(goods); //鍚慻oods鍔犲叆鍥剧墖 - this.setGoodsGalleryParam(goodsOperationDTO.getGoodsGalleryList().get(0), goods); + if (goodsOperationDTO.getGoodsGalleryList() != null&& !goodsOperationDTO.getGoodsGalleryList().isEmpty()) { + this.setGoodsGalleryParam(goodsOperationDTO.getGoodsGalleryList().get(0), goods); + }else { + goods.setOriginal(null); + goods.setSmall(null); + goods.setThumbnail(null); + goodsGalleryService.removeByGoodsId(goodsId); + } //娣诲姞鍟嗗搧鍙傛暟 if (goodsOperationDTO.getGoodsParamsDTOList() != null && !goodsOperationDTO.getGoodsParamsDTOList().isEmpty()) { goods.setParams(JSONUtil.toJsonStr(goodsOperationDTO.getGoodsParamsDTOList())); } + Goods previousGoods = this.getById(goodsId); //淇敼鍟嗗搧 this.updateById(goods); //淇敼鍟嗗搧sku淇℃伅 - this.goodsSkuService.update(goods, goodsOperationDTO); + this.goodsSkuService.update(goods, goodsOperationDTO,previousGoods); //娣诲姞鐩稿唽 if (goodsOperationDTO.getGoodsGalleryList() != null && !goodsOperationDTO.getGoodsGalleryList().isEmpty()) { this.goodsGalleryService.add(goodsOperationDTO.getGoodsGalleryList(), goods.getId()); @@ -227,6 +240,17 @@ //缂撳瓨鑾峰彇锛屽鏋滄病鏈夊垯璇诲彇缂撳瓨 GoodsVO goodsVO = cache.get(CachePrefix.GOODS.getPrefix() + goodsId); if (goodsVO != null) { +// List<String> goodsGalleryList = goodsVO.getGoodsGalleryList(); +// if (goodsGalleryList != null && !goodsGalleryList.isEmpty()) { +// List<String> galleryList = goodsGalleryList.stream().map(item -> { +// if (StringUtils.isNotBlank(item)&&!item.contains("http")) { +// return cosUtil.getPreviewUrl(item); +// }else { +// return item; +// } +// }).collect(Collectors.toList()); +// goodsVO.setGoodsGalleryList(galleryList); +// } return goodsVO; } //鏌ヨ鍟嗗搧淇℃伅 @@ -245,6 +269,12 @@ List<GoodsGallery> galleryList = goodsGalleryService.goodsGalleryList(goodsId); for (GoodsGallery goodsGallery : galleryList) { images.add(goodsGallery.getOriginal()); +// String original = goodsGallery.getOriginal(); +// if (StringUtils.isNotBlank(original)&&!original.contains("http")) { +// images.add(cosUtil.getPreviewUrl(original)); +// }else { +// images.add(goodsGallery.getOriginal()); +// } } goodsVO.setGoodsGalleryList(images); //鍟嗗搧sku璧嬪�� @@ -394,6 +424,22 @@ @Override @Transactional(rollbackFor = Exception.class) + public Boolean goodsSort(GoodsSortDTO req) { + boolean result; + //妫�娴嬬鐞嗗憳鏉冮檺 + this.checkManagerAuthority(); + LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.set(Goods::getGoodsSort,req.getSort()); + updateWrapper.eq(Goods::getId, req.getGoodsId()); + result = this.update(updateWrapper); + List<String> goodsIds = new ArrayList<>(); + goodsIds.add(req.getGoodsId()); + this.updateEsGoods(goodsIds); + return result; + } + + @Override + @Transactional(rollbackFor = Exception.class) @SystemLogPoint(description = "鍒犻櫎鍟嗗搧", customerLog = "'鎿嶄綔瀵硅薄:['+#goodsIds+']'") public Boolean deleteGoods(List<String> goodsIds) { -- Gitblit v1.8.0