From f7e2789a576b2db4217d20d5cfdeb20249c83a5b Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期四, 24 七月 2025 17:47:51 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java | 74 ++++++++++++++++++++++++++++++++++++- 1 files changed, 72 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index adc30c3..0d8e1d9 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -37,7 +37,11 @@ import cn.lili.modules.goods.service.WholesaleService; import cn.lili.modules.goods.sku.GoodsSkuBuilder; import cn.lili.modules.goods.sku.render.SalesModelRender; +import cn.lili.modules.lmk.domain.entity.PriceChange; +import cn.lili.modules.lmk.enums.general.ChangePriceAudioStatusEnum; +import cn.lili.modules.lmk.enums.general.ChangePriceOperationTypeEnum; import cn.lili.modules.lmk.enums.general.ViewTypeEnum; +import cn.lili.modules.lmk.service.PriceChangeService; import cn.lili.modules.member.entity.dos.FootPrint; import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.PromotionGoods; @@ -56,6 +60,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.poi.ss.usermodel.*; @@ -73,8 +78,10 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.net.URLEncoder; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -137,6 +144,9 @@ @Autowired private List<SalesModelRender> salesModelRenders; + @Autowired + private PriceChangeService priceChangeService; + @Override @Transactional(rollbackFor = Exception.class) public void add(Goods goods, GoodsOperationDTO goodsOperationDTO) { @@ -151,12 +161,29 @@ if (!goodsSkus.isEmpty()) { this.saveOrUpdateBatch(goodsSkus); this.updateGoodsStock(goodsSkus); + //璁板綍浠锋牸鍙樺姩 + List<PriceChange> priceChangeList = goodsSkus.stream().map(item -> { + PriceChange priceChange = new PriceChange(); + priceChange.setCurrentPrice(BigDecimal.valueOf(item.getPrice())); + priceChange.setSkuId(item.getId()); + priceChange.setGoodsId(item.getGoodsId()); + priceChange.setPreviousPrice(BigDecimal.ZERO); + priceChange.setPreviousCommission(BigDecimal.ZERO); + priceChange.setCurrentCommission(goods.getCommission()); + priceChange.setOperatorType(ChangePriceOperationTypeEnum.STORE.name()); + priceChange.setExamineStatus(ChangePriceAudioStatusEnum.APPLY.name()); + priceChange.setOperatorId(UserContext.getCurrentUser().getId()); + priceChange.setOperatorName(UserContext.getCurrentUser().getNickName()); + priceChange.setStoreId(item.getStoreId()); + return priceChange; + }).collect(Collectors.toList()); + priceChangeService.saveBatch(priceChangeList); } } @Override @Transactional(rollbackFor = Exception.class) - public void update(Goods goods, GoodsOperationDTO goodsOperationDTO) { + public void update(Goods goods, GoodsOperationDTO goodsOperationDTO,Goods previousGoods) { // 鏄惁瀛樺湪瑙勬牸 if (goodsOperationDTO.getSkuList() == null || goodsOperationDTO.getSkuList().isEmpty()) { throw new ServiceException(ResultCode.MUST_HAVE_GOODS_SKU); @@ -199,9 +226,41 @@ unnecessarySkuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId()); unnecessarySkuIdsQuery.notIn(GoodsSku::getId, skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); + LambdaQueryWrapper<GoodsSku> skuIdsQuery = new LambdaQueryWrapper<>(); + skuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId()); + skuIdsQuery.in(GoodsSku::getId, + skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); + Map<String, GoodsSku> skuMap = this.list(skuIdsQuery).stream().collect(Collectors.toMap(GoodsSku::getId, Function.identity())); this.remove(unnecessarySkuIdsQuery); this.saveOrUpdateBatch(skuList); this.updateGoodsStock(skuList); + //璁板綍浠锋牸鍙樺姩 + //鍒犻櫎褰撳墠瀹℃牳鐘舵�佷负鐢宠鐨勬敼浠风殑鍟嗗搧 搴楅摵id涓�鑷村晢鍝乮d涓�鑷翠笖涓虹敵璇风姸鎬佺殑绉婚櫎 + LambdaQueryWrapper<PriceChange> needRemove = Wrappers.<PriceChange>lambdaQuery() + .eq(PriceChange::getGoodsId, goods.getId()) + .eq(PriceChange::getStoreId, goods.getStoreId()) + .eq(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.APPLY.name()); + priceChangeService.remove(needRemove); + //閲嶆柊娣诲姞鏀逛环鍟嗗搧 + List<PriceChange> priceChangeList = skuList.stream().map(item -> { + PriceChange priceChange = new PriceChange(); + priceChange.setCurrentPrice(BigDecimal.valueOf(item.getPrice())); + GoodsSku goodsSku = skuMap.get(item.getId()); + priceChange.setSkuId(item.getId()); + priceChange.setGoodsId(item.getGoodsId()); + if (Objects.nonNull(goodsSku)) { + priceChange.setPreviousPrice(BigDecimal.valueOf(goodsSku.getPrice())); + } + priceChange.setPreviousCommission(previousGoods.getCommission()); + priceChange.setCurrentCommission(goods.getCommission()); + priceChange.setOperatorType(ChangePriceOperationTypeEnum.STORE.name()); + priceChange.setExamineStatus(ChangePriceAudioStatusEnum.APPLY.name()); + priceChange.setOperatorId(UserContext.getCurrentUser().getId()); + priceChange.setOperatorName(UserContext.getCurrentUser().getNickName()); + priceChange.setStoreId(item.getStoreId()); + return priceChange; + }).collect(Collectors.toList()); + priceChangeService.saveBatch(priceChangeList); } } @@ -366,7 +425,7 @@ //璁板綍鐢ㄦ埛瓒宠抗 if (currentUser != null) { - FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId, ViewTypeEnum.GOODS.getValue(), null); + FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId, ViewTypeEnum.GOODS.getValue(), null, null); String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name(); rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback()); } @@ -389,6 +448,17 @@ updateWrapper.set(GoodsSku::getDeleteFlag, goods.getDeleteFlag()); boolean update = this.update(updateWrapper); if (Boolean.TRUE.equals(update)) { + //淇敼璁㈠崟鏀逛环鐘舵�佷负閫氳繃鎴栬�呭け璐� + LambdaUpdateWrapper<PriceChange> updatePriceChange = Wrappers.<PriceChange>lambdaUpdate() + .eq(PriceChange::getGoodsId, goods.getId()) + .eq(PriceChange::getStoreId, goods.getStoreId()) + .eq(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.APPLY.name()); + if (GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) { + updatePriceChange.set(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.PASS.name()); + }else { + updatePriceChange.set(PriceChange::getExamineStatus, ChangePriceAudioStatusEnum.REFUSE.name()); + } + priceChangeService.update(updatePriceChange); List<GoodsSku> goodsSkus = this.getGoodsSkuListByGoodsId(goods.getId()); for (GoodsSku sku : goodsSkus) { cache.remove(GoodsSkuService.getCacheKeys(sku.getId())); -- Gitblit v1.8.0