ReplaceUtil.ets
15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/**
* Comp数据源通配符替换工具类
*/
import { CompDTO } from '../bean/CompDTO';
import { DataSourceRequest } from '../bean/DataSourceRequest';
import {ConfigConstants} from 'wdConstant'
export class ReplaceUtil {
private static readonly IDFA: string = "{idfa}";
private static readonly APP_ID: string = "{appId}";
private static readonly TERMINAL_ID: string = "{terminalId}";
private static readonly CLIENT_ID: string = "{clientId}";
private static readonly CLIENT_PROVINCE_CODE: string = "{clientProvinceCode}";
private static readonly PROVINCE_CODE: string = "{provinceCode}";
private static readonly CLIENT_CITY_ID: string = "{clientCityId}";
private static readonly USER_TOKEN: string = "{userToken}";
private static readonly APP_VERSION: string = "{appVersion}";
private static readonly SDK_CE_ID: string = "{SDKCEId}";
private static readonly X_UP_CLIENT_CHANNEL_ID: string = "{X-UP-CLIENT-CHANNEL-ID}";
private static readonly IMEI: string = "{imei}";
private static readonly APP_VERSION_CODE: string = "APP-VERSION-CODE";
private static readonly PHONE_INFO: string = "{Phone-Info}";
private static readonly CONTEND_ID: string = "{contentID}";
private static readonly PROGRAM_TYPE: string = "{program_type}";
private static readonly EPS_ID: string = "{epsID}";
private static readonly MSISDN: string = "{msisdn}";
private static readonly CT_INFO: string = "{ctinfo}";
private static readonly MOBILE: string = "{mobile}";
private static readonly USER_ID: string = "{userId}";
private static readonly LOCATION: string = "{pageID}#{groupID}#{compID}";
private static readonly BLOCK_NAME: string = "{blockName}";
private static readonly STAR_ID: string = "{starId}";
private static readonly FIRST_REQUEST: string = "{first_request}";
private static readonly CARDS: string = "{cards}";
private static readonly AD_ID: string = "{adID}";
private static readonly CSJANDROIDADID: string = "{csjAndroidAdID}";
private static readonly MATERIAL_STYLE: string = "{materialStyle}";
private static readonly START_POSITION_OF_AD: string = "{startPositionOfAD}";
private static readonly STEP_OF_AD: string = "{stepOfAD}";
private static readonly LOOP: string = "{loop}";
private static readonly DISPLAYED_COUNT: string = "{displayedCount}";
private static readonly ISFIRST: string = "{isFirst}";
private static readonly DYNAMIC_PUBLISHER_TIME: string = "{dynamicPublisherTime}";
private static readonly RECOMMEND_STATIS_DATA: string = "{actionData}"; //短带长、发现页feed流短视频推荐数据
private static readonly REQUEST_PENDANT: string = "{reqPendant}"; //请求挂件;0:表示不请求,1:表示请求
private static readonly REQUEST_SHORT_VIDEO: string = "{reqShortVideo}"; //是否请求短视频:1是,0否
private static readonly GUIDE_CARD_LABEL: string = "{guideCardLabel}"; //兴趣卡片
private static readonly GUIDE_CARD: string = "{guideCard}";
private static readonly EXTRA_TYPE: string = "{extraType}"; //请求额外信息类型,多个以“,”分开,直播间:liveRoom
private static readonly CLOSE_RECOMMEND: string = "{closeRecommend}"; //关闭个性推荐;0:不关闭,1:关闭
private static readonly REQLIVEROOM2STATUS: string = "{reqLiveRoom2Status}";
/**
* 精彩小视频是否清除缓存,1清除,0不清除
*/
public static readonly CLEAR_EXPOSURE_KEY: string = "clearExposure_extra_video";
private static readonly CLEAR_EXPOSURE: string = "{clearExposure}";
private static KEYS: string[] = [ReplaceUtil.IDFA, ReplaceUtil.APP_ID, ReplaceUtil.TERMINAL_ID, ReplaceUtil.CLIENT_ID,
ReplaceUtil.CLIENT_PROVINCE_CODE, ReplaceUtil.PROVINCE_CODE, ReplaceUtil.CLIENT_CITY_ID, ReplaceUtil.USER_TOKEN, ReplaceUtil.APP_VERSION,
ReplaceUtil.SDK_CE_ID, ReplaceUtil.X_UP_CLIENT_CHANNEL_ID, ReplaceUtil.IMEI, ReplaceUtil.APP_VERSION_CODE, ReplaceUtil.PHONE_INFO, ReplaceUtil.CONTEND_ID, ReplaceUtil.PROGRAM_TYPE,
ReplaceUtil.EPS_ID, ReplaceUtil.MSISDN, ReplaceUtil.CT_INFO, ReplaceUtil.MOBILE, ReplaceUtil.USER_ID, ReplaceUtil.LOCATION, ReplaceUtil.BLOCK_NAME, ReplaceUtil.STAR_ID, ReplaceUtil.FIRST_REQUEST,
ReplaceUtil.CARDS, ReplaceUtil.AD_ID, ReplaceUtil.MATERIAL_STYLE, ReplaceUtil.START_POSITION_OF_AD, ReplaceUtil.STEP_OF_AD, ReplaceUtil.LOOP, ReplaceUtil.DISPLAYED_COUNT,
ReplaceUtil.DYNAMIC_PUBLISHER_TIME, ReplaceUtil.RECOMMEND_STATIS_DATA, ReplaceUtil.REQUEST_PENDANT, ReplaceUtil.REQUEST_SHORT_VIDEO,
ReplaceUtil.GUIDE_CARD_LABEL, ReplaceUtil.GUIDE_CARD, ReplaceUtil.EXTRA_TYPE, ReplaceUtil.CSJANDROIDADID, ReplaceUtil.REQLIVEROOM2STATUS, ReplaceUtil.CLEAR_EXPOSURE, ReplaceUtil.CLOSE_RECOMMEND];
/**
* 替换URL
* @param url
* @param compDTO
* @param dataSourceBean
* @returns
*/
public static replaceUrl(url: string, compDTO: CompDTO, dataSourceBean: DataSourceRequest): string {
// TODO: 根据通配符替换url
for (let index = 0; index < ReplaceUtil.KEYS.length; index++) {
url = ReplaceUtil.replaceString(url, ReplaceUtil.KEYS[index], compDTO, dataSourceBean);
}
return url;
}
private static replaceString(str: string, key: string, compDTO: CompDTO, dataSourceBean: DataSourceRequest): string {
try {
if (str != null && str.includes(key)) {
str = str.replace(key, ReplaceUtil.getReplaceValue(key, compDTO, dataSourceBean));
}
} catch (err) {
}
return str;
}
private static getReplaceValue(key: string, compDTO: CompDTO, dataSourceBean: DataSourceRequest): string {
if (key === ReplaceUtil.IDFA) {
return ConfigConstants.DEVICE_ID;
} else if (key === ReplaceUtil.APP_ID) {
return ConfigConstants.appId;
} else if (key === ReplaceUtil.CLEAR_EXPOSURE) {
// if (compDTO != null) {
// if (compDTO.extraData != null && compDTO.extraData.(ReplaceUtil.CLEAR_EXPOSURE_KEY)) {
// return compDTO.extraData.getString(CLEAR_EXPOSURE_KEY);
// }
// if (compDTO.extraData == null) {
// compDTO.extraData = new MasterObjectData();
// }
// compDTO.extraData.put(CLEAR_EXPOSURE_KEY, "0");
// }
return "1";
} else if (key === ReplaceUtil.TERMINAL_ID) {
return ConfigConstants.terminalId;
} else if (key === ReplaceUtil.CLIENT_ID) {
return ConfigConstants.DEVICE_ID;
} else if (key === ReplaceUtil.CLOSE_RECOMMEND) {
// return RecommendManagerUtil.isRecommendable() ? "0" : "1";
return "0"
} else if (key === ReplaceUtil.CLIENT_PROVINCE_CODE) {
// return GlobalBridge.Companion.getInstance().getProvinceService().getProvinceCode();
return ""
} else if (key === ReplaceUtil.PROVINCE_CODE) {
// return GlobalBridge.Companion.getInstance().getProvinceService().getProvinceCode();
return ""
} else if (key === ReplaceUtil.CLIENT_CITY_ID) {
// return GlobalBridge.Companion.getInstance().getProvinceService().getCityId();
return ""
} else if (key === ReplaceUtil.USER_TOKEN) {
// IUserService userService = ArouterServiceManager.provide(IUserService.class);
// if (userService != null) {
// return userService.getActiveAccountInfo().getUsertoken();
// }
return ""
} else if (key === ReplaceUtil.APP_VERSION) {
// return AppUtil.getVersionName(BaseApplicationContext.application);
return ""
} else if (key === ReplaceUtil.SDK_CE_ID) {
// return Constants.serverClientId;
return ""
} else if (key === ReplaceUtil.X_UP_CLIENT_CHANNEL_ID) {
// return ChannelUtil.getChannelId();
return ""
} else if (key === ReplaceUtil.IMEI) {
// return DeviceUtil.getIMEI();
return ""
} else if (key === ReplaceUtil.APP_VERSION_CODE) {
// return ChannelUtil.getVersionId();
return ""
} else if (key === ReplaceUtil.PHONE_INFO) {
// return DeviceUtil.getSystemModel();
return ""
} else if (key === ReplaceUtil.CONTEND_ID) {
// return GlobalBridge.Companion.getInstance().getPro().getCurrentProgramme();
return ConfigConstants.playingContentId ?? ""
} else if (key === ReplaceUtil.PROGRAM_TYPE) {
// return GlobalBridge.Companion.getInstance().getPro().getProgramType();
return ""
} else if (key === ReplaceUtil.EPS_ID) {
// String epsId = GlobalBridge.Companion.getInstance().getPro().getEpsId();
// if (!TextUtils.isEmpty(epsId)) {
// return epsId;
// } else {
// return GlobalBridge.Companion.getInstance().getPro().getCurrentProgramme();
// }
return ""
} else if (key === ReplaceUtil.MSISDN) {
// IUserService userService = ArouterServiceManager.provide(IUserService.class);
// if (userService != null) {
// return userService.getActiveAccountInfo().getUid();
// }
return ""
} else if (key === ReplaceUtil.CT_INFO) {
// return GlobalBridge.Companion.getInstance().getProvinceService().getCityId();
return ""
} else if (key === ReplaceUtil.MOBILE) {
// IUserService userService = ArouterServiceManager.provide(IUserService.class);
// if (userService != null) {
// return userService.getActiveAccountInfo().getMobile();
// }
return ""
} else if (key === ReplaceUtil.USER_ID) {
// IUserService userService = ArouterServiceManager.provide(IUserService.class);
// if (userService != null) {
// return userService.getActiveAccountInfo().getUid();
// }
return ""
} else if (key === ReplaceUtil.LOCATION) {
// if (request != null && request.locationValue != null) {
// return request.locationValue;
// }
return ""
} else if (key === ReplaceUtil.BLOCK_NAME) {
// String blockType = SPHelper.getString(Constants.FLOOR_TYPE);
// if ("1".equals(blockType) || "2".equals(blockType)) {
// String blockName = SPHelper.getString(Constants.FLOOR_BLOCK_NAME);
// if (!TextUtils.isEmpty(blockName)) {
// return blockName;
// }
// }
return ""
} else if (key === ReplaceUtil.STAR_ID) {
// String blockType = SPHelper.getString(Constants.FLOOR_TYPE);
// if ("1".equals(blockType)) {
// String blockStarId = SPHelper.getString(Constants.FLOOR_STAR_ID);
// if (!TextUtils.isEmpty(blockStarId)) {
// return blockStarId;
// }
// }
return ""
} else if (key === ReplaceUtil.FIRST_REQUEST) {
// return CommonDataUtil.getFirstFlag(compDTO.id);
return ""
} else if (key === ReplaceUtil.ISFIRST) {
// return "true".equals(CommonDataUtil.getFirstFlag(compDTO.id)) ? "1" : "0";
return ""
} else if (key === ReplaceUtil.CARDS) {
// if (compDTO != null && compDTO.extraData != null) {
// try {
// Object cards = compDTO.extraData.get("cards");
// if (cards != null) {
// return JsonUtil.toJson(cards);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
return ""
} else if (key === ReplaceUtil.AD_ID) {
// if (compDTO != null && compDTO.adInfo != null) {
// List<String> adIdList = compDTO.adInfo.getObject("adID");
// if (adIdList != null) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < adIdList.size(); i++) {
// if (i > 0) {
// sb.append(",");
// }
// sb.append(adIdList.get(i));
// }
// return sb.toString();
// }
// }
return ""
} else if (key === ReplaceUtil.CSJANDROIDADID) {
// if (compDTO != null && compDTO.adInfo != null) {
// List<String> csjAndroidAdIdList = compDTO.adInfo.getObject("csjAndroidAdId");
// if (csjAndroidAdIdList != null) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < csjAndroidAdIdList.size(); i++) {
// if (i > 0) {
// sb.append(",");
// }
// sb.append(csjAndroidAdIdList.get(i));
// }
// return sb.toString();
// }
// }
return ""
} else if (key === ReplaceUtil.MATERIAL_STYLE) {
// if (compDTO != null && compDTO.adInfo != null) {
// List<String> materialStyleList = compDTO.adInfo.getObject("materialStyle");
// if (materialStyleList != null) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < materialStyleList.size(); i++) {
// if (i > 0) {
// sb.append(",");
// }
// sb.append(materialStyleList.get(i));
// }
// return sb.toString();
// }
// }
return ""
} else if (key === ReplaceUtil.START_POSITION_OF_AD) {
// if (compDTO != null && compDTO.adInfo != null) {
// return compDTO.adInfo.getString("startPosition");
// }
return ""
} else if (key === ReplaceUtil.STEP_OF_AD) {
// if (compDTO != null && compDTO.adInfo != null) {
// return compDTO.adInfo.getString("displayStride");
// }
return ""
} else if (key === ReplaceUtil.LOOP) {
// if (compDTO != null && compDTO.adInfo != null) {
// return compDTO.adInfo.getString("loop");
// }
return ""
} else if (key === ReplaceUtil.DISPLAYED_COUNT) {
// return String.valueOf(request.displayCount);
return ""
} else if (key === ReplaceUtil.DYNAMIC_PUBLISHER_TIME) {
// return compDTO.dynamicPublisherTime + "";
return ""
} else if (key === ReplaceUtil.RECOMMEND_STATIS_DATA) {
// String pageId = getPageId(request);
// if (!TextUtils.isEmpty(pageId)){
// return GlobalBridge.Companion.getInstance().getRecommendDataStatisManager().getRecommendData(pageId);
// }
return ""
} else if (key === ReplaceUtil.REQUEST_PENDANT) {
return "1";
} else if (key === ReplaceUtil.REQUEST_SHORT_VIDEO) {
return "1";
} else if (key === ReplaceUtil.GUIDE_CARD) {
return "1";
} else if (key === ReplaceUtil.GUIDE_CARD_LABEL) {
// String interestData = GlobalBridge.Companion.getInstance().getRecommendDataStatisManager().getInterestData();
// GlobalBridge.Companion.getInstance().getRecommendDataStatisManager().clearAllInterestData();
// return interestData;
return ""
} else if (key === ReplaceUtil.EXTRA_TYPE) {
return "liveRoom,liveRoom2";
} else if (key === ReplaceUtil.REQLIVEROOM2STATUS) {
return "1,2";
}
return "";
}
/**
* 替换Header
* @param headers
* @param compDTO
* @param dataSourceBean
* @returns
*/
public static replaceHeader(headers: Map<string, string>, compDTO: CompDTO, dataSourceBean: DataSourceRequest): Map<string, string> {
// TODO: 根据通配符替换Header
return ReplaceUtil.replaceMap(headers, compDTO, dataSourceBean);
;
}
/**
* 替换参数
* @param parameters
* @param compDTO
* @param dataSourceBean
* @returns
*/
public static replaceParameter(parameters: Map<string, string>, compDTO: CompDTO, dataSourceBean: DataSourceRequest): Map<string, string> {
// TODO: 根据通配符替换Parameter
return ReplaceUtil.replaceMap(parameters, compDTO, dataSourceBean);
}
private static replaceMap(maps: Map<string, string>, compDTO: CompDTO, dataSourceBean: DataSourceRequest): Map<string, string> {
let map: Map<string, string> = new Map();
try {
// 遍历map
maps.forEach((value: string, key: string, map: Map<string, string>) => {
value = ReplaceUtil.getReplaceValue(value, compDTO, dataSourceBean)
if (value != null) {
map.set(key, value)
} else if (key != null) {
if (!key.includes("{")) {
map.set(key, value)
}
}
});
} catch (err) {
}
return map;
}
// public makeJsonObjectRequest():DataSourceRequest{
//
//
// }
}