common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -14,9 +14,17 @@ import (
|
||||
)
|
||||
|
||||
// OrderQuarterlyStatisticsDAO 订单季度统计DAO
|
||||
type OrderQuarterlyStatisticsDAO struct{}
|
||||
type OrderQuarterlyStatisticsDAO struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
var OrderQuarterlyStatisticsDAOInstance = &OrderQuarterlyStatisticsDAO{}
|
||||
var OrderQuarterlyStatisticsDAOInstance = &OrderQuarterlyStatisticsDAO{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (dao *OrderQuarterlyStatisticsDAO) SetNoCache() {
|
||||
OrderQuarterlyStatisticsDAOInstance.NoCache = true
|
||||
}
|
||||
|
||||
// GenerateStatistics 使用Go代码生成季度统计数据
|
||||
func (dao *OrderQuarterlyStatisticsDAO) GenerateStatistics(ctx context.Context, tenantID int64, year int, quarter int) (*entity.OrderQuarterlyStatistics, error) {
|
||||
@@ -46,7 +54,7 @@ func (dao *OrderQuarterlyStatisticsDAO) GenerateStatistics(ctx context.Context,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -247,7 +255,7 @@ func (dao *OrderQuarterlyStatisticsDAO) calculateQuarterOverQuarterGrowth(ctx co
|
||||
}
|
||||
|
||||
var lastQuarterOrders []*entity.OrderBase
|
||||
err := mongo.Find(ctx, filter, &lastQuarterOrders, consts.OrderCollection)
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &lastQuarterOrders, consts.OrderCollection)
|
||||
if err != nil || len(lastQuarterOrders) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
@@ -278,7 +286,7 @@ func (dao *OrderQuarterlyStatisticsDAO) calculateYearOverYearGrowth(ctx context.
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -323,7 +331,7 @@ func (dao *OrderQuarterlyStatisticsDAO) GetByTenantAndDate(ctx context.Context,
|
||||
"reportDate": reportDate,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, filter, &result, consts.OrderQuarterlyStatisticsCollection)
|
||||
err := mongo.FindOne(ctx, dao.NoCache, filter, &result, consts.OrderQuarterlyStatisticsCollection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user