前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageExtension.ts 3.6KB

1 month ago
1 week ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import Message from "@/views/front/develop/Communication/Message";
  2. import { PackageType } from "@/views/front/develop/Communication/Package/PackageType"
  3. import { TransitType } from "@/views/front/develop/Communication/MessageHelper/TransitType"
  4. import MsgPackage from "@/views/front/develop/Communication/Package/MsgPackage"
  5. /**
  6. * Message的扩展方法集合
  7. */
  8. export class MessageExtension {
  9. /**
  10. * 执行通讯操作
  11. */
  12. public static doTransit(message: Message): boolean {
  13. let packageType = PackageType.Msg858301
  14. switch (message.TransitNode) {
  15. case TransitType.CallServer:
  16. packageType = PackageType.Msg858302
  17. break
  18. case TransitType.CallNoFileSys:
  19. packageType = PackageType.MsgXml01
  20. break
  21. default:
  22. break
  23. }
  24. //此处需要补流程 hulei-s process
  25. if (message.CustomizeTransitEntry) {
  26. //return "";//message.CustomizeTransitEntry.process(message, packageType)
  27. }
  28. return MessageExtension.doTransitInternal(message, packageType)
  29. }
  30. /**
  31. * 执行通讯操作(内部方法)
  32. */
  33. private static doTransitInternal(message: Message, packageType: PackageType): boolean {
  34. return MsgPackage.Trade(message, packageType, message.TransitName)
  35. }
  36. /**
  37. * Message对象域信息序列化,用于授权操作
  38. */
  39. public static serializeForAuth(message: Message): string {
  40. const ret: Record<string, string> = {}
  41. const empty: string[] = []
  42. //hulei 8583域的处理
  43. // for (const fd of Object.values(BitMapInstance.FdBitMap)) {
  44. // const type = fd.getItemType()
  45. // const key = fd.Code
  46. // const value = message.getFdVaule(fd.Code).toString()
  47. // let typeSuffix = ''
  48. // if (type === String) {
  49. // typeSuffix = '_0'
  50. // } else if (type === Number) {
  51. // typeSuffix = '_1'
  52. // } else {
  53. // throw new Error(`不支持的域类型,请检查定义!->${fd.Code}`)
  54. // }
  55. // if (!value.trim()) {
  56. // empty.push(key + typeSuffix)
  57. // } else {
  58. // ret[key + typeSuffix] = value
  59. // }
  60. // }
  61. if (empty.length > 0) {
  62. ret['empty'] = empty.join(',')
  63. }
  64. return JSON.stringify(ret)
  65. }
  66. /**
  67. * 获取报文位图类型信息
  68. */
  69. public static getMsgBitMapTypes(message: Message): Record<string, string> {
  70. const result: Record<string, string> = {}
  71. // for (const item of Object.values(Message.BitMapInstance.FdBitMap)) {//hulei 源文件功能是获取域的信息集合
  72. // const type = item.getItemType()
  73. // const value = type === String ? '1' : '0'
  74. // result[`FD${item.Code}`] = value
  75. // }
  76. return result
  77. }
  78. /**
  79. * 解析报文
  80. */
  81. public static analyze(type: string, returnData: Uint8Array, fileData: Uint8Array): { success: boolean, msg: Message } {
  82. const msg = new Message()
  83. const packageType = PackageType[type as keyof typeof PackageType]
  84. const packageInstance = MsgPackage.PackageList[packageType]
  85. const totalData = new Uint8Array(returnData.length + fileData.length)
  86. totalData.set(returnData, 0)
  87. totalData.set(fileData, returnData.length)
  88. const success = packageInstance.analyze(msg, totalData)
  89. return { success, msg }
  90. }
  91. }
  92. // msgjson辅助类
  93. class MsgJson {
  94. code: string = ''
  95. type: string = ''
  96. values: string = ''
  97. }