!91 修复下架商品没有删除商品索引问题。修复下单使用优惠券使金额变为0元时消费服务获取数据不正确。
Merge pull request !91 from OceansDeep/feature/pg
This commit is contained in:
commit
bf2fdc2761
@ -21,6 +21,7 @@ public class MemberWalletExecute implements MemberRegisterEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void memberRegister(Member member) {
|
public void memberRegister(Member member) {
|
||||||
memberWalletService.save(member.getId(),member.getUsername());
|
// 有些情况下,会同时创建一个member_id的两条数据
|
||||||
|
// memberWalletService.save(member.getId(),member.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import cn.lili.modules.order.order.entity.dos.Receipt;
|
|||||||
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
import cn.lili.modules.order.order.entity.vo.OrderVO;
|
||||||
import cn.lili.modules.order.order.entity.vo.ReceiptVO;
|
import cn.lili.modules.order.order.entity.vo.ReceiptVO;
|
||||||
import cn.lili.modules.order.order.service.ReceiptService;
|
import cn.lili.modules.order.order.service.ReceiptService;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -34,8 +33,7 @@ public class OrderCreateReceiptExecute implements TradeEvent {
|
|||||||
//获取发票信息
|
//获取发票信息
|
||||||
ReceiptVO receiptVO = tradeDTO.getReceiptVO();
|
ReceiptVO receiptVO = tradeDTO.getReceiptVO();
|
||||||
//如果需要获取发票则保存发票信息
|
//如果需要获取发票则保存发票信息
|
||||||
if (tradeDTO.getNeedReceipt()) {
|
if (Boolean.TRUE.equals(tradeDTO.getNeedReceipt()) && !orderList.isEmpty()) {
|
||||||
if (orderList.size() > 0) {
|
|
||||||
List<Receipt> receipts = new ArrayList<>();
|
List<Receipt> receipts = new ArrayList<>();
|
||||||
for (OrderVO orderVO : orderList) {
|
for (OrderVO orderVO : orderList) {
|
||||||
Receipt receipt = new Receipt();
|
Receipt receipt = new Receipt();
|
||||||
@ -54,5 +52,4 @@ public class OrderCreateReceiptExecute implements TradeEvent {
|
|||||||
receiptService.saveBatch(receipts);
|
receiptService.saveBatch(receipts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -186,12 +186,28 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
break;
|
break;
|
||||||
//审核商品
|
//审核商品
|
||||||
case GOODS_AUDIT:
|
case GOODS_AUDIT:
|
||||||
updateGoodsNum(messageExt);
|
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
||||||
|
updateGoodsNum(goods);
|
||||||
break;
|
break;
|
||||||
//删除商品
|
//删除商品
|
||||||
case GOODS_DELETE:
|
case GOODS_DELETE:
|
||||||
deleteGoods(messageExt);
|
try {
|
||||||
updateGoodsNum(messageExt);
|
String goodsIdsJsonStr = new String(messageExt.getBody());
|
||||||
|
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
|
||||||
|
Goods goodsById = this.goodsService.getById(goodsId);
|
||||||
|
if (goodsById != null) {
|
||||||
|
this.deleteGoods(goodsById);
|
||||||
|
this.updateGoodsNum(goodsById);
|
||||||
|
List<String> skuIdsByGoodsId = this.goodsSkuService.getSkuIdsByGoodsId(goodsId);
|
||||||
|
if (skuIdsByGoodsId != null && !skuIdsByGoodsId.isEmpty()) {
|
||||||
|
this.goodsIndexService.deleteIndexByIds(skuIdsByGoodsId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody()));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
//规格删除
|
//规格删除
|
||||||
case SKU_DELETE:
|
case SKU_DELETE:
|
||||||
@ -380,10 +396,9 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
* 2.删除分销员-分销商品绑定关系
|
* 2.删除分销员-分销商品绑定关系
|
||||||
* 3.删除分销商品
|
* 3.删除分销商品
|
||||||
*
|
*
|
||||||
* @param messageExt 消息
|
* @param goods 消息
|
||||||
*/
|
*/
|
||||||
private void deleteGoods(MessageExt messageExt) {
|
private void deleteGoods(Goods goods) {
|
||||||
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
|
||||||
|
|
||||||
DistributionGoodsSearchParams searchParams = new DistributionGoodsSearchParams();
|
DistributionGoodsSearchParams searchParams = new DistributionGoodsSearchParams();
|
||||||
searchParams.setGoodsId(goods.getId());
|
searchParams.setGoodsId(goods.getId());
|
||||||
@ -403,17 +418,15 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
/**
|
/**
|
||||||
* 修改商品数量
|
* 修改商品数量
|
||||||
*
|
*
|
||||||
* @param messageExt 信息体
|
* @param goods 信息体
|
||||||
*/
|
*/
|
||||||
private void updateGoodsNum(MessageExt messageExt) {
|
private void updateGoodsNum(Goods goods) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
|
|
||||||
//更新店铺商品数量
|
//更新店铺商品数量
|
||||||
assert goods != null;
|
assert goods != null;
|
||||||
storeService.updateStoreGoodsNum(goods.getStoreId());
|
storeService.updateStoreGoodsNum(goods.getStoreId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("商品MQ信息错误:{}", messageExt.toString());
|
log.error("修改商品数量错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class OrderMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
//订单创建
|
//订单创建
|
||||||
case ORDER_CREATE:
|
case ORDER_CREATE:
|
||||||
String key = new String(messageExt.getBody());
|
String key = new String(messageExt.getBody());
|
||||||
TradeDTO tradeDTO = (TradeDTO) cache.get(key);
|
TradeDTO tradeDTO = JSONUtil.toBean(cache.getString(key), TradeDTO.class);
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
for (TradeEvent event : tradeEvent) {
|
for (TradeEvent event : tradeEvent) {
|
||||||
try {
|
try {
|
||||||
|
@ -44,7 +44,7 @@ public class PromotionEverydayExecute implements EveryDayExecute {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
//查询条件
|
//清除所以商品索引的无效促销活动
|
||||||
this.esGoodsIndexService.cleanInvalidPromotion();
|
this.esGoodsIndexService.cleanInvalidPromotion();
|
||||||
//定时创建活动
|
//定时创建活动
|
||||||
addSeckill();
|
addSeckill();
|
||||||
|
@ -71,7 +71,7 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
|
|||||||
|
|
||||||
@Bean("elasticsearchRestTemplate")
|
@Bean("elasticsearchRestTemplate")
|
||||||
public ElasticsearchRestTemplate elasticsearchRestTemplate() {
|
public ElasticsearchRestTemplate elasticsearchRestTemplate() {
|
||||||
return new ElasticsearchRestTemplate(elasticsearchClient());
|
return new ElasticsearchRestTemplate(this.client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpHost[] getHttpHosts() {
|
private HttpHost[] getHttpHosts() {
|
||||||
|
@ -2,6 +2,9 @@ package cn.lili.modules.goods.mapper;
|
|||||||
|
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规格项数据处理层
|
* 规格项数据处理层
|
||||||
@ -11,4 +14,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
*/
|
*/
|
||||||
public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品id获取全部skuId的集合
|
||||||
|
*
|
||||||
|
* @param goodsId goodsId
|
||||||
|
* @return 全部skuId的集合
|
||||||
|
*/
|
||||||
|
@Select("SELECT id FROM li_goods_sku WHERE goods_id = #{goodsId}")
|
||||||
|
List<String> getGoodsSkuIdByGoodsId(String goodsId);
|
||||||
|
|
||||||
}
|
}
|
@ -202,4 +202,12 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
|||||||
* @param promotionPrice 促销价格
|
* @param promotionPrice 促销价格
|
||||||
*/
|
*/
|
||||||
void updateGoodsSkuPromotion(String skuId, Double promotionPrice);
|
void updateGoodsSkuPromotion(String skuId, Double promotionPrice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品id获取全部skuId的集合
|
||||||
|
*
|
||||||
|
* @param goodsId goodsId
|
||||||
|
* @return 全部skuId的集合
|
||||||
|
*/
|
||||||
|
List<String> getSkuIdsByGoodsId(String goodsId);
|
||||||
}
|
}
|
@ -304,6 +304,14 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
for (Goods goods : goodsList) {
|
for (Goods goods : goodsList) {
|
||||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
goodsSkuService.updateGoodsSkuStatus(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GoodsStatusEnum.DOWN.equals(goodsStatusEnum)) {
|
||||||
|
|
||||||
|
//商品删除消息
|
||||||
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||||
|
//发送mq消息
|
||||||
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,11 +359,12 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
for (Goods goods : goodsList) {
|
for (Goods goods : goodsList) {
|
||||||
//修改SKU状态
|
//修改SKU状态
|
||||||
goodsSkuService.updateGoodsSkuStatus(goods);
|
goodsSkuService.updateGoodsSkuStatus(goods);
|
||||||
|
}
|
||||||
|
|
||||||
//商品删除消息
|
//商品删除消息
|
||||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name();
|
||||||
//发送mq消息
|
//发送mq消息
|
||||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goods), RocketmqSendCallbackBuilder.commonCallback());
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(goodsIds), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl;
|
|||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@ -13,7 +14,6 @@ import cn.lili.common.enums.ResultCode;
|
|||||||
import cn.lili.common.exception.ServiceException;
|
import cn.lili.common.exception.ServiceException;
|
||||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.utils.StringUtils;
|
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
||||||
@ -221,7 +221,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
//获取商品VO
|
//获取商品VO
|
||||||
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
|
GoodsVO goodsVO = goodsService.getGoodsVO(goodsId);
|
||||||
//如果skuid为空,则使用商品VO中sku信息获取
|
//如果skuid为空,则使用商品VO中sku信息获取
|
||||||
if (StringUtils.isEmpty(skuId) || "undefined".equals(skuId)) {
|
if (CharSequenceUtil.isEmpty(skuId) || "undefined".equals(skuId)) {
|
||||||
skuId = goodsVO.getSkuList().get(0).getId();
|
skuId = goodsVO.getSkuList().get(0).getId();
|
||||||
}
|
}
|
||||||
//从缓存拿商品Sku
|
//从缓存拿商品Sku
|
||||||
@ -532,6 +532,17 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
cache.remove(GoodsSkuService.getCacheKeys(skuId));
|
cache.remove(GoodsSkuService.getCacheKeys(skuId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品id获取全部skuId的集合
|
||||||
|
*
|
||||||
|
* @param goodsId goodsId
|
||||||
|
* @return 全部skuId的集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getSkuIdsByGoodsId(String goodsId) {
|
||||||
|
return this.baseMapper.getGoodsSkuIdByGoodsId(goodsId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送生成ES商品索引
|
* 发送生成ES商品索引
|
||||||
*
|
*
|
||||||
@ -539,6 +550,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void generateEs(Goods goods) {
|
public void generateEs(Goods goods) {
|
||||||
|
// 不生成没有审核通过且没有上架的商品
|
||||||
|
if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ThreadUtil.execAsync(() -> {
|
ThreadUtil.execAsync(() -> {
|
||||||
try {
|
try {
|
||||||
// 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
|
// 延时执行,防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
|
||||||
|
File diff suppressed because one or more lines are too long
@ -93,8 +93,8 @@ public class CouponSearchParams extends BasePromotionsSearchParams implements Se
|
|||||||
queryWrapper.nested(i -> i.gt(PromotionTools.START_TIME_COLUMN, new Date()).gt(PromotionTools.END_TIME_COLUMN, new Date()));
|
queryWrapper.nested(i -> i.gt(PromotionTools.START_TIME_COLUMN, new Date()).gt(PromotionTools.END_TIME_COLUMN, new Date()));
|
||||||
break;
|
break;
|
||||||
case START:
|
case START:
|
||||||
queryWrapper.nested(i -> i.le(PromotionTools.START_TIME_COLUMN, new Date()).ge(PromotionTools.END_TIME_COLUMN, new Date()));
|
queryWrapper.nested(i -> i.le(PromotionTools.START_TIME_COLUMN, new Date()).ge(PromotionTools.END_TIME_COLUMN, new Date()))
|
||||||
// .or(i -> i.gt("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name()));
|
.or(i -> i.gt("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name()));
|
||||||
break;
|
break;
|
||||||
case END:
|
case END:
|
||||||
queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date()));
|
queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date()));
|
||||||
|
@ -15,8 +15,6 @@ import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
|
|||||||
import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams;
|
import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams;
|
||||||
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
|
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
|
||||||
import cn.lili.modules.promotion.mapper.PromotionGoodsMapper;
|
import cn.lili.modules.promotion.mapper.PromotionGoodsMapper;
|
||||||
import cn.lili.modules.promotion.service.CouponService;
|
|
||||||
import cn.lili.modules.promotion.service.FullDiscountService;
|
|
||||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||||
import cn.lili.modules.promotion.service.SeckillApplyService;
|
import cn.lili.modules.promotion.service.SeckillApplyService;
|
||||||
import cn.lili.modules.promotion.tools.PromotionTools;
|
import cn.lili.modules.promotion.tools.PromotionTools;
|
||||||
@ -46,6 +44,8 @@ import java.util.List;
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper, PromotionGoods> implements PromotionGoodsService {
|
public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper, PromotionGoods> implements PromotionGoodsService {
|
||||||
|
|
||||||
|
private static final String SKU_ID_COLUMN = "sku_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis
|
* Redis
|
||||||
*/
|
*/
|
||||||
@ -62,12 +62,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
|||||||
@Autowired
|
@Autowired
|
||||||
private GoodsSkuService goodsSkuService;
|
private GoodsSkuService goodsSkuService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FullDiscountService fullDiscountService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CouponService couponService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
||||||
|
|
||||||
@ -77,7 +71,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
|||||||
}
|
}
|
||||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||||
|
|
||||||
queryWrapper.and(i -> i.or(j -> j.eq("sku_id", skuId))
|
queryWrapper.and(i -> i.or(j -> j.eq(SKU_ID_COLUMN, skuId))
|
||||||
.or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name()))
|
.or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name()))
|
||||||
.or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())
|
.or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())
|
||||||
.and(l -> l.like("scope_id", sku.getCategoryPath())))));
|
.and(l -> l.like("scope_id", sku.getCategoryPath())))));
|
||||||
@ -123,7 +117,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
|||||||
@Override
|
@Override
|
||||||
public PromotionGoods getValidPromotionsGoods(String skuId, List<String> promotionTypes) {
|
public PromotionGoods getValidPromotionsGoods(String skuId, List<String> promotionTypes) {
|
||||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("sku_id", skuId);
|
queryWrapper.eq(SKU_ID_COLUMN, skuId);
|
||||||
queryWrapper.in("promotion_type", promotionTypes);
|
queryWrapper.in("promotion_type", promotionTypes);
|
||||||
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
||||||
return this.getOne(queryWrapper, false);
|
return this.getOne(queryWrapper, false);
|
||||||
@ -139,7 +133,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
|||||||
@Override
|
@Override
|
||||||
public Double getValidPromotionsGoodsPrice(String skuId, List<String> promotionTypes) {
|
public Double getValidPromotionsGoodsPrice(String skuId, List<String> promotionTypes) {
|
||||||
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<PromotionGoods> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("sku_id", skuId);
|
queryWrapper.eq(SKU_ID_COLUMN, skuId);
|
||||||
queryWrapper.in("promotion_type", promotionTypes);
|
queryWrapper.in("promotion_type", promotionTypes);
|
||||||
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START));
|
||||||
return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper);
|
return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper);
|
||||||
|
@ -79,6 +79,13 @@ public interface EsGoodsIndexService {
|
|||||||
*/
|
*/
|
||||||
void deleteIndexById(String id);
|
void deleteIndexById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除索引
|
||||||
|
*
|
||||||
|
* @param ids 商品索引id集合
|
||||||
|
*/
|
||||||
|
void deleteIndexByIds(List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化商品索引
|
* 初始化商品索引
|
||||||
*
|
*
|
||||||
|
@ -49,8 +49,11 @@ import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
|||||||
import org.elasticsearch.script.Script;
|
import org.elasticsearch.script.Script;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@ -100,6 +103,10 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Cache<Object> cache;
|
private Cache<Object> cache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("elasticsearchRestTemplate")
|
||||||
|
private ElasticsearchRestTemplate restTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
//获取索引任务标识
|
//获取索引任务标识
|
||||||
@ -286,6 +293,19 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
goodsIndexRepository.deleteById(id);
|
goodsIndexRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除索引
|
||||||
|
*
|
||||||
|
* @param ids 商品索引id集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteIndexByIds(List<String> ids) {
|
||||||
|
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
|
||||||
|
queryBuilder.withQuery(QueryBuilders.termsQuery("id", ids.toArray()));
|
||||||
|
this.restTemplate.delete(queryBuilder.build(), EsGoodsIndex.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
|
||||||
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
if (goodsIndexList == null || goodsIndexList.isEmpty()) {
|
||||||
@ -480,17 +500,13 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
//获取商品索引
|
//获取商品索引
|
||||||
if (promotionMap != null && !promotionMap.isEmpty()) {
|
if (promotionMap != null && !promotionMap.isEmpty()) {
|
||||||
//促销不为空则进行清洗
|
//促销不为空则进行清洗
|
||||||
for (Map.Entry<String, Object> entry : promotionMap.entrySet()) {
|
promotionMap.entrySet().removeIf(i -> {
|
||||||
BasePromotions promotion = (BasePromotions) entry.getValue();
|
BasePromotions promotion = (BasePromotions) i.getValue();
|
||||||
//判定条件为活动已结束
|
if (i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
|
||||||
if (promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime()) {
|
|
||||||
if (entry.getKey().contains(PromotionTypeEnum.SECKILL.name()) || entry.getKey().contains(PromotionTypeEnum.PINTUAN.name())) {
|
|
||||||
goodsIndex.setPromotionPrice(goodsIndex.getPrice());
|
goodsIndex.setPromotionPrice(goodsIndex.getPrice());
|
||||||
}
|
}
|
||||||
promotionMap.remove(entry.getKey());
|
return promotion.getEndTime() != null && promotion.getEndTime().getTime() < DateUtil.date().getTime();
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goodsIndexRepository.saveAll(all);
|
goodsIndexRepository.saveAll(all);
|
||||||
|
@ -80,6 +80,12 @@ class EsTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cleanInvalidPromotion() {
|
||||||
|
this.esGoodsIndexService.cleanInvalidPromotion();
|
||||||
|
Assertions.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void searchGoods() {
|
void searchGoods() {
|
||||||
EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO();
|
EsGoodsSearchDTO goodsSearchDTO = new EsGoodsSearchDTO();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user