Constraint: 在线热修前必须保存当前迭代分支全部有效代码进展 Confidence: medium Scope-risk: broad Directive: 后续修改需保持审计事件与业务事务边界一致 Tested: git diff --cached --check Not-tested: 未运行全量测试,提交用于切换分支前保存既有工作
40 lines
1.6 KiB
Go
40 lines
1.6 KiB
Go
package order_package_invalidate
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/infrastructure/audit"
|
|
"github.com/break/junhong_cmp_fiber/internal/model"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"github.com/break/junhong_cmp_fiber/pkg/middleware"
|
|
)
|
|
|
|
func (s *Service) writeInvalidateTaskAudit(ctx context.Context, tx *gorm.DB, task *model.OrderPackageInvalidateTask, before, after map[string]any, result, phase, errorCode, errorSummary string) error {
|
|
return s.auditWriter.WriteTask(ctx, tx, audit.TaskInput{
|
|
EventID: audit.TaskEventID(constants.AuditResourceOrderPackageInvalidateTask, task.ID, phase),
|
|
ActionCode: constants.AuditActionOrderPackageInvalidateTaskCreated,
|
|
Summary: "创建订单套餐批量失效任务", TaskID: task.ID, TaskNo: task.TaskNo,
|
|
Actor: audit.ActorInput{
|
|
Kind: constants.AuditActorAccount, ID: strconv.FormatUint(uint64(middleware.GetUserIDFromContext(ctx)), 10),
|
|
Name: middleware.GetUsernameFromContext(ctx),
|
|
},
|
|
Source: constants.AuditSourceAdminAPI, ScopeType: constants.AuditScopePlatform,
|
|
Result: result, ErrorCode: errorCode, ErrorSummary: errorSummary,
|
|
IdentitySnapshot: map[string]any{"id": task.ID, "task_no": task.TaskNo, "file_name": task.FileName},
|
|
BeforeData: before, AfterData: after,
|
|
})
|
|
}
|
|
|
|
func invalidateTaskState(task *model.OrderPackageInvalidateTask) map[string]any {
|
|
if task == nil {
|
|
return nil
|
|
}
|
|
return map[string]any{
|
|
"status": task.Status, "total_count": task.TotalCount,
|
|
"success_count": task.SuccessCount, "fail_count": task.FailCount,
|
|
}
|
|
}
|