|
|
|
@ -167,7 +167,7 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 预约前置检查 |
|
|
|
* 预约前置检查(包含所有前置校验逻辑) |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public R<Void> checkCanReserve(String targetPlanId) { |
|
|
|
@ -177,11 +177,48 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
if (targetPlan == null) { |
|
|
|
return R.fail("目标计划不存在"); |
|
|
|
} |
|
|
|
// 1.1 校验目标计划状态:只有待预约(1)、已取消(4)、预约中可加入(5)的计划才允许预约
|
|
|
|
Long reserveStatus = targetPlan.getReserveStatus(); |
|
|
|
if (reserveStatus == null || !Arrays.asList(1L, 4L, 5L).contains(reserveStatus)) { |
|
|
|
return R.fail("该计划当前状态不允许预约"); |
|
|
|
} |
|
|
|
// 2. 判断当前用户是否有同一时间+同一时段+同一企业的计划
|
|
|
|
EfcodeCpPlan myPlan = findMyMatchingPlan(targetPlan, currentUserId); |
|
|
|
if (myPlan == null) { |
|
|
|
return R.fail("请先添加我的计划再进行预约"); |
|
|
|
} |
|
|
|
// 2.1 校验我的计划状态:只有待预约(1)、已取消(4)、预约中可加入(5)的计划才允许发起预约
|
|
|
|
Long myReserveStatus = myPlan.getReserveStatus(); |
|
|
|
if (myReserveStatus == null || !Arrays.asList(1L, 4L, 5L).contains(myReserveStatus)) { |
|
|
|
return R.fail("您的计划当前状态不允许发起预约"); |
|
|
|
} |
|
|
|
// 2.2 我的计划在efcode_cp_reserve只能存在一条op_status为3的记录
|
|
|
|
long pendingCount = baseMapper.selectCount( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanId, myPlan.getId()) |
|
|
|
.eq(EfcodeCpReserve::getOpStatus, 3L) |
|
|
|
); |
|
|
|
if (pendingCount > 0) { |
|
|
|
return R.fail("您的这条计划已有一条待确认的预约记录,请等待对方处理后再发起新预约"); |
|
|
|
} |
|
|
|
// 2.3 如果我的计划已经作为plan_group_id而存在,则不允许发起预约,除非其他的所有记录的op_status都是2或4
|
|
|
|
String myPlanId = myPlan.getId(); |
|
|
|
long groupCount = baseMapper.selectCount( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, myPlanId) |
|
|
|
); |
|
|
|
if (groupCount > 0) { |
|
|
|
List<EfcodeCpReserve> otherReserves = baseMapper.selectList( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, myPlanId) |
|
|
|
.ne(EfcodeCpReserve::getPlanId, myPlanId) |
|
|
|
); |
|
|
|
boolean allRejectedOrCancelled = otherReserves.stream() |
|
|
|
.allMatch(r -> r.getOpStatus() != null && (r.getOpStatus() == 2L || r.getOpStatus() == 4L)); |
|
|
|
if (!allRejectedOrCancelled) { |
|
|
|
return R.fail("您的计划已有进行中的预约分组,无法再发起新预约"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 3. 判断 plan_group_id 人数是否已达上限
|
|
|
|
String planGroupId = findExistingPlanGroupId(targetPlanId); |
|
|
|
if (planGroupId != null) { |
|
|
|
@ -205,17 +242,16 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public R<Void> doReserve(String targetPlanId, String opMessage) { |
|
|
|
// 前置校验(与 checkCanReserve 一致)
|
|
|
|
R<Void> checkResult = checkCanReserve(targetPlanId); |
|
|
|
if (checkResult.getCode() != 200) { |
|
|
|
return checkResult; |
|
|
|
} |
|
|
|
|
|
|
|
Long currentUserId = LoginHelper.getUserId(); |
|
|
|
// 1. 查询目标计划
|
|
|
|
EfcodeCpPlan targetPlan = cpPlanMapper.selectById(targetPlanId); |
|
|
|
if (targetPlan == null) { |
|
|
|
return R.fail("目标计划不存在"); |
|
|
|
} |
|
|
|
// 2. 查找当前用户匹配的计划
|
|
|
|
EfcodeCpPlan myPlan = findMyMatchingPlan(targetPlan, currentUserId); |
|
|
|
if (myPlan == null) { |
|
|
|
return R.fail("请先添加我的计划再进行预约"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 判断目标计划在reserve表中是否已存在
|
|
|
|
String planGroupId = findExistingPlanGroupId(targetPlanId); |
|
|
|
int maxUnionUnit = cpSettingService.getMaxUnionUnit(); |
|
|
|
@ -229,9 +265,9 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
String senderIdStr = String.valueOf(currentUserId); |
|
|
|
String receiverIdStr = String.valueOf(targetPlan.getCreateBy()); |
|
|
|
// 目标计划记录
|
|
|
|
insertReserveRecord(targetPlanId, planGroupId, "", targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, senderIdStr, receiverIdStr); |
|
|
|
insertReserveRecord(targetPlanId, planGroupId, "", targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, 1L, "manual_system_sender", receiverIdStr); |
|
|
|
// 我的计划记录
|
|
|
|
insertReserveRecord(myPlan.getId(), planGroupId, opMessage, targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, senderIdStr, receiverIdStr); |
|
|
|
insertReserveRecord(myPlan.getId(), planGroupId, opMessage, targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, 3L, senderIdStr, receiverIdStr); |
|
|
|
} else { |
|
|
|
// 已存在:检查人数上限
|
|
|
|
long activeCount = countActiveReserves(planGroupId); |
|
|
|
@ -244,7 +280,7 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
return R.fail("您已经预约过该计划"); |
|
|
|
} |
|
|
|
// 插入1条记录
|
|
|
|
insertReserveRecord(myPlan.getId(), planGroupId, opMessage, targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, String.valueOf(currentUserId), String.valueOf(targetPlan.getCreateBy())); |
|
|
|
insertReserveRecord(myPlan.getId(), planGroupId, opMessage, targetPlan.getPlanDate(), targetPlan.getPlanTime(), 0L, 3L, String.valueOf(currentUserId), String.valueOf(targetPlan.getCreateBy())); |
|
|
|
} |
|
|
|
|
|
|
|
// ===== 插入预约记录后:更新两个计划的 reserve_status =====
|
|
|
|
@ -323,16 +359,17 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
/** |
|
|
|
* 插入一条预约记录 |
|
|
|
* |
|
|
|
* @param opStatus 操作状态:1=同意,2=拒绝,3=待确认,4=超期取消 |
|
|
|
* @param senderId 发送者用户ID |
|
|
|
* @param receiverId 接收者用户ID |
|
|
|
*/ |
|
|
|
private void insertReserveRecord(String planId, String planGroupId, String opMessage, Date opSetDate, Long opSetTime, Long resFrom, |
|
|
|
String senderId, String receiverId) { |
|
|
|
Long opStatus, String senderId, String receiverId) { |
|
|
|
EfcodeCpReserve record = new EfcodeCpReserve(); |
|
|
|
record.setPlanId(planId); |
|
|
|
record.setPlanGroupId(planGroupId); |
|
|
|
record.setReserveTime(new Date()); |
|
|
|
record.setOpStatus(3L); // 待确认
|
|
|
|
record.setOpStatus(opStatus); |
|
|
|
record.setOpOrder(0L); |
|
|
|
record.setOpMessage(opMessage); |
|
|
|
record.setOpSetDate(opSetDate); |
|
|
|
@ -389,6 +426,17 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
*/ |
|
|
|
private void afterOperate(EfcodeCpReserve reserve, String action) { |
|
|
|
log.info("预约记录[{}]执行{}操作后置处理, planGroupId={}", reserve.getId(), action, reserve.getPlanGroupId()); |
|
|
|
|
|
|
|
// 同步更新对应计划的 reserve_status:同意→3(预约完成),拒绝→4(重新预约中)
|
|
|
|
if (StringUtils.isNotBlank(reserve.getPlanId())) { |
|
|
|
Long newPlanStatus = "approve".equals(action) ? 3L : 4L; |
|
|
|
EfcodeCpPlan planUpdate = new EfcodeCpPlan(); |
|
|
|
planUpdate.setId(reserve.getPlanId()); |
|
|
|
planUpdate.setReserveStatus(newPlanStatus); |
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
log.info("[预约后置] 计划[{}] reserve_status 更新为 {}", reserve.getPlanId(), newPlanStatus); |
|
|
|
} |
|
|
|
|
|
|
|
// 同意操作后:检查同一 planGroupId 已同意数量是否达到最大联合单位数
|
|
|
|
if ("approve".equals(action) && StringUtils.isNotBlank(reserve.getPlanGroupId())) { |
|
|
|
int maxUnionUnit = cpSettingService.getMaxUnionUnit(); |
|
|
|
|