diff --git a/config/config.go b/config/config.go index f3524e4..63702f5 100644 --- a/config/config.go +++ b/config/config.go @@ -72,6 +72,7 @@ type ExternalAPIConfig struct { SyncTaskURL string `yaml:"sync_task_url"` SyncTaskBodyURL string `yaml:"sync_task_body_url"` ESUpdateBookURL string `yaml:"es_update_book_url"` + ESSearchBookURL string `yaml:"es_search_book_url"` Timeout int `yaml:"timeout"` } diff --git a/database/tenant.go b/database/tenant.go index 218211a..1bacb58 100644 --- a/database/tenant.go +++ b/database/tenant.go @@ -119,7 +119,7 @@ func createTenantDB(dbName string) (*gorm.DB, error) { sqlDB.SetConnMaxLifetime(10 * time.Minute) // 单个连接最大存活10分钟 sqlDB.SetConnMaxIdleTime(2 * time.Minute) // 空闲连接2分钟后关闭 - migrateTenantTables(tenantDB) + //migrateTenantTables(tenantDB) return tenantDB, nil } diff --git a/service/book.go b/service/book.go index af9093f..4fbb31d 100644 --- a/service/book.go +++ b/service/book.go @@ -9,6 +9,7 @@ import ( "io" "log" "net/http" + "psi/config" "psi/database" "psi/models" systemReq "psi/models/request" @@ -25,7 +26,8 @@ func (s *BookService) GetBookInfo(req systemReq.BookRequest) (*systemRes.ESBook, // 调用ES接口 isbn := req.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) if err != nil { return nil, fmt.Errorf("[ERROR] 请求 ES 接口失败:%v\n", err) diff --git a/service/statist.go b/service/statist.go index 18d9e27..a31f9b9 100644 --- a/service/statist.go +++ b/service/statist.go @@ -184,8 +184,10 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa // 结果结构体 type salesTodayYesterday struct { - TodayCount int64 `gorm:"column:today_count"` - YesterdayCount int64 `gorm:"column:yesterday_count"` + TodayCount int64 `gorm:"column:today_count"` // 今日订单数 + YesterdayCount int64 `gorm:"column:yesterday_count"` // 昨日订单数 + TodayAmount int64 `gorm:"column:today_amount"` // 今日销售金额(分) + YesterdayAmount int64 `gorm:"column:yesterday_amount"` // 昨日销售金额(分) } type receivingTodayYesterday struct { TodayCount int64 `gorm:"column:today_count"` @@ -223,9 +225,11 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa defer wg.Done() statErr = databaseConn.Model(&models.SalesOrder{}). Select(` - COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as today_count, - COALESCE(SUM(CASE WHEN created_at >= ? AND created_at <= ? THEN total_amount ELSE 0 END), 0) as yesterday_count - `, todayStart, todayEnd, yesterdayStart, yesterdayEnd). + COALESCE(COUNT(CASE WHEN created_at >= ? AND created_at <= ? THEN 1 END), 0) as today_count, + COALESCE(COUNT(CASE WHEN created_at >= ? AND created_at <= ? THEN 1 END), 0) as yesterday_count, + 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). Scan(&salesStat).Error }() @@ -338,11 +342,13 @@ func (s *StatistService) getDashboardStatRealtime(databaseConn *gorm.DB, startDa TotalOrderCount: salesStat.TodayCount, TotalReceivingCount: receivingStat.TodayCount, TotalOutboundCount: outboundStat.TodayCount, - TodaySaleAmount: salesStat.TodayCount, + TotalSaleCount: salesStat.TodayCount, + TodaySaleAmount: salesStat.TodayAmount, YesterdayOrderCount: salesStat.YesterdayCount, YesterdayReceivingCount: receivingStat.YesterdayCount, YesterdayOutboundCount: outboundStat.YesterdayCount, - YesterdaySaleAmount: salesStat.YesterdayCount, + YesterdaySaleCount: salesStat.YesterdayCount, + YesterdaySaleAmount: salesStat.YesterdayAmount, UserStats: userStats, ProductTotal: productTotal, InventoryTotal: inventoryTotal,