@@ -11,36 +11,13 @@ namespace RailGo.Core.Query;
1111
1212public class ApiService
1313{
14- #region URL常量定义
15- public const string TrainPreselect_url = "https://data.railgo.zenglingkun.cn/api/train/preselect" ;
16- public const string TrainQuery_url = "https://data.railgo.zenglingkun.cn/api/train/query" ;
17- public const string StationToStationQuery_url = "https://data.railgo.zenglingkun.cn/api/train/sts_query" ;
18- public const string StationPreselect_url = "https://data.railgo.zenglingkun.cn/api/station/preselect" ;
19- public const string StationQuery_url = "https://data.railgo.zenglingkun.cn/api/station/query" ;
20- public const string EmuAssignmentQuery_url = "https://delay.data.railgo.zenglingkun.cn/api/trainAssignment/queryEmu" ;
21- public const string TrainDelayQuery_url = "https://delay.data.railgo.zenglingkun.cn/api/trainDetails/queryTrainDelayDetails" ;
22- public const string PlatformInfoQuery_url = "https://mobile.12306.cn/wxxcx/wechat/bigScreen/getExit" ;
23- private const string GetBigScreenData_url = "https://screen.data.railgo.zenglingkun.cn" ;
24- private const string EmuQuery_url = "https://emu.data.railgo.zenglingkun.cn" ;
25- private const string DownloadEmuImage_url = "https://tp.railgo.zenglingkun.cn/api" ;
26- #endregion
27-
2814 #region 离线模式判断
2915
30- /// <summary>
31- /// 判断是否使用离线模式
32- /// </summary>
33- private static bool IsOfflineMode ( )
34- {
35- return DBGetService . LocalDatabaseExists ( ) ;
36- }
37-
3816 /// <summary>
3917 /// 获取离线服务实例
4018 /// </summary>
41- public static T GetOfflineService < T > ( ) where T : BaseOfflineService
19+ public static T GetOfflineService < T > ( string databasePath ) where T : BaseOfflineService
4220 {
43- var databasePath = DBGetService . GetLocalDatabasePath ( ) ;
4421 return ( T ) Activator . CreateInstance ( typeof ( T ) , databasePath ) ;
4522 }
4623
@@ -51,11 +28,11 @@ public static T GetOfflineService<T>() where T : BaseOfflineService
5128 /// <summary>
5229 /// 车次预选搜索
5330 /// </summary>
54- public static async Task < ObservableCollection < TrainPreselectResult > > TrainPreselectAsync ( string keyword )
31+ public static async Task < ObservableCollection < TrainPreselectResult > > TrainPreselectAsync ( bool isOfflineMode , string urlOrDbPath , string keyword )
5532 {
56- if ( IsOfflineMode ( ) )
33+ if ( isOfflineMode )
5734 {
58- var offlineService = GetOfflineService < TrainOfflineService > ( ) ;
35+ var offlineService = GetOfflineService < TrainOfflineService > ( urlOrDbPath ) ;
5936 var json = await offlineService . TrainPreselectAsync ( keyword ) ;
6037 var stringArray = JsonConvert . DeserializeObject < ObservableCollection < string > > ( json ) ;
6138
@@ -71,7 +48,7 @@ public static async Task<ObservableCollection<TrainPreselectResult>> TrainPresel
7148 }
7249 else
7350 {
74- var stringArray = await OnlineApiService . TrainPreselectAsync ( keyword , TrainPreselect_url ) ;
51+ var stringArray = await OnlineApiService . TrainPreselectAsync ( keyword , urlOrDbPath ) ;
7552 var result = new ObservableCollection < TrainPreselectResult > ( ) ;
7653 if ( stringArray != null )
7754 {
@@ -87,34 +64,34 @@ public static async Task<ObservableCollection<TrainPreselectResult>> TrainPresel
8764 /// <summary>
8865 /// 车次详情查询
8966 /// </summary>
90- public static async Task < Train > TrainQueryAsync ( string trainNumber )
67+ public static async Task < Train > TrainQueryAsync ( bool isOfflineMode , string urlOrDbPath , string trainNumber )
9168 {
92- if ( IsOfflineMode ( ) )
69+ if ( isOfflineMode )
9370 {
94- var offlineService = GetOfflineService < TrainOfflineService > ( ) ;
71+ var offlineService = GetOfflineService < TrainOfflineService > ( urlOrDbPath ) ;
9572 var json = await offlineService . TrainQueryAsync ( trainNumber ) ;
9673 return JsonConvert . DeserializeObject < Train > ( json ) ;
9774 }
9875 else
9976 {
100- return await OnlineApiService . TrainQueryAsync ( trainNumber , TrainQuery_url ) ;
77+ return await OnlineApiService . TrainQueryAsync ( trainNumber , urlOrDbPath ) ;
10178 }
10279 }
10380
10481 /// <summary>
10582 /// 站站查询
10683 /// </summary>
107- public static async Task < List < Train > > StationToStationQueryAsync ( string from , string to , string date )
84+ public static async Task < List < Train > > StationToStationQueryAsync ( bool isOfflineMode , string urlOrDbPath , string from , string to , string date )
10885 {
109- if ( IsOfflineMode ( ) )
86+ if ( isOfflineMode )
11087 {
111- var offlineService = GetOfflineService < TrainOfflineService > ( ) ;
88+ var offlineService = GetOfflineService < TrainOfflineService > ( urlOrDbPath ) ;
11289 var json = await offlineService . StationToStationQueryAsync ( from , to , date ) ;
11390 return JsonConvert . DeserializeObject < List < Train > > ( json ) ;
11491 }
11592 else
11693 {
117- return await OnlineApiService . StationToStationQueryAsync ( from , to , date , StationToStationQuery_url ) ;
94+ return await OnlineApiService . StationToStationQueryAsync ( from , to , date , urlOrDbPath ) ;
11895 }
11996 }
12097
@@ -125,45 +102,45 @@ public static async Task<List<Train>> StationToStationQueryAsync(string from, st
125102 /// <summary>
126103 /// 车站预选搜索
127104 /// </summary>
128- public static async Task < ObservableCollection < StationPreselectResult > > StationPreselectAsync ( string keyword )
105+ public static async Task < ObservableCollection < StationPreselectResult > > StationPreselectAsync ( bool isOfflineMode , string urlOrDbPath , string keyword )
129106 {
130- if ( IsOfflineMode ( ) )
107+ if ( isOfflineMode )
131108 {
132- var offlineService = GetOfflineService < StationOfflineService > ( ) ;
109+ var offlineService = GetOfflineService < StationOfflineService > ( urlOrDbPath ) ;
133110 var json = await offlineService . StationPreselectAsync ( keyword ) ;
134111 return JsonConvert . DeserializeObject < ObservableCollection < StationPreselectResult > > ( json ) ;
135112 }
136113 else
137114 {
138- return await OnlineApiService . StationPreselectAsync ( keyword , StationPreselect_url ) ;
115+ return await OnlineApiService . StationPreselectAsync ( keyword , urlOrDbPath ) ;
139116 }
140117 }
141118
142119 /// <summary>
143120 /// 车站详情查询
144121 /// </summary>
145- public static async Task < StationQueryResponse > StationQueryAsync ( string telecode )
122+ public static async Task < StationQueryResponse > StationQueryAsync ( bool isOfflineMode , string urlOrDbPath , string telecode )
146123 {
147- if ( IsOfflineMode ( ) )
124+ if ( isOfflineMode )
148125 {
149- var offlineService = GetOfflineService < StationOfflineService > ( ) ;
126+ var offlineService = GetOfflineService < StationOfflineService > ( urlOrDbPath ) ;
150127 var json = await offlineService . StationQueryAsync ( telecode ) ;
151128 return JsonConvert . DeserializeObject < StationQueryResponse > ( json ) ;
152129 }
153130 else
154131 {
155- return await OnlineApiService . StationQueryAsync ( telecode , StationQuery_url ) ;
132+ return await OnlineApiService . StationQueryAsync ( telecode , urlOrDbPath ) ;
156133 }
157134 }
158135
159136 /// <summary>
160137 /// 车站大屏数据
161138 /// </summary>
162- public static async Task < BigScreenData > GetBigScreenDataAsync ( string stationName )
139+ public static async Task < BigScreenData > GetBigScreenDataAsync ( bool isOfflineMode , string urlOrDbPath , string stationName )
163140 {
164- if ( ! IsOfflineMode ( ) )
141+ if ( ! isOfflineMode )
165142 {
166- return await OnlineApiService . GetBigScreenDataAsync ( stationName , GetBigScreenData_url ) ;
143+ return await OnlineApiService . GetBigScreenDataAsync ( stationName , urlOrDbPath ) ;
167144 }
168145 return null ;
169146 }
@@ -175,11 +152,11 @@ public static async Task<BigScreenData> GetBigScreenDataAsync(string stationName
175152 /// <summary>
176153 /// 动车组运行交路查询
177154 /// </summary>
178- public static async Task < ObservableCollection < EmuOperation > > EmuQueryAsync ( string type , string keyword )
155+ public static async Task < ObservableCollection < EmuOperation > > EmuQueryAsync ( bool isOfflineMode , string urlOrDbPath , string type , string keyword )
179156 {
180- if ( ! IsOfflineMode ( ) )
157+ if ( ! isOfflineMode )
181158 {
182- return await OnlineApiService . EmuQueryAsync ( type , keyword , EmuQuery_url ) ;
159+ return await OnlineApiService . EmuQueryAsync ( type , keyword , urlOrDbPath ) ;
183160 }
184161 return null ;
185162 }
@@ -188,11 +165,11 @@ public static async Task<ObservableCollection<EmuOperation>> EmuQueryAsync(strin
188165 /// 动车组配属查询
189166 /// </summary>
190167 public static async Task < ObservableCollection < EmuAssignment > > EmuAssignmentQueryAsync (
191- string type , string keyword , int cursor = 0 , int count = 15 )
168+ bool isOfflineMode , string urlOrDbPath , string type , string keyword , int cursor = 0 , int count = 15 )
192169 {
193- if ( ! IsOfflineMode ( ) )
170+ if ( ! isOfflineMode )
194171 {
195- return await OnlineApiService . EmuAssignmentQueryAsync ( type , keyword , cursor , count , EmuAssignmentQuery_url ) ;
172+ return await OnlineApiService . EmuAssignmentQueryAsync ( type , keyword , cursor , count , urlOrDbPath ) ;
196173 }
197174 else
198175 {
@@ -207,25 +184,25 @@ public static async Task<ObservableCollection<EmuAssignment>> EmuAssignmentQuery
207184 /// <summary>
208185 /// 正晚点查询
209186 /// </summary>
210- public static async Task < List < DelayInfo > > QueryTrainDelayAsync ( string date , string trainNumber ,
187+ public static async Task < List < DelayInfo > > QueryTrainDelayAsync ( bool isOfflineMode , string urlOrDbPath , string date , string trainNumber ,
211188 string fromStation , string toStation )
212189 {
213- if ( ! IsOfflineMode ( ) )
190+ if ( ! isOfflineMode )
214191 {
215- return await OnlineApiService . QueryTrainDelayAsync ( date , trainNumber , fromStation , toStation , TrainDelayQuery_url ) ;
192+ return await OnlineApiService . QueryTrainDelayAsync ( date , trainNumber , fromStation , toStation , urlOrDbPath ) ;
216193 }
217194 return null ;
218195 }
219196
220197 /// <summary>
221198 /// 停台检票口查询
222199 /// </summary>
223- public static async Task < PlatformInfo > QueryPlatformInfoAsync ( string stationCode , string trainDate ,
200+ public static async Task < PlatformInfo > QueryPlatformInfoAsync ( bool isOfflineMode , string urlOrDbPath , string stationCode , string trainDate ,
224201 string type , string stationTrainCode )
225202 {
226- if ( ! IsOfflineMode ( ) )
203+ if ( ! isOfflineMode )
227204 {
228- return await OnlineApiService . QueryPlatformInfoAsync ( stationCode , trainDate , type , stationTrainCode , PlatformInfoQuery_url ) ;
205+ return await OnlineApiService . QueryPlatformInfoAsync ( stationCode , trainDate , type , stationTrainCode , urlOrDbPath ) ;
229206 }
230207 return null ;
231208 }
@@ -237,11 +214,11 @@ public static async Task<PlatformInfo> QueryPlatformInfoAsync(string stationCode
237214 /// <summary>
238215 /// 下载动车组图片
239216 /// </summary>
240- public static async Task < byte [ ] > DownloadEmuImageAsync ( string trainModel )
217+ public static async Task < byte [ ] > DownloadEmuImageAsync ( bool isOfflineMode , string urlOrDbPath , string trainModel )
241218 {
242- if ( ! IsOfflineMode ( ) )
219+ if ( ! isOfflineMode )
243220 {
244- return await OnlineApiService . DownloadEmuImageAsync ( trainModel , DownloadEmuImage_url ) ;
221+ return await OnlineApiService . DownloadEmuImageAsync ( trainModel , urlOrDbPath ) ;
245222 }
246223 return null ;
247224 }
0 commit comments