Search in sources :

Example 1 with PromotionGoods

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;
}
Also used : GoodsVO(cn.lili.modules.goods.entity.vos.GoodsVO) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) GoodsGalleryService(cn.lili.modules.goods.service.GoodsGalleryService) GoodsVO(cn.lili.modules.goods.entity.vos.GoodsVO) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) EsGoodsIndex(cn.lili.modules.search.entity.dos.EsGoodsIndex) FootPrint(cn.lili.modules.member.entity.dos.FootPrint) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EvaluationQueryParams(cn.lili.modules.member.entity.dto.EvaluationQueryParams) PromotionTypeEnum(cn.lili.common.enums.PromotionTypeEnum) ResultCode(cn.lili.common.enums.ResultCode) ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) Cache(cn.lili.cache.Cache) JSONObject(cn.hutool.json.JSONObject) EsGoodsIndexService(cn.lili.modules.search.service.EsGoodsIndexService) Collectors(java.util.stream.Collectors) RocketmqSendCallbackBuilder(cn.lili.rocketmq.RocketmqSendCallbackBuilder) GoodsSearchParams(cn.lili.modules.goods.entity.dto.GoodsSearchParams) Goods(cn.lili.modules.goods.entity.dos.Goods) GoodsService(cn.lili.modules.goods.service.GoodsService) GoodsAuthEnum(cn.lili.modules.goods.entity.enums.GoodsAuthEnum) GoodsSkuService(cn.lili.modules.goods.service.GoodsSkuService) UserContext(cn.lili.common.security.context.UserContext) Convert(cn.hutool.core.convert.Convert) GoodsSkuVO(cn.lili.modules.goods.entity.vos.GoodsSkuVO) GoodsSkuMapper(cn.lili.modules.goods.mapper.GoodsSkuMapper) RocketMQTemplate(org.apache.rocketmq.spring.core.RocketMQTemplate) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PageUtil(cn.lili.mybatis.util.PageUtil) GoodsTagsEnum(cn.lili.rocketmq.tags.GoodsTagsEnum) NumberUtil(cn.hutool.core.util.NumberUtil) java.util(java.util) MapUtil(cn.hutool.core.map.MapUtil) SpecValueVO(cn.lili.modules.goods.entity.vos.SpecValueVO) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) JSONUtil(cn.hutool.json.JSONUtil) CategoryService(cn.lili.modules.goods.service.CategoryService) Service(org.springframework.stereotype.Service) GoodsSkuStockDTO(cn.lili.modules.goods.entity.dto.GoodsSkuStockDTO) GoodsSkuSpecVO(cn.lili.modules.goods.entity.vos.GoodsSkuSpecVO) EvaluationGradeEnum(cn.lili.modules.member.entity.enums.EvaluationGradeEnum) ServiceException(cn.lili.common.exception.ServiceException) PromotionGoodsService(cn.lili.modules.promotion.service.PromotionGoodsService) RocketmqCustomProperties(cn.lili.common.properties.RocketmqCustomProperties) SnowFlake(cn.lili.common.utils.SnowFlake) EsGoodsAttribute(cn.lili.modules.search.entity.dos.EsGoodsAttribute) CachePrefix(cn.lili.cache.CachePrefix) GeneratorEsGoodsIndexEvent(cn.lili.modules.goods.event.GeneratorEsGoodsIndexEvent) MemberEvaluationService(cn.lili.modules.member.service.MemberEvaluationService) GoodsStatusEnum(cn.lili.modules.goods.entity.enums.GoodsStatusEnum) EsIndexUtil(cn.lili.modules.search.utils.EsIndexUtil) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) CharSequenceUtil(cn.hutool.core.text.CharSequenceUtil) CouponGetEnum(cn.lili.modules.promotion.entity.enums.CouponGetEnum) Transactional(org.springframework.transaction.annotation.Transactional) FootPrint(cn.lili.modules.member.entity.dos.FootPrint) EsGoodsIndex(cn.lili.modules.search.entity.dos.EsGoodsIndex) ServiceException(cn.lili.common.exception.ServiceException) JSONObject(cn.hutool.json.JSONObject) JSONObject(cn.hutool.json.JSONObject) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) GoodsSkuVO(cn.lili.modules.goods.entity.vos.GoodsSkuVO)

Example 2 with PromotionGoods

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);
    }
}
Also used : JSONObject(cn.hutool.json.JSONObject) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) BasePromotions(cn.lili.modules.promotion.entity.dos.BasePromotions) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) GoodsSearchParams(cn.lili.modules.goods.entity.dto.GoodsSearchParams) DistributionGoodsSearchParams(cn.lili.modules.distribution.entity.dto.DistributionGoodsSearchParams) RetryException(cn.lili.common.exception.RetryException)

Example 3 with PromotionGoods

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);
}
Also used : PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) PromotionGoodsSearchParams(cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with 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);
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods)

Example 5 with PromotionGoods

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;
}
Also used : PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) FullDiscountVO(cn.lili.modules.order.cart.entity.vo.FullDiscountVO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PromotionGoods (cn.lili.modules.promotion.entity.dos.PromotionGoods)27 PromotionGoodsSearchParams (cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams)13 Transactional (org.springframework.transaction.annotation.Transactional)12 GoodsSku (cn.lili.modules.goods.entity.dos.GoodsSku)10 ServiceException (cn.lili.common.exception.ServiceException)9 ArrayList (java.util.ArrayList)8 PromotionTypeEnum (cn.lili.common.enums.PromotionTypeEnum)5 GoodsSkuService (cn.lili.modules.goods.service.GoodsSkuService)4 CouponVO (cn.lili.modules.promotion.entity.vos.CouponVO)4 PromotionGoodsService (cn.lili.modules.promotion.service.PromotionGoodsService)4 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)4 Test (org.junit.jupiter.api.Test)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Service (org.springframework.stereotype.Service)4 DateTime (cn.hutool.core.date.DateTime)3 CharSequenceUtil (cn.hutool.core.text.CharSequenceUtil)3 JSONObject (cn.hutool.json.JSONObject)3 Cache (cn.lili.cache.Cache)3 ResultCode (cn.lili.common.enums.ResultCode)3