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 5f1e2882..b7eef69b 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 @@ -504,8 +504,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //修改规格索引,发送mq消息 Map updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap( - MapUtil.builder().put("id", goodsSku.getId()).build(), - MapUtil.builder().put("commentNum", goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum) + MapUtil.builder(new HashMap()).put("id", goodsSku.getId()).build(), + MapUtil.builder(new HashMap()).put("commentNum", goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum) .put("grade", grade).build()); String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback()); diff --git a/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java b/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java index e6396dcd..21ce926e 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java +++ b/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java @@ -274,4 +274,14 @@ public interface OrderService extends IService { * @return 订单支付记录分页 */ IPage queryPaymentLogs(IPage page, Wrapper queryWrapper); + + /** + * 检查是否开始虚拟成团 + * + * @param pintuanId 拼团活动id + * @param requiredNum 成团人数 + * @param fictitious 是否开启成团 + * @return 是否成功 + */ + boolean checkFictitiousOrder(String pintuanId, Integer requiredNum, Boolean fictitious); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java index 80458c32..52201b71 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java @@ -74,10 +74,8 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; /** * 子订单业务层实现 @@ -684,6 +682,77 @@ public class OrderServiceImpl extends ServiceImpl implements } + /** + * 检查是否开始虚拟成团 + * + * @param pintuanId 拼团活动id + * @param requiredNum 成团人数 + * @param fictitious 是否开启成团 + * @return 是否成功 + */ + @Override + public boolean checkFictitiousOrder(String pintuanId, Integer requiredNum, Boolean fictitious) { + Map> collect = this.queryListByPromotion(pintuanId) + .stream().filter(i -> CharSequenceUtil.isNotEmpty(i.getParentOrderSn())) + .collect(Collectors.groupingBy(Order::getParentOrderSn)); + + for (Map.Entry> entry : collect.entrySet()) { + //是否开启虚拟成团 + if (Boolean.FALSE.equals(fictitious) && entry.getValue().size() < requiredNum) { + //如果未开启虚拟成团且已参团人数小于成团人数,则自动取消订单 + String reason = "拼团活动结束订单未付款,系统自动取消订单"; + if (CharSequenceUtil.isNotEmpty(entry.getKey())) { + this.systemCancel(entry.getKey(), reason); + } else { + for (Order order : entry.getValue()) { + this.systemCancel(order.getSn(), reason); + } + } + } else if (Boolean.TRUE.equals(fictitious)) { + this.fictitiousPintuan(entry, requiredNum); + } + } + return false; + } + + /** + * 虚拟成团 + * + * @param entry 订单列表 + * @param requiredNum 必须参团人数 + */ + private void fictitiousPintuan(Map.Entry> entry, Integer requiredNum) { + Map> listMap = entry.getValue().stream().collect(Collectors.groupingBy(Order::getPayStatus)); + //未付款订单 + List unpaidOrders = listMap.get(PayStatusEnum.UNPAID.name()); + //未付款订单自动取消 + if (unpaidOrders != null && !unpaidOrders.isEmpty()) { + for (Order unpaidOrder : unpaidOrders) { + this.systemCancel(unpaidOrder.getSn(), "拼团活动结束订单未付款,系统自动取消订单"); + } + } + List paidOrders = listMap.get(PayStatusEnum.PAID.name()); + //如待参团人数大于0,并已开启虚拟成团 + if (!paidOrders.isEmpty()) { + //待参团人数 + int waitNum = requiredNum - paidOrders.size(); + //添加虚拟成团 + for (int i = 0; i < waitNum; i++) { + Order order = new Order(); + BeanUtil.copyProperties(paidOrders.get(0), order); + order.setMemberId("-1"); + order.setMemberName("参团人员"); + order.setDeleteFlag(true); + this.save(order); + paidOrders.add(order); + } + for (Order paidOrder : paidOrders) { + paidOrder.setOrderStatus(OrderStatusEnum.UNDELIVERED.name()); + orderStatusMessage(paidOrder); + } + } + } + /** * 订单状态变更消息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java index 0a126c1d..b9244031 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java @@ -42,15 +42,31 @@ public interface SeckillApplyService extends IService { * @param pageVo 分页参数 * @return 限时请购申请列表 */ - IPage getSeckillApply(SeckillSearchParams queryParam, PageVO pageVo); + IPage getSeckillApplyPage(SeckillSearchParams queryParam, PageVO pageVo); /** - * 分页查询限时请购申请列表 + * 查询限时请购申请列表 * * @param queryParam 秒杀活动申请查询参数 * @return 限时请购申请列表 */ - List getSeckillApply(SeckillSearchParams queryParam); + List getSeckillApplyList(SeckillSearchParams queryParam); + + /** + * 查询限时请购申请列表总数 + * + * @param queryParam 查询条件 + * @return 限时请购申请列表总数 + */ + long getSeckillApplyCount(SeckillSearchParams queryParam); + + /** + * 查询限时请购申请 + * + * @param queryParam 秒杀活动申请查询参数 + * @return 限时请购申请 + */ + SeckillApply getSeckillApply(SeckillSearchParams queryParam); /** * 添加秒杀活动申请 @@ -72,4 +88,13 @@ public interface SeckillApplyService extends IService { */ void removeSeckillApply(String seckillId, String id); + /** + * 更新秒杀商品库存 + * + * @param seckillId 秒杀活动id + * @param skuId 商品skuId + * @param quantity 库存 + */ + void updateSeckillApplyQuantity(String seckillId, String skuId, Integer quantity); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java index afbd1789..8564ef73 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java @@ -2,7 +2,6 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.json.JSONUtil; -import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; @@ -32,7 +31,7 @@ import java.util.*; * @author paulG * @since 2021/11/30 **/ -public class AbstractPromotionsServiceImpl, T extends BasePromotions> extends ServiceImpl implements AbstractPromotionsService { +public abstract class AbstractPromotionsServiceImpl, T extends BasePromotions> extends ServiceImpl implements AbstractPromotionsService { /** * 促销商品 @@ -264,13 +263,4 @@ public class AbstractPromotionsServiceImpl, T extends Ba } } - /** - * 当前促销类型 - * - * @return 当前促销类型 - */ - @Override - public PromotionTypeEnum getPromotionType() { - return null; - } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java index dfbcbc78..0b0efbda 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java @@ -1,6 +1,5 @@ package cn.lili.modules.promotion.serviceimpl; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; @@ -34,8 +33,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; /** * 拼团业务层实现 @@ -201,10 +198,7 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl> collect = orderService.queryListByPromotion(promotions.getId()) - .stream().filter(i -> CharSequenceUtil.isNotEmpty(i.getParentOrderSn())) - .collect(Collectors.groupingBy(Order::getParentOrderSn)); - this.isOpenFictitiousPintuan(promotions, collect); + this.orderService.checkFictitiousOrder(promotions.getId(), promotions.getRequiredNum(), promotions.getFictitious()); } } @@ -268,71 +262,6 @@ public class PintuanServiceImpl extends AbstractPromotionsServiceImpl> collect) { - //成团人数 - Integer requiredNum = pintuan.getRequiredNum(); - - for (Map.Entry> entry : collect.entrySet()) { - //是否开启虚拟成团 - if (Boolean.FALSE.equals(pintuan.getFictitious()) && entry.getValue().size() < requiredNum) { - //如果未开启虚拟成团且已参团人数小于成团人数,则自动取消订单 - String reason = "拼团活动结束订单未付款,系统自动取消订单"; - if (CharSequenceUtil.isNotEmpty(entry.getKey())) { - this.orderService.systemCancel(entry.getKey(), reason); - } else { - for (Order order : entry.getValue()) { - this.orderService.systemCancel(order.getSn(), reason); - } - } - } else if (Boolean.TRUE.equals(pintuan.getFictitious())) { - this.fictitiousPintuan(entry, requiredNum); - } - } - } - - /** - * 虚拟成团 - * - * @param entry 订单列表 - * @param requiredNum 必须参团人数 - */ - private void fictitiousPintuan(Map.Entry> entry, Integer requiredNum) { - Map> listMap = entry.getValue().stream().collect(Collectors.groupingBy(Order::getPayStatus)); - //未付款订单 - List unpaidOrders = listMap.get(PayStatusEnum.UNPAID.name()); - //未付款订单自动取消 - if (unpaidOrders != null && !unpaidOrders.isEmpty()) { - for (Order unpaidOrder : unpaidOrders) { - orderService.systemCancel(unpaidOrder.getSn(), "拼团活动结束订单未付款,系统自动取消订单"); - } - } - List paidOrders = listMap.get(PayStatusEnum.PAID.name()); - //如待参团人数大于0,并已开启虚拟成团 - if (!paidOrders.isEmpty()) { - //待参团人数 - int waitNum = requiredNum - paidOrders.size(); - //添加虚拟成团 - for (int i = 0; i < waitNum; i++) { - Order order = new Order(); - BeanUtil.copyProperties(paidOrders.get(0), order); - order.setMemberId("-1"); - order.setMemberName("参团人员"); - orderService.save(order); - paidOrders.add(order); - } - for (Order paidOrder : paidOrders) { - paidOrder.setOrderStatus(OrderStatusEnum.UNDELIVERED.name()); - } - orderService.updateBatchById(paidOrders); - } - } - /** * 更新记录的促销商品信息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java index 92a2dec9..6e632980 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java @@ -2,9 +2,11 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; +import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.PointsGoods; @@ -15,10 +17,13 @@ import cn.lili.modules.promotion.mapper.PointsGoodsMapper; import cn.lili.modules.promotion.service.PointsGoodsService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.modules.search.service.EsGoodsIndexService; +import cn.lili.modules.search.utils.EsIndexUtil; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,14 +56,22 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl promotionsList) { List promotionGoodsList = new ArrayList<>(); - Map skuPoints = new HashMap<>(); for (PointsGoods pointsGoods : promotionsList) { this.initPromotion(pointsGoods); this.checkPromotions(pointsGoods); @@ -73,16 +86,13 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl entry : skuPoints.entrySet()) { - Map query = MapUtil.builder(new HashMap()).put("id", entry.getKey()).build(); - Map update = MapUtil.builder(new HashMap()).put("points", entry.getValue()).build(); - this.goodsIndexService.updateIndex(query, update); + for (PointsGoods pointsGoods : promotionsList) { + this.updateEsGoodsIndex(pointsGoods); } } @@ -205,7 +215,10 @@ public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl query = MapUtil.builder(new HashMap()).put("id", promotions.getSkuId()).build(); Map update = MapUtil.builder(new HashMap()).put("points", promotions.getPoints()).build(); - this.goodsIndexService.updateIndex(query, update); + //修改规格索引,发送mq消息 + Map updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(query, update); + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback()); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index 6bac9eaf..2dc9ff90 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -18,6 +18,7 @@ import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; +import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.FullDiscountService; @@ -264,16 +265,14 @@ public class PromotionGoodsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SeckillApply::getSeckillId, promotionId).eq(SeckillApply::getSkuId, skuId); - SeckillApply seckillApply = this.seckillApplyService.getOne(queryWrapper, false); + SeckillSearchParams searchParams = new SeckillSearchParams(); + searchParams.setSeckillId(promotionId); + searchParams.setSkuId(skuId); + SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams); if (seckillApply == null) { throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(SeckillApply::getSeckillId, promotionId).eq(SeckillApply::getSkuId, skuId); - updateWrapper.set(SeckillApply::getQuantity, quantity); - seckillApplyService.update(updateWrapper); + seckillApplyService.updateSeckillApplyQuantity(promotionId, skuId, quantity); } else { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId); diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java index 45b8a105..70c224de 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java @@ -1,7 +1,6 @@ package cn.lili.modules.promotion.serviceimpl; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.*; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; @@ -64,9 +63,6 @@ public class PromotionServiceImpl implements PromotionService { @Autowired private PointsGoodsService pointsGoodsService; - @Autowired - private GoodsSkuService goodsSkuService; - /** * 获取当前进行的所有促销活动信息 @@ -176,7 +172,7 @@ public class PromotionServiceImpl implements PromotionService { SeckillSearchParams searchParams = new SeckillSearchParams(); searchParams.setSeckillId(promotionGoods.getPromotionId()); searchParams.setSkuId(promotionGoods.getSkuId()); - List seckillApplyList = seckillApplyService.getSeckillApply(searchParams); + List seckillApplyList = seckillApplyService.getSeckillApplyList(searchParams); if (seckillApplyList != null && !seckillApplyList.isEmpty()) { SeckillApply seckillApply = seckillApplyList.get(0); int nextHour = 23; diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java index 56b50ca8..fdffd2a8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java @@ -27,6 +27,7 @@ import cn.lili.modules.promotion.tools.PromotionCacheKeys; import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.mybatis.util.PageUtil; 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.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -100,7 +101,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl getSeckillApply(SeckillSearchParams queryParam, PageVO pageVo) { + public IPage getSeckillApplyPage(SeckillSearchParams queryParam, PageVO pageVo) { IPage seckillApplyPage = this.page(PageUtil.initPage(pageVo), queryParam.queryWrapper()); if (seckillApplyPage != null && !seckillApplyPage.getRecords().isEmpty()) { @@ -126,10 +127,32 @@ public class SeckillApplyServiceImpl extends ServiceImpl getSeckillApply(SeckillSearchParams queryParam) { + public List getSeckillApplyList(SeckillSearchParams queryParam) { return this.list(queryParam.queryWrapper()); } + /** + * 查询限时请购申请列表总数 + * + * @param queryParam 查询条件 + * @return 限时请购申请列表总数 + */ + @Override + public long getSeckillApplyCount(SeckillSearchParams queryParam) { + return this.count(queryParam.queryWrapper()); + } + + /** + * 查询限时请购申请 + * + * @param queryParam 秒杀活动申请查询参数 + * @return 限时请购申请 + */ + @Override + public SeckillApply getSeckillApply(SeckillSearchParams queryParam) { + return this.getOne(queryParam.queryWrapper(), false); + } + @Override public void addSeckillApply(String seckillId, String storeId, List seckillApplyList) { Seckill seckill = this.seckillService.getById(seckillId); @@ -187,7 +210,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(SeckillApply::getSeckillId, seckillId).eq(SeckillApply::getSkuId, skuId); + updateWrapper.set(SeckillApply::getQuantity, quantity); + this.update(updateWrapper); + } + /** * 检查秒杀活动申请列表参数信息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java index 88674fa8..9ea0d877 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillServiceImpl.java @@ -4,34 +4,41 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; +import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.promotion.entity.dos.Seckill; import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum; +import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; import cn.lili.modules.promotion.entity.vos.SeckillVO; import cn.lili.modules.promotion.mapper.SeckillMapper; import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillService; import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.system.entity.dos.Setting; import cn.lili.modules.system.entity.dto.SeckillSetting; import cn.lili.modules.system.entity.enums.SettingEnum; import cn.lili.modules.system.service.SettingService; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 秒杀活动业务层实现 @@ -44,11 +51,6 @@ import java.util.List; @Slf4j public class SeckillServiceImpl extends AbstractPromotionsServiceImpl implements SeckillService { - /** - * 商品索引 - */ - @Autowired - private EsGoodsIndexService goodsIndexService; /** * 设置 */ @@ -58,13 +60,27 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl().eq(SeckillApply::getSeckillId, id))); + SeckillSearchParams searchParams = new SeckillSearchParams(); + searchParams.setSeckillId(id); + seckillVO.setSeckillApplyList(this.seckillApplyService.getSeckillApplyList(searchParams)); return seckillVO; } @@ -76,7 +92,7 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl()); @@ -103,10 +119,12 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(Seckill::getId, seckillId); updateWrapper.set(Seckill::getGoodsNum, - this.seckillApplyService.count(new LambdaQueryWrapper().eq(SeckillApply::getSeckillId, seckillId))); + this.seckillApplyService.getSeckillApplyCount(searchParams)); this.update(updateWrapper); } @@ -126,7 +144,17 @@ public class SeckillServiceImpl extends AbstractPromotionsServiceImpl map = new HashMap<>(); + // es促销key + map.put("esPromotionKey", promotionKey); + // 促销类型全路径名 + map.put("promotionsType", Seckill.class.getName()); + // 促销实体 + map.put("promotions", seckill); + //更新商品促销消息 + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(); + //发送mq消息 + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(map), RocketmqSendCallbackBuilder.commonCallback()); } } } diff --git a/framework/src/main/java/cn/lili/modules/search/utils/EsIndexUtil.java b/framework/src/main/java/cn/lili/modules/search/utils/EsIndexUtil.java index e514f011..1f65638c 100644 --- a/framework/src/main/java/cn/lili/modules/search/utils/EsIndexUtil.java +++ b/framework/src/main/java/cn/lili/modules/search/utils/EsIndexUtil.java @@ -16,8 +16,8 @@ public class EsIndexUtil { private static final String IGNORE_FIELD = "serialVersionUID,promotionMap,id,goodsId"; public static Map getUpdateIndexFieldsMap(EsGoodsIndex queryGoodsIndex, EsGoodsIndex updateGoodsIndex) { - Map queryFieldsMap = new HashMap<>(); - Map updateFieldsMap = new HashMap<>(); + Map queryFieldsMap = new HashMap<>(); + Map updateFieldsMap = new HashMap<>(); for (Map.Entry entry : ReflectUtil.getFieldMap(EsGoodsIndex.class).entrySet()) { Object queryFieldValue = ReflectUtil.getFieldValue(queryGoodsIndex, entry.getValue()); @@ -33,7 +33,7 @@ public class EsIndexUtil { return getUpdateIndexFieldsMap(queryFieldsMap, updateFieldsMap); } - public static Map getUpdateIndexFieldsMap(Map queryFieldsMap, Map updateFieldsMap) { + public static Map getUpdateIndexFieldsMap(Map queryFieldsMap, Map updateFieldsMap) { Map updateIndexMap = new HashMap<>(); updateIndexMap.put("queryFields", queryFieldsMap); diff --git a/framework/src/main/java/cn/lili/modules/store/serviceimpl/StoreDetailServiceImpl.java b/framework/src/main/java/cn/lili/modules/store/serviceimpl/StoreDetailServiceImpl.java index 99799f78..342f138f 100644 --- a/framework/src/main/java/cn/lili/modules/store/serviceimpl/StoreDetailServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/store/serviceimpl/StoreDetailServiceImpl.java @@ -32,10 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** * 店铺详细业务层实现 @@ -103,8 +100,8 @@ public class StoreDetailServiceImpl extends ServiceImpl updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap( - MapUtil.builder().put("storeId", store.getId()).build(), - MapUtil.builder().put("storeName", store.getStoreName()).put("selfOperated", store.getSelfOperated()).build()); + MapUtil.builder(new HashMap()).put("storeId", store.getId()).build(), + MapUtil.builder(new HashMap()).put("storeName", store.getStoreName()).put("selfOperated", store.getSelfOperated()).build()); String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); //发送mq消息 rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback()); diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java index 28e5cae1..2fac508b 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java @@ -81,7 +81,7 @@ public class SeckillManagerController { @ApiOperation(value = "获取秒杀活动申请列表") @GetMapping("/apply") public ResultMessage> getSeckillApply(SeckillSearchParams param, PageVO pageVo) { - IPage seckillApply = seckillApplyService.getSeckillApply(param, pageVo); + IPage seckillApply = seckillApplyService.getSeckillApplyPage(param, pageVo); return ResultUtil.data(seckillApply); } diff --git a/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java b/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java index 8dbdf3f8..90f92c7f 100644 --- a/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java @@ -47,7 +47,7 @@ public class SeckillStoreController { public ResultMessage> getSeckillApplyPage(SeckillSearchParams queryParam, PageVO pageVo) { String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); queryParam.setStoreId(storeId); - IPage seckillPage = seckillApplyService.getSeckillApply(queryParam, pageVo); + IPage seckillPage = seckillApplyService.getSeckillApplyPage(queryParam, pageVo); return ResultUtil.data(seckillPage); }