rabbitmq.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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.UserReceiptInfoRsp: // 新增修改用户发票信息请求响应
  241. var p pb.UserReceiptInfoRsp
  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.DelUserReceiptInfoRsp: // 删除用户发票信息请求响应
  254. var p pb.DelUserReceiptInfoRsp
  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.T2bBankSignRsp: // 签约应答
  267. var p pb.T2BBankSignRsp
  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.T2bBankCancelSignRsp: // 解约应答
  280. var p pb.T2BBankCancelSignRsp
  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.T2bBankWithdrawRsp: // 出金应答
  293. var p pb.T2BBankWithdrawRsp
  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.T2bBankDepositRsp: // 入金应答
  306. var p pb.T2BBankDepositRsp
  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.WarehouseApplyRsp: // 仓库申请应答
  319. var p pb.WarehouseApplyRsp
  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.PerformanceContractedApplyRsp: // 违约申请应答
  332. var p pb.PerformanceContractedApplyRsp
  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.PerformanceDelayApplyRsp: // 延期申请应答
  345. var p pb.PerformanceDelayApplyRsp
  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.PerformanceManualConfirmRsp: // 履约手动确认应答
  358. var p pb.PerformanceManualConfirmRsp
  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.PerformanceModifyContactRsp: // 履约修改联络信息回应
  371. var p pb.PerformanceModifyContactRsp
  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.GoodsFavoriteOperateRsp: // 商品收藏操作接口应答
  384. var p pb.GoodsFavoriteOperateRsp
  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.ZSBuyOrderListingRsp: // 钻石买挂牌接口应答
  397. var p pb.ZSBuyOrderListingRsp
  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.ZSSellOrderListingRsp: // 钻石卖挂牌接口响应
  410. var p pb.ZSSellOrderListingRsp
  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.ZSBuyOrderDestingRsp: // 钻石卖摘牌申请接口响应
  423. var p pb.ZSBuyOrderDestingRsp
  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.ZSSellOrderDestingApplyOperateRsp: // 钻石卖摘牌申请操作接口应答
  436. var p pb.ZSSellOrderDestingApplyOperateRsp
  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.ZSBuyOrderDestingNegPriceRsp: // 买摘牌询价接口应答
  449. var p pb.ZSBuyOrderDestingNegPriceRsp
  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.ZSBuyOrderDestingNegPriceOperateRsp: // 买摘牌询价操作接口应答
  462. var p pb.ZSBuyOrderDestingNegPriceOperateRsp
  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.WRListingCancelOrderRsp: // 挂牌撤单应答
  475. var p pb.WRListingCancelOrderRsp
  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.HdWROrderRsp:
  488. var p pb.HdWROrderRsp
  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.WROutApplyRsp:
  501. var p pb.WROutApplyRsp
  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.ReceiptZSOutApplyRsp: // 钻石出库申请接口响应
  514. var p pb.ReceiptZSOutApplyRsp
  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.SpotPresaleListingOrderRsp: // 铁合金现货预售挂牌接口应答
  527. var p pb.SpotPresaleListingOrderRsp
  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.CJJCMemberOperateRsp: // 出境检测会员操作响应
  540. var p pb.CJJCMemberOperateRsp
  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.BSFWMemberOperateRsp: // 保税服务会员操作响应
  553. var p pb.BSFWMemberOperateRsp
  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.AccountFundInfoRsp: // 账户资金信息响应
  566. var p pb.AccountFundInfoRsp
  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.GZPresaleApplyRsp: // 广钻预售申请响应
  579. var p pb.GZPresaleApplyRsp
  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.GZPresaleOrderRsp: // 广钻预售认购下单响应
  592. var p pb.GZPresaleOrderRsp
  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.GZCenterPurchaseApplyRsp: // 广钻集采申请响应
  605. var p pb.GZCenterPurchaseApplyRsp
  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.GZCenterPurchaseOrderRsp: // 广钻集采认购下单响应
  618. var p pb.GZCenterPurchaseOrderRsp
  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.BSWMSReckonPayRsp: // WMS结算单支付接口响应
  631. var p pb.BSWMSReckonPayRsp
  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.OrderRsp:
  644. var p pb.OrderRsp
  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.CancelOrderRsp:
  657. var p pb.CancelOrderRsp
  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.HolderCloseRsp:
  670. var p pb.HolderCloseRsp
  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.DeliveryOrderRsp:
  683. var p pb.DeliveryOrderRsp
  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.MakeUpDepositRsp:
  696. var p pb.MakeUpDepositRsp
  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.HoldAppendDepositRsp:
  709. var p pb.HoldAppendDepositRsp
  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.OfflineDeliveryRsp:
  722. var p pb.OfflineDeliveryRsp
  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.HdWRDealOrderRsp:
  735. var p pb.HdWRDealOrderRsp
  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.SupplementDepositRsp:
  748. var p pb.SupplementDepositRsp
  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.RefundedDepositRsp:
  761. var p pb.RefundedDepositRsp
  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.MarketOrderDeliveryApplyRsp:
  774. var p pb.MarketOrderDeliveryApplyRsp
  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.DeliveryClientOperatorRsp:
  787. var p pb.DeliveryClientOperatorRsp
  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. }
  800. return
  801. }
  802. // RabbitMQSubscribeTopic 订阅主题
  803. func RabbitMQSubscribeTopic() (err error) {
  804. // 订阅需要的总线响应主题
  805. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_USER); 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_NTF); 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_CLIENT_NTF); err != nil {
  814. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  815. return
  816. }
  817. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_QKERNEL); err != nil {
  818. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  819. return
  820. }
  821. if err = rabbitmq.SubscribeTopic(global.TOPIC_MANAGE_RSP); err != nil {
  822. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  823. return
  824. }
  825. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_BANK); err != nil {
  826. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  827. return
  828. }
  829. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_MONEY); err != nil {
  830. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  831. return
  832. }
  833. if err = rabbitmq.SubscribeTopic(global.TOPIC_PERFORMANCE_RSP); err != nil {
  834. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  835. return
  836. }
  837. if err = rabbitmq.SubscribeTopic(global.TOPIC_WAREHOUSE_RECIEPT_RSP); err != nil {
  838. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  839. return
  840. }
  841. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_TRADE); err != nil {
  842. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  843. return
  844. }
  845. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_TRADE_GZ); err != nil {
  846. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  847. return
  848. }
  849. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_CJBS_TRADE_GZ); err != nil {
  850. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  851. return
  852. }
  853. // 铁合金
  854. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_PRESALE_THJ); 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_MANAGER_THJ_NTF); 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_WAREHOUSE_PRESALE_GZ); err != nil {
  863. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  864. return
  865. }
  866. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_WAREHOUSE_CENTERPURCHASE_GZ); err != nil {
  867. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  868. return
  869. }
  870. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_ORDER); err != nil {
  871. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  872. return
  873. }
  874. if err = rabbitmq.SubscribeTopic(global.TOPIC_RSP_DELIVERY_TRADE); err != nil {
  875. global.M2A_LOG.Error("rabbitmq subscribe topic failed, err:", zap.Error(err))
  876. return
  877. }
  878. global.M2A_LOG.Info("rabbitmq subscribe topic successed.")
  879. return
  880. }
  881. // StartRabbitMQReceive 开始接收总线消息
  882. func StartRabbitMQReceive() {
  883. t := &MQProc{}
  884. go func() {
  885. for _, subinfo := range rabbitmq.SubInfos {
  886. rabbitmq.Receive(subinfo.Topic, subinfo.QueueName, t)
  887. }
  888. }()
  889. }
  890. // InitFuncodeTopic 初始化功能码主题MAP
  891. func InitFuncodeTopic() {
  892. if global.M2A_FuncodeTopic == nil {
  893. global.M2A_FuncodeTopic = make(map[string][]int)
  894. }
  895. global.M2A_FuncodeTopic[global.TOPIC_REQ_QKERNEL] = []int{
  896. global.ModifyPwdReq,
  897. }
  898. global.M2A_FuncodeTopic[global.TOPIC_MANAGE_REQ] = []int{
  899. global.UserReceiveInfoReq,
  900. global.DelUserReceiveInfoReq,
  901. global.UserReceiveIsDefaultReq,
  902. global.UserReceiptInfoReq,
  903. global.DelUserReceiptInfoReq,
  904. global.WarehouseApplyReq,
  905. global.WROutApplyReq,
  906. }
  907. global.M2A_FuncodeTopic[global.TOPIC_REQ_BANK] = []int{
  908. global.T2bBankSignReq,
  909. global.T2bBankCancelSignReq,
  910. global.T2bBankWithdrawReq,
  911. global.T2bBankDepositReq,
  912. }
  913. global.M2A_FuncodeTopic[global.TOPIC_REQ_MONEY] = []int{
  914. global.AccountFundInfoReq,
  915. }
  916. global.M2A_FuncodeTopic[global.TOPIC_PERFORMANCE_REQ] = []int{
  917. global.PerformanceContractedApplyReq,
  918. global.PerformanceDelayApplyReq,
  919. global.PerformanceManualConfirmReq,
  920. global.PerformanceModifyContactReq,
  921. }
  922. global.M2A_FuncodeTopic[global.TOPIC_WAREHOUSE_RECIEPT] = []int{
  923. global.ReceiptZSOutApplyReq,
  924. }
  925. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE] = []int{
  926. global.WRListingCancelOrderReq,
  927. global.HdWROrderReq,
  928. global.HdWRDealOrderReq,
  929. }
  930. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE_GZ] = []int{
  931. global.GoodsFavoriteOperateReq,
  932. global.ZSBuyOrderListingReq,
  933. global.ZSSellOrderListingReq,
  934. global.ZSBuyOrderDestingReq,
  935. global.ZSSellOrderDestingApplyReq,
  936. global.ZSSellOrderDestingApplyOperateReq,
  937. global.ZSBuyOrderDestingNegPriceReq,
  938. global.ZSBuyOrderDestingNegPriceOperateReq,
  939. }
  940. global.M2A_FuncodeTopic[global.TOPIC_REQ_CJBS_TRADE_GZ] = []int{
  941. global.CJJCMemberOperateReq,
  942. global.BSFWMemberOperateReq,
  943. global.BSWMSReckonPayReq,
  944. }
  945. // 铁合金
  946. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_PRESALE_THJ] = []int{
  947. global.SpotPresaleListingOrderReq,
  948. }
  949. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_PRESALE_GZ] = []int{
  950. global.GZPresaleApplyReq,
  951. global.GZPresaleOrderReq,
  952. }
  953. global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_CENTERPURCHASE_GZ] = []int{
  954. global.GZCenterPurchaseApplyReq,
  955. global.GZCenterPurchaseOrderReq,
  956. }
  957. global.M2A_FuncodeTopic[global.TOPIC_REQ_ORDER] = []int{
  958. global.OrderReq,
  959. global.CancelOrderReq,
  960. global.HolderCloseReq,
  961. global.MakeUpDepositReq,
  962. global.HoldAppendDepositReq,
  963. global.OfflineDeliveryReq,
  964. global.SupplementDepositReq,
  965. global.RefundedDepositReq,
  966. global.MarketOrderDeliveryApplyReq,
  967. global.DeliveryClientOperatorReq,
  968. }
  969. global.M2A_FuncodeTopic[global.TOPIC_REQ_DELIVERY_TRADE] = []int{
  970. global.DeliveryOrderReq,
  971. }
  972. global.M2A_FuncodeTopic[global.TOPIC_REQ_USER] = []int{
  973. global.LoginReq,
  974. }
  975. }