123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import Message from "@/views/front/develop/Communication/Message";
- import { PackageType } from "@/views/front/develop/Communication/Package/PackageType"
- import { TransitType } from "@/views/front/develop/Communication/MessageHelper/TransitType"
- import MsgPackage from "@/views/front/develop/Communication/Package/MsgPackage"
-
-
-
- /**
- * Message的扩展方法集合
- */
- export class MessageExtension {
- /**
- * 执行通讯操作
- */
- public static doTransit(message: Message): boolean {
- let packageType = PackageType.Msg858301
- switch (message.TransitNode) {
- case TransitType.CallServer:
- packageType = PackageType.Msg858302
- break
- case TransitType.CallNoFileSys:
- packageType = PackageType.MsgXml01
- break
- default:
- break
- }
- //此处需要补流程 hulei-s process
- if (message.CustomizeTransitEntry) {
- //return "";//message.CustomizeTransitEntry.process(message, packageType)
- }
- return MessageExtension.doTransitInternal(message, packageType)
- }
-
- /**
- * 执行通讯操作(内部方法)
- */
- private static doTransitInternal(message: Message, packageType: PackageType): boolean {
- return MsgPackage.Trade(message, packageType, message.TransitName)
- }
-
- /**
- * Message对象域信息序列化,用于授权操作
- */
- public static serializeForAuth(message: Message): string {
- const ret: Record<string, string> = {}
- const empty: string[] = []
- //hulei 8583域的处理
- // for (const fd of Object.values(BitMapInstance.FdBitMap)) {
- // const type = fd.getItemType()
- // const key = fd.Code
- // const value = message.getFdVaule(fd.Code).toString()
-
- // let typeSuffix = ''
- // if (type === String) {
- // typeSuffix = '_0'
- // } else if (type === Number) {
- // typeSuffix = '_1'
- // } else {
- // throw new Error(`不支持的域类型,请检查定义!->${fd.Code}`)
- // }
-
- // if (!value.trim()) {
- // empty.push(key + typeSuffix)
- // } else {
- // ret[key + typeSuffix] = value
- // }
- // }
-
- if (empty.length > 0) {
- ret['empty'] = empty.join(',')
- }
-
- return JSON.stringify(ret)
- }
-
- /**
- * 获取报文位图类型信息
- */
- public static getMsgBitMapTypes(message: Message): Record<string, string> {
- const result: Record<string, string> = {}
-
- // for (const item of Object.values(Message.BitMapInstance.FdBitMap)) {//hulei 源文件功能是获取域的信息集合
- // const type = item.getItemType()
- // const value = type === String ? '1' : '0'
- // result[`FD${item.Code}`] = value
- // }
-
- return result
- }
-
- /**
- * 解析报文
- */
- public static analyze(type: string, returnData: Uint8Array, fileData: Uint8Array): { success: boolean, msg: Message } {
- const msg = new Message()
- const packageType = PackageType[type as keyof typeof PackageType]
- const packageInstance = MsgPackage.PackageList[packageType]
-
- const totalData = new Uint8Array(returnData.length + fileData.length)
- totalData.set(returnData, 0)
- totalData.set(fileData, returnData.length)
-
- const success = packageInstance.analyze(msg, totalData)
- return { success, msg }
- }
- }
-
- // msgjson辅助类
- class MsgJson {
- code: string = ''
- type: string = ''
- values: string = ''
- }
|