rabbitmq.go 23 KB

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