|
|
@@ -95,10 +95,13 @@ public class CheckInConfigService {
|
|
|
checkinConfigMapper.updateById(config);
|
|
|
|
|
|
boolean active = request.getEnabled() != null && request.getEnabled() == 1;
|
|
|
- if (active && (timeChanged || modeChanged)) {
|
|
|
- regeneratePeriods(config);
|
|
|
- } else if (active && rewardChanged) {
|
|
|
- updatePendingPeriodsConfig(config);
|
|
|
+ if (active) {
|
|
|
+ if (timeChanged || modeChanged) {
|
|
|
+ regeneratePeriods(config);
|
|
|
+ updatePendingPeriodsConfig(config);
|
|
|
+ } else if (rewardChanged) {
|
|
|
+ updatePendingPeriodsConfig(config);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
log.info("签到全局配置已更新: enabled={}, cycleMode={}, requiredDays={}, rewardDays={}",
|
|
|
@@ -117,11 +120,12 @@ public class CheckInConfigService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> deleteWrapper =
|
|
|
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
|
|
- deleteWrapper.eq(CheckInPeriod::getStatus, "PENDING");
|
|
|
+ deleteWrapper.gt(CheckInPeriod::getStartDate, today);
|
|
|
int deleted = periodMapper.delete(deleteWrapper);
|
|
|
- log.info("已删除{}个PENDING周期", deleted);
|
|
|
+ log.info("已删除{}个未开始周期", deleted);
|
|
|
|
|
|
LocalDate activityStart = config.getStartTime().toLocalDate();
|
|
|
LocalDate activityEnd = config.getEndTime().toLocalDate();
|
|
|
@@ -138,7 +142,8 @@ public class CheckInConfigService {
|
|
|
public void updatePendingPeriodsConfig(CheckInConfig config) {
|
|
|
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> wrapper =
|
|
|
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
|
|
- wrapper.in(CheckInPeriod::getStatus, "PENDING", "ACTIVE");
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ wrapper.ge(CheckInPeriod::getEndDate, today);
|
|
|
List<CheckInPeriod> pendingPeriods = periodMapper.selectList(wrapper);
|
|
|
if (pendingPeriods.isEmpty()) {
|
|
|
return;
|
|
|
@@ -148,9 +153,10 @@ public class CheckInConfigService {
|
|
|
period.setRewardMode(orDefault(config.getRewardMode(), "CUMULATIVE"));
|
|
|
period.setRewardDays(config.getRewardDays());
|
|
|
period.setRewardLevel(orDefault(config.getRewardLevel(), "PRO"));
|
|
|
+ period.setStatus(determineStatus(period.getStartDate(), period.getEndDate()));
|
|
|
periodMapper.updateById(period);
|
|
|
}
|
|
|
- log.info("已同步{}个PENDING/ACTIVE周期的区分信息", pendingPeriods.size());
|
|
|
+ log.info("已同步{}个未结束周期的区分信息", pendingPeriods.size());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -209,7 +215,9 @@ public class CheckInConfigService {
|
|
|
* 判断活动是否进行中(enabled=1 且在活动时间范围内)
|
|
|
*/
|
|
|
public boolean isActive(CheckInConfig config) {
|
|
|
- if (config.getEnabled() == null || config.getEnabled() != 1) return false;
|
|
|
+ if (config.getEnabled() == null || config.getEnabled() != 1) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
return !isBeforeStart(config, now) && !isAfterEnd(config, now);
|
|
|
}
|
|
|
@@ -230,7 +238,15 @@ public class CheckInConfigService {
|
|
|
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> wrapper =
|
|
|
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
|
|
wrapper.orderByAsc(CheckInPeriod::getStartDate);
|
|
|
- return periodMapper.selectList(wrapper);
|
|
|
+ List<CheckInPeriod> periods = periodMapper.selectList(wrapper);
|
|
|
+ for (CheckInPeriod period : periods) {
|
|
|
+ String dynamicStatus = determineStatus(period.getStartDate(), period.getEndDate());
|
|
|
+ if (!dynamicStatus.equals(period.getStatus())) {
|
|
|
+ period.setStatus(dynamicStatus);
|
|
|
+ periodMapper.updateById(period);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return periods;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
@@ -289,8 +305,12 @@ public class CheckInConfigService {
|
|
|
/** 根据日期自动判断周期状态 */
|
|
|
private String determineStatus(LocalDate start, LocalDate end) {
|
|
|
LocalDate today = LocalDate.now();
|
|
|
- if (today.isBefore(start)) return "PENDING";
|
|
|
- if (today.isAfter(end)) return "CLOSED";
|
|
|
+ if (today.isBefore(start)) {
|
|
|
+ return "PENDING";
|
|
|
+ }
|
|
|
+ if (today.isAfter(end)) {
|
|
|
+ return "CLOSED";
|
|
|
+ }
|
|
|
return "ACTIVE";
|
|
|
}
|
|
|
|