You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
5.7 KiB
152 lines
5.7 KiB
package com.example.demo.serviceImpl.coin;
|
|
|
|
import com.example.demo.domain.vo.coin.RechargeActivity;
|
|
import com.example.demo.mapper.coin.RechargeActivityCenterMapper;
|
|
import com.example.demo.service.coin.RechargeActivityCenterService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* @program: gold-java
|
|
* @ClassName RechargeActivityCenterServiceImpl
|
|
* @description: 充值活动中心服务实现类
|
|
* @author: Double
|
|
* @create: 2025−10-28 14:40
|
|
* @Version 1.0
|
|
**/
|
|
|
|
@Service
|
|
public class RechargeActivityCenterServiceImpl implements RechargeActivityCenterService {
|
|
|
|
@Autowired
|
|
private RechargeActivityCenterMapper rechargeActivityCenterMapper;
|
|
|
|
private static final String ACTIVITY_NAME_REGEX = "^[\\u4e00-\\u9fa5a-zA-Z0-9,。!?、;:\"'()《》【】——~,.:;!'()\\[\\]-_&+=]{1,100}$";
|
|
private static final Pattern ACTIVITY_NAME_PATTERN = Pattern.compile(ACTIVITY_NAME_REGEX);
|
|
// 根据ID查询活动
|
|
@Override
|
|
public PageInfo<RechargeActivity> queryActivity(Integer pageNum, Integer pageSize, RechargeActivity activity) {
|
|
updateStatus();
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
List<RechargeActivity> activityList = rechargeActivityCenterMapper.queryActivity(activity);
|
|
return new PageInfo<>(activityList);
|
|
}
|
|
|
|
// 新增活动
|
|
@Override
|
|
public void addActivity(RechargeActivity activity) {
|
|
|
|
if (activity.getActivityName().length() > 100) {
|
|
throw new IllegalArgumentException("活动名称不能超过100个字符");
|
|
}
|
|
RechargeActivity activityByName = rechargeActivityCenterMapper.queryActivityByName(activity);
|
|
if (activityByName != null) {
|
|
throw new IllegalArgumentException("活动名称已存在");
|
|
}
|
|
// 3. 字符格式校验
|
|
if (!ACTIVITY_NAME_PATTERN.matcher(activity.getActivityName()).matches()) {
|
|
throw new IllegalArgumentException("活动名称仅允许包含汉字、英文字母、数字及常见标点符号(中英文标点:,。!?、;:\"'()《》【】——~,.:;!'()[]-_&+=)");
|
|
}
|
|
Date startTime = activity.getStartTime();
|
|
Date endTime = activity.getEndTime();
|
|
|
|
//获取当前系统时间(本地时间,与活动时间时区保持一致)
|
|
Date now = new Date();
|
|
|
|
//时间范围判断,设置对应状态
|
|
if (now.before(startTime)) {
|
|
// 当前时间 < 开始时间 → 未开始(状态0)
|
|
activity.setStatus("0");
|
|
} else if (now.after(endTime)) {
|
|
// 当前时间 > 结束时间 → 已结束(状态2)
|
|
activity.setStatus("2");
|
|
} else {
|
|
// 开始时间 ≤ 当前时间 ≤ 结束时间 → 进行中(状态1)
|
|
activity.setStatus("1");
|
|
}
|
|
rechargeActivityCenterMapper.addActivity(activity);
|
|
}
|
|
|
|
// 更新活动
|
|
@Override
|
|
public void updateActivity(RechargeActivity activity) {
|
|
Date startTime = activity.getStartTime();
|
|
Date endTime = activity.getEndTime();
|
|
|
|
//获取当前系统时间(本地时间,与活动时间时区保持一致)
|
|
Date now = new Date();
|
|
|
|
//时间范围判断,设置对应状态
|
|
if (now.before(startTime)) {
|
|
// 当前时间 < 开始时间 → 未开始(状态0)
|
|
activity.setStatus("0");
|
|
} else if (now.after(endTime)) {
|
|
// 当前时间 > 结束时间 → 已结束(状态2)
|
|
activity.setStatus("2");
|
|
} else {
|
|
// 开始时间 ≤ 当前时间 ≤ 结束时间 → 进行中(状态1)
|
|
activity.setStatus("1");
|
|
}
|
|
rechargeActivityCenterMapper.updateActivity(activity);
|
|
if(Objects.equals(activity.getBusinessBelong(), "客户归属地")){
|
|
rechargeActivityCenterMapper.updateActivityArea(activity);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void updateStatus() {
|
|
// 查询所有活动
|
|
List<RechargeActivity> activityList = rechargeActivityCenterMapper.listActivities();
|
|
|
|
if (activityList == null || activityList.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
Date now = new Date();
|
|
|
|
// 遍历所有活动,更新状态
|
|
for (RechargeActivity activity : activityList) {
|
|
Date startTime = activity.getStartTime();
|
|
Date endTime = activity.getEndTime();
|
|
|
|
// 跳过时间为空的活动
|
|
if (startTime == null || endTime == null) {
|
|
continue;
|
|
}
|
|
|
|
String newStatus;
|
|
|
|
// 时间范围判断,设置对应状态
|
|
if (now.before(startTime)) {
|
|
// 当前时间 < 开始时间 → 未开始(状态0)
|
|
newStatus = "0";
|
|
} else if (now.after(endTime)) {
|
|
// 当前时间 > 结束时间 → 已结束(状态2)
|
|
newStatus = "2";
|
|
} else {
|
|
// 开始时间 ≤ 当前时间 ≤ 结束时间 → 进行中(状态1)
|
|
newStatus = "1";
|
|
}
|
|
|
|
// 只有当状态发生变化时才更新
|
|
if (!newStatus.equals(activity.getStatus())) {
|
|
activity.setStatus(newStatus);
|
|
rechargeActivityCenterMapper.updateActivity(activity);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除活动
|
|
@Override
|
|
public void deleteActivity(RechargeActivity activity) {
|
|
rechargeActivityCenterMapper.deleteActivity(activity);
|
|
}
|
|
}
|