首页订单数量 es请求优化
This commit is contained in:
parent
0e7879a9c1
commit
5e638b826d
@ -72,6 +72,7 @@ type ExternalAPIConfig struct {
|
|||||||
SyncTaskURL string `yaml:"sync_task_url"`
|
SyncTaskURL string `yaml:"sync_task_url"`
|
||||||
SyncTaskBodyURL string `yaml:"sync_task_body_url"`
|
SyncTaskBodyURL string `yaml:"sync_task_body_url"`
|
||||||
ESUpdateBookURL string `yaml:"es_update_book_url"`
|
ESUpdateBookURL string `yaml:"es_update_book_url"`
|
||||||
|
ESSearchBookURL string `yaml:"es_search_book_url"`
|
||||||
Timeout int `yaml:"timeout"`
|
Timeout int `yaml:"timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,7 @@ func createTenantDB(dbName string) (*gorm.DB, error) {
|
|||||||
sqlDB.SetConnMaxLifetime(10 * time.Minute) // 单个连接最大存活10分钟
|
sqlDB.SetConnMaxLifetime(10 * time.Minute) // 单个连接最大存活10分钟
|
||||||
sqlDB.SetConnMaxIdleTime(2 * time.Minute) // 空闲连接2分钟后关闭
|
sqlDB.SetConnMaxIdleTime(2 * time.Minute) // 空闲连接2分钟后关闭
|
||||||
|
|
||||||
migrateTenantTables(tenantDB)
|
//migrateTenantTables(tenantDB)
|
||||||
|
|
||||||
return tenantDB, nil
|
return tenantDB, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"psi/config"
|
||||||
"psi/database"
|
"psi/database"
|
||||||
"psi/models"
|
"psi/models"
|
||||||
systemReq "psi/models/request"
|
systemReq "psi/models/request"
|
||||||
@ -25,7 +26,8 @@ func (s *BookService) GetBookInfo(req systemReq.BookRequest) (*systemRes.ESBook,
|
|||||||
// 调用ES接口
|
// 调用ES接口
|
||||||
isbn := req.Isbn
|
isbn := req.Isbn
|
||||||
log.Printf("[GetBookInfo] 请求 ISBN: %s", isbn)
|
log.Printf("[GetBookInfo] 请求 ISBN: %s", isbn)
|
||||||
apiURL := fmt.Sprintf("https://book.center.yushutx.com/api/es/searchByISBNtoPsi?isbn=%s", isbn)
|
apiURL := fmt.Sprintf("%s?isbn=%s", config.AppConfig.ExternalAPI.ESSearchBookURL, isbn)
|
||||||
|
log.Printf("[GetBookInfo] 请求 URL: %s", apiURL)
|
||||||
resp, err := http.Get(apiURL)
|
resp, err := http.Get(apiURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("[ERROR] 请求 ES 接口失败:%v\n", err)
|
return nil, fmt.Errorf("[ERROR] 请求 ES 接口失败:%v\n", err)
|
||||||
|
|||||||
@ -184,8 +184,10 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa
|
|||||||
|
|
||||||
// 结果结构体
|
// 结果结构体
|
||||||
type salesTodayYesterday struct {
|
type salesTodayYesterday struct {
|
||||||
TodayCount int64 `gorm:"column:today_count"`
|
TodayCount int64 `gorm:"column:today_count"` // 今日订单数
|
||||||
YesterdayCount int64 `gorm:"column:yesterday_count"`
|
YesterdayCount int64 `gorm:"column:yesterday_count"` // 昨日订单数
|
||||||
|
TodayAmount int64 `gorm:"column:today_amount"` // 今日销售金额(分)
|
||||||
|
YesterdayAmount int64 `gorm:"column:yesterday_amount"` // 昨日销售金额(分)
|
||||||
}
|
}
|
||||||
type receivingTodayYesterday struct {
|
type receivingTodayYesterday struct {
|
||||||
TodayCount int64 `gorm:"column:today_count"`
|
TodayCount int64 `gorm:"column:today_count"`
|
||||||
@ -223,9 +225,11 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
statErr = databaseConn.Model(&models.SalesOrder{}).
|
statErr = databaseConn.Model(&models.SalesOrder{}).
|
||||||
Select(`
|
Select(`
|
||||||
COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as today_count,
|
COALESCE(COUNT(CASE WHEN created_at >= ? AND created_at <= ? THEN 1 END), 0) as today_count,
|
||||||
COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as yesterday_count
|
COALESCE(COUNT(CASE WHEN created_at >= ? AND created_at <= ? THEN 1 END), 0) as yesterday_count,
|
||||||
`, todayStart, todayEnd, yesterdayStart, yesterdayEnd).
|
COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as today_amount,
|
||||||
|
COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as yesterday_amount
|
||||||
|
`, todayStart, todayEnd, yesterdayStart, yesterdayEnd, todayStart, todayEnd, yesterdayStart, yesterdayEnd).
|
||||||
Where("is_del = ?", 0).
|
Where("is_del = ?", 0).
|
||||||
Scan(&salesStat).Error
|
Scan(&salesStat).Error
|
||||||
}()
|
}()
|
||||||
@ -338,11 +342,13 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa
|
|||||||
TotalOrderCount: salesStat.TodayCount,
|
TotalOrderCount: salesStat.TodayCount,
|
||||||
TotalReceivingCount: receivingStat.TodayCount,
|
TotalReceivingCount: receivingStat.TodayCount,
|
||||||
TotalOutboundCount: outboundStat.TodayCount,
|
TotalOutboundCount: outboundStat.TodayCount,
|
||||||
TodaySaleAmount: salesStat.TodayCount,
|
TotalSaleCount: salesStat.TodayCount,
|
||||||
|
TodaySaleAmount: salesStat.TodayAmount,
|
||||||
YesterdayOrderCount: salesStat.YesterdayCount,
|
YesterdayOrderCount: salesStat.YesterdayCount,
|
||||||
YesterdayReceivingCount: receivingStat.YesterdayCount,
|
YesterdayReceivingCount: receivingStat.YesterdayCount,
|
||||||
YesterdayOutboundCount: outboundStat.YesterdayCount,
|
YesterdayOutboundCount: outboundStat.YesterdayCount,
|
||||||
YesterdaySaleAmount: salesStat.YesterdayCount,
|
YesterdaySaleCount: salesStat.YesterdayCount,
|
||||||
|
YesterdaySaleAmount: salesStat.YesterdayAmount,
|
||||||
UserStats: userStats,
|
UserStats: userStats,
|
||||||
ProductTotal: productTotal,
|
ProductTotal: productTotal,
|
||||||
InventoryTotal: inventoryTotal,
|
InventoryTotal: inventoryTotal,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user