收口审计治理与套餐任务进展
Constraint: 在线热修前必须保存当前迭代分支全部有效代码进展 Confidence: medium Scope-risk: broad Directive: 后续修改需保持审计事件与业务事务边界一致 Tested: git diff --cached --check Not-tested: 未运行全量测试,提交用于切换分支前保存既有工作
This commit is contained in:
@@ -24,6 +24,14 @@ func NewAssetPackageBatchOrderTaskStore(db *gorm.DB) *AssetPackageBatchOrderTask
|
||||
return &AssetPackageBatchOrderTaskStore{db: db}
|
||||
}
|
||||
|
||||
// DB 返回任务 Store 使用的数据库连接。
|
||||
func (s *AssetPackageBatchOrderTaskStore) DB() *gorm.DB { return s.db }
|
||||
|
||||
// WithTx 返回绑定指定事务的任务 Store。
|
||||
func (s *AssetPackageBatchOrderTaskStore) WithTx(tx *gorm.DB) *AssetPackageBatchOrderTaskStore {
|
||||
return &AssetPackageBatchOrderTaskStore{db: tx}
|
||||
}
|
||||
|
||||
// Create 创建批量订购任务。
|
||||
func (s *AssetPackageBatchOrderTaskStore) Create(ctx context.Context, task *model.AssetPackageBatchOrderTask) error {
|
||||
return s.db.WithContext(ctx).Create(task).Error
|
||||
|
||||
@@ -17,6 +17,16 @@ func NewCarrierStore(db *gorm.DB) *CarrierStore {
|
||||
return &CarrierStore{db: db}
|
||||
}
|
||||
|
||||
// WithTx 返回复用当前事务的运营商 Store。
|
||||
func (s *CarrierStore) WithTx(tx *gorm.DB) *CarrierStore {
|
||||
return &CarrierStore{db: tx}
|
||||
}
|
||||
|
||||
// DB 返回底层数据库连接,用于业务事实与审计同事务提交。
|
||||
func (s *CarrierStore) DB() *gorm.DB {
|
||||
return s.db
|
||||
}
|
||||
|
||||
func (s *CarrierStore) Create(ctx context.Context, carrier *model.Carrier) error {
|
||||
return s.db.WithContext(ctx).Create(carrier).Error
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ func NewExportTaskStore(db *gorm.DB, redis *redis.Client) *ExportTaskStore {
|
||||
return &ExportTaskStore{db: db, redis: redis}
|
||||
}
|
||||
|
||||
// WithTx 返回绑定指定事务的导出任务 Store。
|
||||
func (s *ExportTaskStore) WithTx(tx *gorm.DB) *ExportTaskStore {
|
||||
return &ExportTaskStore{db: tx, redis: s.redis}
|
||||
}
|
||||
|
||||
// Create 创建导出主任务。
|
||||
func (s *ExportTaskStore) Create(ctx context.Context, task *model.ExportTask) error {
|
||||
return s.db.WithContext(ctx).Create(task).Error
|
||||
@@ -208,7 +213,7 @@ func (s *ExportTaskStore) SetCancelRequested(ctx context.Context, taskID uint, u
|
||||
now := time.Now()
|
||||
result := s.db.WithContext(ctx).
|
||||
Model(&model.ExportTask{}).
|
||||
Where("id = ? AND status = ?", taskID, constants.ExportTaskStatusProcessing).
|
||||
Where("id = ? AND status = ? AND cancel_requested = ?", taskID, constants.ExportTaskStatusProcessing, false).
|
||||
Updates(map[string]any{
|
||||
"cancel_requested": true,
|
||||
"updated_at": now,
|
||||
|
||||
@@ -22,6 +22,22 @@ func NewOrderPackageInvalidateTaskStore(db *gorm.DB) *OrderPackageInvalidateTask
|
||||
return &OrderPackageInvalidateTaskStore{db: db}
|
||||
}
|
||||
|
||||
// DB 返回任务 Store 使用的数据库连接。
|
||||
func (s *OrderPackageInvalidateTaskStore) DB() *gorm.DB { return s.db }
|
||||
|
||||
// WithTx 返回绑定指定事务的任务 Store。
|
||||
func (s *OrderPackageInvalidateTaskStore) WithTx(tx *gorm.DB) *OrderPackageInvalidateTaskStore {
|
||||
return &OrderPackageInvalidateTaskStore{db: tx}
|
||||
}
|
||||
|
||||
// Claim 原子领取待处理任务,避免并发重复消费。
|
||||
func (s *OrderPackageInvalidateTaskStore) Claim(ctx context.Context, id uint) (bool, error) {
|
||||
result := s.db.WithContext(ctx).Model(&model.OrderPackageInvalidateTask{}).
|
||||
Where("id = ? AND status = ?", id, model.ImportTaskStatusPending).
|
||||
Updates(map[string]any{"status": model.ImportTaskStatusProcessing, "started_at": time.Now(), "updated_at": time.Now()})
|
||||
return result.RowsAffected == 1, result.Error
|
||||
}
|
||||
|
||||
// Create 创建任务
|
||||
func (s *OrderPackageInvalidateTaskStore) Create(ctx context.Context, task *model.OrderPackageInvalidateTask) error {
|
||||
return s.db.WithContext(ctx).Create(task).Error
|
||||
|
||||
@@ -18,6 +18,11 @@ func NewPollingAlertRuleStore(db *gorm.DB) *PollingAlertRuleStore {
|
||||
return &PollingAlertRuleStore{db: db}
|
||||
}
|
||||
|
||||
// WithTx 返回绑定指定事务的轮询告警规则存储。
|
||||
func (s *PollingAlertRuleStore) WithTx(tx *gorm.DB) *PollingAlertRuleStore {
|
||||
return &PollingAlertRuleStore{db: tx}
|
||||
}
|
||||
|
||||
// Create 创建告警规则
|
||||
func (s *PollingAlertRuleStore) Create(ctx context.Context, rule *model.PollingAlertRule) error {
|
||||
return s.db.WithContext(ctx).Create(rule).Error
|
||||
|
||||
@@ -18,6 +18,11 @@ func NewPollingConcurrencyConfigStore(db *gorm.DB) *PollingConcurrencyConfigStor
|
||||
return &PollingConcurrencyConfigStore{db: db}
|
||||
}
|
||||
|
||||
// WithTx 返回绑定指定事务的轮询并发配置存储。
|
||||
func (s *PollingConcurrencyConfigStore) WithTx(tx *gorm.DB) *PollingConcurrencyConfigStore {
|
||||
return &PollingConcurrencyConfigStore{db: tx}
|
||||
}
|
||||
|
||||
// List 获取所有并发控制配置
|
||||
func (s *PollingConcurrencyConfigStore) List(ctx context.Context) ([]*model.PollingConcurrencyConfig, error) {
|
||||
var configs []*model.PollingConcurrencyConfig
|
||||
|
||||
@@ -19,6 +19,11 @@ func NewPollingConfigStore(db *gorm.DB) *PollingConfigStore {
|
||||
return &PollingConfigStore{db: db}
|
||||
}
|
||||
|
||||
// WithTx 返回绑定指定事务的轮询配置存储。
|
||||
func (s *PollingConfigStore) WithTx(tx *gorm.DB) *PollingConfigStore {
|
||||
return &PollingConfigStore{db: tx}
|
||||
}
|
||||
|
||||
// Create 创建轮询配置
|
||||
func (s *PollingConfigStore) Create(ctx context.Context, config *model.PollingConfig) error {
|
||||
return s.db.WithContext(ctx).Create(config).Error
|
||||
|
||||
@@ -19,6 +19,11 @@ func NewPollingManualTriggerLogStore(db *gorm.DB) *PollingManualTriggerLogStore
|
||||
return &PollingManualTriggerLogStore{db: db}
|
||||
}
|
||||
|
||||
// WithTx 返回绑定指定事务的手动轮询日志存储。
|
||||
func (s *PollingManualTriggerLogStore) WithTx(tx *gorm.DB) *PollingManualTriggerLogStore {
|
||||
return &PollingManualTriggerLogStore{db: tx}
|
||||
}
|
||||
|
||||
// Create 创建手动触发日志
|
||||
func (s *PollingManualTriggerLogStore) Create(ctx context.Context, log *model.PollingManualTriggerLog) error {
|
||||
return s.db.WithContext(ctx).Create(log).Error
|
||||
|
||||
@@ -21,6 +21,11 @@ func NewWechatConfigStore(db *gorm.DB, rdb *redis.Client) *WechatConfigStore {
|
||||
return &WechatConfigStore{db: db, rdb: rdb}
|
||||
}
|
||||
|
||||
// WithTx 返回复用当前事务的支付配置 Store。
|
||||
func (s *WechatConfigStore) WithTx(tx *gorm.DB) *WechatConfigStore {
|
||||
return &WechatConfigStore{db: tx, rdb: s.rdb}
|
||||
}
|
||||
|
||||
// Create 创建微信参数配置
|
||||
func (s *WechatConfigStore) Create(ctx context.Context, config *model.WechatConfig) error {
|
||||
return s.db.WithContext(ctx).Create(config).Error
|
||||
|
||||
Reference in New Issue
Block a user