|
|
@@ -21,7 +21,6 @@ import com.kym.service.jobs.DelayService;
|
|
|
import com.kym.service.miniapp.UserCouponService;
|
|
|
import com.kym.service.miniapp.UserRechargeRightsService;
|
|
|
import com.kym.service.miniapp.UserService;
|
|
|
-import com.kym.service.queue.producer.CouponMessageProducer;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
@@ -65,11 +64,9 @@ public class ActivityServiceImpl extends MPJBaseServiceImpl<ActivityMapper, Acti
|
|
|
|
|
|
private final UserCouponService userCouponService;
|
|
|
|
|
|
- private final CouponMessageProducer couponMessageProducer;
|
|
|
-
|
|
|
public ActivityServiceImpl(ActivityStationService activityStationService, RechargeRightsService rechargeRightsService, CouponService couponService,
|
|
|
UserRechargeRightsService userRechargeRightsService, StationService stationService,
|
|
|
- @Lazy DelayService<DelayActivity> activityDelayService, BannerService bannerService, UserService userService, UserCouponService userCouponService, CouponMessageProducer couponMessageProducer) {
|
|
|
+ @Lazy DelayService<DelayActivity> activityDelayService, BannerService bannerService, UserService userService, UserCouponService userCouponService) {
|
|
|
this.activityStationService = activityStationService;
|
|
|
this.rechargeRightsService = rechargeRightsService;
|
|
|
this.couponService = couponService;
|
|
|
@@ -79,7 +76,6 @@ public class ActivityServiceImpl extends MPJBaseServiceImpl<ActivityMapper, Acti
|
|
|
this.bannerService = bannerService;
|
|
|
this.userService = userService;
|
|
|
this.userCouponService = userCouponService;
|
|
|
- this.couponMessageProducer = couponMessageProducer;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -150,7 +146,7 @@ public class ActivityServiceImpl extends MPJBaseServiceImpl<ActivityMapper, Acti
|
|
|
break;
|
|
|
}
|
|
|
userCouponService.saveBatch(userCouponList);
|
|
|
- userCouponList.forEach(couponMessageProducer::sendMessage);
|
|
|
+// userCouponList.forEach(couponMessageProducer::sendMessage);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -242,9 +238,11 @@ public class ActivityServiceImpl extends MPJBaseServiceImpl<ActivityMapper, Acti
|
|
|
@Async
|
|
|
public void handleRechargeActivity(long userId, int rechargeAmount) {
|
|
|
asyncHandleRechargeActivity(userId, rechargeAmount);
|
|
|
-// executor.execute(new RechargeActivityTask(userId, rechargeAmount));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理充值活动
|
|
|
+ */
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void asyncHandleRechargeActivity(long userId, int rechargeAmount) {
|
|
|
log.info("RechargeActivityTask run....");
|
|
|
@@ -275,46 +273,4 @@ public class ActivityServiceImpl extends MPJBaseServiceImpl<ActivityMapper, Acti
|
|
|
log.info("RechargeActivityTask run end....");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理充值活动
|
|
|
- */
|
|
|
- private class RechargeActivityTask implements Runnable {
|
|
|
- private final long userId;
|
|
|
- private final int rechargeAmount;
|
|
|
-
|
|
|
- public RechargeActivityTask(long userId, int rechargeAmount) {
|
|
|
- this.userId = userId;
|
|
|
- this.rechargeAmount = rechargeAmount;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- log.info("RechargeActivityTask run....");
|
|
|
- // 进行中的充值权益活动
|
|
|
- // 手动切换数据源
|
|
|
- DynamicDataSourceContextHolder.push("db-admin");
|
|
|
- var activity = lambdaQuery().eq(Activity::getDiscountType, DISCOUNT_TYPE_服务费折扣权益).eq(Activity::getStatus, Activity.STATUS_进行中).one();
|
|
|
- // 充值金额,匹配到到具体的充值权益,生成用户权益
|
|
|
- if (activity != null) {
|
|
|
- var rechargeRights = rechargeRightsService.lambdaQuery().eq(RechargeRights::getActivityId, activity.getId())
|
|
|
- .le(RechargeRights::getAmountMin, rechargeAmount)
|
|
|
- .ge(RechargeRights::getAmountMax, rechargeAmount) // 最后一档最大值设置成10000
|
|
|
- .one();
|
|
|
- DynamicDataSourceContextHolder.poll();
|
|
|
- if (rechargeRights != null) {
|
|
|
- var userRechargeRights = new UserRechargeRights().setRightsId(rechargeRights.getId()).setUserId(userId).setRightsBalance(rechargeAmount);
|
|
|
- BeanUtils.copyProperties(rechargeRights, userRechargeRights, "id", "createTime", "updateTime");
|
|
|
- // 计算有效期
|
|
|
- var endTime = LocalDateTime.now().with(LocalTime.MAX).plusDays(rechargeRights.getValidity() - 1);
|
|
|
- // 手动切换数据源
|
|
|
- DynamicDataSourceContextHolder.push("db-miniapp");
|
|
|
- userRechargeRightsService.save(userRechargeRights.setStartTime(LocalDateTime.now()).setEndTime(endTime));
|
|
|
- DynamicDataSourceContextHolder.poll();
|
|
|
- }
|
|
|
- } else {
|
|
|
- DynamicDataSourceContextHolder.poll();
|
|
|
- }
|
|
|
- log.info("RechargeActivityTask run end....");
|
|
|
- }
|
|
|
- }
|
|
|
}
|