|
|
|
@ -745,7 +745,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public Map<String, List<EfcodeCpReserve>> autoMatchReserveV3(boolean forceMatch, boolean updatePlan, boolean insertReserve) { |
|
|
|
log.info("[CpPlan-V2] 开始执行计划自动匹配预约, forceMatch={}, updatePlan={}, insertReserve={}", forceMatch, updatePlan, insertReserve); |
|
|
|
log.info("[CpPlan-V3] 开始执行计划自动匹配预约, forceMatch={}, updatePlan={}, insertReserve={}", forceMatch, updatePlan, insertReserve); |
|
|
|
Map<String, List<EfcodeCpReserve>> resultMap = new HashMap<>(); |
|
|
|
|
|
|
|
// 1. 日期校验:如果不是强制匹配,则判断当前天数是否等于 CP_SETTING_AUTO_MATCH_START
|
|
|
|
@ -753,7 +753,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
int autoMatchStart = cpSettingService.getAutoMatchStart(); |
|
|
|
int today = LocalDate.now().getDayOfMonth(); |
|
|
|
if (today != autoMatchStart) { |
|
|
|
log.info("[CpPlan-V2] 当前日期{}号,不等于设定的自动匹配日期{}号,跳过执行", today, autoMatchStart); |
|
|
|
log.info("[CpPlan-V3] 当前日期{}号,不等于设定的自动匹配日期{}号,跳过执行", today, autoMatchStart); |
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -763,7 +763,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
|
|
|
|
// 2.1 获取系统匹配预约周数范围
|
|
|
|
int systemMatchWeeks = cpSettingService.getSystemMatchWeeks(); |
|
|
|
log.info("[CpPlan-V2] 系统匹配周数范围={}", systemMatchWeeks); |
|
|
|
log.info("[CpPlan-V3] 系统匹配周数范围={}", systemMatchWeeks); |
|
|
|
|
|
|
|
// 3. 查询待匹配的计划:plan_date > 当前时间 且 system_reserved=0, manual_reserved=0, reserve_status=1, is_public=1, is_union=1
|
|
|
|
Date now = new Date(); |
|
|
|
@ -780,11 +780,11 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
List<EfcodeCpPlan> pendingPlans = baseMapper.selectList(lqw); |
|
|
|
|
|
|
|
if (pendingPlans.isEmpty()) { |
|
|
|
log.info("[CpPlan-V2] 没有找到待匹配的计划记录,执行结束"); |
|
|
|
log.info("[CpPlan-V3] 没有找到待匹配的计划记录,执行结束"); |
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
|
|
|
|
log.info("[CpPlan-V2] 共查询到{}条待匹配计划", pendingPlans.size()); |
|
|
|
log.info("[CpPlan-V3] 共查询到{}条待匹配计划", pendingPlans.size()); |
|
|
|
|
|
|
|
// 预查询所有待匹配计划的手动联合记录,构建互斥关系映射(已手动联合的计划对不应再被放入同一系统组)
|
|
|
|
Set<String> pendingPlanIdSet = pendingPlans.stream() |
|
|
|
@ -811,7 +811,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
} |
|
|
|
} |
|
|
|
manualUnionPeers.forEach((pid, peers) -> peers.remove(pid)); |
|
|
|
log.info("[CpPlan-V2] 存在手动联合互斥关系的计划数量: {}", manualUnionPeers.size()); |
|
|
|
log.info("[CpPlan-V3] 存在手动联合互斥关系的计划数量: {}", manualUnionPeers.size()); |
|
|
|
|
|
|
|
// 存储将要保存的联合记录列表
|
|
|
|
List<EfcodeCpReserve> unionReserveList = new ArrayList<>(); |
|
|
|
@ -825,7 +825,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
if (processedPlanIds.contains(plan.getId())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
log.info("[CpPlan-V2] 开始处理计划记录,计划ID={}", plan.getId()); |
|
|
|
log.info("[CpPlan-V3] 开始处理计划记录,计划ID={}", plan.getId()); |
|
|
|
String enterpriseNumber = plan.getEnterpriseNumber(); |
|
|
|
if (StringUtils.isBlank(enterpriseNumber)) { |
|
|
|
continue; |
|
|
|
@ -835,7 +835,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
LocalDate planLocalDate = plan.getPlanDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
|
LocalDate weekStartDate = planLocalDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); |
|
|
|
LocalDate weekEndDate = weekStartDate.plusWeeks(systemMatchWeeks).minusDays(1); // 扩展N周后的周日
|
|
|
|
log.info("[CpPlan-V2] 计划ID={}的时间范围是:{} ~ {}", plan.getId(), weekStartDate, weekEndDate); |
|
|
|
log.info("[CpPlan-V3] 计划ID={}的时间范围是:{} ~ {}", plan.getId(), weekStartDate, weekEndDate); |
|
|
|
|
|
|
|
// 6. 获取当前计划的手动联合伙伴(与当前计划已手动联合过的计划ID)
|
|
|
|
Set<String> currentPlanPeers = manualUnionPeers.getOrDefault(plan.getId(), Collections.emptySet()); |
|
|
|
@ -869,7 +869,7 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
}) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
log.info("[CpPlan-V2] 计划ID={}, 在时间范围内找到{}条非本人发布的同企业候选计划", plan.getId(), matchedPlans.size()); |
|
|
|
log.info("[CpPlan-V3] 计划ID={}, 在时间范围内找到{}条非本人发布的同企业候选计划", plan.getId(), matchedPlans.size()); |
|
|
|
|
|
|
|
// 8. 从matchedPlans中选取计划,确保同组内不含已手动联合过的计划对
|
|
|
|
int limit = maxUnionUnit - 1; |
|
|
|
@ -885,11 +885,11 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.info("[CpPlan-V2] 计划ID={}, 最终选取{}条计划参与联合(最大允许{}条)", plan.getId(), selectedPlans.size(), limit); |
|
|
|
log.info("[CpPlan-V3] 计划ID={}, 最终选取{}条计划参与联合(最大允许{}条)", plan.getId(), selectedPlans.size(), limit); |
|
|
|
|
|
|
|
// 8. 如果没有可联合的计划,跳过
|
|
|
|
if (selectedPlans.isEmpty()) { |
|
|
|
log.debug("[CpPlan-V2] 计划ID={} 没有找到可联合的计划,跳过", plan.getId()); |
|
|
|
log.debug("[CpPlan-V3] 计划ID={} 没有找到可联合的计划,跳过", plan.getId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
@ -951,11 +951,11 @@ public class EfcodeCpPlanServiceImpl implements IEfcodeCpPlanService { |
|
|
|
} |
|
|
|
|
|
|
|
matchedCount++; |
|
|
|
log.info("[CpPlan-V2] 计划ID={} 匹配成功,联合{}个单位,planGroupId={}", |
|
|
|
log.info("[CpPlan-V3] 计划ID={} 匹配成功,联合{}个单位,planGroupId={}", |
|
|
|
plan.getId(), groupPlans.size(), planGroupId); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("[CpPlan-V2] 计划自动匹配预约执行完毕,共匹配{}组联合预约,共生成{}条预约记录", matchedCount, unionReserveList.size()); |
|
|
|
log.info("[CpPlan-V3] 计划自动匹配预约执行完毕,共匹配{}组联合预约,共生成{}条预约记录", matchedCount, unionReserveList.size()); |
|
|
|
|
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
|