重构通道管理逻辑,支持通过任务删除不同类型通道;引入 Asynq 处理异步任务;更新数据库结构以支持通道类型区分

This commit is contained in:
2025-05-23 14:53:01 +08:00
parent 09a9cc573e
commit c83ffda611
17 changed files with 380 additions and 188 deletions

View File

@@ -155,11 +155,20 @@ func (b *bill) fillFieldMap() {
func (b bill) clone(db *gorm.DB) bill {
b.billDo.ReplaceConnPool(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
return b
}
func (b bill) replaceDB(db *gorm.DB) bill {
b.billDo.ReplaceDB(db)
b.Trade.db = db.Session(&gorm.Session{})
b.Refund.db = db.Session(&gorm.Session{})
b.Resource.db = db.Session(&gorm.Session{})
return b
}
@@ -196,6 +205,11 @@ func (a billBelongsToTrade) Model(m *models.Bill) *billBelongsToTradeTx {
return &billBelongsToTradeTx{a.db.Model(m).Association(a.Name())}
}
func (a billBelongsToTrade) Unscoped() *billBelongsToTrade {
a.db = a.db.Unscoped()
return &a
}
type billBelongsToTradeTx struct{ tx *gorm.Association }
func (a billBelongsToTradeTx) Find() (result *models.Trade, err error) {
@@ -234,6 +248,11 @@ func (a billBelongsToTradeTx) Count() int64 {
return a.tx.Count()
}
func (a billBelongsToTradeTx) Unscoped() *billBelongsToTradeTx {
a.tx = a.tx.Unscoped()
return &a
}
type billBelongsToRefund struct {
db *gorm.DB
@@ -267,6 +286,11 @@ 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) {
@@ -305,6 +329,11 @@ 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
@@ -345,6 +374,11 @@ func (a billBelongsToResource) Model(m *models.Bill) *billBelongsToResourceTx {
return &billBelongsToResourceTx{a.db.Model(m).Association(a.Name())}
}
func (a billBelongsToResource) Unscoped() *billBelongsToResource {
a.db = a.db.Unscoped()
return &a
}
type billBelongsToResourceTx struct{ tx *gorm.Association }
func (a billBelongsToResourceTx) Find() (result *models.Resource, err error) {
@@ -383,6 +417,11 @@ func (a billBelongsToResourceTx) Count() int64 {
return a.tx.Count()
}
func (a billBelongsToResourceTx) Unscoped() *billBelongsToResourceTx {
a.tx = a.tx.Unscoped()
return &a
}
type billDo struct{ gen.DO }
func (b billDo) Debug() *billDo {