use of cn.lili.modules.promotion.entity.dos.PromotionGoods in project lilishop by lilishop.
the class GoodsSkuServiceImpl method getGoodsSkuDetail.
@Override
public Map<String, Object> getGoodsSkuDetail(String goodsId, String skuId) {
Map<String, Object> map = new HashMap<>(16);
// 获取商品VO
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
// 如果skuid为空,则使用商品VO中sku信息获取
if (CharSequenceUtil.isEmpty(skuId) || "undefined".equals(skuId)) {
skuId = goodsVO.getSkuList().get(0).getId();
}
// 从缓存拿商品Sku
GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId);
// 如果使用商品ID无法查询SKU则返回错误
if (goodsVO == null || goodsSku == null) {
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
}
// 商品下架||商品未审核通过||商品删除,则提示:商品已下架
if (GoodsStatusEnum.DOWN.name().equals(goodsVO.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goodsVO.getAuthFlag()) || Boolean.TRUE.equals(goodsVO.getDeleteFlag())) {
throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
}
// 获取当前商品的索引信息
EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId);
if (goodsIndex == null) {
goodsIndex = goodsIndexService.getResetEsGoodsIndex(goodsSku, goodsVO.getGoodsParamsDTOList());
}
// 商品规格
GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
Map<String, Object> promotionMap = goodsIndex.getPromotionMap();
// 设置当前商品的促销价格
if (promotionMap != null && !promotionMap.isEmpty()) {
promotionMap = promotionMap.entrySet().stream().parallel().filter(i -> {
JSONObject jsonObject = JSONUtil.parseObj(i.getValue());
// 过滤活动赠送优惠券和无效时间的活动
return (jsonObject.get("getType") == null || jsonObject.get("getType", String.class).equals(CouponGetEnum.FREE.name())) && (jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).getTime() <= System.currentTimeMillis()) && (jsonObject.get("endTime") == null || jsonObject.get("endTime", Date.class).getTime() >= System.currentTimeMillis());
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Optional<Map.Entry<String, Object>> containsPromotion = promotionMap.entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst();
if (containsPromotion.isPresent()) {
JSONObject jsonObject = JSONUtil.parseObj(containsPromotion.get().getValue());
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setSkuId(skuId);
searchParams.setPromotionId(jsonObject.get("id").toString());
PromotionGoods promotionsGoods = promotionGoodsService.getPromotionsGoods(searchParams);
if (promotionsGoods != null && promotionsGoods.getPrice() != null) {
goodsSkuDetail.setPromotionFlag(true);
goodsSkuDetail.setPromotionPrice(promotionsGoods.getPrice());
}
} else {
goodsSkuDetail.setPromotionFlag(false);
goodsSkuDetail.setPromotionPrice(null);
}
}
map.put("data", goodsSkuDetail);
// 获取分类
String[] split = goodsSkuDetail.getCategoryPath().split(",");
map.put("categoryName", categoryService.getCategoryNameByIds(Arrays.asList(split)));
// 获取规格信息
map.put("specs", this.groupBySkuAndSpec(goodsVO.getSkuList()));
map.put("promotionMap", promotionMap);
// 获取参数信息
if (goodsVO.getGoodsParamsDTOList() != null && !goodsVO.getGoodsParamsDTOList().isEmpty()) {
map.put("goodsParamsDTOList", goodsVO.getGoodsParamsDTOList());
}
// 记录用户足迹
if (UserContext.getCurrentUser() != null) {
FootPrint footPrint = new FootPrint(UserContext.getCurrentUser().getId(), goodsId, skuId);
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name();
rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback());
}
return map;
}
use of cn.lili.modules.promotion.entity.dos.PromotionGoods in project lilishop by lilishop.
the class GoodsMessageListener method updateGoodsIndexPromotions.
private void updateGoodsIndexPromotions(String promotionsJsonStr) {
try {
log.info("更新商品索引促销信息: {}", promotionsJsonStr);
JSONObject jsonObject = JSONUtil.parseObj(promotionsJsonStr);
BasePromotions promotions = (BasePromotions) jsonObject.get("promotions", ClassLoaderUtil.loadClass(jsonObject.get("promotionsType").toString()));
String esPromotionKey = jsonObject.get("esPromotionKey").toString();
if (PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType())) {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setPromotionId(promotions.getId());
List<PromotionGoods> promotionGoodsList = this.promotionGoodsService.listFindAll(searchParams);
List<String> skuIds = promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList());
this.goodsIndexService.deleteEsGoodsPromotionByPromotionKey(skuIds, esPromotionKey);
this.goodsIndexService.updateEsGoodsIndexByList(promotionGoodsList, promotions, esPromotionKey);
} else if (PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name().equals(promotions.getScopeType())) {
GoodsSearchParams searchParams = new GoodsSearchParams();
searchParams.setCategoryPath(promotions.getScopeId());
List<GoodsSku> goodsSkuByList = this.goodsSkuService.getGoodsSkuByList(searchParams);
List<String> skuIds = goodsSkuByList.stream().map(GoodsSku::getId).collect(Collectors.toList());
this.goodsIndexService.deleteEsGoodsPromotionByPromotionKey(skuIds, esPromotionKey);
this.goodsIndexService.updateEsGoodsIndexPromotions(skuIds, promotions, esPromotionKey);
} else if (PromotionsScopeTypeEnum.ALL.name().equals(promotions.getScopeType())) {
this.goodsIndexService.deleteEsGoodsPromotionByPromotionKey(esPromotionKey);
this.goodsIndexService.updateEsGoodsIndexAllByList(promotions, esPromotionKey);
}
} catch (Exception e) {
log.error("生成商品索引促销信息执行异常", e);
}
}
use of cn.lili.modules.promotion.entity.dos.PromotionGoods in project lilishop by lilishop.
the class PromotionManagerController method getPromotionGoods.
@GetMapping("/{promotionId}/goods")
@ApiOperation(value = "获取当前进行中的促销活动商品")
public ResultMessage<IPage<PromotionGoods>> getPromotionGoods(@PathVariable String promotionId, String promotionType, PageVO pageVO) {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setPromotionId(promotionId);
searchParams.setPromotionType(promotionType);
searchParams.setPromotionStatus(PromotionsStatusEnum.START.name());
IPage<PromotionGoods> promotionGoods = promotionGoodsService.pageFindAll(searchParams, pageVO);
return ResultUtil.data(promotionGoods);
}
use of cn.lili.modules.promotion.entity.dos.PromotionGoods in project lilishop by lilishop.
the class EsGoodsIndexServiceImpl method updateEsGoodsIndexByList.
@Override
public void updateEsGoodsIndexByList(List<PromotionGoods> promotionGoodsList, BasePromotions promotion, String key) {
BulkRequest bulkRequest = new BulkRequest();
log.info("修改商品活动索引");
log.info("促销商品信息: {}", promotionGoodsList);
log.info("活动关键字: {}", key);
log.info("活动: {}", promotion);
if (promotionGoodsList != null) {
// 循环更新 促销商品索引
for (PromotionGoods promotionGoods : promotionGoodsList) {
promotion.setStartTime(promotionGoods.getStartTime());
promotion.setEndTime(promotionGoods.getEndTime());
UpdateRequest updateRequest = this.updateEsGoodsIndexPromotions(promotionGoods.getSkuId(), promotion, key);
if (updateRequest != null) {
bulkRequest.add(updateRequest);
}
}
}
this.executeBulkUpdateRequest(bulkRequest);
}
use of cn.lili.modules.promotion.entity.dos.PromotionGoods in project lilishop by lilishop.
the class FullDiscountServiceImpl method updatePromotionsGoods.
/**
* 更新促销商品信息
*
* @param promotions 促销实体
* @return 是否更新成功
*/
@Override
@Transactional(rollbackFor = { Exception.class })
public boolean updatePromotionsGoods(FullDiscount promotions) {
boolean result = super.updatePromotionsGoods(promotions);
if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus()) && PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType()) && promotions instanceof FullDiscountVO) {
FullDiscountVO fullDiscountVO = (FullDiscountVO) promotions;
List<PromotionGoods> promotionGoodsList = PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT);
this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId()));
// 促销活动商品更新
result = this.promotionGoodsService.saveBatch(promotionGoodsList);
}
return result;
}
Aggregations