rabbitmq.go 28 KB

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