|
|
@@ -1,8 +1,6 @@
|
|
|
package com.kym.service.admin.impl;
|
|
|
|
|
|
-import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
-import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
import com.kym.common.utils.IDGenerator;
|
|
|
@@ -14,10 +12,10 @@ import com.kym.entity.common.PageBean;
|
|
|
import com.kym.entity.common.RedisKeys;
|
|
|
import com.kym.entity.miniapp.UserRechargeRights;
|
|
|
import com.kym.mapper.admin.ActivityMapper;
|
|
|
-import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
import com.kym.service.admin.*;
|
|
|
import com.kym.service.jobs.DelayService;
|
|
|
import com.kym.service.miniapp.UserRechargeRightsService;
|
|
|
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
@@ -43,7 +41,6 @@ import static com.kym.entity.admin.Activity.*;
|
|
|
* @since 2023-10-18
|
|
|
*/
|
|
|
@Service
|
|
|
-@DS("db-admin")
|
|
|
@Slf4j
|
|
|
public class ActivityServiceImpl extends MyBaseServiceImpl<ActivityMapper, Activity> implements ActivityService {
|
|
|
|
|
|
@@ -78,7 +75,7 @@ public class ActivityServiceImpl extends MyBaseServiceImpl<ActivityMapper, Activ
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- @DSTransactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void createActivity(ActivityVo activityVo) {
|
|
|
// 新增activity
|
|
|
var activity = new Activity();
|
|
|
@@ -235,8 +232,6 @@ public class ActivityServiceImpl extends MyBaseServiceImpl<ActivityMapper, Activ
|
|
|
public void asyncHandleRechargeActivity(long userId, int rechargeAmount) {
|
|
|
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) {
|
|
|
@@ -244,19 +239,14 @@ public class ActivityServiceImpl extends MyBaseServiceImpl<ActivityMapper, Activ
|
|
|
.le(RechargeRights::getAmountMin, rechargeAmount)
|
|
|
.gt(RechargeRights::getAmountMax, rechargeAmount)
|
|
|
.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....");
|
|
|
}
|