This commit is contained in:
pikachu1995@126.com 2024-01-24 14:54:29 +08:00
commit cfbb1a1519
7 changed files with 92 additions and 60 deletions

View File

@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -189,12 +190,15 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
//如果促销类型需要库存判定则做对应处理 //如果促销类型需要库存判定则做对应处理
orderItems.forEach(orderItem -> { orderItems.forEach(orderItem -> {
if (orderItem.getPromotionType() != null) { if (orderItem.getPromotionType() != null) {
String[] skuPromotions = orderItem.getPromotionType().split(",");
for (int i = 0; i < skuPromotions.length; i++) {
int currentIndex = i;
//如果此促销有库存概念则计入 //如果此促销有库存概念则计入
if (PromotionTypeEnum.haveStock(orderItem.getPromotionType())) { Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
.findFirst()
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType()); .ifPresent(promotionTypeEnum -> {
String promotionId = orderItem.getPromotionId().split(",")[currentIndex];
String cacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId()); String cacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId());
switch (promotionTypeEnum) { switch (promotionTypeEnum) {
case KANJIA: case KANJIA:
@ -205,12 +209,14 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
return; return;
case SECKILL: case SECKILL:
case PINTUAN: case PINTUAN:
cache.put(cacheKey, promotionGoodsService.getPromotionGoodsStock(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId())); cache.put(cacheKey, promotionGoodsService.getPromotionGoodsStock(promotionTypeEnum, promotionId, orderItem.getSkuId()));
return; return;
default: default:
break; break;
} }
});
} }
} }
}); });
} }
@ -222,7 +228,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
* @param orderSn 失败入库订单信息 * @param orderSn 失败入库订单信息
*/ */
private void errorOrder(String orderSn) { private void errorOrder(String orderSn) {
orderService.systemCancel(orderSn, outOfStockMessage,true); orderService.systemCancel(orderSn, outOfStockMessage, true);
} }
@ -236,13 +242,17 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) { private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) {
if (sku.getPromotionType() != null) { if (sku.getPromotionType() != null) {
//如果此促销有库存概念则计入 //如果此促销有库存概念则计入
if (!PromotionTypeEnum.haveStock(sku.getPromotionType())) { String[] skuPromotions = sku.getPromotionType().split(",");
return; for (int i = 0; i < skuPromotions.length; i++) {
int currentIndex = i;
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
.findFirst()
.ifPresent(promotionTypeEnum -> {
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId().split(",")[currentIndex], sku.getSkuId()));
int num = -sku.getNum();
values.add(Integer.toString(num));
});
} }
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(sku.getPromotionType());
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId(), sku.getSkuId()));
int i = -sku.getNum();
values.add(Integer.toString(i));
} }
} }
@ -277,41 +287,51 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
goodsSku.setId(orderItem.getSkuId()); goodsSku.setId(orderItem.getSkuId());
goodsSku.setGoodsId(orderItem.getGoodsId()); goodsSku.setGoodsId(orderItem.getGoodsId());
//如果有促销信息 //如果有促销信息
if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId() && PromotionTypeEnum.haveStock(orderItem.getPromotionType())) { if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId()) {
//如果促销有库存信息 //如果促销有库存信息
PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(orderItem.getPromotionType()); String[] skuPromotions = orderItem.getPromotionType().split(",");
for (int i = 0; i < skuPromotions.length; i++) {
int currentIndex = i;
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
.findFirst()
.ifPresent(promotionTypeEnum -> {
//修改砍价商品库存
String promotionId = orderItem.getPromotionId().split(",")[currentIndex];
//修改砍价商品库存 //修改砍价商品库存
if (promotionTypeEnum.equals(PromotionTypeEnum.KANJIA)) { if (promotionTypeEnum.equals(PromotionTypeEnum.KANJIA)) {
KanjiaActivity kanjiaActivity = kanjiaActivityService.getById(orderItem.getPromotionId()); KanjiaActivity kanjiaActivity = kanjiaActivityService.getById(promotionId);
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsDetail(kanjiaActivity.getKanjiaActivityGoodsId()); KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsDetail(kanjiaActivity.getKanjiaActivityGoodsId());
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId())).toString()); Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
kanjiaActivityGoodsDTO.setStock(stock); kanjiaActivityGoodsDTO.setStock(stock);
kanjiaActivityGoodsService.updateById(kanjiaActivityGoodsDTO); kanjiaActivityGoodsService.updateById(kanjiaActivityGoodsDTO);
//修改积分商品库存 //修改积分商品库存
} else if (promotionTypeEnum.equals(PromotionTypeEnum.POINTS_GOODS)) { } else if (promotionTypeEnum.equals(PromotionTypeEnum.POINTS_GOODS)) {
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetail(orderItem.getPromotionId()); PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetail(promotionId);
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId())).toString()); Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
pointsGoodsVO.setActiveStock(stock); pointsGoodsVO.setActiveStock(stock);
pointsGoodsService.updateById(pointsGoodsVO); pointsGoodsService.updateById(pointsGoodsVO);
} else { } else {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setPromotionType(promotionTypeEnum.name()); searchParams.setPromotionType(promotionTypeEnum.name());
searchParams.setPromotionId(orderItem.getPromotionId()); searchParams.setPromotionId(promotionId);
searchParams.setSkuId(orderItem.getSkuId()); searchParams.setSkuId(orderItem.getSkuId());
PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams); PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams);
//记录需要更新的促销库存信息 //记录需要更新的促销库存信息
promotionKey.add( promotionKey.add(
PromotionGoodsService.getPromotionGoodsStockCacheKey( PromotionGoodsService.getPromotionGoodsStockCacheKey(
promotionTypeEnum, promotionTypeEnum,
orderItem.getPromotionId(), orderItem.getSkuId()) promotionId, orderItem.getSkuId())
); );
if (pGoods != null) { if (pGoods != null) {
promotionGoods.add(pGoods); promotionGoods.add(pGoods);
} }
} }
});
}
} }
goodsSkus.add(goodsSku); goodsSkus.add(goodsSku);
} }

