|
@@ -1,11 +1,18 @@
|
|
|
import APP from '@/services';
|
|
import APP from '@/services';
|
|
|
import { funCode } from '@/services/funcode/index';
|
|
import { funCode } from '@/services/funcode/index';
|
|
|
import { buildSubscribePeq, parseSubscribeRsp } from '@/services/socket/quota/adapter/index';
|
|
import { buildSubscribePeq, parseSubscribeRsp } from '@/services/socket/quota/adapter/index';
|
|
|
|
|
+import Bus from '@/utils/eventBus/index';
|
|
|
|
|
+import timerUtil from '@/utils/timer/timerUtil';
|
|
|
import { Callback } from '@/utils/websocket/index';
|
|
import { Callback } from '@/utils/websocket/index';
|
|
|
import { SubscribeInfoType } from './interface';
|
|
import { SubscribeInfoType } from './interface';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const subscribeGoodsList = new Map<string, SubscribeInfoType[]>(); // 订阅商品数据中心池
|
|
const subscribeGoodsList = new Map<string, SubscribeInfoType[]>(); // 订阅商品数据中心池
|
|
|
|
|
|
|
|
|
|
+let isSubscribeSucess = false; // 订阅是否成功
|
|
|
|
|
+
|
|
|
|
|
+const timeDiff = 2 * 1000 // 没有订阅成功,下次发起订阅的间隔时间
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 重组订阅商品(包括去重,组合)
|
|
* 重组订阅商品(包括去重,组合)
|
|
|
*/
|
|
*/
|
|
@@ -23,25 +30,48 @@ function recombinationSubscribeGoods(): SubscribeInfoType[] {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 尝试商品订阅,如果订阅不成功,则 timeDiff 后续继续发起订阅请求,直到订阅成功后为止
|
|
|
|
|
+ */
|
|
|
|
|
+function trySubcribe() {
|
|
|
|
|
+ const timer = 'quoteSucribe'
|
|
|
|
|
+ actionSubcribe()
|
|
|
|
|
+ timerUtil.setInterval(() => {
|
|
|
|
|
+ if (isSubscribeSucess) {
|
|
|
|
|
+ // 订阅成功后,不在继续尝试订阅了
|
|
|
|
|
+ timerUtil.clearInterval(timer)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 订阅失败,重新发起订阅
|
|
|
|
|
+ actionSubcribe()
|
|
|
|
|
+ }
|
|
|
|
|
+ }, timeDiff, timer)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
* 开始商品订阅
|
|
* 开始商品订阅
|
|
|
* @param subscribeInfos
|
|
* @param subscribeInfos
|
|
|
*/
|
|
*/
|
|
|
function actionSubcribe() {
|
|
function actionSubcribe() {
|
|
|
const arr = recombinationSubscribeGoods();
|
|
const arr = recombinationSubscribeGoods();
|
|
|
const req = buildSubscribePeq(arr);
|
|
const req = buildSubscribePeq(arr);
|
|
|
|
|
+ isSubscribeSucess = false
|
|
|
APP.sendQuoteServer(req, funCode.MainClassNumber_Quota_SubscriptRsp, {
|
|
APP.sendQuoteServer(req, funCode.MainClassNumber_Quota_SubscriptRsp, {
|
|
|
onSuccess: (res: any) => {
|
|
onSuccess: (res: any) => {
|
|
|
parseSubscribeRsp(res)
|
|
parseSubscribeRsp(res)
|
|
|
.then((value) => {
|
|
.then((value) => {
|
|
|
- if (value) {
|
|
|
|
|
- console.log('订阅成功!', value);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ console.log('订阅成功!', value);
|
|
|
|
|
+ isSubscribeSucess = true
|
|
|
})
|
|
})
|
|
|
.catch((err) => {
|
|
.catch((err) => {
|
|
|
|
|
+ isSubscribeSucess = false
|
|
|
console.log('订阅失败:', err);
|
|
console.log('订阅失败:', err);
|
|
|
|
|
+ // 失败原因:行情断
|
|
|
|
|
+ // 重新 走行情链接逻辑
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- onFail: (err) => console.log('订阅失败:', err),
|
|
|
|
|
|
|
+ onFail: (err) => {
|
|
|
|
|
+ isSubscribeSucess = false
|
|
|
|
|
+ console.log('订阅失败:', err)
|
|
|
|
|
+ },
|
|
|
} as Callback);
|
|
} as Callback);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -52,7 +82,7 @@ function actionSubcribe() {
|
|
|
export function addSubscribeQuotation(uuid: string, subscribeInfos: SubscribeInfoType[]) {
|
|
export function addSubscribeQuotation(uuid: string, subscribeInfos: SubscribeInfoType[]) {
|
|
|
APP.connectQuote().then(() => {
|
|
APP.connectQuote().then(() => {
|
|
|
subscribeGoodsList.set(uuid, subscribeInfos);
|
|
subscribeGoodsList.set(uuid, subscribeInfos);
|
|
|
- actionSubcribe();
|
|
|
|
|
|
|
+ trySubcribe();
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -63,10 +93,16 @@ export function removeSubscribeQuotation(uuid: string) {
|
|
|
if (subscribeGoodsList.has(uuid)) {
|
|
if (subscribeGoodsList.has(uuid)) {
|
|
|
subscribeGoodsList.delete(uuid);
|
|
subscribeGoodsList.delete(uuid);
|
|
|
if (subscribeGoodsList.size) {
|
|
if (subscribeGoodsList.size) {
|
|
|
- actionSubcribe();
|
|
|
|
|
|
|
+ trySubcribe();
|
|
|
} else {
|
|
} else {
|
|
|
// 没有订阅商品时候,主动断开行情链路
|
|
// 没有订阅商品时候,主动断开行情链路
|
|
|
APP.closeQuote();
|
|
APP.closeQuote();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// 行情链路 重连成功后,重新订阅商品
|
|
|
|
|
+Bus.$onOnly('quoteReconnectSucess', () => {
|
|
|
|
|
+ console.log('======== 行情链路 重连成功后,开启重新订阅商品')
|
|
|
|
|
+ trySubcribe()
|
|
|
|
|
+})
|