写入功能完成

This commit is contained in:
2026-01-02 17:06:16 +08:00
parent fcdefce214
commit 76ad6bcbd7

View File

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