兑换能量包新增开关

This commit is contained in:
2026-03-30 01:16:47 +08:00
parent a929e49db7
commit 16fcb1c714
3 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
package org.springblade.job.processor;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.market.constant.BladeMarketConstant;
import org.springblade.modules.system.pojo.entity.Param;
import org.springblade.modules.system.service.IParamService;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import java.time.LocalTime;
// 支持 SpringBean 的形式
@Slf4j
@Component
@AllArgsConstructor
public class BenefitPackActivationProcessor implements BasicProcessor {
private final IParamService paramService;
@Override
public ProcessResult process(TaskContext context) {
try {
// 1. 获取当前时间 (只关注 时:分)
LocalTime now = LocalTime.now();
// 2. 定义时间边界
LocalTime startMaintenance = LocalTime.of(0, 0); // 0点
LocalTime endMaintenance = LocalTime.of(7, 0); // 7点
// 3. 判断当前是否处于维护时间段 [00:00, 07:00)
// 即:时间 >= 0点 且 时间 < 7点
boolean isMaintenanceTime = !now.isBefore(startMaintenance) && now.isBefore(endMaintenance);
// 4. 决定开关状态
// 维护时间内 -> false (关闭/维护中)
// 维护时间外 -> true (开启/正常)
boolean targetStatus = !isMaintenanceTime;
// 5. 更新数据库
Param param = paramService.getOne(
Wrappers.lambdaQuery(Param.class)
.eq(Param::getParamKey, BladeMarketConstant.APP_BENEFIT_PACK_ALLOCATE_ENABLED)
);
if (param != null) {
String newValue = String.valueOf(targetStatus);
// 优化:如果值没变,可以跳过更新,减少数据库压力
if (!newValue.equals(param.getParamValue())) {
param.setParamValue(newValue);
paramService.updateById(param);
log.info("福利包开关已更新为: {}", targetStatus ? "开启" : "关闭");
} else {
log.info("福利包开关状态未变更,当前状态: {}", targetStatus ? "开启" : "关闭");
}
} else {
log.error("未找到福利包开关配置参数,初始化");
String title = "app是否开启兑换福利包";
Param saveParam = new Param();
saveParam.setParamName(title);
saveParam.setParamKey(BladeMarketConstant.APP_BENEFIT_PACK_ALLOCATE_ENABLED);
saveParam.setParamValue(String.valueOf(targetStatus));
saveParam.setRemark(title);
paramService.save(saveParam);
}
return new ProcessResult(true, "执行成功,当前状态: " + (targetStatus ? "开启" : "关闭"));
} catch (Exception e) {
log.error("福利包开关定时任务执行失败", e);
return new ProcessResult(false, "执行失败: " + e.getMessage());
}
}
}

View File

@@ -12,5 +12,8 @@ public interface BladeMarketConstant {
// 用户兑换福利包-上级福利积分奖励配置 // 用户兑换福利包-上级福利积分奖励配置
String BENEFIT_PACK_SUPERIOR_REWARD_CONFIG = "market.benefit.pack.superior.reward.config"; String BENEFIT_PACK_SUPERIOR_REWARD_CONFIG = "market.benefit.pack.superior.reward.config";
// 是否开启兑换福利包
String APP_BENEFIT_PACK_ALLOCATE_ENABLED = "app.market.benefit.pack.allocate.enabled";
} }

View File

@@ -30,6 +30,7 @@ import org.springblade.modules.market.pojo.vo.UserMallSpendVO;
import org.springblade.modules.market.pojo.vo.UserPerformanceVO; import org.springblade.modules.market.pojo.vo.UserPerformanceVO;
import org.springblade.modules.market.service.*; import org.springblade.modules.market.service.*;
import org.springblade.modules.system.pojo.entity.User; import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IParamService;
import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -62,6 +63,8 @@ public class MarketUserManager {
private final IMarketCashPerformanceService cashPerformanceService; private final IMarketCashPerformanceService cashPerformanceService;
private final IMarketWelfarePerformanceService welfarePerformanceService; private final IMarketWelfarePerformanceService welfarePerformanceService;
private final IParamService paramService;
public List<MarketDirectInfoApiVO> findUserPackList() { public List<MarketDirectInfoApiVO> findUserPackList() {
Long userId = AuthUtil.getUserId(); Long userId = AuthUtil.getUserId();
MarketInfoEntity marketInfoEntity = marketInfoService.getById(userId); MarketInfoEntity marketInfoEntity = marketInfoService.getById(userId);
@@ -150,6 +153,11 @@ public class MarketUserManager {
@Transactional(rollbackFor = ServiceException.class) @Transactional(rollbackFor = ServiceException.class)
public boolean acquireBenefitPackage(AcquireBenefitPackageRequest request) { public boolean acquireBenefitPackage(AcquireBenefitPackageRequest request) {
if (!Boolean.parseBoolean(paramService.getValue(BladeMarketConstant.APP_BENEFIT_PACK_ALLOCATE_ENABLED))){
throw new ServiceException("系统结算中,请于结算完成之后再兑换。");
}
Long userId = AuthUtil.getUserId(); Long userId = AuthUtil.getUserId();
User user = userService.getById(userId); User user = userService.getById(userId);
if(user == null){ if(user == null){