Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 8m39s
- 迁移 000259~000265:套餐记录沉默期字段与扫描索引、套餐默认沉默期、延期政策/流水/订单/批次/明细 5 张表、默认政策与系统配置(总开关默认关闭)、企微审批白名单、卡与设备出库时间及出库记录 - 沉默期设置(订单发放、自动购包、钱包续费)、后台购买时调整(超默认值按政策免审或企微审批)、统一判定与激活闸门、排队与孤儿扫描跳过过期套餐、过期套餐禁止退款、每 10 分钟扫描 - 总开关专用接口与打开前 4 项检查;延期政策;延期资格与计费;H5 自助与后台二维码在线支付(商户池路由)、支付回调与查单恢复、线下登记、特殊/批量延期、异常重试与原路退款;沉默期审批场景与终态处理 - 换货沉默期流水与出库时间;卡/设备列表、详情、导出与出库记录接口;延期订单与即将过期套餐列表及导出;财务流水纳入延期支付 - 沉默期与出库时间回填工具 cmd/silence-backfill;前端接口变更说明 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
3.3 KiB
Go
82 lines
3.3 KiB
Go
package audit
|
||
|
||
import (
|
||
"context"
|
||
"strconv"
|
||
|
||
"gorm.io/gorm"
|
||
|
||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||
"github.com/break/junhong_cmp_fiber/pkg/auditcontext"
|
||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||
)
|
||
|
||
// SilenceAuditInput 是沉默期相关审计事实。
|
||
type SilenceAuditInput struct {
|
||
ActionCode string
|
||
Summary string
|
||
Usage *model.PackageUsage
|
||
BeforeData map[string]any
|
||
AfterData map[string]any
|
||
Metadata map[string]any
|
||
}
|
||
|
||
// AppendSilenceUsage 在调用方事务内追加一条套餐记录级沉默期审计。
|
||
// 请求上下文没有操作者时(Worker、定时任务、回调)按系统任务记录。
|
||
func (w *Writer) AppendSilenceUsage(ctx context.Context, tx *gorm.DB, input SilenceAuditInput) error {
|
||
if w == nil || input.Usage == nil || input.Usage.ID == 0 {
|
||
return nil
|
||
}
|
||
resource := PackageUsageResource(input.Usage, constants.AuditResourceRelationPrimary,
|
||
constants.AuditResourceRolePackageUsageTarget, input.BeforeData, input.AfterData)
|
||
return w.Append(ctx, tx, silenceAppendInput(ctx, input.ActionCode, input.Summary, input.Metadata, []ResourceInput{resource}))
|
||
}
|
||
|
||
// AppendSilenceResource 追加一条主资源为非套餐记录(套餐、政策、配置、出库记录)的沉默期审计。
|
||
func (w *Writer) AppendSilenceResource(ctx context.Context, tx *gorm.DB, actionCode, summary string, resource ResourceInput, metadata map[string]any) error {
|
||
if w == nil {
|
||
return nil
|
||
}
|
||
resource.Relation = constants.AuditResourceRelationPrimary
|
||
if resource.Role == "" {
|
||
resource.Role = constants.AuditResourceRoleConfig
|
||
}
|
||
return w.Append(ctx, tx, silenceAppendInput(ctx, actionCode, summary, metadata, []ResourceInput{resource}))
|
||
}
|
||
|
||
// SilencePolicyResource 构造延期政策审计资源。
|
||
func SilencePolicyResource(policy *model.PackageSilenceExtensionPolicy, beforeData, afterData map[string]any) ResourceInput {
|
||
id := strconv.FormatUint(uint64(policy.ID), 10)
|
||
return ResourceInput{
|
||
Type: AuditResourcePackageSilencePolicy, ID: &id, Key: id, DisplayName: policy.Name,
|
||
IdentitySnapshot: map[string]any{"id": policy.ID, "name": policy.Name, "scope_type": policy.ScopeType, "status": policy.Status},
|
||
BeforeData: beforeData, AfterData: afterData,
|
||
}
|
||
}
|
||
|
||
// AssetOutboundResource 构造出库记录审计资源。
|
||
func AssetOutboundResource(record *model.AssetOutboundRecord, afterData map[string]any) ResourceInput {
|
||
id := strconv.FormatUint(uint64(record.ID), 10)
|
||
return ResourceInput{
|
||
Type: AuditResourceAssetOutboundRecord, ID: &id, Key: id, DisplayName: record.AssetIdentifierSnapshot,
|
||
Role: constants.AuditResourceRoleConfig,
|
||
IdentitySnapshot: map[string]any{
|
||
"id": record.ID, "asset_type": record.AssetType, "asset_id": record.AssetID,
|
||
"generation": record.Generation, "source": record.Source,
|
||
},
|
||
AfterData: afterData,
|
||
}
|
||
}
|
||
|
||
func silenceAppendInput(ctx context.Context, actionCode, summary string, metadata map[string]any, resources []ResourceInput) AppendInput {
|
||
input := AppendInput{
|
||
ActionCode: actionCode, Summary: summary, ScopeType: constants.AuditScopePlatform,
|
||
Result: constants.AuditResultSuccess, Metadata: metadata, Resources: resources,
|
||
}
|
||
if auditcontext.From(ctx).ActorID == "" {
|
||
input.Actor = ActorInput{Kind: constants.AuditActorSystemTask, ID: "package_silence", Name: "沉默期规则"}
|
||
input.Source = constants.AuditSourceWorker
|
||
}
|
||
return input
|
||
}
|