写入功能完成

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 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<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(
new LambdaQueryWrapper<BizSendJob>()
.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<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(
new LambdaQueryWrapper<BizSendJobItem>()
.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
}