View File

@ -23,7 +23,7 @@ public enum PromotionTypeEnum {
/** /**
* 有促销库存的活动类型 * 有促销库存的活动类型
*/ */
static final PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS}; public static final PromotionTypeEnum[] haveStockPromotion = new PromotionTypeEnum[]{PINTUAN, SECKILL, KANJIA, POINTS_GOODS};
private final String description; private final String description;

View File

@ -132,7 +132,7 @@ public class GoodsSearchParams extends PageVO {
queryWrapper.le("quantity", leQuantity); queryWrapper.le("quantity", leQuantity);
} }
if (geQuantity != null) { if (geQuantity != null) {
queryWrapper.ge("quantity", geQuantity); queryWrapper.gt("quantity", geQuantity);
} }
if (recommend != null) { if (recommend != null) {
queryWrapper.le("recommend", recommend); queryWrapper.le("recommend", recommend);
@ -145,6 +145,7 @@ public class GoodsSearchParams extends PageVO {
} }
if(alertQuantity != null && alertQuantity){ if(alertQuantity != null && alertQuantity){
queryWrapper.apply("quantity <= alert_quantity"); queryWrapper.apply("quantity <= alert_quantity");
queryWrapper.ge("alert_quantity", 0);
} }
queryWrapper.in(CollUtil.isNotEmpty(ids), "id", ids); queryWrapper.in(CollUtil.isNotEmpty(ids), "id", ids);

View File

@ -328,7 +328,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
} }
} }
if (goodsSkuDetail.getGoodsGalleryList() == null || goodsSkuDetail.getGoodsGalleryList().isEmpty()) {
goodsSkuDetail.setGoodsGalleryList(goodsVO.getGoodsGalleryList());
} else {
goodsSkuDetail.getGoodsGalleryList().addAll(goodsVO.getGoodsGalleryList()); goodsSkuDetail.getGoodsGalleryList().addAll(goodsVO.getGoodsGalleryList());
}
map.put("data", goodsSkuDetail); map.put("data", goodsSkuDetail);
//获取分类 //获取分类

View File

@ -399,6 +399,8 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
Object quantity = cache.get(promotionGoodsStockCacheKey); Object quantity = cache.get(promotionGoodsStockCacheKey);
if (quantity != null) { if (quantity != null) {
goodsVO.setQuantity((Integer) quantity); goodsVO.setQuantity((Integer) quantity);
} else {
cache.put(promotionGoodsStockCacheKey, seckillApply.getQuantity());
} }
seckillGoodsVoS.add(goodsVO); seckillGoodsVoS.add(goodsVO);
} }

View File

@ -28,6 +28,10 @@ public interface GoodsStatisticsService extends IService<Goods> {
*/ */
long todayUpperNum(); long todayUpperNum();
/**
* 预警库存数
* @return
*/
long alertQuantityNum(); long alertQuantityNum();
} }

View File

@ -68,6 +68,7 @@ public class GoodsStatisticsServiceImpl extends ServiceImpl<GoodsStatisticsMappe
"store_id", currentUser.getStoreId()); "store_id", currentUser.getStoreId());
queryWrapper.eq("market_enable",GoodsStatusEnum.UPPER.name()); queryWrapper.eq("market_enable",GoodsStatusEnum.UPPER.name());
queryWrapper.apply("quantity < alert_quantity"); queryWrapper.apply("quantity < alert_quantity");
queryWrapper.gt("alert_quantity",0);
return goodsSkuService.count(queryWrapper); return goodsSkuService.count(queryWrapper);
} }
} }