common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -10,10 +10,18 @@ import (
|
||||
"order/model/entity"
|
||||
)
|
||||
|
||||
type paymentConfig struct{}
|
||||
type paymentConfig struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
// PaymentConfig 支付配置数据访问对象
|
||||
var PaymentConfig = new(paymentConfig)
|
||||
var PaymentConfig = &paymentConfig{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (d *paymentConfig) SetNoCache() {
|
||||
PaymentConfig.NoCache = true
|
||||
}
|
||||
|
||||
// Create 创建支付配置
|
||||
func (d *paymentConfig) Create(ctx context.Context, config *entity.PaymentConfig) error {
|
||||
@@ -31,7 +39,7 @@ func (d *paymentConfig) GetByTenantAndMethod(ctx context.Context, tenantID, payM
|
||||
"enabled": true,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, filter, &config, consts.PaymentConfigCollection)
|
||||
err := mongo.FindOne(ctx, d.NoCache, filter, &config, consts.PaymentConfigCollection)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -76,7 +84,7 @@ func (d *paymentConfig) GetByID(ctx context.Context, id bson.ObjectID) (*entity.
|
||||
var config entity.PaymentConfig
|
||||
|
||||
filter := bson.M{"_id": id}
|
||||
err := mongo.FindOne(ctx, filter, &config, consts.PaymentConfigCollection)
|
||||
err := mongo.FindOne(ctx, d.NoCache, filter, &config, consts.PaymentConfigCollection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -89,7 +97,7 @@ func (d *paymentConfig) GetByTenantID(ctx context.Context, tenantID string) ([]e
|
||||
var configs []entity.PaymentConfig
|
||||
|
||||
filter := bson.M{"tenant_id": tenantID}
|
||||
err := mongo.Find(ctx, filter, &configs, consts.PaymentConfigCollection)
|
||||
err := mongo.Find(ctx, d.NoCache, filter, &configs, consts.PaymentConfigCollection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -109,14 +117,22 @@ func (d *paymentConfig) ListByTenant(ctx context.Context, tenantID string) ([]en
|
||||
|
||||
filter := bson.M{"tenant_id": tenantID}
|
||||
|
||||
err := mongo.Find(ctx, filter, &configs, consts.PaymentConfigCollection)
|
||||
err := mongo.Find(ctx, d.NoCache, filter, &configs, consts.PaymentConfigCollection)
|
||||
return configs, err
|
||||
}
|
||||
|
||||
type paymentRecord struct{}
|
||||
type paymentRecord struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
// PaymentRecord 支付记录数据访问对象
|
||||
var PaymentRecord = new(paymentRecord)
|
||||
var PaymentRecord = &paymentRecord{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (d *paymentRecord) SetNoCache() {
|
||||
PaymentRecord.NoCache = true
|
||||
}
|
||||
|
||||
// Create 创建支付记录
|
||||
func (d *paymentRecord) Create(ctx context.Context, record *entity.PaymentRecord) error {
|
||||
@@ -136,7 +152,7 @@ func (d *paymentRecord) GetByOrderNo(ctx context.Context, tenantID, orderNo stri
|
||||
"order_no": orderNo,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, filter, &record, consts.PaymentRecordCollection)
|
||||
err := mongo.FindOne(ctx, d.NoCache, filter, &record, consts.PaymentRecordCollection)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -158,10 +174,18 @@ func (d *paymentRecord) UpdateStatus(ctx context.Context, id string, status, tra
|
||||
return err
|
||||
}
|
||||
|
||||
type refundRecord struct{}
|
||||
type refundRecord struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
// RefundRecord 退款记录数据访问对象
|
||||
var RefundRecord = new(refundRecord)
|
||||
var RefundRecord = &refundRecord{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (d *refundRecord) SetNoCache() {
|
||||
RefundRecord.NoCache = true
|
||||
}
|
||||
|
||||
// Create 创建退款记录
|
||||
func (d *refundRecord) Create(ctx context.Context, record *entity.RefundRecord) error {
|
||||
@@ -181,7 +205,7 @@ func (d *refundRecord) GetByRefundNo(ctx context.Context, tenantID, refundNo str
|
||||
"refund_no": refundNo,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, filter, &record, consts.RefundRecordCollection)
|
||||
err := mongo.FindOne(ctx, d.NoCache, filter, &record, consts.RefundRecordCollection)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user