修复看板上次同步时间显示 Invalid Date

This commit is contained in:
2026-07-04 11:58:58 +08:00
parent aa37a93a35
commit ab14eb9c30
2 changed files with 12 additions and 4 deletions
+4 -1
View File
@@ -147,7 +147,10 @@ func (s *StockSyncService) doSync(ctx context.Context) (int, error) {
func (s *StockSyncService) LatestJob(ctx context.Context) (*models.StockSyncJob, error) {
var job models.StockSyncJob
if err := s.db.WithContext(ctx).Order("started_at DESC").First(&job).Error; err != nil {
if err := s.db.WithContext(ctx).
Where("started_at > ?", time.Time{}).
Order("started_at DESC").
First(&job).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
}
+8 -3
View File
@@ -233,9 +233,14 @@ function StockList({
function formatSyncStatus(job: SyncJob): string {
if (job.status === 'running') return '同步中…'
const timeStr = job.finished_at
? new Date(job.finished_at).toLocaleString()
: new Date(job.started_at).toLocaleString()
const ts = job.finished_at || job.started_at
let timeStr = '时间未知'
if (ts && ts !== '0001-01-01T00:00:00Z') {
const d = new Date(ts)
if (!isNaN(d.getTime())) {
timeStr = d.toLocaleString()
}
}
const statusText = job.status === 'success' ? '成功' : '失败'
return `${statusText} · ${timeStr}`
}