diff --git a/src/main/java/com/budwk/app/zhgh/activity/family/service/impl/FamilyActivityServiceImpl.java b/src/main/java/com/budwk/app/zhgh/activity/family/service/impl/FamilyActivityServiceImpl.java index e68f734..002d45a 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/family/service/impl/FamilyActivityServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/activity/family/service/impl/FamilyActivityServiceImpl.java @@ -755,7 +755,25 @@ public class FamilyActivityServiceImpl extends BaseServiceImpl i if (currentSignUp == null || !Objects.equals(currentSignUp.getId(), familyUser.getId())) { throw new BaseException("未找到本人在该课程的报名信息"); } - validateUpdateSignUpData(familyUser, currentSignUp); + FamilyCourse course = dao().fetch(FamilyCourse.class, familyUser.getCourseId()); + if (course == null || !Objects.equals(course.getActivityId(), currentSignUp.getActivityId())) { + throw new BaseException("报名课程不存在或已变更"); + } + FamilyActivity activity = dao().fetch(FamilyActivity.class, course.getActivityId()); + validateSignUpTimeAndScope(activity, currentUserId, true); + FamilyType type = dao().fetch(FamilyType.class, course.getCourseType()); + if (type == null) { + throw new BaseException("报名类型不存在或已变更"); + } + validateUpdateSignUpData(familyUser, currentSignUp, course, activity, type); + + // 正式报名和候补转正都占正式名额,按类型计人数以识别本次修改实际释放的名额。 + int oldFamilyNumber = Lang.isNotEmpty(currentSignUp.getMobileColumnsValue()) + ? currentSignUp.getMobileColumnsValue().size() : 0; + boolean releasedFormalSlots = (Objects.equals(currentSignUp.getState(), 1) + || Objects.equals(currentSignUp.getState(), 3)) + && getFamilyContribution(type, oldFamilyNumber) + > getFamilyContribution(type, familyUser.getMobileColumnsValue().size()); String oldActivityCourseId = currentSignUp.getActivityCourseId(); currentSignUp.setMobile(familyUser.getMobile()); @@ -763,26 +781,21 @@ public class FamilyActivityServiceImpl extends BaseServiceImpl i currentSignUp.setActivityCourseId(familyUser.getActivityCourseId()); dao().update(currentSignUp); syncUpdatedUserCourse(currentSignUp, oldActivityCourseId); + // 保存减员及其时段记录后,在同一课程锁内按最新占用人数执行递补。 + if (releasedFormalSlots && Objects.equals(course.getReserveMode(), 2) && isWithinSignUpTime(activity)) { + promoteWaitingUsers(course); + } return currentSignUp; } /** - * 修改按钮预校验与最终保存共用本方法,确保两处业务规则不会产生偏差。 + * 保存修改前校验家属信息、报名名额与时段,人数及冲突校验须排除本人的原记录。 */ - private void validateUpdateSignUpData(FamilyUser familyUser, FamilyUser currentSignUp) { - FamilyCourse course = dao().fetch(FamilyCourse.class, familyUser.getCourseId()); - if (course == null || !Objects.equals(course.getActivityId(), currentSignUp.getActivityId())) { - throw new BaseException("报名课程不存在或已变更"); - } - FamilyActivity activity = dao().fetch(FamilyActivity.class, course.getActivityId()); - validateSignUpTimeAndScope(activity, SecurityUtil.getUserId(), true); + private void validateUpdateSignUpData(FamilyUser familyUser, FamilyUser currentSignUp, + FamilyCourse course, FamilyActivity activity, FamilyType type) { if (!Boolean.TRUE.equals(course.getCourseIsLimitApply())) { familyUser.setActivityCourseId(null); } - FamilyType type = dao().fetch(FamilyType.class, course.getCourseType()); - if (type == null) { - throw new BaseException("报名类型不存在或已变更"); - } if (Lang.isEmpty(familyUser.getMobileColumnsValue())) { throw new BaseException("请填写" + activity.getKeyWord() + "信息");