common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -14,9 +14,17 @@ import (
|
||||
)
|
||||
|
||||
// OrderMonthlyStatisticsDAO 订单月统计DAO
|
||||
type OrderMonthlyStatisticsDAO struct{}
|
||||
type OrderMonthlyStatisticsDAO struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
var OrderMonthlyStatisticsDAOInstance = &OrderMonthlyStatisticsDAO{}
|
||||
var OrderMonthlyStatisticsDAOInstance = &OrderMonthlyStatisticsDAO{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (dao *OrderMonthlyStatisticsDAO) SetNoCache() {
|
||||
OrderMonthlyStatisticsDAOInstance.NoCache = true
|
||||
}
|
||||
|
||||
// GenerateStatistics 使用Go代码生成月统计数据
|
||||
func (dao *OrderMonthlyStatisticsDAO) GenerateStatistics(ctx context.Context, tenantID int64, year int, month int) (*entity.OrderMonthlyStatistics, error) {
|
||||
@@ -36,28 +44,28 @@ func (dao *OrderMonthlyStatisticsDAO) GenerateStatistics(ctx context.Context, te
|
||||
"$lt": endDate,
|
||||
},
|
||||
}
|
||||
err := mongo.Find(ctx, filter, &pendingOrders, consts.OrderPendingCollection)
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &pendingOrders, consts.OrderPendingCollection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询待支付订单数据失败: %v", err)
|
||||
}
|
||||
|
||||
// 查询已支付订单
|
||||
var paidOrderEntities []*entity.OrderPaid
|
||||
err = mongo.Find(ctx, filter, &paidOrderEntities, consts.OrderPaidCollection)
|
||||
err = mongo.Find(ctx, dao.NoCache, filter, &paidOrderEntities, consts.OrderPaidCollection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询已支付订单数据失败: %v", err)
|
||||
}
|
||||
|
||||
// 查询已发货订单
|
||||
var shippedOrders []*entity.OrderShipped
|
||||
err = mongo.Find(ctx, filter, &shippedOrders, consts.OrderShippedCollection)
|
||||
err = mongo.Find(ctx, dao.NoCache, filter, &shippedOrders, consts.OrderShippedCollection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询已发货订单数据失败: %v", err)
|
||||
}
|
||||
|
||||
// 查询已完成订单
|
||||
var completedOrderEntities []*entity.OrderCompleted
|
||||
err = mongo.Find(ctx, filter, &completedOrderEntities, consts.OrderCompletedCollection)
|
||||
err = mongo.Find(ctx, dao.NoCache, filter, &completedOrderEntities, consts.OrderCompletedCollection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询已完成订单数据失败: %v", err)
|
||||
}
|
||||
@@ -294,7 +302,7 @@ func (dao *OrderMonthlyStatisticsDAO) calculateMonthOverMonthGrowth(ctx context.
|
||||
}
|
||||
|
||||
var lastMonthOrders []*entity.OrderBase
|
||||
err := mongo.Find(ctx, filter, &lastMonthOrders, consts.OrderCollection)
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &lastMonthOrders, consts.OrderCollection)
|
||||
if err != nil || len(lastMonthOrders) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
@@ -339,7 +347,7 @@ func (dao *OrderMonthlyStatisticsDAO) GetByTenantAndDate(ctx context.Context, te
|
||||
"reportDate": reportDate,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, filter, &result, consts.OrderMonthlyStatisticsCollection)
|
||||
err := mongo.FindOne(ctx, dao.NoCache, filter, &result, consts.OrderMonthlyStatisticsCollection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user