|
@@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.entity.store.LifeNotice;
|
|
import shop.alien.entity.store.LifeNotice;
|
|
|
import shop.alien.entity.store.LifeUser;
|
|
import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
@@ -173,6 +174,7 @@ public class OperationalActivitySignupServiceImpl implements OperationalActivity
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int approveSignup(Integer id) {
|
|
public int approveSignup(Integer id) {
|
|
|
log.info("OperationalActivitySignupServiceImpl.approveSignup: id={}", id);
|
|
log.info("OperationalActivitySignupServiceImpl.approveSignup: id={}", id);
|
|
|
|
|
|
|
@@ -180,26 +182,37 @@ public class OperationalActivitySignupServiceImpl implements OperationalActivity
|
|
|
throw new IllegalArgumentException("报名ID不能为空");
|
|
throw new IllegalArgumentException("报名ID不能为空");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ StoreOperationalActivitySignup signup = signupMapper.selectById(id);
|
|
|
|
|
+ if (signup == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("报名记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (signup.getStatus() == null || signup.getStatus() != 0) {
|
|
|
|
|
+ throw new IllegalArgumentException("仅待审核的报名可通过");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
LambdaUpdateWrapper<StoreOperationalActivitySignup> wrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StoreOperationalActivitySignup> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.eq(StoreOperationalActivitySignup::getId, id)
|
|
wrapper.eq(StoreOperationalActivitySignup::getId, id)
|
|
|
|
|
+ .eq(StoreOperationalActivitySignup::getStatus, 0)
|
|
|
.set(StoreOperationalActivitySignup::getStatus, 2) // 2-通过
|
|
.set(StoreOperationalActivitySignup::getStatus, 2) // 2-通过
|
|
|
.set(StoreOperationalActivitySignup::getAuditTime, new Date()); // 设置审核时间为当前时间
|
|
.set(StoreOperationalActivitySignup::getAuditTime, new Date()); // 设置审核时间为当前时间
|
|
|
|
|
|
|
|
int result = signupMapper.update(null, wrapper);
|
|
int result = signupMapper.update(null, wrapper);
|
|
|
-
|
|
|
|
|
- // 审核成功后发送通知
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 审核成功后同步活动状态并发送通知
|
|
|
if (result > 0) {
|
|
if (result > 0) {
|
|
|
|
|
+ syncActivitySignupStatus(signup.getActivityId());
|
|
|
try {
|
|
try {
|
|
|
sendApprovalNotice(id, true);
|
|
sendApprovalNotice(id, true);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("发送审核通过通知失败,signupId={}, error={}", id, e.getMessage(), e);
|
|
log.error("发送审核通过通知失败,signupId={}, error={}", id, e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int rejectSignup(Integer id, String rejectReason) {
|
|
public int rejectSignup(Integer id, String rejectReason) {
|
|
|
log.info("OperationalActivitySignupServiceImpl.rejectSignup: id={}, rejectReason={}", id, rejectReason);
|
|
log.info("OperationalActivitySignupServiceImpl.rejectSignup: id={}, rejectReason={}", id, rejectReason);
|
|
|
|
|
|
|
@@ -207,11 +220,20 @@ public class OperationalActivitySignupServiceImpl implements OperationalActivity
|
|
|
throw new IllegalArgumentException("报名ID不能为空");
|
|
throw new IllegalArgumentException("报名ID不能为空");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ StoreOperationalActivitySignup signup = signupMapper.selectById(id);
|
|
|
|
|
+ if (signup == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("报名记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (signup.getStatus() == null || signup.getStatus() != 0) {
|
|
|
|
|
+ throw new IllegalArgumentException("仅待审核的报名可拒绝");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
LambdaUpdateWrapper<StoreOperationalActivitySignup> wrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StoreOperationalActivitySignup> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.eq(StoreOperationalActivitySignup::getId, id)
|
|
wrapper.eq(StoreOperationalActivitySignup::getId, id)
|
|
|
|
|
+ .eq(StoreOperationalActivitySignup::getStatus, 0)
|
|
|
.set(StoreOperationalActivitySignup::getStatus, 1) // 1-拒绝
|
|
.set(StoreOperationalActivitySignup::getStatus, 1) // 1-拒绝
|
|
|
.set(StoreOperationalActivitySignup::getAuditTime, new Date()); // 设置审核时间为当前时间
|
|
.set(StoreOperationalActivitySignup::getAuditTime, new Date()); // 设置审核时间为当前时间
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果提供了拒绝原因,则保存;否则使用默认值
|
|
// 如果提供了拒绝原因,则保存;否则使用默认值
|
|
|
if (rejectReason != null && !rejectReason.trim().isEmpty()) {
|
|
if (rejectReason != null && !rejectReason.trim().isEmpty()) {
|
|
|
wrapper.set(StoreOperationalActivitySignup::getRejectReason, rejectReason.trim());
|
|
wrapper.set(StoreOperationalActivitySignup::getRejectReason, rejectReason.trim());
|
|
@@ -220,20 +242,83 @@ public class OperationalActivitySignupServiceImpl implements OperationalActivity
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int result = signupMapper.update(null, wrapper);
|
|
int result = signupMapper.update(null, wrapper);
|
|
|
-
|
|
|
|
|
- // 审核拒绝后发送通知
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 审核拒绝后同步活动人数与状态,并发送通知
|
|
|
if (result > 0) {
|
|
if (result > 0) {
|
|
|
|
|
+ syncActivitySignupStatus(signup.getActivityId());
|
|
|
try {
|
|
try {
|
|
|
sendApprovalNotice(id, false);
|
|
sendApprovalNotice(id, false);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("发送审核拒绝通知失败,signupId={}, error={}", id, e.getMessage(), e);
|
|
log.error("发送审核拒绝通知失败,signupId={}, error={}", id, e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 根据有效报名人数同步活动状态:
|
|
|
|
|
+ * 满员时将未开始/进行中活动置为已售罄(4);
|
|
|
|
|
+ * 拒绝后名额释放时将已售罄(4)恢复为未开始(2)/进行中(5)。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void syncActivitySignupStatus(Integer activityId) {
|
|
|
|
|
+ if (activityId == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ StoreOperationalActivity activity = activityMapper.selectById(activityId);
|
|
|
|
|
+ if (activity == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer limitPeople = activity.getActivityLimitPeople();
|
|
|
|
|
+ if (limitPeople == null || limitPeople <= 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer signupCount = signupMapper.countSignupByActivityId(activityId);
|
|
|
|
|
+ int currentCount = signupCount != null ? signupCount : 0;
|
|
|
|
|
+ Integer currentStatus = activity.getStatus();
|
|
|
|
|
+ Integer targetStatus = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (currentCount >= limitPeople) {
|
|
|
|
|
+ if (currentStatus != null && (currentStatus == 2 || currentStatus == 5)) {
|
|
|
|
|
+ targetStatus = 4;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (currentStatus != null && currentStatus == 4) {
|
|
|
|
|
+ targetStatus = resolveTimelineStatus(activity);
|
|
|
|
|
+ if (targetStatus != 2 && targetStatus != 5) {
|
|
|
|
|
+ targetStatus = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (targetStatus != null && !targetStatus.equals(currentStatus)) {
|
|
|
|
|
+ LambdaUpdateWrapper<StoreOperationalActivity> activityWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ activityWrapper.eq(StoreOperationalActivity::getId, activityId)
|
|
|
|
|
+ .set(StoreOperationalActivity::getStatus, targetStatus);
|
|
|
|
|
+ activityMapper.update(null, activityWrapper);
|
|
|
|
|
+ log.info("同步活动报名状态,activityId={}, signupCount={}, limitPeople={}, status: {} -> {}",
|
|
|
|
|
+ activityId, currentCount, limitPeople, currentStatus, targetStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按活动时间轴计算未开始/进行中/已结束状态。
|
|
|
|
|
+ */
|
|
|
|
|
+ private int resolveTimelineStatus(StoreOperationalActivity activity) {
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ if (activity.getStartTime() == null || activity.getEndTime() == null) {
|
|
|
|
|
+ return 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (now.before(activity.getStartTime())) {
|
|
|
|
|
+ return 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!now.after(activity.getEndTime())) {
|
|
|
|
|
+ return 5;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 7;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取状态文字
|
|
* 获取状态文字
|
|
|
*
|
|
*
|
|
|
* @param status 状态值
|
|
* @param status 状态值
|