diff --git a/business/src/main/java/com/fizz/business/service/impl/SendJobQueryServiceImpl.java b/business/src/main/java/com/fizz/business/service/impl/SendJobQueryServiceImpl.java index aaa5910..976c6ed 100644 --- a/business/src/main/java/com/fizz/business/service/impl/SendJobQueryServiceImpl.java +++ b/business/src/main/java/com/fizz/business/service/impl/SendJobQueryServiceImpl.java @@ -16,6 +16,7 @@ import com.fizz.business.service.IBizSendTemplateService; import com.fizz.business.service.ISendJobQueryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.lang.reflect.Field; import java.util.Collections; @@ -44,11 +45,26 @@ public class SendJobQueryServiceImpl implements ISendJobQueryService { @Override public SendJobLastSuccessVO getLastSuccess(String groupType) { - // 1) 先找最近一次 COMPLETED 的 job(倒序) + // 1. 根据 groupType 从 group 表中找到所有相关的 job_id + List groupsWithType = groupMapper.selectList( + new LambdaQueryWrapper().eq(BizSendJobGroup::getGroupType, groupType) + ); + + if (CollectionUtils.isEmpty(groupsWithType)) { + // 如果一个相关的 group 都没有,直接走 fallback 逻辑 + return getFallbackValues(groupType); + } + + List jobIds = groupsWithType.stream() + .map(BizSendJobGroup::getJobId) + .distinct() + .collect(Collectors.toList()); + + // 2. 在这些 job_id 中,找到状态为 COMPLETED 且时间最新的一个 job BizSendJob lastJob = jobMapper.selectOne( new LambdaQueryWrapper() + .in(BizSendJob::getJobId, jobIds) .eq(BizSendJob::getStatus, "COMPLETED") - .eq(BizSendJob::getGroupType, groupType) .orderByDesc(BizSendJob::getFinishTime) .last("LIMIT 1") ); @@ -60,10 +76,10 @@ public class SendJobQueryServiceImpl implements ISendJobQueryService { .eq(BizSendJobGroup::getJobId, lastJob.getJobId()) ); if (groups != null && !groups.isEmpty()) { - List groupIds = groups.stream().map(BizSendJobGroup::getGroupId).collect(Collectors.toList()); + List groupIdsForJob = groups.stream().map(BizSendJobGroup::getGroupId).collect(Collectors.toList()); List items = itemMapper.selectList( new LambdaQueryWrapper() - .in(BizSendJobItem::getGroupId, groupIds) + .in(BizSendJobItem::getGroupId, groupIdsForJob) .eq(BizSendJobItem::getResultStatus, "SUCCESS") .orderByAsc(BizSendJobItem::getItemId) ); @@ -84,13 +100,16 @@ public class SendJobQueryServiceImpl implements ISendJobQueryService { } } - // 2) 如果没找到,根据 groupType 返回模板或计划值 + // 如果没找到符合条件的 job,走 fallback 逻辑 + return getFallbackValues(groupType); + } + + private SendJobLastSuccessVO getFallbackValues(String groupType) { if ("FURNACE".equalsIgnoreCase(groupType)) { return getFurnaceTemplateValues(); } else if ("DRIVE".equalsIgnoreCase(groupType)) { return getDrivePlanValues(); } - return null; // 其他情况返回 null }