You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.0 KiB
57 lines
2.0 KiB
package com.autovoucher.job;
|
|
|
|
import com.autovoucher.config.AppProperties;
|
|
import com.autovoucher.domain.ScheduledJob;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Pushes due vouchers to NCC. The cadence comes from the job's cron expression,
|
|
* replacing the former fixed-delay scheduler.
|
|
*/
|
|
@Component
|
|
public class NccPushHandler implements ScheduledJobHandler {
|
|
|
|
public static final String TYPE = "NCC_PUSH";
|
|
|
|
private final AppProperties properties;
|
|
private final NccPushRunner runner;
|
|
|
|
public NccPushHandler(AppProperties properties, NccPushRunner runner) {
|
|
this.properties = properties;
|
|
this.runner = runner;
|
|
}
|
|
|
|
@Override
|
|
public String type() {
|
|
return TYPE;
|
|
}
|
|
|
|
@Override
|
|
public JobExecutionResult execute(ScheduledJob job) {
|
|
if (!properties.getPush().isEnabled()) {
|
|
return JobExecutionResult.ok("NCC 推送已停用(av.push.enabled=false)",
|
|
Map.of("enabled", false));
|
|
}
|
|
NccPushRunner.Result result = runner.runDue(
|
|
job.getTenantId(), properties.getPush().getBatchSize());
|
|
|
|
Map<String, Object> detail = new LinkedHashMap<>();
|
|
detail.put("enabled", result.enabled());
|
|
detail.put("reconciled", result.reconciled());
|
|
detail.put("pushed", result.pushed());
|
|
detail.put("failed", result.failed());
|
|
detail.put("failedTaskIds", result.failedTaskIds());
|
|
detail.put("partialFailure", result.partialFailure());
|
|
|
|
String message = result.reconciled() == 0 && result.pushed() == 0 && result.failed() == 0
|
|
? "没有待处理的推送任务"
|
|
: "核对 " + result.reconciled() + " 条,推送 " + result.pushed()
|
|
+ " 条,失败 " + result.failed() + " 条";
|
|
return result.allAttemptsFailed()
|
|
? JobExecutionResult.failed(message, detail)
|
|
: JobExecutionResult.ok(message, detail);
|
|
}
|
|
}
|
|
|