|
|
@@ -21,6 +21,7 @@ import com.kym.service.admin.StationService;
|
|
|
import com.kym.service.miniapp.UserRechargeRightsService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -156,10 +157,34 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
|
|
|
* @param rechargeAmount
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Async("AsyncExecutor")
|
|
|
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....");
|
|
|
+ // 进行中的充值权益活动
|
|
|
+ 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();
|
|
|
+ if (rechargeRights != null) {
|
|
|
+ var userRechargeRights = new UserRechargeRights().setRightsId(rechargeRights.getId()).setUserId(userId).setRightsBalance(rechargeAmount);
|
|
|
+ BeanUtils.copyProperties(rechargeRights, userRechargeRights, "id");
|
|
|
+ // 计算有效期
|
|
|
+ var endTime = LocalDateTime.now().with(LocalTime.MAX).plusDays(rechargeRights.getValidity() - 1);
|
|
|
+ userRechargeRightsService.save(userRechargeRights.setStartTime(LocalDateTime.now()).setEndTime(endTime));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("RechargeActivityTask run end....");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理充值活动
|
|
|
*/
|