common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -13,9 +13,17 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AdPosition = &adPosition{}
|
var AdPosition = &adPosition{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type adPosition struct{}
|
type adPosition struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *adPosition) SetNoCache() {
|
||||||
|
AdPosition.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// Insert 插入广告位
|
// Insert 插入广告位
|
||||||
func (d *adPosition) Insert(ctx context.Context, adPosition *entity.AdPosition) (err error) {
|
func (d *adPosition) Insert(ctx context.Context, adPosition *entity.AdPosition) (err error) {
|
||||||
@@ -156,7 +164,7 @@ func (d *adPosition) GetOne(ctx context.Context, id string) (adPosition *entity.
|
|||||||
filter := bson.M{"_id": objectId}
|
filter := bson.M{"_id": objectId}
|
||||||
|
|
||||||
adPosition = &entity.AdPosition{}
|
adPosition = &entity.AdPosition{}
|
||||||
err = mongo.FindOne(ctx, filter, adPosition, entity.AdPositionCollection)
|
err = mongo.FindOne(ctx, d.NoCache, filter, adPosition, entity.AdPositionCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +173,7 @@ func (d *adPosition) GetByCode(ctx context.Context, code string) (adPosition *en
|
|||||||
filter := bson.M{"positionCode": code}
|
filter := bson.M{"positionCode": code}
|
||||||
|
|
||||||
adPosition = &entity.AdPosition{}
|
adPosition = &entity.AdPosition{}
|
||||||
err = mongo.FindOne(ctx, filter, adPosition, entity.AdPositionCollection)
|
err = mongo.FindOne(ctx, d.NoCache, filter, adPosition, entity.AdPositionCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +215,7 @@ func (d *adPosition) buildListFilter(req *dto.ListAdPositionReq) bson.M {
|
|||||||
|
|
||||||
// checkTotalCount 检查总数
|
// checkTotalCount 检查总数
|
||||||
func (d *adPosition) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
func (d *adPosition) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
||||||
total, err = mongo.Count(ctx, filter, entity.AdPositionCollection)
|
total, err = mongo.Count(ctx, d.NoCache, filter, entity.AdPositionCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +248,7 @@ func (d *adPosition) List(ctx context.Context, req *dto.ListAdPositionReq) (list
|
|||||||
|
|
||||||
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
||||||
|
|
||||||
err = mongo.Find(ctx, filter, &list, entity.AdPositionCollection, opts)
|
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdPositionCollection, opts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +260,6 @@ func (d *adPosition) GetAvailableAdPositions(ctx context.Context) (list []*entit
|
|||||||
|
|
||||||
opts := options.Find().SetSort(bson.M{"createdAt": -1})
|
opts := options.Find().SetSort(bson.M{"createdAt": -1})
|
||||||
|
|
||||||
err = mongo.Find(ctx, filter, &list, entity.AdPositionCollection, opts)
|
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdPositionCollection, opts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,26 +9,34 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AdSource = &adSourceDao{}
|
var AdSource = &adSourceDao{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type adSourceDao struct{}
|
type adSourceDao struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *adSourceDao) SetNoCache() {
|
||||||
|
AdSource.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// GetByName 根据名称获取广告源
|
// GetByName 根据名称获取广告源
|
||||||
func (d *adSourceDao) GetByName(ctx context.Context, name string) (adSource *entity.AdSource, err error) {
|
func (d *adSourceDao) GetByName(ctx context.Context, name string) (adSource *entity.AdSource, err error) {
|
||||||
err = mongo.FindOne(ctx, bson.M{"name": name}, &adSource, "ad_sources")
|
err = mongo.FindOne(ctx, d.NoCache, bson.M{"name": name}, &adSource, "ad_sources")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAvailableSources 获取可用的广告源
|
// GetAvailableSources 获取可用的广告源
|
||||||
func (d *adSourceDao) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
func (d *adSourceDao) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
||||||
err = mongo.Find(ctx, bson.M{"status": "active"}, &list, "ad_sources",
|
err = mongo.Find(ctx, d.NoCache, bson.M{"status": "active"}, &list, "ad_sources",
|
||||||
options.Find().SetSort(bson.M{"priority": -1, "createdAt": 1}))
|
options.Find().SetSort(bson.M{"priority": -1, "createdAt": 1}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourcesByProvider 根据提供商获取广告源
|
// GetSourcesByProvider 根据提供商获取广告源
|
||||||
func (d *adSourceDao) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
func (d *adSourceDao) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
||||||
err = mongo.Find(ctx, bson.M{"provider": provider, "status": "active"}, &list, "ad_sources",
|
err = mongo.Find(ctx, d.NoCache, bson.M{"provider": provider, "status": "active"}, &list, "ad_sources",
|
||||||
options.Find().SetSort(bson.M{"priority": -1}))
|
options.Find().SetSort(bson.M{"priority": -1}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -65,7 +73,7 @@ func (d *adSourceDao) Delete(ctx context.Context, id string) (affected int64, er
|
|||||||
|
|
||||||
// GetByID 根据ID获取广告源
|
// GetByID 根据ID获取广告源
|
||||||
func (d *adSourceDao) GetByID(ctx context.Context, id string) (adSource *entity.AdSource, err error) {
|
func (d *adSourceDao) GetByID(ctx context.Context, id string) (adSource *entity.AdSource, err error) {
|
||||||
err = mongo.FindOne(ctx, bson.M{"_id": id}, &adSource, "ad_sources")
|
err = mongo.FindOne(ctx, d.NoCache, bson.M{"_id": id}, &adSource, "ad_sources")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,17 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Advertisement = &advertisement{}
|
var Advertisement = &advertisement{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type advertisement struct{}
|
type advertisement struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *advertisement) SetNoCache() {
|
||||||
|
Advertisement.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// Insert 插入广告
|
// Insert 插入广告
|
||||||
func (d *advertisement) Insert(ctx context.Context, advertisement *entity.Advertisement) (err error) {
|
func (d *advertisement) Insert(ctx context.Context, advertisement *entity.Advertisement) (err error) {
|
||||||
@@ -173,7 +181,7 @@ func (d *advertisement) GetOne(ctx context.Context, id string) (advertisement *e
|
|||||||
filter := bson.M{"_id": objectId}
|
filter := bson.M{"_id": objectId}
|
||||||
|
|
||||||
advertisement = &entity.Advertisement{}
|
advertisement = &entity.Advertisement{}
|
||||||
err = mongo.FindOne(ctx, filter, advertisement, entity.AdvertisementCollection)
|
err = mongo.FindOne(ctx, d.NoCache, filter, advertisement, entity.AdvertisementCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +223,7 @@ func (d *advertisement) buildListFilter(req *dto.ListAdvertisementReq) bson.M {
|
|||||||
|
|
||||||
// checkTotalCount 检查总数
|
// checkTotalCount 检查总数
|
||||||
func (d *advertisement) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
func (d *advertisement) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
||||||
total, err = mongo.Count(ctx, filter, entity.AdvertisementCollection)
|
total, err = mongo.Count(ctx, d.NoCache, filter, entity.AdvertisementCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +256,6 @@ func (d *advertisement) List(ctx context.Context, req *dto.ListAdvertisementReq)
|
|||||||
|
|
||||||
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
||||||
|
|
||||||
err = mongo.Find(ctx, filter, &list, entity.AdvertisementCollection, opts)
|
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdvertisementCollection, opts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,17 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Advertiser = &advertiser{}
|
var Advertiser = &advertiser{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type advertiser struct{}
|
type advertiser struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *advertiser) SetNoCache() {
|
||||||
|
Advertiser.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// Insert 插入广告主
|
// Insert 插入广告主
|
||||||
func (d *advertiser) Insert(ctx context.Context, advertiser *entity.Advertiser) (err error) {
|
func (d *advertiser) Insert(ctx context.Context, advertiser *entity.Advertiser) (err error) {
|
||||||
@@ -183,7 +191,7 @@ func (d *advertiser) Recharge(ctx context.Context, id string, amount int64, rema
|
|||||||
|
|
||||||
// 先获取当前余额
|
// 先获取当前余额
|
||||||
advertiser := &entity.Advertiser{}
|
advertiser := &entity.Advertiser{}
|
||||||
err = mongo.FindOne(ctx, filter, advertiser, entity.AdvertiserCollection)
|
err = mongo.FindOne(ctx, d.NoCache, filter, advertiser, entity.AdvertiserCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -218,7 +226,7 @@ func (d *advertiser) GetOne(ctx context.Context, id string) (advertiser *entity.
|
|||||||
filter := bson.M{"_id": objectId}
|
filter := bson.M{"_id": objectId}
|
||||||
|
|
||||||
advertiser = &entity.Advertiser{}
|
advertiser = &entity.Advertiser{}
|
||||||
err = mongo.FindOne(ctx, filter, advertiser, entity.AdvertiserCollection)
|
err = mongo.FindOne(ctx, d.NoCache, filter, advertiser, entity.AdvertiserCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +268,7 @@ func (d *advertiser) buildListFilter(req *dto.ListAdvertiserReq) bson.M {
|
|||||||
|
|
||||||
// checkTotalCount 检查总数
|
// checkTotalCount 检查总数
|
||||||
func (d *advertiser) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
func (d *advertiser) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
||||||
total, err = mongo.Count(ctx, filter, entity.AdvertiserCollection)
|
total, err = mongo.Count(ctx, d.NoCache, filter, entity.AdvertiserCollection)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,6 +301,6 @@ func (d *advertiser) List(ctx context.Context, req *dto.ListAdvertiserReq) (list
|
|||||||
|
|
||||||
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
||||||
|
|
||||||
err = mongo.Find(ctx, filter, &list, entity.AdvertiserCollection, opts)
|
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdvertiserCollection, opts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// applicationDao 应用DAO
|
// applicationDao 应用DAO
|
||||||
type applicationDao struct{}
|
type applicationDao struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
var Application = &applicationDao{}
|
var Application = &applicationDao{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *applicationDao) SetNoCache() {
|
||||||
|
Application.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// Create 创建应用
|
// Create 创建应用
|
||||||
func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (string, error) {
|
func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (string, error) {
|
||||||
@@ -29,21 +37,23 @@ func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (s
|
|||||||
// GetByID 根据ID获取应用
|
// GetByID 根据ID获取应用
|
||||||
func (d *applicationDao) GetByID(ctx context.Context, id string) (*entity.Application, error) {
|
func (d *applicationDao) GetByID(ctx context.Context, id string) (*entity.Application, error) {
|
||||||
var app *entity.Application
|
var app *entity.Application
|
||||||
err := mongo.FindOne(ctx, bson.M{"_id": id}, &app, "application")
|
err := mongo.FindOne(ctx, d.NoCache, bson.M{"_id": id}, &app, "application")
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByTenantID 根据租户ID获取应用列表
|
// GetByTenantID 根据租户ID获取应用列表
|
||||||
func (d *applicationDao) GetByTenantID(ctx context.Context, tenantID string) ([]*entity.Application, error) {
|
func (d *applicationDao) GetByTenantID(ctx context.Context, tenantID string) ([]*entity.Application, error) {
|
||||||
var apps []*entity.Application
|
var apps []*entity.Application
|
||||||
err := mongo.Find(ctx, bson.M{"tenantId": tenantID}, &apps, "application")
|
err := mongo.Find(ctx, d.NoCache,
|
||||||
|
bson.M{"tenantId": tenantID}, &apps, "application")
|
||||||
return apps, err
|
return apps, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByAPIKey 根据API密钥获取应用
|
// GetByAPIKey 根据API密钥获取应用
|
||||||
func (d *applicationDao) GetByAPIKey(ctx context.Context, apiKey string) (*entity.Application, error) {
|
func (d *applicationDao) GetByAPIKey(ctx context.Context, apiKey string) (*entity.Application, error) {
|
||||||
var app *entity.Application
|
var app *entity.Application
|
||||||
err := mongo.FindOne(ctx, bson.M{"appKey": apiKey}, &app, "application")
|
err := mongo.FindOne(ctx, d.NoCache,
|
||||||
|
bson.M{"appKey": apiKey}, &app, "application")
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +77,13 @@ func (d *applicationDao) List(ctx context.Context, tenantID string, page, pageSi
|
|||||||
}
|
}
|
||||||
|
|
||||||
var apps []*entity.Application
|
var apps []*entity.Application
|
||||||
total, err := mongo.Count(ctx, filter, "application")
|
total, err := mongo.Count(ctx, d.NoCache, filter, "application")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := (page - 1) * pageSize
|
offset := (page - 1) * pageSize
|
||||||
err = mongo.Find(ctx, filter, &apps, "application",
|
err = mongo.Find(ctx, d.NoCache, filter, &apps, "application",
|
||||||
options.Find().SetSort(bson.M{"createdAt": -1}).
|
options.Find().SetSort(bson.M{"createdAt": -1}).
|
||||||
SetSkip(int64(offset)).
|
SetSkip(int64(offset)).
|
||||||
SetLimit(int64(pageSize)))
|
SetLimit(int64(pageSize)))
|
||||||
@@ -87,7 +97,7 @@ func (d *applicationDao) List(ctx context.Context, tenantID string, page, pageSi
|
|||||||
// GetByName 根据名称获取应用
|
// GetByName 根据名称获取应用
|
||||||
func (d *applicationDao) GetByName(ctx context.Context, name string) (*entity.Application, error) {
|
func (d *applicationDao) GetByName(ctx context.Context, name string) (*entity.Application, error) {
|
||||||
var app *entity.Application
|
var app *entity.Application
|
||||||
err := mongo.FindOne(ctx, bson.M{"name": name}, &app, "application")
|
err := mongo.FindOne(ctx, d.NoCache, bson.M{"name": name}, &app, "application")
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,17 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CIDRequest = &cidRequestDao{}
|
var CIDRequest = &cidRequestDao{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type cidRequestDao struct{}
|
type cidRequestDao struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *cidRequestDao) SetNoCache() {
|
||||||
|
CIDRequest.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// Create 创建CID请求记录
|
// Create 创建CID请求记录
|
||||||
func (d *cidRequestDao) Create(ctx context.Context, request *entity.CidRequest) (id string, err error) {
|
func (d *cidRequestDao) Create(ctx context.Context, request *entity.CidRequest) (id string, err error) {
|
||||||
@@ -30,14 +38,14 @@ func (d *cidRequestDao) GetHistory(ctx context.Context, userId string, page, siz
|
|||||||
filter := bson.M{"userId": userId}
|
filter := bson.M{"userId": userId}
|
||||||
|
|
||||||
// 获取总数
|
// 获取总数
|
||||||
total, err = mongo.Count(ctx, filter, entity.CidRequestCollection)
|
total, err = mongo.Count(ctx, d.NoCache, filter, entity.CidRequestCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页查询
|
// 分页查询
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
err = mongo.Find(ctx, filter, &list, entity.CidRequestCollection,
|
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.CidRequestCollection,
|
||||||
options.Find().SetSort(bson.M{"createdAt": -1}).
|
options.Find().SetSort(bson.M{"createdAt": -1}).
|
||||||
SetSkip(int64(offset)).
|
SetSkip(int64(offset)).
|
||||||
SetLimit(int64(size)))
|
SetLimit(int64(size)))
|
||||||
@@ -50,14 +58,14 @@ func (d *cidRequestDao) GetStatistics(ctx context.Context, userId string) (stats
|
|||||||
stats = make(map[string]interface{})
|
stats = make(map[string]interface{})
|
||||||
|
|
||||||
// 总请求数
|
// 总请求数
|
||||||
totalRequests, err := mongo.Count(ctx, bson.M{"userId": userId}, entity.CidRequestCollection)
|
totalRequests, err := mongo.Count(ctx, d.NoCache, bson.M{"userId": userId}, entity.CidRequestCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
stats["total_requests"] = totalRequests
|
stats["total_requests"] = totalRequests
|
||||||
|
|
||||||
// 成功请求数
|
// 成功请求数
|
||||||
successfulRequests, err := mongo.Count(ctx, bson.M{"userId": userId, "status": "completed"}, entity.CidRequestCollection)
|
successfulRequests, err := mongo.Count(ctx, d.NoCache, bson.M{"userId": userId, "status": "completed"}, entity.CidRequestCollection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,25 +9,33 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Strategy = &strategyDao{}
|
var Strategy = &strategyDao{
|
||||||
|
NoCache: true,
|
||||||
|
}
|
||||||
|
|
||||||
type strategyDao struct{}
|
type strategyDao struct {
|
||||||
|
NoCache bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *strategyDao) SetNoCache() {
|
||||||
|
Strategy.NoCache = true
|
||||||
|
}
|
||||||
|
|
||||||
// GetByName 根据名称获取策略
|
// GetByName 根据名称获取策略
|
||||||
func (d *strategyDao) GetByName(ctx context.Context, name string) (strategy *entity.Strategy, err error) {
|
func (d *strategyDao) GetByName(ctx context.Context, name string) (strategy *entity.Strategy, err error) {
|
||||||
err = mongo.FindOne(ctx, bson.M{"name": name}, &strategy, "strategies")
|
err = mongo.FindOne(ctx, d.NoCache, bson.M{"name": name}, &strategy, "strategies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID 根据ID获取策略
|
// GetByID 根据ID获取策略
|
||||||
func (d *strategyDao) GetByID(ctx context.Context, id string) (strategy *entity.Strategy, err error) {
|
func (d *strategyDao) GetByID(ctx context.Context, id string) (strategy *entity.Strategy, err error) {
|
||||||
err = mongo.FindOne(ctx, bson.M{"_id": id}, &strategy, "strategies")
|
err = mongo.FindOne(ctx, d.NoCache, bson.M{"_id": id}, &strategy, "strategies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByTenantLevel 根据租户级别获取策略
|
// GetByTenantLevel 根据租户级别获取策略
|
||||||
func (d *strategyDao) GetByTenantLevel(ctx context.Context, tenantLevel string) (strategy *entity.Strategy, err error) {
|
func (d *strategyDao) GetByTenantLevel(ctx context.Context, tenantLevel string) (strategy *entity.Strategy, err error) {
|
||||||
err = mongo.FindOne(ctx, bson.M{"tenantLevel": tenantLevel, "status": "active"}, &strategy, "strategies",
|
err = mongo.FindOne(ctx, d.NoCache, bson.M{"tenantLevel": tenantLevel, "status": "active"}, &strategy, "strategies",
|
||||||
options.FindOne().SetSort(bson.M{"priority": -1, "createdAt": 1}))
|
options.FindOne().SetSort(bson.M{"priority": -1, "createdAt": 1}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -75,14 +83,14 @@ func (d *strategyDao) GetList(ctx context.Context, page, size int, tenantLevel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取总数
|
// 获取总数
|
||||||
total, err = mongo.Count(ctx, filter, "strategies")
|
total, err = mongo.Count(ctx, d.NoCache, filter, "strategies")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页查询
|
// 分页查询
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
err = mongo.Find(ctx, filter, &list, "strategies",
|
err = mongo.Find(ctx, d.NoCache, filter, &list, "strategies",
|
||||||
options.Find().SetSort(bson.M{"priority": -1, "createdAt": -1}).
|
options.Find().SetSort(bson.M{"priority": -1, "createdAt": -1}).
|
||||||
SetSkip(int64(offset)).
|
SetSkip(int64(offset)).
|
||||||
SetLimit(int64(size)))
|
SetLimit(int64(size)))
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -3,7 +3,7 @@ module cid
|
|||||||
go 1.25.3
|
go 1.25.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitee.com/red-future---jilin-g/common v0.2.1
|
gitee.com/red-future---jilin-g/common v0.2.6
|
||||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.5
|
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.5
|
||||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.5
|
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.5
|
||||||
github.com/gogf/gf/v2 v2.9.5
|
github.com/gogf/gf/v2 v2.9.5
|
||||||
@@ -11,7 +11,7 @@ require (
|
|||||||
golang.org/x/net v0.47.0
|
golang.org/x/net v0.47.0
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace gitee.com/red-future---jilin-g/common v0.2.1 => ../common
|
//replace gitee.com/red-future---jilin-g/common v0.2.6 => ../common
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user