|
|
|
@ -382,9 +382,181 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 同意预约 |
|
|
|
* <p> |
|
|
|
* opOrder==0 时为第一个操作的用户: |
|
|
|
* - 必须传入 opSetDate、opSetTime(用户选择的时间) |
|
|
|
* - 重新设置同组记录的 opOrder 为 1,2,3,4,5... |
|
|
|
* - 更新当前记录及关联记录的 op_set_date、op_set_time |
|
|
|
* - 生成 warringMessage,设置到关联记录(warring_is_pass=0) |
|
|
|
* - 当前记录 warring_is_pass=1 |
|
|
|
* <p> |
|
|
|
* opOrder>0 时为后续操作的用户: |
|
|
|
* - 设置当前记录 warring_is_pass=1 |
|
|
|
* - 备份关联计划的 plan_date/plan_time 到 plan_source_date/plan_source_time |
|
|
|
* - 将预约的 op_set_date/op_set_time 更新回关联计划的 plan_date/plan_time |
|
|
|
* - 同步更新 efcode_cp_plan 的 reserve_status |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public R<Void> approveReserveBySystem(String reserveId, String opSetDate, Long opSetTime) { |
|
|
|
EfcodeCpReserve reserve = baseMapper.selectById(reserveId); |
|
|
|
if (reserve == null) { |
|
|
|
return R.fail("预约记录不存在"); |
|
|
|
} |
|
|
|
if (!Long.valueOf(3L).equals(reserve.getOpStatus())) { |
|
|
|
return R.fail("该预约记录已被处理"); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询关联计划
|
|
|
|
EfcodeCpPlan myPlan = cpPlanMapper.selectById(reserve.getPlanId()); |
|
|
|
if (myPlan == null) { |
|
|
|
return R.fail("关联计划不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询同组其他预约记录
|
|
|
|
List<EfcodeCpReserve> groupReserves = baseMapper.selectList( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, reserve.getPlanGroupId()) |
|
|
|
.ne(EfcodeCpReserve::getId, reserveId) |
|
|
|
); |
|
|
|
|
|
|
|
if (reserve.getOpOrder() != null && reserve.getOpOrder() == 0L) { |
|
|
|
// ===== opOrder==0:第一个操作的用户 =====
|
|
|
|
if (StringUtils.isBlank(opSetDate) || opSetTime == null) { |
|
|
|
return R.fail("请选择执行时间"); |
|
|
|
} |
|
|
|
|
|
|
|
// 解析日期
|
|
|
|
Date selectedDate; |
|
|
|
try { |
|
|
|
selectedDate = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(opSetDate); |
|
|
|
} catch (Exception e) { |
|
|
|
return R.fail("日期格式不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 更新当前记录:同意 + 设置时间 + warring_is_pass=1
|
|
|
|
reserve.setOpStatus(1L); |
|
|
|
reserve.setOpTime(new Date()); |
|
|
|
reserve.setOpSetDate(selectedDate); |
|
|
|
reserve.setOpSetTime(opSetTime); |
|
|
|
reserve.setWarringIsPass(1); |
|
|
|
reserve.setOpOrder(1L); // 第一个操作用户排序号为1
|
|
|
|
baseMapper.updateById(reserve); |
|
|
|
|
|
|
|
// 2. 生成 warringMessage
|
|
|
|
String timeDesc = opSetDate + " " + getPlanTimeText(opSetTime); |
|
|
|
String warringMsg = "第一个操作的" + myPlan.getBureauDeptName() + "执法部门用户选择了" + timeDesc + "时间,请确认时间安排是否合适"; |
|
|
|
|
|
|
|
// 3. 更新关联记录:设置 op_set_date/op_set_time、warringMessage、warring_is_pass=0、重新分配 opOrder
|
|
|
|
int order = 2; |
|
|
|
for (EfcodeCpReserve r : groupReserves) { |
|
|
|
r.setOpSetDate(selectedDate); |
|
|
|
r.setOpSetTime(opSetTime); |
|
|
|
r.setWarringMessage(warringMsg); |
|
|
|
r.setWarringIsPass(0); |
|
|
|
r.setOpOrder((long) order++); |
|
|
|
baseMapper.updateById(r); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 备份当前计划的 plan_date/plan_time 到 plan_source_date/plan_source_time,并更新为选定时间
|
|
|
|
EfcodeCpPlan planUpdate = new EfcodeCpPlan(); |
|
|
|
planUpdate.setId(myPlan.getId()); |
|
|
|
if (myPlan.getPlanSourceDate() == null) { |
|
|
|
// 只有第一次才备份,避免多次覆盖
|
|
|
|
planUpdate.setPlanSourceDate(myPlan.getPlanDate()); |
|
|
|
planUpdate.setPlanSourceTime(myPlan.getPlanTime()); |
|
|
|
} |
|
|
|
planUpdate.setPlanDate(selectedDate); |
|
|
|
planUpdate.setPlanTime(opSetTime); |
|
|
|
planUpdate.setReserveStatus(3L); // 预约完成
|
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
|
|
|
|
} else { |
|
|
|
// ===== opOrder>0:后续操作的用户 =====
|
|
|
|
|
|
|
|
// 1. 设置当前记录:同意 + warring_is_pass=1
|
|
|
|
reserve.setOpStatus(1L); |
|
|
|
reserve.setOpTime(new Date()); |
|
|
|
reserve.setWarringIsPass(1); |
|
|
|
baseMapper.updateById(reserve); |
|
|
|
|
|
|
|
// 2. 备份关联计划的 plan_date/plan_time 到 plan_source_date/plan_source_time
|
|
|
|
EfcodeCpPlan planUpdate = new EfcodeCpPlan(); |
|
|
|
planUpdate.setId(myPlan.getId()); |
|
|
|
if (myPlan.getPlanSourceDate() == null) { |
|
|
|
// 只有第一次才备份,避免多次覆盖
|
|
|
|
planUpdate.setPlanSourceDate(myPlan.getPlanDate()); |
|
|
|
planUpdate.setPlanSourceTime(myPlan.getPlanTime()); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 将预约的 op_set_date/op_set_time 更新回关联计划的 plan_date/plan_time
|
|
|
|
planUpdate.setPlanDate(reserve.getOpSetDate()); |
|
|
|
planUpdate.setPlanTime(reserve.getOpSetTime()); |
|
|
|
planUpdate.setReserveStatus(3L); // 预约完成
|
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
} |
|
|
|
|
|
|
|
// 后置处理:检查是否所有同组记录都已同意,若是则生成任务
|
|
|
|
afterApproveCheck(reserve); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 同意操作后置检查:检查同组是否全部同意,若是则生成任务 |
|
|
|
*/ |
|
|
|
private void afterApproveCheck(EfcodeCpReserve reserve) { |
|
|
|
if (StringUtils.isBlank(reserve.getPlanGroupId())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// 查询同组全部记录
|
|
|
|
List<EfcodeCpReserve> allGroupReserves = baseMapper.selectList( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, reserve.getPlanGroupId()) |
|
|
|
); |
|
|
|
// 检查是否全部同意
|
|
|
|
boolean allApproved = allGroupReserves.stream() |
|
|
|
.allMatch(r -> Long.valueOf(1L).equals(r.getOpStatus())); |
|
|
|
if (!allApproved) { |
|
|
|
log.info("[预约后置] planGroupId={} 尚有未同意的记录,等待其他用户操作", reserve.getPlanGroupId()); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 全部同意:生成1条任务,所有同组计划共享该 task_id
|
|
|
|
String sharedTaskId = null; |
|
|
|
for (EfcodeCpReserve r : allGroupReserves) { |
|
|
|
EfcodeCpPlan plan = cpPlanMapper.selectById(r.getPlanId()); |
|
|
|
if (plan == null || StringUtils.isNotBlank(plan.getTaskId())) continue; |
|
|
|
if (sharedTaskId == null) { |
|
|
|
sharedTaskId = cpTaskService.forceGenerateTask(plan); |
|
|
|
} else { |
|
|
|
EfcodeCpPlan planUpdate = new EfcodeCpPlan(); |
|
|
|
planUpdate.setId(plan.getId()); |
|
|
|
planUpdate.setTaskId(sharedTaskId); |
|
|
|
planUpdate.setReserveStatus(3L); |
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
} |
|
|
|
} |
|
|
|
log.info("[预约后置] planGroupId={} 全部同意,生成任务taskId={},关联{}条计划", |
|
|
|
reserve.getPlanGroupId(), sharedTaskId, allGroupReserves.size()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 时段文本 |
|
|
|
*/ |
|
|
|
private String getPlanTimeText(Long time) { |
|
|
|
if (time == null) return ""; |
|
|
|
switch (time.intValue()) { |
|
|
|
case 1: return "上午"; |
|
|
|
case 2: return "下午"; |
|
|
|
case 3: return "其他"; |
|
|
|
default: return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 同意预约(手动匹配专用分支) |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public R<Void> approveReserve(String reserveId) { |
|
|
|
public R<Void> approveReserveByManual(String reserveId) { |
|
|
|
EfcodeCpReserve reserve = baseMapper.selectById(reserveId); |
|
|
|
if (reserve == null) { |
|
|
|
return R.fail("预约记录不存在"); |
|
|
|
@ -436,42 +608,6 @@ public class EfcodeCpReserveServiceImpl implements IEfcodeCpReserveService { |
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
log.info("[预约后置] 计划[{}] reserve_status 更新为 {}", reserve.getPlanId(), newPlanStatus); |
|
|
|
} |
|
|
|
|
|
|
|
// 同意操作后:检查同一 planGroupId 已同意数量是否达到最大联合单位数
|
|
|
|
if ("approve".equals(action) && StringUtils.isNotBlank(reserve.getPlanGroupId())) { |
|
|
|
int maxUnionUnit = cpSettingService.getMaxUnionUnit(); |
|
|
|
long approvedCount = baseMapper.selectCount( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, reserve.getPlanGroupId()) |
|
|
|
.eq(EfcodeCpReserve::getOpStatus, 1L) // 1=已同意
|
|
|
|
); |
|
|
|
log.info("[预约后置] planGroupId={}, 已同意数量={}, 最大联合数={}", reserve.getPlanGroupId(), approvedCount, maxUnionUnit); |
|
|
|
if (approvedCount >= maxUnionUnit) { |
|
|
|
// 达标:只生成1条任务,所有同组计划共享该task_id
|
|
|
|
List<EfcodeCpReserve> groupReserves = baseMapper.selectList( |
|
|
|
Wrappers.<EfcodeCpReserve>lambdaQuery() |
|
|
|
.eq(EfcodeCpReserve::getPlanGroupId, reserve.getPlanGroupId()) |
|
|
|
.eq(EfcodeCpReserve::getOpStatus, 1L) |
|
|
|
); |
|
|
|
String sharedTaskId = null; |
|
|
|
for (EfcodeCpReserve r : groupReserves) { |
|
|
|
EfcodeCpPlan plan = cpPlanMapper.selectById(r.getPlanId()); |
|
|
|
if (plan == null || StringUtils.isNotBlank(plan.getTaskId())) continue; |
|
|
|
if (sharedTaskId == null) { |
|
|
|
// 用第一条计划生成唯一一条任务
|
|
|
|
sharedTaskId = cpTaskService.forceGenerateTask(plan); |
|
|
|
} else { |
|
|
|
// 其余计划直接回写同一个task_id
|
|
|
|
EfcodeCpPlan planUpdate = new EfcodeCpPlan(); |
|
|
|
planUpdate.setId(plan.getId()); |
|
|
|
planUpdate.setTaskId(sharedTaskId); |
|
|
|
planUpdate.setReserveStatus(3L); |
|
|
|
cpPlanMapper.updateById(planUpdate); |
|
|
|
} |
|
|
|
} |
|
|
|
log.info("[预约后置] planGroupId={} 联合数量达标,生成1条任务taskId={},关联{}条计划", reserve.getPlanGroupId(), sharedTaskId, groupReserves.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|