明确进度与取消契约
This commit is contained in:
@@ -161,7 +161,7 @@ public class MyBatisExportWindow {
|
||||
modeLabel, filterModeCmb, filterValueField, filterHint, exportBtn);
|
||||
|
||||
OperationStatusPane progressRow = new OperationStatusPane(
|
||||
exportOperation, fsBody() - 2);
|
||||
exportOperation, fsBody() - 2, true);
|
||||
|
||||
// === 日志区域 ===
|
||||
Label logTitle = new Label("执行日志");
|
||||
|
||||
+8
-8
@@ -24,19 +24,19 @@ public final class RunSqlExportUseCase {
|
||||
new MyBatisExportService.ExportCallback() {
|
||||
@Override
|
||||
public void onProjectStart(int current, int total, String projectName) {
|
||||
context.report(current + "/" + total + " " + projectName,
|
||||
total == 0 ? 0 : (double) (current - 1) / total);
|
||||
progressConsumer.accept(new SqlExportProgress(
|
||||
current, total, projectName, 0));
|
||||
SqlExportProgress progress = new SqlExportProgress(
|
||||
current, total, projectName, 0);
|
||||
context.report(progress.message(), progress.fraction());
|
||||
progressConsumer.accept(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProjectDone(int current, int total,
|
||||
String projectName, int recordCount) {
|
||||
context.report(current + "/" + total + " " + projectName,
|
||||
total == 0 ? 0 : (double) current / total);
|
||||
progressConsumer.accept(new SqlExportProgress(
|
||||
current, total, projectName, recordCount));
|
||||
SqlExportProgress progress = new SqlExportProgress(
|
||||
current, total, projectName, recordCount);
|
||||
context.report(progress.message(), progress.fraction());
|
||||
progressConsumer.accept(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+17
@@ -2,7 +2,24 @@ package com.example.workutils.biz.mybatisexport.application;
|
||||
|
||||
public record SqlExportProgress(int current, int total, String projectName, int recordCount) {
|
||||
|
||||
public SqlExportProgress {
|
||||
projectName = projectName == null ? "" : projectName.trim();
|
||||
if (current < 0 || total < 0 || recordCount < 0) {
|
||||
throw new IllegalArgumentException("progress counts must not be negative");
|
||||
}
|
||||
if (current > total) {
|
||||
throw new IllegalArgumentException("current must not exceed total");
|
||||
}
|
||||
if (projectName.isEmpty()) {
|
||||
throw new IllegalArgumentException("projectName must not be blank");
|
||||
}
|
||||
}
|
||||
|
||||
public double fraction() {
|
||||
return total == 0 ? 0 : (double) current / total;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return current + "/" + total + " " + projectName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ public final class RunScanUseCase {
|
||||
}
|
||||
|
||||
public Result execute(ScanRequest request, OperationContext context) throws Exception {
|
||||
context.report("正在扫描项目", -1);
|
||||
report(context, new ScanProgress("正在扫描项目", -1));
|
||||
ScannerService.ScanResult scanResult = scannerService.scanAllProjects(
|
||||
ScannerService.ScanType.KEYWORD, request.effectivePattern());
|
||||
|
||||
context.report("正在生成 CSV", -1);
|
||||
report(context, new ScanProgress("正在生成 CSV", -1));
|
||||
String fileName = outputHelper.generateOutputFileName("scan_result", "csv");
|
||||
scannerService.exportScanResults(scanResult, fileName);
|
||||
return new Result(scanResult, fileName);
|
||||
@@ -27,4 +27,8 @@ public final class RunScanUseCase {
|
||||
|
||||
public record Result(ScannerService.ScanResult scanResult, String fileName) {
|
||||
}
|
||||
|
||||
private void report(OperationContext context, ScanProgress progress) {
|
||||
context.report(progress.message(), progress.progress());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
package com.example.workutils.biz.scanner.application;
|
||||
|
||||
public record ScanProgress(String message, double progress) {
|
||||
|
||||
public ScanProgress {
|
||||
message = message == null ? "" : message.trim();
|
||||
if (message.isEmpty()) {
|
||||
throw new IllegalArgumentException("message must not be blank");
|
||||
}
|
||||
if (Double.isNaN(progress) || progress < -1 || progress > 1) {
|
||||
throw new IllegalArgumentException("progress must be -1 or between 0 and 1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user