@@ -25,13 +25,15 @@ public class DbDailySyncWorker : BackgroundService, IDbDailySyncWorker
25
25
private readonly IExportServiceFactory _factory ;
26
26
private readonly ExportOptions _options ;
27
27
private readonly TimeSpan _time ;
28
+ private readonly TimeSpan _offset ;
28
29
private readonly string _path ;
29
30
30
31
public DbDailySyncWorker ( ILogger < DbDailySyncWorker > logger , IFreeSql freeSql , IConfiguration configuration , IExportServiceFactory exportService )
31
32
{
32
33
_options = configuration . GetSection ( ExportOptions . Export ) . Get < ExportOptions > ( ) ?? throw new InvalidOperationException ( ) ;
33
34
_path = string . IsNullOrWhiteSpace ( _options . Path ) ? Path . Combine ( Environment . CurrentDirectory , "Data" ) : _options . Path ;
34
35
_time = _options . Trigger ;
36
+ _offset = _options . Offset ?? TimeSpan . FromHours ( 6 ) ;
35
37
_logger = logger ;
36
38
_freeSql = freeSql ;
37
39
_factory = exportService ;
@@ -63,7 +65,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
63
65
64
66
if ( launch )
65
67
{
66
- await HandlerAsync ( DateTime . Now , dir , types , timeout , stoppingToken ) ;
68
+ await HandlerAsync ( DateTime . Now , _offset , dir , types , timeout , stoppingToken ) ;
67
69
}
68
70
69
71
while ( ! stoppingToken . IsCancellationRequested )
@@ -75,7 +77,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
75
77
_logger . LogDebug ( "Sync Check: {ret}" , ret ) ;
76
78
if ( ! ret ) continue ;
77
79
78
- await HandlerAsync ( now , dir , types , timeout , stoppingToken ) ;
80
+ await HandlerAsync ( now , _offset , dir , types , timeout , stoppingToken ) ;
79
81
}
80
82
catch ( Exception ex )
81
83
{
@@ -86,7 +88,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
86
88
_logger . LogInformation ( "Sync Executed" ) ;
87
89
}
88
90
89
- protected async Task HandlerAsync ( DateTime now , string dir , ConcurrentDictionary < string , TableInfo > types , int timeout , CancellationToken stoppingToken )
91
+ protected async Task HandlerAsync ( DateTime now , TimeSpan offset , string dir , ConcurrentDictionary < string , TableInfo > types , int timeout , CancellationToken stoppingToken )
90
92
{
91
93
_logger . LogInformation ( "Sync Handler Executing" ) ;
92
94
@@ -125,7 +127,7 @@ protected async Task HandlerAsync(DateTime now,string dir, ConcurrentDictionary<
125
127
_ => null
126
128
} ;
127
129
128
- var total = await FetchRecordAsync ( _freeSql , timeout , table , date , _path , types [ table . Code ] , exportService , _logger , stoppingToken ) ;
130
+ var total = await FetchRecordAsync ( _freeSql , timeout , table , date , offset , _path , types [ table . Code ] , exportService , _logger , stoppingToken ) ;
129
131
sw . Stop ( ) ;
130
132
_logger . LogInformation ( "Executing synchronously [{Table}]-{Date:yyyy-MM-dd} export to {Output} {Total} records completed used {Time}."
131
133
, table . Name
@@ -189,6 +191,7 @@ private static async Task<int> FetchRecordAsync(IFreeSql freeSql,
189
191
int timeout ,
190
192
TableOptions table ,
191
193
DateTime date ,
194
+ TimeSpan offset ,
192
195
string dir ,
193
196
TableInfo info ,
194
197
IExportService exportService ,
@@ -205,13 +208,13 @@ CancellationToken stoppingToken
205
208
{
206
209
Field = $ "a.{ table . Filter } ",
207
210
Operator = DynamicFilterOperator . GreaterThanOrEqual ,
208
- Value = date . Date
211
+ Value = date . Date + offset
209
212
} ,
210
213
new ( )
211
214
{
212
215
Field = $ "a.{ table . Filter } ",
213
216
Operator = DynamicFilterOperator . LessThan ,
214
- Value = date . Date . AddDays ( 1 )
217
+ Value = date . Date . AddDays ( 1 ) + offset
215
218
}
216
219
}
217
220
} ;
0 commit comments