优化表结构,重构模型,重新实现基于白银网关的提取节点流程

This commit is contained in:
2025-11-24 18:44:06 +08:00
parent 9a574f55cb
commit cb2a963a37
142 changed files with 6528 additions and 5808 deletions

View File

@@ -28,33 +28,43 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
tableName := _bill.billDo.TableName()
_bill.ALL = field.NewAsterisk(tableName)
_bill.ID = field.NewInt32(tableName, "id")
_bill.CreatedAt = field.NewTime(tableName, "created_at")
_bill.UpdatedAt = field.NewTime(tableName, "updated_at")
_bill.DeletedAt = field.NewField(tableName, "deleted_at")
_bill.UserID = field.NewInt32(tableName, "user_id")
_bill.TradeID = field.NewInt32(tableName, "trade_id")
_bill.ResourceID = field.NewInt32(tableName, "resource_id")
_bill.RefundID = field.NewInt32(tableName, "refund_id")
_bill.BillNo = field.NewString(tableName, "bill_no")
_bill.Info = field.NewString(tableName, "info")
_bill.Type = field.NewInt32(tableName, "type")
_bill.Type = field.NewInt(tableName, "type")
_bill.Amount = field.NewField(tableName, "amount")
_bill.CreatedAt = field.NewField(tableName, "created_at")
_bill.UpdatedAt = field.NewField(tableName, "updated_at")
_bill.DeletedAt = field.NewField(tableName, "deleted_at")
_bill.User = billBelongsToUser{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"),
Admin: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Admin", "models.Admin"),
},
}
_bill.Trade = billBelongsToTrade{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Trade", "models.Trade"),
}
_bill.Refund = billBelongsToRefund{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Refund", "models.Refund"),
}
_bill.Resource = billBelongsToResource{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Resource", "models.Resource"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("Resource.User", "models.User"),
},
Short: struct {
field.RelationField
}{
@@ -67,6 +77,12 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
},
}
_bill.Refund = billBelongsToRefund{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Refund", "models.Refund"),
}
_bill.fillFieldMap()
return _bill
@@ -76,24 +92,26 @@ type bill struct {
billDo
ALL field.Asterisk
ID field.Int32 // 账单ID
UserID field.Int32 // 用户ID
TradeID field.Int32 // 订单ID
ResourceID field.Int32 // 套餐ID
RefundID field.Int32 // 退款ID
BillNo field.String // 易读账单号
Info field.String // 产品可读信息
Type field.Int32 // 账单类型1-消费2-退款3-充值
Amount field.Field // 账单金额
CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间
Trade billBelongsToTrade
ID field.Int32
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
UserID field.Int32
TradeID field.Int32
ResourceID field.Int32
RefundID field.Int32
BillNo field.String
Info field.String
Type field.Int
Amount field.Field
User billBelongsToUser
Refund billBelongsToRefund
Trade billBelongsToTrade
Resource billBelongsToResource
Refund billBelongsToRefund
fieldMap map[string]field.Expr
}
@@ -110,17 +128,17 @@ func (b bill) As(alias string) *bill {
func (b *bill) updateTableName(table string) *bill {
b.ALL = field.NewAsterisk(table)
b.ID = field.NewInt32(table, "id")
b.CreatedAt = field.NewTime(table, "created_at")
b.UpdatedAt = field.NewTime(table, "updated_at")
b.DeletedAt = field.NewField(table, "deleted_at")
b.UserID = field.NewInt32(table, "user_id")
b.TradeID = field.NewInt32(table, "trade_id")
b.ResourceID = field.NewInt32(table, "resource_id")
b.RefundID = field.NewInt32(table, "refund_id")
b.BillNo = field.NewString(table, "bill_no")
b.Info = field.NewString(table, "info")
b.Type = field.NewInt32(table, "type")
b.Type = field.NewInt(table, "type")
b.Amount = field.NewField(table, "amount")
b.CreatedAt = field.NewField(table, "created_at")
b.UpdatedAt = field.NewField(table, "updated_at")
b.DeletedAt = field.NewField(table, "deleted_at")
b.fillFieldMap()
@@ -137,8 +155,11 @@ func (b *bill) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
}
func (b *bill) fillFieldMap() {
b.fieldMap = make(map[string]field.Expr, 15)
b.fieldMap = make(map[string]field.Expr, 16)
b.fieldMap["id"] = b.ID
b.fieldMap["created_at"] = b.CreatedAt
b.fieldMap["updated_at"] = b.UpdatedAt
b.fieldMap["deleted_at"] = b.DeletedAt
b.fieldMap["user_id"] = b.UserID
b.fieldMap["trade_id"] = b.TradeID
b.fieldMap["resource_id"] = b.ResourceID
@@ -147,31 +168,116 @@ func (b *bill) fillFieldMap() {
b.fieldMap["info"] = b.Info
b.fieldMap["type"] = b.Type
b.fieldMap["amount"] = b.Amount
b.fieldMap["created_at"] = b.CreatedAt
b.fieldMap["updated_at"] = b.UpdatedAt
b.fieldMap["deleted_at"] = b.DeletedAt
}
func (b bill) clone(db *gorm.DB) bill {
b.billDo.ReplaceConnPool(db.Statement.ConnPool)
b.User.db = db.Session(&gorm.Session{Initialized: true})
b.User.db.Statement.ConnPool = db.Statement.ConnPool
b.Trade.db = db.Session(&gorm.Session{Initialized: true})
b.Trade.db.Statement.ConnPool = db.Statement.ConnPool
b.Refund.db = db.Session(&gorm.Session{Initialized: true})
b.Refund.db.Statement.ConnPool = db.Statement.ConnPool
b.Resource.db = db.Session(&gorm.Session{Initialized: true})
b.Resource.db.Statement.ConnPool = db.Statement.ConnPool
b.Refund.db = db.Session(&gorm.Session{Initialized: true})
b.Refund.db.Statement.ConnPool = db.Statement.ConnPool
return b
}
func (b bill) replaceDB(db *gorm.DB) bill {
b.billDo.ReplaceDB(db)
b.User.db = db.Session(&gorm.Session{})
b.Trade.db = db.Session(&gorm.Session{})
b.Refund.db = db.Session(&gorm.Session{})
b.Resource.db = db.Session(&gorm.Session{})
b.Refund.db = db.Session(&gorm.Session{})
return b
}
type billBelongsToUser struct {
db *gorm.DB
field.RelationField
Admin struct {
field.RelationField
}
}
func (a billBelongsToUser) Where(conds ...field.Expr) *billBelongsToUser {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a billBelongsToUser) WithContext(ctx context.Context) *billBelongsToUser {
a.db = a.db.WithContext(ctx)
return &a
}
func (a billBelongsToUser) Session(session *gorm.Session) *billBelongsToUser {
a.db = a.db.Session(session)
return &a
}
func (a billBelongsToUser) Model(m *models.Bill) *billBelongsToUserTx {
return &billBelongsToUserTx{a.db.Model(m).Association(a.Name())}
}
func (a billBelongsToUser) Unscoped() *billBelongsToUser {
a.db = a.db.Unscoped()
return &a
}
type billBelongsToUserTx struct{ tx *gorm.Association }
func (a billBelongsToUserTx) Find() (result *models.User, err error) {
return result, a.tx.Find(&result)
}
func (a billBelongsToUserTx) Append(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a billBelongsToUserTx) Replace(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a billBelongsToUserTx) Delete(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a billBelongsToUserTx) Clear() error {
return a.tx.Clear()
}
func (a billBelongsToUserTx) Count() int64 {
return a.tx.Count()
}
func (a billBelongsToUserTx) Unscoped() *billBelongsToUserTx {
a.tx = a.tx.Unscoped()
return &a
}
type billBelongsToTrade struct {
db *gorm.DB
@@ -253,92 +359,14 @@ func (a billBelongsToTradeTx) Unscoped() *billBelongsToTradeTx {
return &a
}
type billBelongsToRefund struct {
db *gorm.DB
field.RelationField
}
func (a billBelongsToRefund) Where(conds ...field.Expr) *billBelongsToRefund {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a billBelongsToRefund) WithContext(ctx context.Context) *billBelongsToRefund {
a.db = a.db.WithContext(ctx)
return &a
}
func (a billBelongsToRefund) Session(session *gorm.Session) *billBelongsToRefund {
a.db = a.db.Session(session)
return &a
}
func (a billBelongsToRefund) Model(m *models.Bill) *billBelongsToRefundTx {
return &billBelongsToRefundTx{a.db.Model(m).Association(a.Name())}
}
func (a billBelongsToRefund) Unscoped() *billBelongsToRefund {
a.db = a.db.Unscoped()
return &a
}
type billBelongsToRefundTx struct{ tx *gorm.Association }
func (a billBelongsToRefundTx) Find() (result *models.Refund, err error) {
return result, a.tx.Find(&result)
}
func (a billBelongsToRefundTx) Append(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a billBelongsToRefundTx) Replace(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a billBelongsToRefundTx) Delete(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a billBelongsToRefundTx) Clear() error {
return a.tx.Clear()
}
func (a billBelongsToRefundTx) Count() int64 {
return a.tx.Count()
}
func (a billBelongsToRefundTx) Unscoped() *billBelongsToRefundTx {
a.tx = a.tx.Unscoped()
return &a
}
type billBelongsToResource struct {
db *gorm.DB
field.RelationField
User struct {
field.RelationField
}
Short struct {
field.RelationField
}
@@ -422,6 +450,87 @@ func (a billBelongsToResourceTx) Unscoped() *billBelongsToResourceTx {
return &a
}
type billBelongsToRefund struct {
db *gorm.DB
field.RelationField
}
func (a billBelongsToRefund) Where(conds ...field.Expr) *billBelongsToRefund {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a billBelongsToRefund) WithContext(ctx context.Context) *billBelongsToRefund {
a.db = a.db.WithContext(ctx)
return &a
}
func (a billBelongsToRefund) Session(session *gorm.Session) *billBelongsToRefund {
a.db = a.db.Session(session)
return &a
}
func (a billBelongsToRefund) Model(m *models.Bill) *billBelongsToRefundTx {
return &billBelongsToRefundTx{a.db.Model(m).Association(a.Name())}
}
func (a billBelongsToRefund) Unscoped() *billBelongsToRefund {
a.db = a.db.Unscoped()
return &a
}
type billBelongsToRefundTx struct{ tx *gorm.Association }
func (a billBelongsToRefundTx) Find() (result *models.Refund, err error) {
return result, a.tx.Find(&result)
}
func (a billBelongsToRefundTx) Append(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a billBelongsToRefundTx) Replace(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a billBelongsToRefundTx) Delete(values ...*models.Refund) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a billBelongsToRefundTx) Clear() error {
return a.tx.Clear()
}
func (a billBelongsToRefundTx) Count() int64 {
return a.tx.Count()
}
func (a billBelongsToRefundTx) Unscoped() *billBelongsToRefundTx {
a.tx = a.tx.Unscoped()
return &a
}
type billDo struct{ gen.DO }
func (b billDo) Debug() *billDo {