package api import ( "ssq-desk/internal/service" "ssq-desk/internal/storage/repository" ) // SyncAPI 数据同步 API type SyncAPI struct { syncService *service.SyncService } // NewSyncAPI 创建数据同步 API func NewSyncAPI() (*SyncAPI, error) { // 获取 MySQL 和 SQLite Repository mysqlRepo, err := repository.NewMySQLSsqRepository() if err != nil { return nil, err } sqliteRepo, err := repository.NewSQLiteSsqRepository() if err != nil { return nil, err } syncService := service.NewSyncService(mysqlRepo, sqliteRepo) return &SyncAPI{ syncService: syncService, }, nil } // Sync 执行数据同步 func (api *SyncAPI) Sync() (map[string]interface{}, error) { if api.syncService == nil { newAPI, err := NewSyncAPI() if err != nil { return nil, err } api.syncService = newAPI.syncService } result, err := api.syncService.Sync() if err != nil { return nil, err } return map[string]interface{}{ "total_count": result.TotalCount, "synced_count": result.SyncedCount, "new_count": result.NewCount, "updated_count": result.UpdatedCount, "error_count": result.ErrorCount, "latest_issue": result.LatestIssue, }, nil } // GetSyncStatus 获取同步状态 func (api *SyncAPI) GetSyncStatus() (map[string]interface{}, error) { if api.syncService == nil { newAPI, err := NewSyncAPI() if err != nil { return nil, err } api.syncService = newAPI.syncService } return api.syncService.GetSyncStatus() }