rabbitmq.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. package initialize
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. "mtp20access/client"
  6. "mtp20access/global"
  7. rsp "mtp20access/model/mq/response"
  8. "mtp20access/packet"
  9. "mtp20access/rabbitmq"
  10. "mtp20access/res/pb"
  11. accountSrv "mtp20access/service/account"
  12. "mtp20access/utils"
  13. // "github.com/golang/protobuf/proto"
  14. "github.com/streadway/amqp"
  15. "go.uber.org/zap"
  16. "google.golang.org/protobuf/encoding/protojson"
  17. "google.golang.org/protobuf/proto"
  18. )
  19. func RabbitMQ() *global.RabbitMQ {
  20. url := global.M2A_CONFIG.Rabbitmq.Url
  21. connection, err := amqp.Dial(url)
  22. if err != nil {
  23. global.M2A_LOG.Error("rabbitmq connect failed, err:", zap.Error(err))
  24. return nil
  25. }
  26. channel, err := connection.Channel()
  27. if err != nil {
  28. global.M2A_LOG.Error("rabbitmq open channel failed, err:", zap.Error(err))
  29. return nil
  30. }
  31. global.M2A_LOG.Info("rabbitmq connect successed.")
  32. return &global.RabbitMQ{
  33. Connection: connection,
  34. Channel: channel,
  35. }
  36. }
  37. // MQProc 消息处理对象
  38. type MQProc struct{}
  39. // process 消息处理接口
  40. func (t *MQProc) Process(topic, queuename string, msg *[]byte) {
  41. // info := fmt.Sprintf("rabbitmq receive message from: topic[%s] queue[%s] contentLen[%d]",
  42. // topic,
  43. // queuename,
  44. // len(string(*msg)))
  45. // global.M2A_LOG.Info(info)
  46. if funcode, sessionId, bytes, serialNumber, err := t.getRspProtobuf(msg); err == nil && bytes != nil {
  47. if sessionId == 0 {
  48. // 通知类
  49. t.onNtf(funcode, bytes)
  50. } else {
  51. // 请求回复W
  52. // 尝试获取对应异步任务
  53. if client, exists := client.Clients[int(sessionId)]; exists {
  54. key := fmt.Sprintf("%v_%v_%v", sessionId, funcode, serialNumber)
  55. // 银行服务相关的回复流水号是错误的,所以需要特殊处理
  56. if int(funcode) == global.T2bBankSignRsp ||
  57. int(funcode) == global.T2bBankCancelSignRsp ||
  58. int(funcode) == global.T2bBankWithdrawRsp ||
  59. int(funcode) == global.T2bBankDepositRsp {
  60. key = fmt.Sprintf("%v_%v", sessionId, funcode)
  61. }
  62. asyncTask := client.GetAsyncTask(key)
  63. if asyncTask != nil {
  64. rspData := string(*bytes)
  65. // 判断是否要加密
  66. if asyncTask.IsEncrypted {
  67. if b, err := packet.Encrypt(*bytes, packet.AESKey, true); err != nil {
  68. global.M2A_LOG.Error("总线回复数据加密失败", zap.Error(err))
  69. return
  70. } else {
  71. rspData = base64.StdEncoding.EncodeToString(b)
  72. }
  73. }
  74. // 给客户端回调
  75. global.M2A_LOG.Info("[S->C]", zap.Any("rsp", funcode), zap.Any("sessionId", sessionId), zap.Any("data", string(rspData)))
  76. r := rsp.MQBodyRsp{
  77. FunCode: funcode,
  78. IsEncrypted: asyncTask.IsEncrypted,
  79. Data: rspData,
  80. }
  81. asyncTask.Rsp <- r
  82. } else {
  83. global.M2A_LOG.Info("找不到对应KEY的异步任务", zap.Any("key", key), zap.Any("AsyncMap", client.GetAllAsyncTask()))
  84. }
  85. } else {
  86. global.M2A_LOG.Info("找不到对应的client", zap.Any("sessionId", sessionId))
  87. }
  88. }
  89. }
  90. }
  91. func (t *MQProc) onNtf(funcode uint32, bytes *[]byte) {
  92. switch int(funcode) {
  93. case global.MoneyChangedNtf: // 资金变化通知
  94. var p pb.MoneyChangedNtf
  95. if err := proto.Unmarshal(*bytes, &p); err != nil {
  96. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  97. return
  98. }
  99. // 组装待发送给客户端的5.0报文包
  100. b, err := packet.BuildPacket(funcode, 0, 0, *bytes, true)
  101. if err != nil {
  102. global.M2A_LOG.Error("组装5.0报文失败", zap.Error(err))
  103. return
  104. }
  105. // 获取目标客户
  106. clients, err := accountSrv.GetClientsByAccountID(*p.AccountID)
  107. if err != nil {
  108. return
  109. }
  110. // 发送信息
  111. for i := range clients {
  112. c := clients[i]
  113. c.WriteTradeWsBuf(b)
  114. }
  115. }
  116. }
  117. // getRspProtobuf 将总线回复的数据反序列化为Protobuf
  118. func (t *MQProc) getRspProtobuf(msg *[]byte) (funcode uint32, sessionId uint32, bytes *[]byte, serialNumber uint32, err error) {
  119. // 分解总线包信息
  120. funcode = utils.BytesToUint32((*msg)[0:4])
  121. sessionId = utils.BytesToUint32((*msg)[4:8])
  122. b := (*msg)[8:]
  123. global.M2A_LOG.Info("收到总线消息", zap.Any("funcode", funcode), zap.Any("sessionId", sessionId), zap.Any("len", len(b)))
  124. switch int(funcode) {
  125. case global.MoneyChangedNtf: // 资金变化通知
  126. bytes = &b
  127. case global.ModifyPwdRsp: // 修改账户密码应答
  128. var p pb.ModifyPwdRsp
  129. if err = proto.Unmarshal(b, &p); err != nil {
  130. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  131. return
  132. }
  133. if bs, e := protojson.Marshal(&p); e != nil {
  134. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  135. return
  136. } else {
  137. bytes = &bs
  138. serialNumber = p.GetHeader().GetRequestID()
  139. }
  140. case global.UserReceiveInfoRsp: // 新增修改收货地址请求响应
  141. var p pb.UserReceiveInfoRsp
  142. if err = proto.Unmarshal(b, &p); err != nil {
  143. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  144. return
  145. }
  146. if bs, e := protojson.Marshal(&p); e != nil {
  147. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  148. return
  149. } else {
  150. bytes = &bs
  151. serialNumber = p.GetHeader().GetRequestID()
  152. }
  153. case global.DelUserReceiveInfoRsp: // 删除收货地址请求响应
  154. var p pb.DelUserReceiveInfoRsp
  155. if err = proto.Unmarshal(b, &p); err != nil {
  156. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  157. return
  158. }
  159. if bs, e := protojson.Marshal(&p); e != nil {
  160. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  161. return
  162. } else {
  163. bytes = &bs
  164. serialNumber = p.GetHeader().GetRequestID()
  165. }
  166. case global.UserReceiptInfoRsp: // 新增修改用户发票信息请求响应
  167. var p pb.UserReceiptInfoRsp
  168. if err = proto.Unmarshal(b, &p); err != nil {
  169. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  170. return
  171. }
  172. if bs, e := protojson.Marshal(&p); e != nil {
  173. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  174. return
  175. } else {
  176. bytes = &bs
  177. serialNumber = p.GetHeader().GetRequestID()
  178. }
  179. case global.DelUserReceiptInfoRsp: // 删除用户发票信息请求响应
  180. var p pb.DelUserReceiptInfoRsp
  181. if err = proto.Unmarshal(b, &p); err != nil {
  182. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  183. return
  184. }
  185. if bs, e := protojson.Marshal(&p); e != nil {
  186. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  187. return
  188. } else {
  189. bytes = &bs
  190. serialNumber = p.GetHeader().GetRequestID()
  191. }
  192. case global.T2bBankSignRsp: // 签约应答
  193. var p pb.T2BBankSignRsp
  194. if err = proto.Unmarshal(b, &p); err != nil {
  195. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  196. return
  197. }
  198. if bs, e := protojson.Marshal(&p); e != nil {
  199. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  200. return
  201. } else {
  202. bytes = &bs
  203. serialNumber = p.GetHeader().GetRequestID()
  204. }
  205. case global.T2bBankCancelSignRsp: // 解约应答
  206. var p pb.T2BBankCancelSignRsp
  207. if err = proto.Unmarshal(b, &p); err != nil {
  208. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  209. return
  210. }
  211. if bs, e := protojson.Marshal(&p); e != nil {
  212. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  213. return
  214. } else {
  215. bytes = &bs
  216. serialNumber = p.GetHeader().GetRequestID()
  217. }
  218. case global.T2bBankWithdrawRsp: // 出金应答
  219. var p pb.T2BBankWithdrawRsp
  220. if err = proto.Unmarshal(b, &p); err != nil {
  221. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  222. return
  223. }
  224. if bs, e := protojson.Marshal(&p); e != nil {
  225. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  226. return
  227. } else {
  228. bytes = &bs
  229. serialNumber = p.GetHeader().GetRequestID()
  230. }
  231. case global.T2bBankDepositRsp: // 入金应答
  232. var p pb.T2BBankDepositRsp
  233. if err = proto.Unmarshal(b, &p); err != nil {
  234. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  235. return
  236. }
  237. if bs, e := protojson.Marshal(&p); e != nil {
  238. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  239. return
  240. } else {
  241. bytes = &bs
  242. serialNumber = p.GetHeader().GetRequestID()
  243. }
  244. case global.WarehouseApplyRsp: // 仓库申请应答
  245. var p pb.WarehouseApplyRsp
  246. if err = proto.Unmarshal(b, &p); err != nil {
  247. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  248. return
  249. }
  250. if bs, e := protojson.Marshal(&p); e != nil {
  251. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  252. return
  253. } else {
  254. bytes = &bs
  255. serialNumber = p.GetHeader().GetRequestID()
  256. }
  257. case global.PerformanceContractedApplyRsp: // 违约申请应答
  258. var p pb.PerformanceContractedApplyRsp
  259. if err = proto.Unmarshal(b, &p); err != nil {
  260. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  261. return
  262. }
  263. if bs, e := protojson.Marshal(&p); e != nil {
  264. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  265. return
  266. } else {
  267. bytes = &bs
  268. serialNumber = p.GetHeader().GetRequestID()
  269. }
  270. case global.PerformanceDelayApplyRsp: // 延期申请应答
  271. var p pb.PerformanceDelayApplyRsp
  272. if err = proto.Unmarshal(b, &p); err != nil {
  273. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  274. return
  275. }
  276. if bs, e := protojson.Marshal(&p); e != nil {
  277. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  278. return
  279. } else {
  280. bytes = &bs
  281. serialNumber = p.GetHeader().GetRequestID()
  282. }
  283. case global.PerformanceManualConfirmRsp: // 履约手动确认应答
  284. var p pb.PerformanceManualConfirmRsp
  285. if err = proto.Unmarshal(b, &p); err != nil {
  286. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  287. return
  288. }
  289. if bs, e := protojson.Marshal(&p); e != nil {
  290. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  291. return
  292. } else {
  293. bytes = &bs
  294. serialNumber = p.GetHeader().GetRequestID()
  295. }
  296. case global.PerformanceModifyContactRsp: // 履约修改联络信息回应
  297. var p pb.PerformanceModifyContactRsp
  298. if err = proto.Unmarshal(b, &p); err != nil {
  299. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  300. return
  301. }
  302. if bs, e := protojson.Marshal(&p); e != nil {
  303. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  304. return
  305. } else {
  306. bytes = &bs
  307. serialNumber = p.GetHeader().GetRequestID()
  308. }
  309. case global.GoodsFavoriteOperateRsp: // 商品收藏操作接口应答
  310. var p pb.GoodsFavoriteOperateRsp
  311. if err = proto.Unmarshal(b, &p); err != nil {
  312. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  313. return
  314. }
  315. if bs, e := protojson.Marshal(&p); e != nil {
  316. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  317. return
  318. } else {
  319. bytes = &bs
  320. serialNumber = p.GetHeader().GetRequestID()
  321. }
  322. case global.ZSBuyOrderListingRsp: // 钻石买挂牌接口应答
  323. var p pb.ZSBuyOrderListingRsp
  324. if err = proto.Unmarshal(b, &p); err != nil {
  325. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  326. return
  327. }
  328. if bs, e := protojson.Marshal(&p); e != nil {
  329. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  330. return
  331. } else {
  332. bytes = &bs
  333. serialNumber = p.GetHeader().GetRequestID()
  334. }
  335. case global.ZSSellOrderListingRsp: // 钻石卖挂牌接口响应
  336. var p pb.ZSSellOrderListingRsp
  337. if err = proto.Unmarshal(b, &p); err != nil {
  338. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  339. return
  340. }
  341. if bs, e := protojson.Marshal(&p); e != nil {
  342. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  343. return
  344. } else {
  345. bytes = &bs
  346. serialNumber = p.GetHeader().GetRequestID()
  347. }
  348. case global.ZSBuyOrderDestingRsp: // 钻石卖摘牌申请接口响应
  349. var p pb.ZSBuyOrderDestingRsp
  350. if err = proto.Unmarshal(b, &p); err != nil {
  351. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  352. return
  353. }
  354. if bs, e := protojson.Marshal(&p); e != nil {
  355. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  356. return
  357. } else {
  358. bytes = &bs
  359. serialNumber = p.GetHeader().GetRequestID()
  360. }
  361. case global.ZSSellOrderDestingApplyOperateRsp: // 钻石卖摘牌申请操作接口应答
  362. var p pb.ZSSellOrderDestingApplyOperateRsp
  363. if err = proto.Unmarshal(b, &p); err != nil {
  364. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  365. return
  366. }
  367. if bs, e := protojson.Marshal(&p); e != nil {
  368. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  369. return
  370. } else {
  371. bytes = &bs
  372. serialNumber = p.GetHeader().GetRequestID()
  373. }
  374. case global.ZSBuyOrderDestingNegPriceRsp: // 买摘牌询价接口应答
  375. var p pb.ZSBuyOrderDestingNegPriceRsp
  376. if err = proto.Unmarshal(b, &p); err != nil {
  377. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  378. return
  379. }
  380. if bs, e := protojson.Marshal(&p); e != nil {
  381. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  382. return
  383. } else {
  384. bytes = &bs
  385. serialNumber = p.GetHeader().GetRequestID()
  386. }
  387. case global.ZSBuyOrderDestingNegPriceOperateRsp: // 买摘牌询价操作接口应答
  388. var p pb.ZSBuyOrderDestingNegPriceOperateRsp
  389. if err = proto.Unmarshal(b, &p); err != nil {
  390. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  391. return
  392. }
  393. if bs, e := protojson.Marshal(&p); e != nil {
  394. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  395. return
  396. } else {
  397. bytes = &bs
  398. serialNumber = p.GetHeader().GetRequestID()
  399. }
  400. case global.WRListingCancelOrderRsp: // 挂牌撤单应答
  401. var p pb.WRListingCancelOrderRsp
  402. if err = proto.Unmarshal(b, &p); err != nil {
  403. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  404. return
  405. }
  406. if bs, e := protojson.Marshal(&p); e != nil {
  407. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  408. return
  409. } else {
  410. bytes = &bs
  411. serialNumber = p.GetHeader().GetRequestID()
  412. }
  413. case global.HdWROrderRsp:
  414. var p pb.HdWROrderRsp
  415. if err = proto.Unmarshal(b, &p); err != nil {
  416. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  417. return
  418. }
  419. if bs, e := protojson.Marshal(&p); e != nil {
  420. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  421. return
  422. } else {
  423. bytes = &bs
  424. serialNumber = p.GetHeader().GetRequestID()
  425. }
  426. case global.WROutApplyRsp:
  427. var p pb.WROutApplyRsp
  428. if err = proto.Unmarshal(b, &p); err != nil {
  429. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  430. return
  431. }
  432. if bs, e := protojson.Marshal(&p); e != nil {
  433. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  434. return
  435. } else {
  436. bytes = &bs
  437. serialNumber = p.GetHeader().GetRequestID()
  438. }
  439. case global.ReceiptZSOutApplyRsp: // 钻石出库申请接口响应
  440. var p pb.ReceiptZSOutApplyRsp
  441. if err = proto.Unmarshal(b, &p); err != nil {
  442. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  443. return
  444. }
  445. if bs, e := protojson.Marshal(&p); e != nil {
  446. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  447. return
  448. } else {
  449. bytes = &bs
  450. serialNumber = p.GetHeader().GetRequestID()
  451. }
  452. case global.SpotPresaleListingOrderRsp: // 铁合金现货预售挂牌接口应答
  453. var p pb.SpotPresaleListingOrderRsp
  454. if err = proto.Unmarshal(b, &p); err != nil {
  455. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  456. return
  457. }
  458. if bs, e := protojson.Marshal(&p); e != nil {
  459. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  460. return
  461. } else {
  462. bytes = &bs
  463. serialNumber = p.GetHeader().GetRequestID()
  464. }
  465. case global.CJJCMemberOperateRsp: // 出境检测会员操作响应
  466. var p pb.CJJCMemberOperateRsp
  467. if err = proto.Unmarshal(b, &p); err != nil {
  468. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  469. return
  470. }
  471. if bs, e := protojson.Marshal(&p); e != nil {
  472. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  473. return
  474. } else {
  475. bytes = &bs
  476. serialNumber = p.GetHeader().GetRequestID()
  477. }
  478. case global.BSFWMemberOperateRsp: // 保税服务会员操作响应
  479. var p pb.BSFWMemberOperateRsp
  480. if err = proto.Unmarshal(b, &p); err != nil {
  481. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  482. return
  483. }
  484. if bs, e := protojson.Marshal(&p); e != nil {
  485. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  486. return
  487. } else {
  488. bytes = &bs
  489. serialNumber = p.GetHeader().GetRequestID()
  490. }
  491. case global.AccountFundInfoRsp: // 账户资金信息响应
  492. var p pb.AccountFundInfoRsp
  493. if err = proto.Unmarshal(b, &p); err != nil {
  494. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  495. return
  496. }
  497. if bs, e := protojson.Marshal(&p); e != nil {
  498. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  499. return
  500. } else {
  501. bytes = &bs
  502. serialNumber = p.GetHeader().GetRequestID()
  503. }
  504. case global.GZPresaleApplyRsp: // 广钻预售申请响应
  505. var p pb.GZPresaleApplyRsp
  506. if err = proto.Unmarshal(b, &p); err != nil {
  507. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  508. return
  509. }
  510. if bs, e := protojson.Marshal(&p); e != nil {
  511. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  512. return
  513. } else {
  514. bytes = &bs
  515. serialNumber = p.GetHeader().GetRequestID()
  516. }
  517. case global.GZPresaleOrderRsp: // 广钻预售认购下单响应
  518. var p pb.GZPresaleOrderRsp
  519. if err = proto.Unmarshal(b, &p); err != nil {
  520. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  521. return
  522. }
  523. if bs, e := protojson.Marshal(&p); e != nil {
  524. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  525. return
  526. } else {
  527. bytes = &bs
  528. serialNumber = p.GetHeader().GetRequestID()
  529. }
  530. case global.GZCenterPurchaseApplyRsp: // 广钻集采申请响应
  531. var p pb.GZCenterPurchaseApplyRsp
  532. if err = proto.Unmarshal(b, &p); err != nil {
  533. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  534. return
  535. }
  536. if bs, e := protojson.Marshal(&p); e != nil {
  537. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  538. return
  539. } else {
  540. bytes = &bs
  541. serialNumber = p.GetHeader().GetRequestID()
  542. }
  543. case global.GZCenterPurchaseOrderRsp: // 广钻集采认购下单响应
  544. var p pb.GZCenterPurchaseOrderRsp
  545. if err = proto.Unmarshal(b, &p); err != nil {
  546. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  547. return
  548. }
  549. if bs, e := protojson.Marshal(&p); e != nil {
  550. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  551. return
  552. } else {
  553. bytes = &bs
  554. serialNumber = p.GetHeader().GetRequestID()
  555. }
  556. case global.BSWMSReckonPayRsp: // WMS结算单支付接口响应
  557. var p pb.BSWMSReckonPayRsp
  558. if err = proto.Unmarshal(b, &p); err != nil {
  559. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  560. return
  561. }
  562. if bs, e := protojson.Marshal(&p); e != nil {
  563. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  564. return
  565. } else {
  566. bytes = &bs
  567. serialNumber = p.GetHeader().GetRequestID()
  568. }
  569. case global.OrderRsp:
  570. var p pb.OrderRsp
  571. if err = proto.Unmarshal(b, &p); err != nil {
  572. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  573. return
  574. }
  575. if bs, e := protojson.Marshal(&p); e != nil {
  576. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  577. return
  578. } else {
  579. bytes = &bs
  580. serialNumber = p.GetHeader().GetRequestID()
  581. }
  582. case global.CancelOrderRsp:
  583. var p pb.CancelOrderRsp
  584. if err = proto.Unmarshal(b, &p); err != nil {
  585. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  586. return
  587. }
  588. if bs, e := protojson.Marshal(&p); e != nil {
  589. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  590. return
  591. } else {
  592. bytes = &bs
  593. serialNumber = p.GetHeader().GetRequestID()
  594. }
  595. case global.HolderCloseRsp:
  596. var p pb.HolderCloseRsp
  597. if err = proto.Unmarshal(b, &p); err != nil {
  598. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  599. return
  600. }
  601. if bs, e := protojson.Marshal(&p); e != nil {
  602. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  603. return
  604. } else {
  605. bytes = &bs
  606. serialNumber = p.GetHeader().GetRequestID()
  607. }
  608. case global.DeliveryOrderRsp:
  609. var p pb.DeliveryOrderRsp
  610. if err = proto.Unmarshal(b, &p); err != nil {
  611. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  612. return
  613. }
  614. if bs, e := protojson.Marshal(&p); e != nil {
  615. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  616. return
  617. } else {
  618. bytes = &bs
  619. serialNumber = p.GetHeader().GetRequestID()
  620. }
  621. case global.MakeUpDepositRsp:
  622. var p pb.MakeUpDepositRsp
  623. if err = proto.Unmarshal(b, &p); err != nil {
  624. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  625. return
  626. }
  627. if bs, e := protojson.Marshal(&p); e != nil {
  628. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  629. return
  630. } else {
  631. bytes = &bs
  632. serialNumber = p.GetHeader().GetRequestID()
  633. }
  634. case global.HoldAppendDepositRsp:
  635. var p pb.HoldAppendDepositRsp
  636. if err = proto.Unmarshal(b, &p); err != nil {
  637. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  638. return
  639. }
  640. if bs, e := protojson.Marshal(&p); e != nil {
  641. global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
  642. return
  643. } else {
  644. bytes = &bs
  645. serialNumber = p.GetHeader().GetRequestID()
  646. }
  647. }
  648. return
  649. }
  650. // RabbitMQSubscribeTopic 订阅主题
  651. func RabbitMQSubscribeTopic() (err error) {
  652. // 订阅需要的总线响应主题
  653. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_NTF); err != nil {
  654. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  655. return
  656. }
  657. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_QKERNEL); err != nil {
  658. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  659. return
  660. }
  661. if err = rabbitmq.SubscribeTopic(global.TOPIC_MANAGE_RSP); err != nil {
  662. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  663. return
  664. }
  665. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_BANK); err != nil {
  666. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  667. return
  668. }
  669. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_MONEY); err != nil {
  670. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  671. return
  672. }
  673. if err = rabbitmq.SubscribeTopic(global.TOPIC_PERFORMANCE_RSP); err != nil {
  674. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  675. return
  676. }
  677. if err = rabbitmq.SubscribeTopic(global.TOPIC_WAREHOUSE_RECIEPT_RSP); err != nil {
  678. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  679. return
  680. }
  681. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_TRADE); err != nil {
  682. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  683. return
  684. }
  685. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_TRADE_GZ); err != nil {
  686. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  687. return
  688. }
  689. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_CJBS_TRADE_GZ); err != nil {
  690. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  691. return
  692. }
  693. // 铁合金
  694. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_PRESALE_THJ); err != nil {
  695. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  696. return
  697. }
  698. if err = rabbitmq.SubscribeTopic(global.TOPIC_MANAGER_THJ_NTF); err != nil {
  699. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  700. return
  701. }
  702. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_PRESALE_GZ); err != nil {
  703. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  704. return
  705. }
  706. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_CENTERPURCHASE_GZ); err != nil {
  707. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  708. return
  709. }
  710. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_ORDER); err != nil {
  711. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  712. return
  713. }
  714. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_DELIVERY_TRADE); err != nil {
  715. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  716. return
  717. }
  718. global.M2A_LOG.Info("rabbitmq subscribe topic successed.")
  719. return
  720. }
  721. // StartRabbitMQReceive 开始接收总线消息
  722. func StartRabbitMQReceive() {
  723. t := &MQProc{}
  724. go func() {
  725. for _, subinfo := range rabbitmq.SubInfos {
  726. rabbitmq.Receive(subinfo.Topic, subinfo.QueueName, t)
  727. }
  728. }()
  729. }
  730. // InitFuncodeTopic 初始化功能码主题MAP
  731. func InitFuncodeTopic() {
  732. if global.M2A_FuncodeTopic == nil {
  733. global.M2A_FuncodeTopic = make(map[string][]int)
  734. }
  735. global.M2A_FuncodeTopic[global.TOPIC_REQ_QKERNEL] = []int{
  736. global.ModifyPwdReq,
  737. }
  738. global.M2A_FuncodeTopic[global.TOPIC_MANAGE_REQ] = []int{
  739. global.UserReceiveInfoReq,
  740. global.DelUserReceiveInfoReq,
  741. global.UserReceiveIsDefaultReq,
  742. global.UserReceiptInfoReq,
  743. global.DelUserReceiptInfoReq,
  744. global.WarehouseApplyReq,
  745. global.WROutApplyReq,
  746. }
  747. global.M2A_FuncodeTopic[global.TOPIC_REQ_BANK] = []int{
  748. global.T2bBankSignReq,
  749. global.T2bBankCancelSignReq,
  750. global.T2bBankWithdrawReq,
  751. global.T2bBankDepositReq,
  752. }
  753. global.M2A_FuncodeTopic[global.TOPIC_REQ_MONEY] = []int{
  754. global.AccountFundInfoReq,
  755. }
  756. global.M2A_FuncodeTopic[global.TOPIC_PERFORMANCE_REQ] = []int{
  757. global.PerformanceContractedApplyReq,
  758. global.PerformanceDelayApplyReq,
  759. global.PerformanceManualConfirmReq,
  760. global.PerformanceModifyContactReq,
  761. }
  762. global.M2A_FuncodeTopic[global.TOPIC_WAREHOUSE_RECIEPT] = []int{
  763. global.ReceiptZSOutApplyReq,
  764. }
  765. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE] = []int{
  766. global.WRListingCancelOrderReq,
  767. global.HdWROrderReq,
  768. }
  769. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE_GZ] = []int{
  770. global.GoodsFavoriteOperateReq,
  771. global.ZSBuyOrderListingReq,
  772. global.ZSSellOrderListingReq,
  773. global.ZSBuyOrderDestingReq,
  774. global.ZSSellOrderDestingApplyReq,
  775. global.ZSSellOrderDestingApplyOperateReq,
  776. global.ZSBuyOrderDestingNegPriceReq,
  777. global.ZSBuyOrderDestingNegPriceOperateReq,
  778. }
  779. global.M2A_FuncodeTopic[global.TOPIC_REQ_CJBS_TRADE_GZ] = []int{
  780. global.CJJCMemberOperateReq,
  781. global.BSFWMemberOperateReq,
  782. global.BSWMSReckonPayReq,
  783. }
  784. // 铁合金
  785. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_PRESALE_THJ] = []int{
  786. global.SpotPresaleListingOrderReq,
  787. }
  788. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_PRESALE_GZ] = []int{
  789. global.GZPresaleApplyReq,
  790. global.GZPresaleOrderReq,
  791. }
  792. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_CENTERPURCHASE_GZ] = []int{
  793. global.GZCenterPurchaseApplyReq,
  794. global.GZCenterPurchaseOrderReq,
  795. }
  796. global.M2A_FuncodeTopic[global.TOPIC_REQ_ORDER] = []int{
  797. global.OrderReq,
  798. global.CancelOrderReq,
  799. global.HolderCloseReq,
  800. global.MakeUpDepositReq,
  801. global.HoldAppendDepositReq,
  802. }
  803. global.M2A_FuncodeTopic[global.TOPIC_REQ_DELIVERY_TRADE] = []int{
  804. global.DeliveryOrderReq,
  805. }
  806. }