mongo.go重构
This commit is contained in:
@@ -5,26 +5,20 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/do"
|
||||
"gitee.com/red-future---jilin-g/common/mongo"
|
||||
"order/consts"
|
||||
"order/model/entity"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/do"
|
||||
"gitee.com/red-future---jilin-g/common/mongo"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// OrderQuarterlyStatisticsDAO 订单季度统计DAO
|
||||
type OrderQuarterlyStatisticsDAO struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
var OrderQuarterlyStatisticsDAOInstance = &OrderQuarterlyStatisticsDAO{
|
||||
NoCache: false,
|
||||
}
|
||||
|
||||
func (dao *OrderQuarterlyStatisticsDAO) SetNoCache() {
|
||||
OrderQuarterlyStatisticsDAOInstance.NoCache = true
|
||||
}
|
||||
var OrderQuarterlyStatisticsDAOInstance = &OrderQuarterlyStatisticsDAO{}
|
||||
|
||||
// GenerateStatistics 使用Go代码生成季度统计数据
|
||||
func (dao *OrderQuarterlyStatisticsDAO) GenerateStatistics(ctx context.Context, tenantID int64, year int, quarter int) (*entity.OrderQuarterlyStatistics, error) {
|
||||
@@ -54,7 +48,7 @@ func (dao *OrderQuarterlyStatisticsDAO) GenerateStatistics(ctx context.Context,
|
||||
}
|
||||
|
||||
var orders []*entity.OrderBase
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &orders, consts.OrderCollection)
|
||||
err := mongo.DB().Find(ctx, filter, &orders, consts.OrderCollection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("查询订单数据失败: %v", err)
|
||||
}
|
||||
@@ -255,7 +249,7 @@ func (dao *OrderQuarterlyStatisticsDAO) calculateQuarterOverQuarterGrowth(ctx co
|
||||
}
|
||||
|
||||
var lastQuarterOrders []*entity.OrderBase
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &lastQuarterOrders, consts.OrderCollection)
|
||||
err := mongo.DB().Find(ctx, filter, &lastQuarterOrders, consts.OrderCollection)
|
||||
if err != nil || len(lastQuarterOrders) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
@@ -286,7 +280,7 @@ func (dao *OrderQuarterlyStatisticsDAO) calculateYearOverYearGrowth(ctx context.
|
||||
}
|
||||
|
||||
var lastYearOrders []*entity.OrderBase
|
||||
err := mongo.Find(ctx, dao.NoCache, filter, &lastYearOrders, consts.OrderCollection)
|
||||
err := mongo.DB().Find(ctx, filter, &lastYearOrders, consts.OrderCollection)
|
||||
if err != nil || len(lastYearOrders) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
@@ -303,7 +297,7 @@ func (dao *OrderQuarterlyStatisticsDAO) calculateYearOverYearGrowth(ctx context.
|
||||
|
||||
// Save 保存季度统计数据
|
||||
func (dao *OrderQuarterlyStatisticsDAO) Save(ctx context.Context, statistics *entity.OrderQuarterlyStatistics) error {
|
||||
_, err := mongo.Insert(ctx, []interface{}{statistics}, consts.OrderQuarterlyStatisticsCollection)
|
||||
_, err := mongo.DB().Insert(ctx, []interface{}{statistics}, consts.OrderQuarterlyStatisticsCollection)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -318,7 +312,7 @@ func (dao *OrderQuarterlyStatisticsDAO) Update(ctx context.Context, statistics *
|
||||
"$set": statistics,
|
||||
}
|
||||
|
||||
_, err := mongo.Update(ctx, filter, update, consts.OrderQuarterlyStatisticsCollection)
|
||||
_, err := mongo.DB().Update(ctx, filter, update, consts.OrderQuarterlyStatisticsCollection)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -331,7 +325,7 @@ func (dao *OrderQuarterlyStatisticsDAO) GetByTenantAndDate(ctx context.Context,
|
||||
"reportDate": reportDate,
|
||||
}
|
||||
|
||||
err := mongo.FindOne(ctx, dao.NoCache, filter, &result, consts.OrderQuarterlyStatisticsCollection)
|
||||
err := mongo.DB().FindOne(ctx, filter, &result, consts.OrderQuarterlyStatisticsCollection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user