common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关

This commit is contained in:
2025-12-29 15:58:48 +08:00
parent ca7b1cd989
commit c150f38a87
9 changed files with 129 additions and 56 deletions

View File

@@ -14,9 +14,17 @@ import (
)
// OrderYearlyStatisticsDAO 订单年度统计DAO
type OrderYearlyStatisticsDAO struct{}
type OrderYearlyStatisticsDAO struct {
NoCache bool
}
var OrderYearlyStatisticsDAOInstance = &OrderYearlyStatisticsDAO{}
var OrderYearlyStatisticsDAOInstance = &OrderYearlyStatisticsDAO{
NoCache: false,
}
func (dao *OrderYearlyStatisticsDAO) SetNoCache() {
OrderYearlyStatisticsDAOInstance.NoCache = true
}
// GenerateStatistics 使用Go代码生成年度统计数据
func (dao *OrderYearlyStatisticsDAO) GenerateStatistics(ctx context.Context, tenantID int64, year int) (*entity.OrderYearlyStatistics, error) {
@@ -34,7 +42,7 @@ func (dao *OrderYearlyStatisticsDAO) GenerateStatistics(ctx context.Context, ten
}
var orders []*entity.OrderBase
err := mongo.Find(ctx, filter, &orders, consts.OrderCollection)
err := mongo.Find(ctx, dao.NoCache, filter, &orders, consts.OrderCollection)
if err != nil {
return nil, fmt.Errorf("查询订单数据失败: %v", err)
}
@@ -222,7 +230,7 @@ func (dao *OrderYearlyStatisticsDAO) calculateYearOverYearGrowth(ctx context.Con
}
var lastYearOrders []*entity.OrderBase
err := mongo.Find(ctx, filter, &lastYearOrders, consts.OrderCollection)
err := mongo.Find(ctx, dao.NoCache, filter, &lastYearOrders, consts.OrderCollection)
if err != nil || len(lastYearOrders) == 0 {
return 0.0
}
@@ -267,7 +275,7 @@ func (dao *OrderYearlyStatisticsDAO) GetByTenantAndDate(ctx context.Context, ten
"reportDate": reportDate,
}
err := mongo.FindOne(ctx, filter, &result, consts.OrderYearlyStatisticsCollection)
err := mongo.FindOne(ctx, dao.NoCache, filter, &result, consts.OrderYearlyStatisticsCollection)
if err != nil {
return nil, err
}