sync: 同步 v1.0.4 开源代码并脱敏
This commit is contained in:
@@ -283,6 +283,9 @@ func (r *Repository) Commit(ctx context.Context, task *Task) error {
|
||||
markAtomicFailure(task, "划拨批次存在失败明细,整批未执行")
|
||||
}
|
||||
successCount, failCount := countResult(task)
|
||||
if failCount > 0 {
|
||||
failCount = countValidationFailures(task)
|
||||
}
|
||||
autoSplitChild := strings.TrimSpace(task.Batch.ParentBatchNo) != ""
|
||||
var artifact batchresult.Artifact
|
||||
var artifactErr error
|
||||
@@ -443,7 +446,7 @@ func (r *Repository) aggregateParentOnce(ctx context.Context, parentBatchNo stri
|
||||
finalInfo["successCount"] = successCount
|
||||
finalInfo["failCount"] = failCount
|
||||
startTime := resolveAllocateParentStartTime(parent.StartTime, aggregate.EarliestStartTime, now)
|
||||
data := do.BatchMain{StartTime: startTime, BatchAsyncStatus: status, RunResult: runResult, TotalCount: len(task.Details), ValidCount: successCount, SuccessCount: successCount, FailCount: failCount, FailReason: failReason, BatchInfo: mergeBatchInfo(gjson.New(finalInfo), ossID, downloadID, artifactErr != nil), EndTime: now, UpdatedBy: parent.CreatedBy, UpdatedAt: now}
|
||||
data := do.BatchMain{StartTime: startTime, BatchAsyncStatus: status, RunResult: runResult, TotalCount: len(task.Details), ValidCount: len(task.Details) - failCount, SuccessCount: successCount, FailCount: failCount, FailReason: failReason, BatchInfo: mergeBatchInfo(gjson.New(finalInfo), ossID, downloadID, artifactErr != nil), EndTime: now, UpdatedBy: parent.CreatedBy, UpdatedAt: now}
|
||||
result, err := tx.Ctx(ctx).Model(dao.BatchMain.Table()).Where(mainColumns.Id, parent.Id).WhereIn(mainColumns.BatchAsyncStatus, []int{consts.BatchAsyncStatusPending, consts.BatchAsyncStatusProcessing}).Data(data).Update()
|
||||
if err != nil {
|
||||
if artifactErr == nil {
|
||||
@@ -536,7 +539,7 @@ func normalizeAtomicParentResult(task *Task) (int, int) {
|
||||
}
|
||||
task.FailureReason = coalesce(task.FailureReason, "划拨批次存在失败明细,整批未执行")
|
||||
markAtomicFailure(task, task.FailureReason)
|
||||
return 0, len(task.Details)
|
||||
return 0, countValidationFailures(task)
|
||||
}
|
||||
|
||||
func (r *Repository) updateDetails(ctx context.Context, tx gdb.TX, task *Task, now *gtime.Time) error {
|
||||
@@ -644,10 +647,7 @@ func validatePersistedDetailResults(task *Task, details []*Detail, persisted []*
|
||||
}
|
||||
for _, detail := range details {
|
||||
row := byID[detail.ID]
|
||||
status := consts.BatchDetailStatusFailed
|
||||
if detail.Success() {
|
||||
status = consts.BatchDetailStatusSuccess
|
||||
}
|
||||
status := persistedAllocationDetailStatus(task, detail)
|
||||
if row == nil || row.DetailStatus != status || row.ErrorReason != detail.Reason || row.UpdatedBy != task.Batch.CreatedBy || row.Snapshot == nil || !sameDetailSnapshot(row.Snapshot, detail.Snapshot(task.Batch)) {
|
||||
return gerror.Newf("划拨明细最终结果不一致,明细ID:%d", detail.ID)
|
||||
}
|
||||
@@ -669,12 +669,9 @@ func buildDetailUpdateStatement(task *Task, details []*Detail, now *gtime.Time)
|
||||
columns := dao.BatchDetail.Columns()
|
||||
var builder strings.Builder
|
||||
fmt.Fprintf(&builder, "UPDATE %s SET %s = CASE %s ", dao.BatchDetail.Table(), columns.DetailStatus, columns.Id)
|
||||
args := make([]any, 0, len(details)*7+8)
|
||||
args := make([]any, 0, len(details)*7+9)
|
||||
for _, detail := range details {
|
||||
status := consts.BatchDetailStatusFailed
|
||||
if detail.Success() {
|
||||
status = consts.BatchDetailStatusSuccess
|
||||
}
|
||||
status := persistedAllocationDetailStatus(task, detail)
|
||||
builder.WriteString("WHEN ? THEN ? ")
|
||||
args = append(args, detail.ID, status)
|
||||
}
|
||||
@@ -690,7 +687,7 @@ func buildDetailUpdateStatement(task *Task, details []*Detail, now *gtime.Time)
|
||||
}
|
||||
fmt.Fprintf(&builder, "ELSE %s END, %s = ?, %s = ? ", columns.Snapshot, columns.UpdatedBy, columns.UpdatedAt)
|
||||
args = append(args, task.Batch.CreatedBy, now)
|
||||
fmt.Fprintf(&builder, "WHERE %s = ? AND %s = ? AND %s = ? AND %s IN (?, ?, ?, ?) AND %s IN (%s)",
|
||||
fmt.Fprintf(&builder, "WHERE %s = ? AND %s = ? AND %s = ? AND %s IN (?, ?, ?, ?, ?) AND %s IN (%s)",
|
||||
columns.BatchNo,
|
||||
columns.BatchType,
|
||||
columns.TenantId,
|
||||
@@ -706,6 +703,7 @@ func buildDetailUpdateStatement(task *Task, details []*Detail, now *gtime.Time)
|
||||
consts.BatchDetailStatusRunning,
|
||||
consts.BatchDetailStatusSuccess,
|
||||
consts.BatchDetailStatusFailed,
|
||||
consts.BatchDetailStatusNotExecuted,
|
||||
)
|
||||
for _, detail := range details {
|
||||
args = append(args, detail.ID)
|
||||
@@ -845,10 +843,7 @@ func (r *Repository) updateDetail(ctx context.Context, tx gdb.TX, task *Task, de
|
||||
detail.DetailStatus != consts.BatchDetailStatusRunning) {
|
||||
return nil
|
||||
}
|
||||
status := consts.BatchDetailStatusFailed
|
||||
if detail.Success() {
|
||||
status = consts.BatchDetailStatusSuccess
|
||||
}
|
||||
status := persistedAllocationDetailStatus(task, detail)
|
||||
result, err := tx.Ctx(ctx).Model(dao.BatchDetail.Table()).
|
||||
Where(dao.BatchDetail.Columns().Id, detail.ID).
|
||||
Where(dao.BatchDetail.Columns().BatchNo, task.Batch.BatchNo).
|
||||
@@ -949,7 +944,7 @@ func (r *Repository) finalizeBatch(ctx context.Context, tx gdb.TX, task *Task, s
|
||||
BatchAsyncStatus: batchAsyncStatus,
|
||||
RunResult: runResult,
|
||||
TotalCount: len(task.Details),
|
||||
ValidCount: successCount,
|
||||
ValidCount: len(task.Details) - failCount,
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
FailReason: task.FailureReason,
|
||||
|
||||
Reference in New Issue
Block a user