|
|
@@ -1,13 +1,15 @@
|
|
|
import APP from '@/services';
|
|
|
-import { getAccount_longType, getUserId } from '@/services/bus/account';
|
|
|
+import { getUserId } from '@/services/bus/account';
|
|
|
import { getErrorInfoByCode } from '@/services/bus/error';
|
|
|
import { funCode } from '@/services/funcode/index';
|
|
|
import ProtobufCtr from '@/services/socket/protobuf/index';
|
|
|
+import { Callback } from '@/utils/websocket';
|
|
|
import { Package50 } from '@/utils/websocket/package';
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
import * as type from './interface';
|
|
|
import { CommonSearchParam, ParseRsp, SoleSearchParam } from './interface';
|
|
|
import { IMessageHead } from './proto.d';
|
|
|
+import { getProtoHeadParam, HeadEnum } from './protoHeader';
|
|
|
|
|
|
/**
|
|
|
* 构建proto50 报文
|
|
|
@@ -96,7 +98,6 @@ function buildMsgHead(funCodeName: string, params: IMessageHead) {
|
|
|
const head = {
|
|
|
FunCode: code,
|
|
|
UUID: uuidv4(),
|
|
|
- AccountID: getAccount_longType(),
|
|
|
UserID: getUserId(),
|
|
|
};
|
|
|
Object.assign(messageHead, head, params);
|
|
|
@@ -108,13 +109,12 @@ function buildMsgHead(funCodeName: string, params: IMessageHead) {
|
|
|
* @param params SoleSearchParam
|
|
|
*/
|
|
|
function buildSoleProtoReq50(params: SoleSearchParam): Package50 {
|
|
|
- const { protobufName, funCodeName, reqParams, msgHeadParams } = params;
|
|
|
- const headParam = msgHeadParams ? msgHeadParams : {};
|
|
|
- // 消息头
|
|
|
- const messageHead = buildMsgHead(funCodeName, headParam);
|
|
|
+ const { protobufName, funCodeName, reqParams, headerEnum } = params;
|
|
|
+ // // // 消息头
|
|
|
+ // const messageHead = buildMsgHead(funCodeName, headParam);
|
|
|
// 登录报文
|
|
|
const Req = buildSoleProtoReq(protobufName, reqParams);
|
|
|
- Req.Header = messageHead;
|
|
|
+ Req.Header = getProtoHeadParam(funCodeName, headerEnum);
|
|
|
return setPackage50(funCodeName, Req);
|
|
|
}
|
|
|
|
|
|
@@ -136,7 +136,7 @@ function buildCommonProtoReq50(param: CommonSearchParam): Package50 {
|
|
|
funCodeName = 'QueryCommonReq';
|
|
|
}
|
|
|
// 消息头
|
|
|
- const messageHead = buildMsgHead(funCodeName, {});
|
|
|
+ const messageHead = getProtoHeadParam(funCodeName, 0);
|
|
|
queryReq.setStatement(statement);
|
|
|
// 构建查询参数
|
|
|
const paramValues = [];
|
|
|
@@ -253,3 +253,33 @@ export const noticeParseRsp = (rspPackage: any, funCodeName: string) => {
|
|
|
function lower(value: string): string {
|
|
|
return value.toLowerCase();
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @param param proto除去head 剩下参数
|
|
|
+ * @param headerEnum 自定义的proto参数枚举值,减小重复抒写 默认0
|
|
|
+ * @param reqFuncodeName proto 发送请求定义的头名字,特别需要注意,自已的funCodeName要与这个一致
|
|
|
+ * @param rspFuncodeName proto 响应请求定义的头名字
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export function protoMiddleware<T>(param: T, reqName: string, rspName: string, headerEnum: HeadEnum = 0): Promise<any> {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const params = {
|
|
|
+ protobufName: reqName,
|
|
|
+ funCodeName: reqName,
|
|
|
+ reqParams: param,
|
|
|
+ headerEnum,
|
|
|
+ };
|
|
|
+ const package50 = buildProtoReq50(params);
|
|
|
+ APP.sendTradingServer(package50, undefined, {
|
|
|
+ onSuccess: (res) => {
|
|
|
+ const { isSuccess, result } = parseProtoRsp50(res, rspName);
|
|
|
+ if (isSuccess) {
|
|
|
+ resolve(result);
|
|
|
+ } else {
|
|
|
+ reject(result);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onFail: (err) => reject(err.message),
|
|
|
+ } as Callback);
|
|
|
+ });
|
|
|
+}
|