rabbitmq.go 31 KB

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