diff --git a/framework/pom.xml b/framework/pom.xml index 952d1c71..7b6af4cb 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -15,6 +15,11 @@ jar + + org.springframework.boot + spring-boot-properties-migrator + runtime + org.junit.vintage junit-vintage-engine @@ -161,6 +166,12 @@ com.aliyun dysmsapi20170525 ${aliyun-sdk-dysms-version} + + + org.jacoco.agent + org.jacoco + + @@ -172,6 +183,12 @@ org.apache.rocketmq rocketmq-spring-boot-starter ${rocketmq-version} + + + fastjson + com.alibaba + + @@ -220,6 +237,10 @@ groovy org.codehaus.groovy + + commons-collections4 + org.apache.commons + @@ -248,6 +269,20 @@ com.alipay.sdk alipay-sdk-java ${alipay-sdk-version} + + + bcprov-jdk15on + org.bouncycastle + + + commons-logging + commons-logging + + + xml-apis + xml-apis + + @@ -314,6 +349,12 @@ com.googlecode.owasp-java-html-sanitizer owasp-java-html-sanitizer ${owasp-java-html-sanitizer} + + + guava + com.google.guava + + diff --git a/framework/src/main/java/cn/lili/common/utils/SnowFlake.java b/framework/src/main/java/cn/lili/common/utils/SnowFlake.java index 18379ea7..e3cb3d70 100644 --- a/framework/src/main/java/cn/lili/common/utils/SnowFlake.java +++ b/framework/src/main/java/cn/lili/common/utils/SnowFlake.java @@ -33,7 +33,6 @@ public class SnowFlake { */ public static void initialize(long workerId, long datacenterId) { snowflake = IdUtil.getSnowflake(workerId, datacenterId); - log.error(workerId+""+datacenterId); } public static long getId() { diff --git a/framework/src/main/java/cn/lili/modules/goods/event/GeneratorEsGoodsIndexEvent.java b/framework/src/main/java/cn/lili/modules/goods/event/GeneratorEsGoodsIndexEvent.java new file mode 100644 index 00000000..ff5da90f --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/goods/event/GeneratorEsGoodsIndexEvent.java @@ -0,0 +1,19 @@ +package cn.lili.modules.goods.event; + +import lombok.Data; +import org.springframework.context.ApplicationEvent; + +/** + * @author paulG + * @since 2022/1/19 + **/ +@Data +public class GeneratorEsGoodsIndexEvent extends ApplicationEvent { + + private String goodsId; + + public GeneratorEsGoodsIndexEvent(Object source, String goodsId) { + super(source); + this.goodsId = goodsId; + } +} diff --git a/framework/src/main/java/cn/lili/modules/goods/listener/GeneratorEsGoodsIndexListener.java b/framework/src/main/java/cn/lili/modules/goods/listener/GeneratorEsGoodsIndexListener.java new file mode 100644 index 00000000..7c5b95ba --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/goods/listener/GeneratorEsGoodsIndexListener.java @@ -0,0 +1,38 @@ +package cn.lili.modules.goods.listener; + +import cn.lili.common.properties.RocketmqCustomProperties; +import cn.lili.modules.goods.event.GeneratorEsGoodsIndexEvent; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.GoodsTagsEnum; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; + +/** + * @author paulG + * @since 2022/1/19 + **/ +@Component +public class GeneratorEsGoodsIndexListener { + + /** + * rocketMq + */ + @Autowired + private RocketMQTemplate rocketMQTemplate; + /** + * rocketMq配置 + */ + @Autowired + private RocketmqCustomProperties rocketmqCustomProperties; + + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + public void generatorEsGoodsIndex(GeneratorEsGoodsIndexEvent esGoodsIndexEvent) { + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(); + //发送mq消息 + rocketMQTemplate.asyncSend(destination, esGoodsIndexEvent.getGoodsId(), RocketmqSendCallbackBuilder.commonCallback()); + } + +} diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index 90ebd4c4..6a68590a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -383,6 +383,7 @@ public class GoodsServiceImpl extends ServiceImpl implements } @Override + @Transactional(rollbackFor = Exception.class) public void updateStock(String goodsId, Integer quantity) { LambdaUpdateWrapper lambdaUpdateWrapper = Wrappers.lambdaUpdate(); lambdaUpdateWrapper.set(Goods::getQuantity, quantity); 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 2cc0f9e4..40cc4192 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 @@ -22,6 +22,7 @@ import cn.lili.modules.goods.entity.vos.GoodsSkuSpecVO; import cn.lili.modules.goods.entity.vos.GoodsSkuVO; import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.SpecValueVO; +import cn.lili.modules.goods.event.GeneratorEsGoodsIndexEvent; import cn.lili.modules.goods.mapper.GoodsSkuMapper; import cn.lili.modules.goods.service.CategoryService; import cn.lili.modules.goods.service.GoodsGalleryService; @@ -48,10 +49,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.event.TransactionPhase; -import org.springframework.transaction.event.TransactionalEventListener; import java.util.*; import java.util.stream.Collectors; @@ -109,6 +109,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Autowired private PromotionGoodsService promotionGoodsService; + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + @Override public void add(List> skuList, Goods goods) { // 检查是否需要生成索引 @@ -128,6 +131,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } @Override + @Transactional(rollbackFor = Exception.class) public void update(List> skuList, Goods goods, Boolean regeneratorSkuFlag) { // 是否存在规格 if (skuList == null || skuList.isEmpty()) { @@ -543,15 +547,12 @@ public class GoodsSkuServiceImpl extends ServiceImpl i * @param goods 商品信息 */ @Override - @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) public void generateEs(Goods goods) { // 不生成没有审核通过且没有上架的商品 if (!GoodsStatusEnum.UPPER.name().equals(goods.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goods.getAuthFlag())) { return; } - String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(); - //发送mq消息 - rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback()); + applicationEventPublisher.publishEvent(new GeneratorEsGoodsIndexEvent("生成商品索引事件", goods.getId())); } /** @@ -577,7 +578,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i * @param skuList sku列表 * @param goods 商品信息 */ - private List addGoodsSku(List> skuList, Goods goods) { + @Transactional(rollbackFor = Exception.class) + List addGoodsSku(List> skuList, Goods goods) { List skus = new ArrayList<>(); for (Map skuVO : skuList) { Map resultMap = this.add(skuVO, goods); diff --git a/framework/src/main/java/cn/lili/modules/promotion/event/UpdateEsGoodsIndexPromotionsEvent.java b/framework/src/main/java/cn/lili/modules/promotion/event/UpdateEsGoodsIndexPromotionsEvent.java new file mode 100644 index 00000000..94442bf7 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/promotion/event/UpdateEsGoodsIndexPromotionsEvent.java @@ -0,0 +1,19 @@ +package cn.lili.modules.promotion.event; + +import lombok.Data; +import org.springframework.context.ApplicationEvent; + +/** + * @author paulG + * @since 2022/1/19 + **/ +@Data +public class UpdateEsGoodsIndexPromotionsEvent extends ApplicationEvent { + + private String promotionsJsonStr; + + public UpdateEsGoodsIndexPromotionsEvent(Object source, String promotionsJsonStr) { + super(source); + this.promotionsJsonStr = promotionsJsonStr; + } +} diff --git a/framework/src/main/java/cn/lili/modules/promotion/listener/UpdateEsGoodsIndexPromotionsListener.java b/framework/src/main/java/cn/lili/modules/promotion/listener/UpdateEsGoodsIndexPromotionsListener.java new file mode 100644 index 00000000..00417c5f --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/promotion/listener/UpdateEsGoodsIndexPromotionsListener.java @@ -0,0 +1,41 @@ +package cn.lili.modules.promotion.listener; + +import cn.lili.common.properties.RocketmqCustomProperties; +import cn.lili.modules.promotion.event.UpdateEsGoodsIndexPromotionsEvent; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.GoodsTagsEnum; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; + +/** + * @author paulG + * @since 2022/1/19 + **/ +@Component +public class UpdateEsGoodsIndexPromotionsListener { + + /** + * rocketMq + */ + @Autowired + private RocketMQTemplate rocketMQTemplate; + /** + * rocketMq配置 + */ + @Autowired + private RocketmqCustomProperties rocketmqCustomProperties; + + + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true) + public void updateEsGoodsIndexPromotions(UpdateEsGoodsIndexPromotionsEvent event) { + //更新商品促销消息 + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(); + //发送mq消息 + rocketMQTemplate.asyncSend(destination, event.getPromotionsJsonStr(), RocketmqSendCallbackBuilder.commonCallback()); + } + + +} 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 d10f8579..1baa838a 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 @@ -10,6 +10,7 @@ import cn.lili.modules.promotion.entity.dos.BasePromotions; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.BasePromotionsSearchParams; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.event.UpdateEsGoodsIndexPromotionsEvent; import cn.lili.modules.promotion.service.AbstractPromotionsService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.tools.PromotionTools; @@ -23,6 +24,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.transaction.annotation.Transactional; import java.util.*; @@ -51,6 +53,9 @@ public abstract class AbstractPromotionsServiceImpl, T e @Autowired private RocketMQTemplate rocketMQTemplate; + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + /** * 通用促销保存 * 调用顺序: @@ -263,10 +268,7 @@ public abstract class AbstractPromotionsServiceImpl, T e map.put("promotionsType", promotions.getClass().getName()); // 促销实体 map.put("promotions", promotions); - //更新商品促销消息 - String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(); - //发送mq消息 - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(map), RocketmqSendCallbackBuilder.commonCallback()); + applicationEventPublisher.publishEvent(new UpdateEsGoodsIndexPromotionsEvent("更新商品索引促销事件", JSONUtil.toJsonStr(map))); } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java index 03eedfa4..b7fcde45 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java @@ -7,6 +7,7 @@ import cn.lili.modules.promotion.service.CouponActivityItemService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -37,6 +38,7 @@ public class CouponActivityItemServiceImpl extends ServiceImpl couponIds) { this.remove(new LambdaQueryWrapper() .in(CouponActivityItem::getCouponId, couponIds)); diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java index c413e6a4..ee56fcdc 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java @@ -23,6 +23,7 @@ import cn.lili.modules.promotion.tools.PromotionTools; import groovy.util.logging.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @@ -140,6 +141,7 @@ public class CouponActivityServiceImpl extends AbstractPromotionsServiceImpl> memberList, List couponActivityItems) { + @Transactional(rollbackFor = {Exception.class}) + void sendCoupon(List> memberList, List couponActivityItems) { for (CouponActivityItem couponActivityItem : couponActivityItems) { //获取优惠券 diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java index e8c494d9..076d45ea 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java @@ -77,6 +77,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl ids) { //删除优惠券信息 this.memberCouponService.closeMemberCoupon(ids); @@ -103,6 +105,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl ids, Long startTime, Long endTime) { List list = this.list(new LambdaQueryWrapper().in(Coupon::getId, ids).eq(Coupon::getRangeDayType, CouponRangeDayEnum.DYNAMICTIME.name())); if (!list.isEmpty()) { @@ -220,6 +224,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl seckillApplyList) { Seckill seckill = this.seckillService.getById(seckillId); if (seckill == null) { 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 9dd74121..e210ab2c 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 @@ -39,9 +39,7 @@ 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; /** * 秒杀活动业务层实现 @@ -153,19 +151,7 @@ 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()); + this.updateEsGoodsIndex(seckill); } } } diff --git a/pom.xml b/pom.xml index ba666989..30e18428 100644 --- a/pom.xml +++ b/pom.xml @@ -21,18 +21,18 @@ 4.2.3 registry.cn-beijing.aliyuncs.com/lili-images 1 - 4.13.40.ALL - 5.1.48 + 4.22.17.ALL + 8.0.27 3.4.3.4 - 5.7.16 + 5.7.18 2.0.3.RELEASE 3.0.0 2.9.10 1.18.22 4.5.18 3.11.1 - 2.0.1 - 2.1.1 + 2.0.8 + 2.2.1 0.10.7 4.7.2 4.0.0 @@ -48,12 +48,12 @@ 2.3.1 1.21 1.2 - 4.1.2 - 4.1.2 + 5.1.0 + 5.1.0 6.6 3.4.1 1.7.28 - 2.2.0 + 3.2.3 1.4 4.3 2.3.0