rabbitmq.go 33 KB

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