Browse Source

修改proto

huangbin 4 năm trước cách đây
mục cha
commit
43af089f75

+ 38 - 30
src/services/proto/warehouse/index.ts

@@ -1,14 +1,14 @@
 import APP from "@/services";
-import { Callback } from "@/utils/websocket";
 import { getSelectedAccountId, getUserId } from "@/services/bus/account";
+import { getLongTypeLoginID } from "@/services/bus/login";
 import {
     AreaInOutApplyAuditPassReq, AuditERMCPAreaInOutStockApplyReq, ERMCPAreaInOutStockApplyReq,
     WarehouseApplyReq,
     WarehouseStateChangeReq
 } from "@/services/proto/warehouse/interface";
-import {getUUID} from "@/utils/qt/common";
-import {buildProtoReq50, parseProtoRsp50} from "@/services/socket/protobuf/buildReq";
-import {getLongTypeLoginID} from "@/services/bus/login";
+import { buildProtoReq50, parseProtoRsp50, protoMiddleware } from "@/services/socket/protobuf/buildReq";
+import { getUUID } from "@/utils/qt/common";
+import { Callback } from "@/utils/websocket";
 
 /**
  * 新增 / 修改 仓库信息请求  修改需要传仓库id
@@ -18,33 +18,40 @@ import {getLongTypeLoginID} from "@/services/bus/login";
  * @param param.warehousetype (必填)   仓库类型
  */
 export const addWarehouseApply = (param: WarehouseApplyReq): Promise<any> => {
-    return new Promise((resolve, reject) => {
-        const userid = getUserId();
-        const accountid = getSelectedAccountId()
+    const userid = getUserId();
+    // const accountid = getSelectedAccountId()
 
-        const params = {
-            protobufName: 'WarehouseApplyReq',
-            funCodeName: 'WarehouseApplyReq',
-            reqParams: Object.assign(param, { userid, accountid }),
-            msgHeadParams: {
-                AccountID: accountid,
-                MarketID: 18,
-                GoodsID: 0,
-            }
-        };
-        const package50 = buildProtoReq50(params);
-        APP.sendTradingServer(package50, undefined, {
-            onSuccess: (res) => {
-                const { isSuccess, result } = parseProtoRsp50(res, 'WarehouseApplyRsp');
-                if (isSuccess) {
-                    resolve(result);
-                } else {
-                    reject(result);
-                }
-            },
-            onFail: (err) => reject(err.message),
-        } as Callback);
-    });
+    Object.assign(param, { userid },)
+
+    debugger
+    return protoMiddleware<WarehouseApplyReq>(param, 'WarehouseApplyReq', 'WarehouseApplyRsp', 2)
+    // return new Promise((resolve, reject) => {
+    //     const userid = getUserId();
+    //     const accountid = getSelectedAccountId()
+
+    //     const params = {
+    //         protobufName: 'WarehouseApplyReq',
+    //         funCodeName: 'WarehouseApplyReq',
+    //         reqParams: Object.assign(param, { userid, accountid }),
+    //         msgHeadParams: {
+    //             AccountID: accountid,
+    //             MarketID: 18,
+    //             GoodsID: 0,
+    //         }
+    //     };
+    //     const package50 = buildProtoReq50(params);
+    //     APP.sendTradingServer(package50, undefined, {
+    //         onSuccess: (res) => {
+    //             const { isSuccess, result } = parseProtoRsp50(res, 'WarehouseApplyRsp');
+    //             if (isSuccess) {
+    //                 resolve(result);
+    //             } else {
+    //                 reject(result);
+    //             }
+    //         },
+    //         onFail: (err) => reject(err.message),
+    //     } as Callback);
+    // });
 }
 
 /**
@@ -146,6 +153,7 @@ export const refuseStockApplyReq = (param: AuditERMCPAreaInOutStockApplyReq): Pr
     });
 }
 
+
 /**
  * 出入库申请
  * @param param

+ 6 - 3
src/services/proto/warehouse/interface.ts

@@ -1,5 +1,8 @@
+import { IMessageHead } from "@/services/socket/protobuf/proto";
+
 // 仓库申请请求 0 29 141
 export interface WarehouseApplyReq {
+    Header?: IMessageHead,
     // accountid: number
     // userid: number// uint64 用户ID
     type: number // int32 类型 1 新增 2 修改
@@ -36,7 +39,7 @@ export interface AreaInOutApplyAuditPassReq {
     ClientTicket?: string; // string 客户端流水号
 }
 // 机构出入库申请审核通过响应 0 18 11
-export interface  AreaInOutApplyAuditPassRsp {
+export interface AreaInOutApplyAuditPassRsp {
     RetCode: number; // int32 返回码
     RetDesc: string; // string 描述信息
     InOutApplyID: number; // uint64 操作申请ID(607+Unix秒时间戳(10位)+xxxxxx)
@@ -46,7 +49,7 @@ export interface  AreaInOutApplyAuditPassRsp {
 }
 
 // 机构出入库申请审核拒绝撤回请求 0 29 139
-export interface  AuditERMCPAreaInOutStockApplyReq {
+export interface AuditERMCPAreaInOutStockApplyReq {
     InOutApplyID: number; // uint64 申请ID
     AuditID: number; // uint64 审核人
     AuditRemark: string; // string 审核备注
@@ -54,7 +57,7 @@ export interface  AuditERMCPAreaInOutStockApplyReq {
     ApplyStatus: number; // int32 审核状态:3-审核拒绝 5-已撤回
 }
 // 机构出入库申请审核拒绝撤回响应 0 29 140
-export interface  AuditERMCPAreaInOutStockApplyRsp {
+export interface AuditERMCPAreaInOutStockApplyRsp {
     RetCode: number; // int32 返回码
     RetDesc: string; // string 描述信息
     InOutApplyID: number; // uint64 申请ID

+ 16 - 42
src/services/socket/login/index.ts

@@ -3,7 +3,7 @@ import APP from '@/services';
 import { getLongTypeLoginID, isLogin } from '@/services/bus/login';
 import { getToken } from '@/services/bus/token';
 import { LongType } from '@/services/socket/login/interface/index';
-import { buildProtoReq50, parseProtoRsp50 } from '@/services/socket/protobuf/buildReq';
+import { buildProtoReq50, parseProtoRsp50, protoMiddleware } from '@/services/socket/protobuf/buildReq';
 import { Callback } from '@/utils/websocket/index';
 import { sha256 } from 'js-sha256';
 import moment from 'moment';
@@ -13,47 +13,21 @@ import { LoginResponse } from './interface/index';
 let preDate = Date.now();
 
 export const loginAction = (logidCode: String, password: String, ClientSystemInfo: Uint8Array[]): Promise<LoginResponse> => {
-    return new Promise((resolve, reject) => {
-        const userAPassWord = `${logidCode}${password}`;
-        const LoginPWD = sha256.hex(userAPassWord);
-        const params = {
-            protobufName: 'LoginReq',
-            funCodeName: 'LoginReq',
-            reqParams: {
-                LoginPWD,
-                LoginID: logidCode,
-                GUID: uuidv4(),
-                LoginType: 0,
-                ClientType: 4,
-                Version: '2.0.0.0',
-                DeviceID: '',
-            },
-        };
-        if (ClientSystemInfo.length) {  // 与qt交互消息
-            Object.assign(params.reqParams, { ClientSystemInfo, ClientAppID: 'muchinfo_mtpclient_5.0.1' })
-        }
-        const package50 = buildProtoReq50(params);
-        APP.sendTradingServer(package50, undefined, {
-            onSuccess: (res) => {
-                const { isSuccess, result } = parseProtoRsp50(res, 'LoginRsp');
-                if (isSuccess) {
-                    resolve(result);
-                } else {
-                    if (result.includes('1003')) {
-                        reject('账号或密码不匹配');
-                    } else if (result.includes('1004')) {
-                        reject('无效账号');
-                    } else {
-                        reject(result);
-                    }
-                }
-            },
-            onFail: (err) => {
-                console.log(err);
-                reject(err.message);
-            },
-        } as Callback);
-    });
+    const userAPassWord = `${logidCode}${password}`;
+    const LoginPWD = sha256.hex(userAPassWord);
+    const reqParams = {
+        LoginPWD,
+        LoginID: logidCode,
+        GUID: uuidv4(),
+        LoginType: 0,
+        ClientType: 4,
+        Version: '2.0.0.0',
+        DeviceID: '',
+    }
+    if (ClientSystemInfo.length) {  // 与qt交互消息
+        Object.assign(reqParams, { ClientSystemInfo, ClientAppID: 'muchinfo_mtpclient_5.0.1' })
+    }
+    return protoMiddleware(reqParams, 'LoginReq', 'LoginRsp', 1)
 };
 
 /**

+ 38 - 8
src/services/socket/protobuf/buildReq.ts

@@ -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);
+    });
+}

+ 6 - 1
src/services/socket/protobuf/interface.ts

@@ -1,10 +1,11 @@
 import { IMessageHead } from '@/services/socket/protobuf/proto.d';
+import { HeadEnum } from './protoHeader';
 
 export interface ReqParams {
     [key: string]: any;
 }
 
-export interface BuildReqParam {}
+export interface BuildReqParam { }
 
 export interface CommonSearchParam {
     statement: string | null; // 查询语句编号
@@ -16,6 +17,10 @@ export interface SoleSearchParam {
     protobufName: string; // protobuf名
     funCodeName: string; // funCode名
     reqParams: ReqParams; // 传入后台报文中的各种参数
+    headerEnum?: HeadEnum, // messgeHead 参数枚举
+    headParam?: IMessageHead; // messgeHead 参数
+
+    Header?: IMessageHead; // messgeHead 参数
     msgHeadParams?: IMessageHead; // messgeHead 参数
 }
 

+ 40 - 0
src/services/socket/protobuf/protoHeader.ts

@@ -0,0 +1,40 @@
+import { getSelectedAccountId, getUserId } from "@/services/bus/account";
+import { funCode } from "@/services/funcode";
+import { v4 as uuidv4 } from 'uuid';
+import { IMessageHead } from "./proto";
+
+export enum HeadEnum {
+    common, // funcode uuid userID
+    AccountID,  // funcode uuid userID AccountID
+    MarketID18_GoodsID0, // funcode uuid userID, MarketID:18, GoodsID: 0
+}
+
+/**
+ * 设置 proto header 参数
+ * @param funCodeName funCodeName
+ * @param type HeadEnum
+ */
+export function getProtoHeadParam(funCodeName: string, type: HeadEnum = 0): IMessageHead {
+    const code = funCode[funCodeName];
+    if (!code) console.error('没有找到对应的funCode值,请配置');
+    let result: IMessageHead = {
+        FunCode: code,
+        UUID: uuidv4(),
+        UserID: getUserId(),
+    }
+    switch (type) {
+        case HeadEnum.common:
+            break
+        case HeadEnum.AccountID:
+            result = Object.assign(result, { AccountID: getSelectedAccountId() })
+            break
+        case HeadEnum.MarketID18_GoodsID0:
+            result = Object.assign(result, {
+                MarketID: 18,
+                GoodsID: 0,
+            })
+            break
+    }
+    return result
+}
+