feat: add operator and business reference fields to tenant ledgers

- Added `operator_user_id`, `biz_ref_type`, and `biz_ref_id` fields to the TenantLedger model for enhanced auditing and traceability.
- Updated the tenant ledgers query generation to include new fields.
- Introduced new API endpoint for retrieving tenant ledger records with filtering options based on the new fields.
- Enhanced Swagger documentation to reflect the new endpoint and its parameters.
- Created DTOs for admin ledger filtering and item representation.
- Implemented the admin ledger retrieval logic in the tenant service.
- Added database migration scripts to introduce new fields and indexes for efficient querying.
This commit is contained in:
2025-12-22 21:35:10 +08:00
parent 3cb2a6f586
commit 5dc0f89ac0
17 changed files with 983 additions and 171 deletions

View File

@@ -39,6 +39,9 @@ func newTenantLedger(db *gorm.DB, opts ...gen.DOOption) tenantLedgerQuery {
_tenantLedgerQuery.Remark = field.NewString(tableName, "remark")
_tenantLedgerQuery.CreatedAt = field.NewTime(tableName, "created_at")
_tenantLedgerQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
_tenantLedgerQuery.OperatorUserID = field.NewInt64(tableName, "operator_user_id")
_tenantLedgerQuery.BizRefType = field.NewString(tableName, "biz_ref_type")
_tenantLedgerQuery.BizRefID = field.NewInt64(tableName, "biz_ref_id")
_tenantLedgerQuery.Order = tenantLedgerQueryBelongsToOrder{
db: db.Session(&gorm.Session{}),
@@ -68,6 +71,9 @@ type tenantLedgerQuery struct {
Remark field.String // 备注:业务说明/后台操作原因等;用于审计
CreatedAt field.Time // 创建时间:默认 now()
UpdatedAt field.Time // 更新时间:默认 now()
OperatorUserID field.Int64 // 操作者用户ID谁触发该流水admin/buyer/system用于审计与追责可为空历史数据或无法识别时
BizRefType field.String // 业务引用类型order/refund/topup/etc与 biz_ref_id 组成可选的结构化幂等/追溯键
BizRefID field.Int64 // 业务引用ID与 biz_ref_type 配合使用(例如 orders.id用于对账与审计
Order tenantLedgerQueryBelongsToOrder
fieldMap map[string]field.Expr
@@ -99,6 +105,9 @@ func (t *tenantLedgerQuery) updateTableName(table string) *tenantLedgerQuery {
t.Remark = field.NewString(table, "remark")
t.CreatedAt = field.NewTime(table, "created_at")
t.UpdatedAt = field.NewTime(table, "updated_at")
t.OperatorUserID = field.NewInt64(table, "operator_user_id")
t.BizRefType = field.NewString(table, "biz_ref_type")
t.BizRefID = field.NewInt64(table, "biz_ref_id")
t.fillFieldMap()
@@ -131,7 +140,7 @@ func (t *tenantLedgerQuery) GetFieldByName(fieldName string) (field.OrderExpr, b
}
func (t *tenantLedgerQuery) fillFieldMap() {
t.fieldMap = make(map[string]field.Expr, 15)
t.fieldMap = make(map[string]field.Expr, 18)
t.fieldMap["id"] = t.ID
t.fieldMap["tenant_id"] = t.TenantID
t.fieldMap["user_id"] = t.UserID
@@ -146,6 +155,9 @@ func (t *tenantLedgerQuery) fillFieldMap() {
t.fieldMap["remark"] = t.Remark
t.fieldMap["created_at"] = t.CreatedAt
t.fieldMap["updated_at"] = t.UpdatedAt
t.fieldMap["operator_user_id"] = t.OperatorUserID
t.fieldMap["biz_ref_type"] = t.BizRefType
t.fieldMap["biz_ref_id"] = t.BizRefID
}