AccountProtobufAdapter.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  1. //----------------------------------------------------------------
  2. //Module Name: Muchinfo.MTPClient.Adapter
  3. //Purpose:
  4. //CopyRight: Muchinfo
  5. //History:
  6. //----------------------------------------------------------------
  7. //DateTime 2016/1/13 13:45:06
  8. //Author
  9. //Description Create
  10. //----------------------------------------------------------------
  11. using Muchinfo.MTPClient.Adapter.Abstract;
  12. using Muchinfo.MTPClient.Adapter.Utilities;
  13. using Muchinfo.MTPClient.Data;
  14. using Muchinfo.MTPClient.Data.Enums;
  15. using Muchinfo.MTPClient.Data.Helper;
  16. using Muchinfo.MTPClient.Data.Model;
  17. using Muchinfo.MTPClient.Data.Model.Account;
  18. using Muchinfo.MTPClient.Data.Model.GoodRules;
  19. using Muchinfo.MTPClient.Data.Model.Message;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using tas;
  24. namespace Muchinfo.MTPClient.Adapter.ProtoBuf
  25. {
  26. /// <summary>
  27. /// Class AccountProtobufAdapter.
  28. /// </summary>
  29. public class AccountProtobufAdapter : AccountAdapter
  30. {
  31. /// <summary>
  32. /// 通知查询转换
  33. /// </summary>
  34. /// <param name="loginId">The login identifier.</param>
  35. /// <param name="lastNoticeId">The last notice identifier.</param>
  36. /// <returns>System.Byte[][].</returns>
  37. public override byte[] ToReqeustNoticeQuery(ulong loginId, long lastNoticeId)
  38. {
  39. var baseQueryReq = new NoticeQueryReq()
  40. {
  41. Header = new MessageHead() { },
  42. LoginID = loginId,
  43. LastNoticeId = (uint)lastNoticeId,
  44. //MsgType = 0,
  45. };
  46. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  47. }
  48. /// <summary>
  49. /// 通知查询转换-应答
  50. /// </summary>
  51. /// <param name="data">数据内容</param>
  52. /// <returns></returns>
  53. public override ResponeEntity<List<NoticeMsg>> ResponeNoticeQuery(object data)
  54. {
  55. var byteArr = data as byte[];
  56. if (data == null)
  57. {
  58. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  59. }
  60. var itemRespone = ProtoBufHelper.EntityDeSerialize<NoticeQueryRsp>(byteArr);
  61. var resultEntity = new ResponeEntity<List<NoticeMsg>>()
  62. {
  63. RetCode = itemRespone.RetCode,
  64. RetMessage = itemRespone.RetDesc,
  65. Entity = new List<NoticeMsg>()
  66. };
  67. foreach (var item in itemRespone.NoticeInfoList)
  68. {
  69. var itemNoticeInfo = BufToNoticeInfo(item);
  70. resultEntity.Entity.Add(itemNoticeInfo);
  71. }
  72. return resultEntity;
  73. }
  74. /// <summary>
  75. /// 通知item转换
  76. /// </summary>
  77. /// <param name="good"></param>
  78. /// <returns></returns>
  79. private NoticeMsg BufToNoticeInfo(NoticeInfo tasModel)
  80. {
  81. var localModel = new NoticeMsg()
  82. {
  83. MSG_ID = tasModel.NoticeId, //NoticeId id uint32
  84. TITLE = tasModel.NoticeTitle, //NoticeTitle 标题 string
  85. CONTENT = tasModel.NoticeContent, //NoticeContent 内容 string
  86. Sending_Time = TimeHelper.ConvertStringToDateTime(tasModel.NoticeTime.ToString()),
  87. NoticeType = tasModel.NoticeType, //NoticeType 类型 uint32
  88. };
  89. return localModel;
  90. }
  91. /// <summary>
  92. /// 风险协议书转换
  93. /// </summary>
  94. /// <param name="RiskMsgUTime">上次更新配置时间</param>
  95. /// <returns></returns>
  96. public override byte[] ToReqeustRiskTipQueryReq(ulong RiskMsgUTime)
  97. {
  98. var baseQueryReq = new RiskTipQueryReq()
  99. {
  100. Header = new MessageHead() { },
  101. RiskMsgUTime = RiskMsgUTime,
  102. };
  103. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  104. }
  105. /// <summary>
  106. /// 风险协议书转换-应答
  107. /// </summary>
  108. /// <param name="data">数据内容</param>
  109. /// <returns></returns>
  110. public override ResponeEntity<RiskTipQueryRspModel> ResponeRiskTipQueryReq(object data)
  111. {
  112. var byteArr = data as byte[];
  113. if (data == null)
  114. {
  115. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  116. }
  117. var itemRespone = ProtoBufHelper.EntityDeSerialize<RiskTipQueryRsp>(byteArr);
  118. var resultEntity = new ResponeEntity<RiskTipQueryRspModel>()
  119. {
  120. RetCode = itemRespone.RetCode,
  121. RetMessage = itemRespone.RetDesc,
  122. Entity = new RiskTipQueryRspModel()
  123. {
  124. TipTitle = itemRespone.TipTitle,
  125. TipMsg = itemRespone.TipMsg
  126. }
  127. };
  128. return resultEntity;
  129. }
  130. /// <summary>
  131. /// 市场转换
  132. /// </summary>
  133. /// <param name="MarketsUTime">上次更新配置时间</param>
  134. /// <returns></returns>
  135. public override byte[] ToReqeustMarketsQueryReq(ulong MarketsUTime)
  136. {
  137. var baseQueryReq = new MarketsQueryReq()
  138. {
  139. Header = new MessageHead() { },
  140. MarketsUTime = MarketsUTime,
  141. };
  142. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  143. }
  144. /// <summary>
  145. /// 市场转换-应答
  146. /// </summary>
  147. /// <param name="data">数据内容</param>
  148. /// <returns></returns>
  149. public override ResponeEntity<List<MarketsInfoModel>> ResponeMarketsQueryReq(object data)
  150. {
  151. var byteArr = data as byte[];
  152. if (data == null)
  153. {
  154. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  155. }
  156. var itemRespone = ProtoBufHelper.EntityDeSerialize<MarketsQueryRsp>(byteArr);
  157. var resultEntity = new ResponeEntity<List<MarketsInfoModel>>()
  158. {
  159. RetCode = itemRespone.RetCode,
  160. RetMessage = itemRespone.RetDesc,
  161. Entity = new List<MarketsInfoModel>()
  162. {
  163. }
  164. };
  165. foreach (var item in itemRespone.MarketsList)
  166. {
  167. var itemMarketsInfo = BufToMarketsInfo(item);
  168. resultEntity.Entity.Add(itemMarketsInfo);
  169. }
  170. return resultEntity;
  171. }
  172. /// <summary>
  173. /// 市场item转换
  174. /// </summary>
  175. /// <param name="good"></param>
  176. /// <returns></returns>
  177. private MarketsInfoModel BufToMarketsInfo(MarketsInfo tasModel)
  178. {
  179. var localModel = new MarketsInfoModel()
  180. {
  181. MarketID = tasModel.MarketID,// 市场id uint32
  182. MarketName = tasModel.MarketName,// 市场名称 string
  183. TradeMode = (eTradeMode)tasModel.TradeMode,// 交易模式 uint32
  184. TradeProperty = (eTradeProperty)tasModel.TradeProperty,//交易属性
  185. };
  186. return localModel;
  187. }
  188. /// <summary>
  189. /// 枚举常量字典转换
  190. /// </summary>
  191. /// <param name="DirctionaryUTime">上次更新配置时间</param>
  192. /// <returns></returns>
  193. public override byte[] ToReqeustDictionaryQueryReq(ulong DirctionaryUTime)
  194. {
  195. var baseQueryReq = new DictionaryQueryReq()
  196. {
  197. Header = new MessageHead() { },
  198. DirctionaryUTime = DirctionaryUTime,
  199. };
  200. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  201. }
  202. /// <summary>
  203. /// 枚举常量字典转换-应答
  204. /// </summary>
  205. /// <param name="data">数据内容</param>
  206. /// <returns></returns>
  207. public override ResponeEntity<List<DictionaryInfoModel>> ResponeDictionaryQueryReq(object data)
  208. {
  209. var byteArr = data as byte[];
  210. if (data == null)
  211. {
  212. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  213. }
  214. var itemRespone = ProtoBufHelper.EntityDeSerialize<DictionaryQueryRsp>(byteArr);
  215. var resultEntity = new ResponeEntity<List<DictionaryInfoModel>>()
  216. {
  217. RetCode = itemRespone.RetCode,
  218. RetMessage = itemRespone.RetDesc,
  219. Entity = new List<DictionaryInfoModel>()
  220. {
  221. }
  222. };
  223. foreach (var item in itemRespone.DictionaryList)
  224. {
  225. var itemDictionaryList = BufToDictionaryList(item);
  226. resultEntity.Entity.Add(itemDictionaryList);
  227. }
  228. return resultEntity;
  229. }
  230. /// <summary>
  231. /// 枚举常量字典item转换
  232. /// </summary>
  233. /// <param name="good"></param>
  234. /// <returns></returns>
  235. private DictionaryInfoModel BufToDictionaryList(DictionaryInfo tasModel)
  236. {
  237. var localModel = new DictionaryInfoModel()
  238. {
  239. FieldCode = tasModel.FieldCode, // 枚举类型代码 string
  240. FieldName = tasModel.FieldName,// 枚举类型名称 string
  241. Key = tasModel.Key,// 枚举值 string
  242. Value = tasModel.Value,// 枚举名称 string
  243. };
  244. return localModel;
  245. }
  246. /// <summary>
  247. /// 错误码字典转换
  248. /// </summary>
  249. /// <param name="ErrorcodeUTime">上次更新配置时间</param>
  250. /// <returns></returns>
  251. public override byte[] ToReqeustErrorCodeQueryReq(ulong ErrorcodeUTime)
  252. {
  253. var baseQueryReq = new ErrorCodeQueryReq()
  254. {
  255. Header = new MessageHead() { },
  256. ErrorcodeUTime = ErrorcodeUTime,
  257. };
  258. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  259. }
  260. /// <summary>
  261. /// 错误码字典转换-应答
  262. /// </summary>
  263. /// <param name="data">数据内容</param>
  264. /// <returns></returns>
  265. public override ResponeEntity<List<ErrorCodeInfoModel>> ResponeErrorCodeQueryReq(object data)
  266. {
  267. var byteArr = data as byte[];
  268. if (data == null)
  269. {
  270. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  271. }
  272. var itemRespone = ProtoBufHelper.EntityDeSerialize<ErrorCodeQueryRsp>(byteArr);
  273. var resultEntity = new ResponeEntity<List<ErrorCodeInfoModel>>()
  274. {
  275. RetCode = itemRespone.RetCode,
  276. RetMessage = itemRespone.RetDesc,
  277. Entity = new List<ErrorCodeInfoModel>()
  278. {
  279. }
  280. };
  281. foreach (var item in itemRespone.ErrorCodeList)
  282. {
  283. var itemErrorCodeList = BufToErrorCodeList(item);
  284. resultEntity.Entity.Add(itemErrorCodeList);
  285. }
  286. return resultEntity;
  287. }
  288. /// <summary>
  289. /// 错误码字典转换item转换
  290. /// </summary>
  291. /// <param name="good"></param>
  292. /// <returns></returns>
  293. private ErrorCodeInfoModel BufToErrorCodeList(ErrorCodeInfo tasModel)
  294. {
  295. var localModel = new ErrorCodeInfoModel()
  296. {
  297. ErrorCode = tasModel.ErrorCode, // 错误码 string
  298. ErrorMsg = tasModel.ErrorMsg,// 提示信息 string
  299. };
  300. return localModel;
  301. }
  302. /// <summary>
  303. /// 市场运行计划转换
  304. /// </summary>
  305. /// <param name="TradeDate">交易日</param>
  306. /// <returns></returns>
  307. public override byte[] ToReqeustMarketRunQueryReq(string TradeDate)
  308. {
  309. var baseQueryReq = new MarketRunQueryReq()
  310. {
  311. Header = new MessageHead() { },
  312. TradeDate = TradeDate,
  313. };
  314. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  315. }
  316. /// <summary>
  317. /// 市场运行计划转换-应答
  318. /// </summary>
  319. /// <param name="data">数据内容</param>
  320. /// <returns></returns>
  321. public override ResponeEntity<MarketRunQueryRspModel> ResponeMarketRunQueryReq(object data)
  322. {
  323. var byteArr = data as byte[];
  324. if (data == null)
  325. {
  326. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  327. }
  328. var itemRespone = ProtoBufHelper.EntityDeSerialize<MarketRunQueryRsp>(byteArr);
  329. var resultEntity = new ResponeEntity<MarketRunQueryRspModel>()
  330. {
  331. RetCode = itemRespone.RetCode,
  332. RetMessage = itemRespone.RetDesc,
  333. Entity = new MarketRunQueryRspModel()
  334. {
  335. TradeDate = itemRespone.TradeDate, //交易日 string
  336. //MarketRunList 市场及其日计划列表 MarketRun
  337. }
  338. };
  339. foreach (var item in itemRespone.MarketRunList)
  340. {
  341. var itemMarketRun = BufToMarketRun(item);
  342. resultEntity.Entity.MarketRunList.Add(itemMarketRun);
  343. }
  344. return resultEntity;
  345. }
  346. /// <summary>
  347. /// 市场运行计划item转换
  348. /// </summary>
  349. /// <param name="good"></param>
  350. /// <returns></returns>
  351. private MarketRunModel BufToMarketRun(MarketRun tasModel)
  352. {
  353. var localModel = new MarketRunModel()
  354. {
  355. MarketId = tasModel.MarketId, // 市场id uint32
  356. //DayRunList 市场日运行计划表 DayRun
  357. };
  358. foreach (var item in tasModel.DayRunList)
  359. {
  360. var itemDayRun = BufToDayRun(item);
  361. localModel.DayRunList.Add(itemDayRun);
  362. }
  363. return localModel;
  364. }
  365. /// <summary>
  366. /// 市场日运行计划表item转换
  367. /// </summary>
  368. /// <param name="good"></param>
  369. /// <returns></returns>
  370. private DayRunModel BufToDayRun(DayRun tasModel)
  371. {
  372. var localModel = new DayRunModel()
  373. {
  374. TradeWeekDay = tasModel.TradeWeekDay,// 交易归属日 uint32
  375. RunStep = tasModel.RunStep,// 运行阶段 uint32
  376. StartWeekDay = tasModel.StartWeekDay,// 起始周几 uint32
  377. StartTime = tasModel.StartTime,// 起始时间 string
  378. EndWeekDay = tasModel.EndWeekDay,// 结束周几 uint32
  379. EndTime = tasModel.EndTime,// 结束时间 string
  380. };
  381. return localModel;
  382. }
  383. /// <summary>
  384. /// 终端系统参数查询转换
  385. /// </summary>
  386. /// <param name="accountCode">配置时间</param>
  387. /// <returns></returns>
  388. public override byte[] ToReqeustConfigQueryReq(ulong ConfigUTime)
  389. {
  390. var baseQueryReq = new ConfigQueryReq()
  391. {
  392. Header = new MessageHead() { },
  393. // ConfigUTime = ConfigUTime,
  394. };
  395. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  396. }
  397. /// <summary>
  398. /// 终端系统参数查询应答转换
  399. /// </summary>
  400. /// <param name="data">数据内容</param>
  401. /// <returns></returns>
  402. public override ResponeEntity<List<ConfigInfoModel>> ResponeConfigQueryReq(object data)
  403. {
  404. var byteArr = data as byte[];
  405. if (data == null)
  406. {
  407. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  408. }
  409. var itemResponeList = ProtoBufHelper.EntityDeSerialize<ConfigQueryRsp>(byteArr);
  410. var resultEntity = new ResponeEntity<List<ConfigInfoModel>>()
  411. {
  412. RetCode = itemResponeList.RetCode,
  413. RetMessage = itemResponeList.RetDesc,
  414. Entity = new List<ConfigInfoModel>() { }
  415. };
  416. foreach (var item in itemResponeList.ConfigInfoList)
  417. {
  418. var good = BufToConfigInfo(item);
  419. resultEntity.Entity.Add(good);
  420. }
  421. return resultEntity;
  422. }
  423. /// <summary>
  424. /// 终端系统参数item转换
  425. /// </summary>
  426. /// <param name="good"></param>
  427. /// <returns></returns>
  428. private ConfigInfoModel BufToConfigInfo(ConfigInfo tasModel)
  429. {
  430. var localModel = new ConfigInfoModel()
  431. {
  432. ParamCode = tasModel.ParamCode,//参数代码 string
  433. ParamName = tasModel.ParamName,// 参数名称 string
  434. ParamValue = tasModel.ParamValue,// 参数值 string
  435. ParamRemark = tasModel.ParamRemark,//说明 string
  436. };
  437. return localModel;
  438. }
  439. /// <summary>
  440. /// 商品查询请求转换-管理端查询
  441. /// </summary>
  442. /// <param name="accountCode">账号信息</param>
  443. /// <returns></returns>
  444. public override byte[] ToReqeustGoodsQueryReq(ulong GoodsUTime)
  445. {
  446. var baseGoodsQueryReq = new GoodsQueryReq()
  447. {
  448. Header = new MessageHead() { },
  449. GoodsUTime = GoodsUTime,
  450. };
  451. return ProtoBufHelper.EntitySerialize(baseGoodsQueryReq);
  452. }
  453. /// <summary>
  454. /// 商品查询回应转换-管理端返回
  455. /// </summary>
  456. /// <param name="data">数据内容</param>
  457. /// <returns></returns>
  458. public override ResponeEntity<List<QuoteGoods>> ResponeGoodsQueryReq(object data)
  459. {
  460. var byteArr = data as byte[];
  461. if (data == null)
  462. {
  463. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  464. }
  465. var itemResponeList = ProtoBufHelper.EntityDeSerialize<GoodsQueryRsp>(byteArr);
  466. var resultEntity = new ResponeEntity<List<QuoteGoods>>()
  467. {
  468. RetCode = itemResponeList.RetCode,
  469. RetMessage = itemResponeList.RetDesc,
  470. Entity = new List<QuoteGoods>() { }
  471. };
  472. foreach (var item in itemResponeList.GoodsList)
  473. {
  474. var good = BufToQuoteGoods(item);
  475. resultEntity.Entity.Add(good);
  476. }
  477. return resultEntity;
  478. }
  479. /// <summary>
  480. /// 商品转换
  481. /// </summary>
  482. /// <param name="good"></param>
  483. /// <returns></returns>
  484. private QuoteGoods BufToQuoteGoods(GoodsInfo good)
  485. {
  486. var category = QuoteCategoryType.PreciousMetal; //暂时随意定义
  487. var entityPara = new GoodsParameters()
  488. {
  489. AgreeUnit = Convert.ToDecimal(good.AgreeUnit),
  490. GoodsCode = good.GoodsCode,
  491. GoodsId = good.GoodsId,
  492. GoodsName = good.GoodsName,
  493. ExchAreaID = 250,
  494. MoneyMode = eMoneyMode.MONEYMODE_MARGIN,
  495. HqExchFigures = (int)good.DecimalPlace,
  496. // TradeMode = eTradeMode., // 交易模式
  497. ////todo:服务未返回,设置调试值
  498. ReckonRate = 1,
  499. };
  500. if (good.MarketID == 9)//全额转让市场,其他都是保证金市场
  501. {
  502. entityPara.MoneyMode = eMoneyMode.MONEYMODE_PAY;
  503. }
  504. var localGoods = new QuoteGoods("", good.GoodsCode, good.GoodsCode, category)
  505. {
  506. EndDate = good.EndDate, //EndDate 交割结束日期
  507. BeginDate = good.BeginDate,//BeginDate 交割起始日期
  508. PGoodsID1 = good.PGoodsID1,
  509. PGoodsID2 = good.PGoodsID2,
  510. MinDeliveryQty = good.MinDeliveryQty,//LimitSum 最小交割手数
  511. DeliveryGoodsName = good.DeliveryGoodsName, //DeliveryGoodsName 交割品种名称
  512. DeliveryGoodsCode = good.DeliveryGoodsCode,//DeliveryGoodsCode 交割品种代码
  513. DeliveryGoodsId = good.DeliveryGoodsId,//DeliveryGoodsId 交割品种代码
  514. GoodsUnit = good.GoodsUnit, //GoodsUnit 商品单位 uint32
  515. AgreeUnit = (uint)good.AgreeUnit, //AgreeUnit 合约单位 uint32
  516. Currency = good.Currency,//Currency 报价货币 uint32
  517. DecimalPlaces = (int)good.DecimalPlace,//DecimalPlace 价格小数位 uint32
  518. ListingDate = good.ListingDate, //ListingDate 上市时间 int32
  519. MarketID = good.MarketID, //MarketID 商品所属市场ID uint32
  520. Name = good.GoodsName,//GoodsName 商品名称 String
  521. GoodsCode = good.GoodsCode,//GoodsCode 商品代码 String
  522. GoodsId = good.GoodsId, //商品id uint32
  523. GoodsParameters = entityPara,
  524. DeliveryFlag = good.DeliveryFlag, //DeliveryFlag 是否交割 uint32 0:不交割1:要交割
  525. DeliveryGoodsUnit = good.DeliveryGoodsUnit, //DeliveryGoodsUnit 交割商品单位 string
  526. XDeliveryRatio = good.XDeliveryRatio,//XDeliveryRatio 主辅商品比的主手数 uint32 如3手主+2手辅=1份基准头寸
  527. PDeliveryRatio1 = good.PDeliveryRatio1, //PDeliveryRatio1 主辅商品比的辅手数 uint32
  528. PDeliveryRatio2 = good.PDeliveryRatio2,
  529. P1Type = good.P1Type,
  530. P2Type = good.P2Type,
  531. P1value = (uint)good.P1value,
  532. P2value = (uint)good.P2value,
  533. GoodsPMList = ToLocalPriceMove(good.GoodsPMList),
  534. ClosePriceMode = good.ClosePriceMode,
  535. ClosePriceParam = good.ClosePriceParam,
  536. Currencyid = good.Currencyid,
  537. DelistingMode = good.DelistingMode,
  538. GoodsStatus = good.GoodsStatus,
  539. GoodsType = good.GoodsType,
  540. GroupID = good.GroupID,
  541. InnerDealMode = good.InnerDealMode,
  542. IsBuyLimited = good.IsBuyLimited,
  543. Lotsize = good.Lotsize,
  544. QtyDecimalPlace = good.QtyDecimalPlace,
  545. QuoteMinUnit = good.QuoteMinUnit
  546. };
  547. return localGoods;
  548. }
  549. private List<PriceMoveModel> ToLocalPriceMove(List<PriceMove> priceMoveLst)
  550. {
  551. List<PriceMoveModel> retLst = new List<PriceMoveModel>();
  552. if (priceMoveLst != null)
  553. {
  554. foreach (var item in priceMoveLst)
  555. {
  556. PriceMoveModel pricemove = new PriceMoveModel()
  557. {
  558. PriceMoveID = item.PriceMoveID,
  559. PriceMoveType = item.PriceMoveType,
  560. PriceMoveDesc = item.PriceMoveDesc
  561. };
  562. retLst.Add(pricemove);
  563. }
  564. }
  565. return retLst;
  566. }
  567. /// <summary>
  568. /// 获取最后更新时间转换
  569. /// </summary>
  570. /// <returns></returns>
  571. public override byte[] ToReqeustLastUpdateTimeReq()
  572. {
  573. var baseReq = new LastUpdateTimeReq()
  574. {
  575. Header = new MessageHead() { },
  576. };
  577. return ProtoBufHelper.EntitySerialize(baseReq);
  578. }
  579. /// <summary>
  580. /// 获取最后更新时间回应转换
  581. /// </summary>
  582. /// <param name="data">数据内容</param>
  583. /// <returns></returns>
  584. public override ResponeEntity<LastUpdateTimeModel> ResponeLastUpdateTimeReq(object data)
  585. {
  586. var byteArr = data as byte[];
  587. if (data == null)
  588. {
  589. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  590. }
  591. var itemRespone = ProtoBufHelper.EntityDeSerialize<LastUpdateTimeRsp>(byteArr);
  592. var result = new ResponeEntity<LastUpdateTimeModel>()
  593. {
  594. RetCode = itemRespone.RetCode,
  595. RetMessage = itemRespone.RetDesc,
  596. Entity = new LastUpdateTimeModel()
  597. {
  598. TradeDate = itemRespone.TradeDate,
  599. RiskMsgUTime = itemRespone.RiskMsgUTime,
  600. ConfigUTime = itemRespone.ConfigUTime,
  601. GoodsUTime = itemRespone.GoodsUTime,
  602. MarketsUTime = itemRespone.MarketsUTime,
  603. ErrorcodeUTime = itemRespone.ErrorcodeUTime,
  604. DirctionaryUTime = itemRespone.DirctionaryUTime,
  605. }
  606. };
  607. return result;
  608. }
  609. /// <summary>
  610. /// 登录查询请求转换
  611. /// </summary>
  612. /// <param name="accountCode">账号信息</param>
  613. /// <returns></returns>
  614. public override byte[] ToReqeustLoginQueryReq(ulong LoginID, string QueryItem)
  615. {
  616. QueryItem = QueryItem == "0" ? "" : QueryItem;
  617. var baseReq = new LoginQueryReq()
  618. {
  619. Header = new MessageHead() { },
  620. LoginID = LoginID,
  621. QueryItem = QueryItem
  622. };
  623. baseReq.Header.UserID = ProtoBufHelper.Head.UserID;
  624. return ProtoBufHelper.EntitySerialize(baseReq, false);
  625. }
  626. /// <summary>
  627. /// 登录查询回应转换
  628. /// </summary>
  629. /// <param name="data">数据内容</param>
  630. /// <returns></returns>
  631. public override ResponeEntity<AccountBaseInfoModel> ResponeLoginQueryReq(object data)
  632. {
  633. var byteArr = data as byte[];
  634. if (byteArr == null)
  635. {
  636. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  637. }
  638. var itemRespone = ProtoBufHelper.EntityDeSerialize<LoginQueryRsp>(byteArr);
  639. var resultEntity = new ResponeEntity<AccountBaseInfoModel>()
  640. {
  641. RetCode = itemRespone.RetCode,
  642. RetMessage = itemRespone.RetDesc,
  643. Entity = new AccountBaseInfoModel()
  644. {
  645. ServerLastNoticeId = itemRespone.ServerLastNoticeId
  646. },
  647. };
  648. var accountInfo = resultEntity.Entity;
  649. accountInfo.TAAccountList = ToLocalTAAccountList(itemRespone.TAAccountList); // 账户列表
  650. accountInfo.TradeAccount = ToLocalTradeAccount(itemRespone.AccountInfo); ////账号信息
  651. accountInfo.GoodsRuleAndFeeList = ToLocalGoodsRuleAndFeeList(itemRespone.GoodsRuleAndFeeList); ////商品交易规则和费用规则列表
  652. accountInfo.LastUpdateTimeList = ToLocalLastUpdateTimeList(itemRespone.ParamValues); ////最后更新时间列表
  653. return resultEntity;
  654. }
  655. /// <summary>
  656. /// 菜单转换
  657. /// </summary>
  658. /// <param name="MenuUTime"></param>
  659. /// <returns></returns>
  660. public override byte[] ToReqeustFuncMenuQueryReq(ulong MenuUTime)
  661. {
  662. var baseQueryReq = new FuncMenuReq()
  663. {
  664. Header = new MessageHead() { },
  665. MenuUTime = MenuUTime,
  666. };
  667. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  668. }
  669. /// <summary>
  670. /// 菜单权限列表转换
  671. /// </summary>
  672. /// <param name="accountInfos"></param>
  673. /// <returns></returns>
  674. private List<SysMenuItem> ToLocalSysMenuItems(List<tas.FuncMenu> FuncMenu)
  675. {
  676. var SysMenuList = new List<SysMenuItem>();
  677. if (FuncMenu == null || FuncMenu.Count <= 0)
  678. {
  679. return SysMenuList;
  680. }
  681. foreach (var item in FuncMenu)
  682. {
  683. var menu = BuildFuncMenu(item);
  684. SysMenuList.Add(menu);
  685. }
  686. return SysMenuList;
  687. }
  688. /// <summary>
  689. /// 账户列表转换
  690. /// </summary>
  691. /// <param name="accountInfos"></param>
  692. /// <returns></returns>
  693. private List<TAAccountAllModel> ToLocalTAAccountList(List<tas.TAAccountAll> tAAccountAll)
  694. {
  695. var itemResultList = new List<TAAccountAllModel>();
  696. if (tAAccountAll == null)
  697. {
  698. return itemResultList;
  699. }
  700. foreach (var item in tAAccountAll)
  701. {
  702. var type = ConverTAAccountAllModel(item);
  703. itemResultList.Add(type);
  704. }
  705. return itemResultList;
  706. }
  707. private TAAccountAllModel ConverTAAccountAllModel(tas.TAAccountAll tasModel)
  708. {
  709. var model = new TAAccountAllModel();
  710. var goodsPositionList = new List<TradePositionModel>();
  711. var marketsIdList = new List<uint>();
  712. #region 资金信息/资金账户信息
  713. var fundsAccounts = new FundsAccount()
  714. {
  715. AccountId = tasModel.TaAccountInfo.AccountId,// 账户id
  716. TradeStatus = tasModel.TaAccountInfo.TradeStatus,
  717. Currency = tasModel.TaAccountInfo.Currency,
  718. IsMain = tasModel.TaAccountInfo.IsMain,
  719. ParentAccountID = tasModel.TaAccountInfo.ParentAccountID,
  720. TAAccountType = tasModel.TaAccountInfo.TAAccountType,
  721. RelatedMainAccountID = tasModel.TaAccountInfo.RelatedMainAccountID,
  722. Balance = (decimal)tasModel.TaAccountInfo.Balance,// 期初余额
  723. CurrentBalance = (decimal)tasModel.TaAccountInfo.CurrentBalance,// 期末余额
  724. UsedMargin = (decimal)tasModel.TaAccountInfo.UsedMargin,// 占用保证金
  725. FreezeMargin = (decimal)tasModel.TaAccountInfo.FreezeMargin,// 冻结保证金
  726. OtherFreezeMargin = (decimal)tasModel.TaAccountInfo.OtherFreezeMargin,
  727. FreezeCharge = (decimal)tasModel.TaAccountInfo.FreezeCharge,
  728. MortgageCredit = (decimal)tasModel.TaAccountInfo.MortgageCredit,
  729. OtherCredit = (decimal)tasModel.TaAccountInfo.OtherCredit,
  730. OutAmountFreeze = (decimal)tasModel.TaAccountInfo.OutAmountFreeze,
  731. OutAmount = (decimal)tasModel.TaAccountInfo.OutAmount,// 今日出金
  732. InAmount = (decimal)tasModel.TaAccountInfo.InAmount,// 今日入金
  733. PayCharge = (decimal)tasModel.TaAccountInfo.PayCharge,
  734. CreditIncrease = (decimal)tasModel.TaAccountInfo.CreditIncrease,
  735. CreditDecrease = (decimal)tasModel.TaAccountInfo.CreditDecrease,
  736. OtherCreditIncrease = (decimal)tasModel.TaAccountInfo.OtherCreditIncrease,
  737. OtherCreditDecrease = (decimal)tasModel.TaAccountInfo.OtherCreditDecrease,
  738. TransferAmount = (decimal)tasModel.TaAccountInfo.TransferAmount,
  739. OtherPay = (decimal)tasModel.TaAccountInfo.OtherPay,
  740. OtherIncome = (decimal)tasModel.TaAccountInfo.OtherIncome,
  741. ClosePL = (decimal)tasModel.TaAccountInfo.ClosePL,// 今日平仓盈亏
  742. OutThreshold = (decimal)tasModel.TaAccountInfo.OutThreshold, // 出金阀值
  743. CurrencyID = tasModel.TaAccountInfo.Currencyid, //todo:服务端需返回此字段
  744. };
  745. model.FundsAccounts = fundsAccounts;
  746. #endregion
  747. #region 持仓头寸列表
  748. foreach (var item in tasModel.TradePositionList)
  749. {
  750. var goodsPM = new TradePositionModel()
  751. {
  752. GoodsId = item.GoodsId, // 商品id
  753. BuyFrozenQty = item.BuyFrozenQty, // 买持仓冻结
  754. BuyOtherFrozenQty = item.BuyOtherFrozenQty, // 买持仓其他冻结
  755. SellFrozenQty = item.SellFrozenQty, // 卖持仓冻结
  756. SellOtherFrozenQty = item.SellOtherFrozenQty, // 卖持仓其他冻结
  757. BuyCurPositionQty = item.BuyCurPositionQty, //买当前持仓数量 uint32
  758. BuyCurHolderAmount = item.BuyCurHolderAmount, //买当前持仓金额 double
  759. SellCurPositionQty = item.SellCurPositionQty, //卖当前持仓数量 uint32
  760. SellCurHolderAmount = item.SellCurHolderAmount, //卖当前持仓金额 double
  761. };
  762. goodsPositionList.Add(goodsPM);
  763. }
  764. model.GoodsPositionList = goodsPositionList;
  765. #endregion
  766. #region 市场权限列表
  767. foreach (var item in tasModel.MarketsIdList)
  768. {
  769. marketsIdList.Add(item);
  770. }
  771. model.MarketsIdList = marketsIdList;
  772. #endregion
  773. return model;
  774. }
  775. /// <summary>
  776. /// 商品交易规则和费用规则列表转换
  777. /// </summary>
  778. /// <param name="accountInfos"></param>
  779. /// <returns></returns>
  780. private List<Data.Model.GoodRules.TradeGoodsFeeRule> ToLocalGoodsRuleAndFeeList(List<tas.GoodsRuleAndFee> goodsRuleAndFee)
  781. {
  782. var ruleAndFeeList = new List<Data.Model.GoodRules.TradeGoodsFeeRule>();
  783. if (goodsRuleAndFee == null || goodsRuleAndFee.Count <= 0)
  784. {
  785. return ruleAndFeeList;
  786. }
  787. foreach (var item in goodsRuleAndFee)
  788. {
  789. var feeRule = ConverFeeRuleType(item);
  790. ruleAndFeeList.Add(feeRule);
  791. }
  792. return ruleAndFeeList;
  793. }
  794. /// <summary>
  795. /// 最后更新时间列表
  796. /// </summary>
  797. /// <param name="accountInfos"></param>
  798. /// <returns></returns>
  799. private List<LastUpdateTimeKeyValueModel> ToLocalLastUpdateTimeList(List<tas.ParamValue> lastUpdateTimeKeyValue)
  800. {
  801. var lastUpdateTimeList = new List<LastUpdateTimeKeyValueModel>();
  802. if (lastUpdateTimeKeyValue == null || lastUpdateTimeKeyValue.Count <= 0)
  803. {
  804. return lastUpdateTimeList;
  805. }
  806. foreach (var item in lastUpdateTimeKeyValue)
  807. {
  808. if (string.IsNullOrEmpty(item.Key))
  809. {
  810. continue;
  811. }
  812. var itemKeyValue = ConverLastUpdateTime(item);
  813. lastUpdateTimeList.Add(itemKeyValue);
  814. }
  815. return lastUpdateTimeList;
  816. }
  817. /// <summary>
  818. /// 最后更新时间列表ITEM 转换
  819. /// </summary>
  820. /// <param name="goodsInce"></param>
  821. /// <returns></returns>
  822. private LastUpdateTimeKeyValueModel ConverLastUpdateTime(tas.ParamValue tasModel)
  823. {
  824. var model = new LastUpdateTimeKeyValueModel()
  825. {
  826. TimeKey = (LastUpdateTimeType)Convert.ToInt16(tasModel.Key),
  827. TimeValue = tasModel.Value
  828. };
  829. return model;
  830. }
  831. //============================MTP2.0 above==================================================
  832. public override ResponeEntity<TradeAccount> ToLocalAccountEntity(object obj)
  833. {
  834. return new ResponeEntity<TradeAccount>();
  835. //var protoObject = obj as ProtobufAccount;
  836. //if (null == protoObject) return null;
  837. //return new TradeAccount()
  838. //{
  839. // //初始化值
  840. //};
  841. }
  842. public override ResponeEntity<TradeAccount> ToLocalLoginEntity(object obj)
  843. {
  844. var byteArr = obj as byte[];
  845. if (byteArr == null)
  846. {
  847. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  848. }
  849. var loginRsq = ProtoBufHelper.EntityDeSerialize<LoginRsp>(byteArr);
  850. var result = new ResponeEntity<TradeAccount>()
  851. {
  852. RetCode = loginRsq.RetCode,
  853. RetMessage = loginRsq.RetDesc,
  854. Entity = new TradeAccount()
  855. {
  856. AccountStatus = (eAccountStatus)loginRsq.AccountStatus,
  857. AccountType = (eUserType)loginRsq.LoginUserType,
  858. LoginID = loginRsq.LoginID,
  859. MemberAreaId = (uint)loginRsq.MemberUserID,
  860. SystemTime = loginRsq.SystemTime,
  861. Token = loginRsq.Token,
  862. FundsAccountIds = loginRsq.AccountIDs,
  863. CustomerId = loginRsq.UserID,
  864. HasUpdatedPwd = loginRsq.HasUpdatedPwd,
  865. PwdWrongCnt = loginRsq.PwdWrongCnt,
  866. PwdWrongLockCnt = loginRsq.PwdWrongLockCnt,
  867. LoginLockHourNum = loginRsq.LoginLockHourNum,
  868. ClientSystemInfo = loginRsq.ClientSystemInfo,
  869. ClientId = loginRsq.ClientID
  870. }
  871. };
  872. if (loginRsq.Header != null && loginRsq.RetCode == 0)
  873. {
  874. loginRsq.Header.UserID = loginRsq.UserID;
  875. result.Entity.FundsAccountId = loginRsq.Header.AccountID;
  876. ProtoBufHelper.Head = loginRsq.Header; ////保存头内容
  877. }
  878. return result;
  879. }
  880. /// <summary>
  881. /// To the reqeust login.
  882. /// </summary>
  883. /// <param name="loginType">Type of the login.</param>
  884. /// <param name="passWord">The pass word.</param>
  885. /// <param name="loginID">The login code.</param>
  886. /// <param name="guid">The unique identifier.</param>
  887. /// <param name="loginIP">login IP Address.</param>
  888. /// <param name="systemDesc">The system desc.</param>
  889. /// <returns>System.Byte[][].</returns>
  890. public override byte[] ToReqeustLogin(int loginType, string passWord, ulong loginID, string guid, string loginIP, string systemDesc, string version, byte[] clientSystemInfo, string clientAppID)
  891. {
  892. var loginReq = new LoginReq()
  893. {
  894. LoginPWD = passWord,
  895. ClientType = (int)eClientType.CLIENTTYPE_PC_TRADE_CLIENT,
  896. LoginType = (uint)loginType,
  897. LoginID = loginID,
  898. LoginIp = loginIP,
  899. GUID = guid,
  900. DeviceID = string.Empty,
  901. Version = version,
  902. EnvironmentInfo = systemDesc,
  903. ClientSystemInfo = clientSystemInfo,
  904. ClientAppID = clientAppID,
  905. };
  906. var uuid = Guid.NewGuid();
  907. loginReq.Header = new MessageHead() { UUID = uuid.ToString() };
  908. return ProtoBufHelper.EntitySerialize(loginReq, false);
  909. }
  910. /// <summary>
  911. /// 交易端登出
  912. /// </summary>
  913. /// <returns></returns>
  914. public override byte[] ToReqeustLogOut(ulong loginID)
  915. {
  916. var logOutReq = new LogoutReq() { LoginID = loginID };
  917. return ProtoBufHelper.EntitySerialize(logOutReq);
  918. }
  919. /// <summary>
  920. /// 商品组信息转换=>市场信息转换
  921. /// </summary>
  922. /// <param name="goodsGroupInfos">商品组信息=>市场信息</param>
  923. /// <param name="exchanges">The exchanges.</param>
  924. /// <returns>System.Collections.Generic.List{Muchinfo.TASClient.Data.Model.Market}.</returns>
  925. private List<Muchinfo.MTPClient.Data.Model.GoodsGroup> ToLocalGoodsGroupsInfo(List<MarketsInfo> goodsGroupInfos)
  926. {
  927. var goodsGroups = new List<Muchinfo.MTPClient.Data.Model.GoodsGroup>();
  928. if (goodsGroupInfos == null || goodsGroupInfos.Count <= 0)
  929. {
  930. return goodsGroups;
  931. }
  932. foreach (var item in goodsGroupInfos)
  933. {
  934. var goodsGroup = new Muchinfo.MTPClient.Data.Model.GoodsGroup()
  935. {
  936. MarketTypeID = (int)item.MarketID,
  937. GoodsGroupName = item.MarketName,
  938. TradeMode = (eTradeMode)item.TradeMode,
  939. //GoodsGroupCode = item.GoodsGroupCode,
  940. //GoodsGroupName = item.GoodsGroupName,
  941. //GoodsGroupLevelTypeID = item.GoodsGroupLevelTypeID,
  942. //GoodsGroupid = item.GoodsGroupid,
  943. //MarketTypeID = item.MarketTypeID,
  944. //ReckonMode = (ReckonModeType)item.ReckonMode,
  945. //TradeMode = (eTradeMode)item.TradeMode,
  946. //ExchAreaId = item.ExchAreaId,
  947. //ParentGoodsGroupId = item.ParentGoodsGroupId,
  948. };
  949. goodsGroups.Add(goodsGroup);
  950. }
  951. return goodsGroups;
  952. }
  953. /// <summary>
  954. /// 资金账户转换
  955. /// </summary>
  956. /// <param name="taAccountInfos"></param>
  957. /// <returns></returns>
  958. private FundsAccount ToLocalFundsAccounts(TaAccountInfo taAccountInfos)
  959. {
  960. return new FundsAccount();
  961. }
  962. /// <summary>
  963. /// 交易账号信息转换
  964. /// </summary>
  965. /// <param name="accountInfos"></param>
  966. /// <returns></returns>
  967. private TradeAccount ToLocalTradeAccount(AccountInfo accountInfos)
  968. {
  969. if (null == accountInfos)
  970. {
  971. //todo:异常信息提示
  972. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "查询账号信息异常!");
  973. }
  974. return new TradeAccount()
  975. {
  976. CustomerId = accountInfos.UserID,
  977. MemberAreaId = accountInfos.ParentUserID,
  978. CustomerName = accountInfos.AccountName
  979. };
  980. }
  981. /// <summary>
  982. /// 商品信息参数配置
  983. /// </summary>
  984. /// <param name="goodsInfos">The goods infos.</param>
  985. /// <param name="goodsGroups">The goods groups.</param>
  986. /// <returns>List{LocalEntity.Exchange}.</returns>
  987. public List<QuoteGoods> ToLocalGoodsList(List<GoodsInfo> goodsInfos, List<Muchinfo.MTPClient.Data.Model.GoodsGroup> goodsGroups)
  988. {
  989. var goodsList = new List<QuoteGoods>();
  990. if (null == goodsInfos || goodsInfos.Count <= 0)
  991. {
  992. return goodsList;
  993. }
  994. foreach (var serviceEntity in goodsInfos)
  995. {
  996. if (serviceEntity == null)
  997. {
  998. continue;
  999. }
  1000. var goodsGroup = goodsGroups.FirstOrDefault(z => z.GoodsGroupid == serviceEntity.MarketID);
  1001. if (goodsGroup == null) continue;
  1002. var entity = new GoodsParameters()
  1003. {
  1004. AgreeUnit = Convert.ToDecimal(serviceEntity.AgreeUnit),
  1005. GoodsCode = serviceEntity.GoodsCode,
  1006. GoodsId = serviceEntity.GoodsId,
  1007. GoodsName = serviceEntity.GoodsName,
  1008. ExchAreaID = goodsGroup.ExchAreaId,
  1009. TradeMode = goodsGroup.TradeMode, // 交易模式
  1010. ////todo:服务未返回,设置调试值
  1011. ReckonRate = 1,
  1012. };
  1013. //DateTime listedtime;
  1014. //if (DateTime.TryParse(serviceEntity.ListedTime, out listedtime))
  1015. //{
  1016. // entity.ListedTime = listedtime;
  1017. //}
  1018. var quoteGoods = ToQuoteGoods(entity);
  1019. goodsList.Add(quoteGoods);
  1020. }
  1021. return goodsList;
  1022. }
  1023. private QuoteGoods ToQuoteGoods(GoodsParameters parameter)
  1024. {
  1025. if (parameter == null) return null;
  1026. //todo:商品类别
  1027. //var sort = dataModel.Sort.ToString();
  1028. var category = QuoteCategoryType.PreciousMetal; //GoodsSortHelper.GetQuoteCategoryBySorts(sort);
  1029. return new QuoteGoods(parameter.ExchHqCode, parameter.GoodsCode, parameter.GoodsHqCode, category)
  1030. {
  1031. ListingStatus = parameter.GoodsStatus.ToString(), // ListStatus.ToString(),
  1032. //LotUnit = dataModel.LotSize,
  1033. Name = parameter.GoodsName,
  1034. GoodsId = (uint)parameter.GoodsId,
  1035. // QuoteCurrency = parameter.QuoteCurrency, //PriceCurrency,
  1036. // QuoteUnit = parameter.PriceUnit.ToString(),
  1037. // Sort = QuoteCategoryType.PreciousMetal.ToString(), //sort,
  1038. GoodsParameters = parameter,
  1039. TradeMode = parameter.TradeMode,
  1040. DecimalPlaces = parameter.HqExchFigures,
  1041. //RelevanceCode = dataModel.RelevanceCode,
  1042. //SectorCode = dataModel.Sector2,推荐
  1043. };
  1044. }
  1045. /// <summary>
  1046. ///
  1047. /// </summary>
  1048. /// <param name="obj"></param>ToLocalLoginEntity
  1049. /// <returns></returns>
  1050. public override ResponeEntity<Data.Model.AccountInfoEntity> TolocalAccountInfoEntity(object obj)
  1051. {
  1052. return null;
  1053. //var byteArr = obj as byte[];
  1054. //if (byteArr == null)
  1055. //{
  1056. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1057. //}
  1058. //var accountRespone = ProtoBufHelper.EntityDeSerialize<QueryAccountAndGoodsRsp>(byteArr);
  1059. //var resultEntity = new ResponeEntity<AccountInfoEntity>()
  1060. //{
  1061. // RetCode = accountRespone.RetCode,
  1062. // RetMessage = accountRespone.RetDesc,
  1063. // Entity = new AccountInfoEntity(),
  1064. //};
  1065. //if (accountRespone.Rsps == null || !accountRespone.Rsps.Any())
  1066. //{
  1067. // //todo:查询内容空
  1068. // return resultEntity;
  1069. //}
  1070. //var account = resultEntity.Entity;
  1071. //account.GoodsGroups = ToLocalGoodsGroupsInfo(accountRespone.Rsps[0].GoodsGroupInfoRsps); //市场
  1072. //account.QuoteGoodses = ToLocalGoodsList(accountRespone.Rsps[0].GoodsInfoRsps, account.GoodsGroups); ////商品信息
  1073. // account.FundsAccounts = ToLocalFundsAccounts(accountRespone.Rsps[0].TaAccountInfoRsps); //资金账号 单独查询资金信息
  1074. //account.TradeAccount = ToLocalTradeAccount(accountRespone.Rsps[0].AccountInfoRsps); ////交易账号
  1075. //if (account.FundsAccounts != null && account.FundsAccounts.Any() && account.TradeAccount!=null) ////设置会员证件
  1076. //{
  1077. // account.TradeAccount.MemberCardType = account.FundsAccounts[0].CardType;
  1078. // account.TradeAccount.MemberCardNum = account.FundsAccounts[0].CardNum;
  1079. //}
  1080. //return resultEntity;
  1081. }
  1082. /// <summary>
  1083. /// 账号基本信息查询与交易所市场商品信息
  1084. /// </summary>
  1085. /// <param name="accountId">The account identifier.</param>
  1086. /// <returns>System.Byte[][].</returns>
  1087. public override byte[] ToReqeustAccountInfo(ulong accountId)
  1088. {
  1089. return null;
  1090. //var accountGoodsReq = new QueryAccountAndGoodsReq()
  1091. //{
  1092. // Header = new MessageHead() { },
  1093. // AccountId = accountId,
  1094. //};
  1095. //return ProtoBufHelper.EntitySerialize(accountGoodsReq);
  1096. }
  1097. /// <summary>
  1098. /// 请求校验Token的Protobuf对象装箱方法
  1099. /// </summary>
  1100. /// <param name="token"></param>
  1101. /// <returns></returns>
  1102. public override byte[] ToTokenCheck(ulong loginID, string token, ulong octTime)
  1103. {
  1104. var tokenCheckReq = new TokenCheckReq()
  1105. {
  1106. LoginID = loginID,
  1107. Token = token,
  1108. SystemTime = octTime
  1109. };
  1110. return ProtoBufHelper.EntitySerialize(tokenCheckReq);
  1111. }
  1112. /// <summary>
  1113. /// 从检验Token返回信息中获取Token状态的方法
  1114. /// </summary>
  1115. /// <param name="obj">检验Token返回信息</param>
  1116. /// <returns>Token状态值</returns>
  1117. public override ResponeEntity<ulong> GetTokenStatus(object obj)
  1118. {
  1119. var byteArr = obj as byte[];
  1120. if (byteArr == null)
  1121. {
  1122. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1123. }
  1124. var tokenCheckRsp = ProtoBufHelper.EntityDeSerialize<TokenCheckRsp>(byteArr);
  1125. var resultEntity = new ResponeEntity<ulong>
  1126. {
  1127. RetCode = tokenCheckRsp.RetCode,
  1128. RetMessage = tokenCheckRsp.RetDesc,
  1129. Entity = tokenCheckRsp.SystemTime //服务器时间
  1130. };
  1131. return resultEntity;
  1132. }
  1133. /// <summary>
  1134. /// 转换修改密码
  1135. /// </summary>
  1136. /// <param name="accountPwds"></param>
  1137. /// <returns></returns>
  1138. public override byte[] ToReqeustModifyPwds(AccountPwds accountPwds)
  1139. {
  1140. var modifyPwdReq = new ModifyPwdReq()
  1141. {
  1142. ModifyPwdType = accountPwds.ModifyPwdType,
  1143. ModifyPwdID = accountPwds.ModifyPwdID,
  1144. NewPwd = accountPwds.NewPwd,
  1145. OldPwd = accountPwds.OldPwd
  1146. };
  1147. return ProtoBufHelper.EntitySerialize(modifyPwdReq);
  1148. }
  1149. /// <summary>
  1150. /// 解释修改密码返回对象
  1151. /// </summary>
  1152. /// <param name="obj"></param>
  1153. /// <returns></returns>
  1154. public override ResponeEntity<int> ResponeModifyPWDEntity(object obj)
  1155. {
  1156. var byteArr = obj as byte[];
  1157. if (byteArr == null)
  1158. {
  1159. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1160. }
  1161. var modifyPwd = ProtoBufHelper.EntityDeSerialize<ModifyPwdRsp>(byteArr);
  1162. var responeEntity = new ResponeEntity<int>()
  1163. {
  1164. RetCode = modifyPwd.RetCode,
  1165. RetMessage = modifyPwd.RetDesc,
  1166. };
  1167. return responeEntity;
  1168. }
  1169. public override byte[] ToReqeustFuncMenu(string loginCode)
  1170. {
  1171. return null;
  1172. //var modifyPwdReq = new QueryAccountFuncMenuReq()
  1173. //{
  1174. // LoginCode = loginCode,
  1175. // RoleType = 0, ////客户端类型
  1176. //};
  1177. //return ProtoBufHelper.EntitySerialize(modifyPwdReq);
  1178. }
  1179. public override ResponeEntity<List<SysMenuItem>> ResponeLocalFuncMenu(object data)
  1180. {
  1181. var byteArr = data as byte[];
  1182. if (data == null)
  1183. {
  1184. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1185. }
  1186. var menusRespone = ProtoBufHelper.EntityDeSerialize<FuncMenuRsp>(byteArr);
  1187. var resultEntity = new ResponeEntity<List<SysMenuItem>>()
  1188. {
  1189. RetCode = menusRespone.RetCode,
  1190. RetMessage = menusRespone.RetDesc,
  1191. Entity = new List<SysMenuItem>(),
  1192. };
  1193. if (menusRespone.FuncMenuList == null || !menusRespone.FuncMenuList.Any())
  1194. {
  1195. //todo:查询内容空
  1196. return resultEntity;
  1197. }
  1198. foreach (var queryAccount in menusRespone.FuncMenuList)
  1199. {
  1200. var menu = BuildFuncMenu(queryAccount);
  1201. resultEntity.Entity.Add(menu);
  1202. }
  1203. if (resultEntity.Entity != null) ////对子菜单进行排序
  1204. {
  1205. resultEntity.Entity = resultEntity.Entity.OrderBy((item) => item.SortId).ToList();
  1206. }
  1207. return resultEntity;
  1208. }
  1209. /// <summary>
  1210. /// 生成树菜单
  1211. /// </summary>
  1212. /// <returns></returns>
  1213. private SysMenuItem BuildFuncMenu(tas.FuncMenu menus)
  1214. {
  1215. var localMenu = new SysMenuItem(menus.FuncMenuName)
  1216. {
  1217. FuncMenuCode = menus.FuncMenuCode,
  1218. ParentFuncMenuCode = menus.Parentfuncmenucode,
  1219. Children = new List<SysMenuItem>(),
  1220. };
  1221. foreach (var funcMenuList in menus.SonMenus)
  1222. {
  1223. var childMenu = BuildFuncMenu(funcMenuList);
  1224. if (childMenu.Children != null) ////对子菜单进行排序
  1225. {
  1226. childMenu.Children = childMenu.Children.OrderBy((item) => item.SortId).ToList();
  1227. }
  1228. localMenu.Children.Add(childMenu);
  1229. }
  1230. if (localMenu.Children != null) ////对子菜单进行排序
  1231. {
  1232. localMenu.Children = localMenu.Children.OrderBy((item) => item.SortId).ToList();
  1233. }
  1234. return localMenu;
  1235. }
  1236. /// <summary>
  1237. /// 转换请求
  1238. /// </summary>
  1239. /// <param name="accountid"></param>
  1240. /// <returns></returns>
  1241. public override byte[] ToReqeustTradeFeeRules(uint accountid)
  1242. {
  1243. //var tradeRulesReq = new QueryAccountAndGoodsReq()
  1244. //{
  1245. // AccountId = accountid,
  1246. //};
  1247. //return ProtoBufHelper.EntitySerialize(tradeRulesReq);
  1248. return null;
  1249. }
  1250. public override ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>> ResoneLocalGoodsFeeRules(object data)
  1251. {
  1252. return null;
  1253. //var byteArr = data as byte[];
  1254. //if (data == null)
  1255. //{
  1256. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1257. //}
  1258. //var goodsResult=ProtoBufHelper.EntityDeSerialize<QueryAccountGoodsTypeRsp>(byteArr);
  1259. //var resultEntity = new ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>>()
  1260. //{
  1261. // RetCode = goodsResult.RetCode,
  1262. // RetMessage = goodsResult.RetDesc,
  1263. // Entity = new List<Data.Model.GoodRules.TradeGoodsFeeRule>(),
  1264. //};
  1265. //if (goodsResult.Rsps == null || !goodsResult.Rsps.Any())
  1266. //{
  1267. // //todo:查询内容空
  1268. // return resultEntity;
  1269. //}
  1270. //foreach (var rspItem in goodsResult.Rsps)
  1271. //{
  1272. // var goodsFeeRules = new Dictionary<int, TradeGoodsFeeRule>();
  1273. // foreach (var goodsRules in rspItem.GoodsRuleAndFee)
  1274. // {
  1275. // var feeRule = ConverFeeRuleType(goodsRules);
  1276. // resultEntity.Entity.Add(feeRule);
  1277. // //goodsFeeRules[feeRule.GoodsID].GoodsFees[feeRule.] = goodsFeeType;
  1278. // }
  1279. //}
  1280. //return resultEntity;
  1281. }
  1282. /// <summary>
  1283. ///
  1284. /// </summary>
  1285. /// <param name="goodsInce"></param>
  1286. /// <returns></returns>
  1287. private Data.Model.GoodRules.TradeGoodsFeeRule ConverFeeRuleType(tas.GoodsRuleAndFee goodsInce)
  1288. {
  1289. var feeRule = new Data.Model.GoodRules.TradeGoodsFeeRule();
  1290. feeRule.GoodsID = goodsInce.GoodsID;
  1291. ////商品交易规则
  1292. foreach (var goodsFeeType in goodsInce.GoodsRuleList)
  1293. {
  1294. var rule = new Data.Model.GoodRules.GoodsRuleModel()
  1295. {
  1296. Ruleid = goodsFeeType.Ruleid,
  1297. RuleName = goodsFeeType.RuleName,
  1298. ParamValue = goodsFeeType.ParamValue
  1299. };
  1300. feeRule.GoodsRuleList.Add(rule);
  1301. }
  1302. return feeRule;
  1303. }
  1304. public override byte[] ToReqeustRiskChecked(ulong accountid, uint isChecked)
  1305. {
  1306. return null;
  1307. //var riskReq = new RiskCheckNotifyReq()
  1308. //{
  1309. // AccountId = (uint)accountid,
  1310. // IsChecked = isChecked,
  1311. //};
  1312. //return ProtoBufHelper.EntitySerialize(riskReq);
  1313. }
  1314. public override ResponeEntity<uint> ResponeRiskChecked(object data)
  1315. {
  1316. return null;
  1317. //var byteArr = data as byte[];
  1318. //if (byteArr == null)
  1319. //{
  1320. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1321. //}
  1322. //var riskChecked = ProtoBufHelper.EntityDeSerialize<RiskCheckNotifyRsp>(byteArr);
  1323. //var responeEntity = new ResponeEntity<uint>()
  1324. //{
  1325. // RetCode = riskChecked.RetCode,
  1326. // RetMessage = riskChecked.RetDesc,
  1327. // Entity = riskChecked.AccountId,
  1328. //};
  1329. //return responeEntity;
  1330. }
  1331. public override byte[] ToReqeustDeliveryGoodsReq(ulong DeliveryGoodsUTime)
  1332. {
  1333. var baseQueryReq = new DeliveryGoodsQueryReq()
  1334. {
  1335. Header = new MessageHead() { },
  1336. DeliveryGoodsUTime = DeliveryGoodsUTime
  1337. };
  1338. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  1339. }
  1340. public override ResponeEntity<List<DeliveryGoodsInfoModel>> ResponeDeliveryGoodsReq(object data)
  1341. {
  1342. var byteArr = data as byte[];
  1343. if (data == null)
  1344. {
  1345. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1346. }
  1347. var itemResponeList = ProtoBufHelper.EntityDeSerialize<DeliveryGoodsQueryRsp>(byteArr);
  1348. var resultEntity = new ResponeEntity<List<DeliveryGoodsInfoModel>>()
  1349. {
  1350. RetCode = itemResponeList.RetCode,
  1351. RetMessage = itemResponeList.RetDesc,
  1352. Entity = new List<DeliveryGoodsInfoModel>() { }
  1353. };
  1354. foreach (var item in itemResponeList.DeliveryGoodsList)
  1355. {
  1356. var good = ToLocalDeliveryGoodsInfo(item);
  1357. resultEntity.Entity.Add(good);
  1358. }
  1359. return resultEntity;
  1360. }
  1361. private DeliveryGoodsInfoModel ToLocalDeliveryGoodsInfo(DeliveryGoodsInfo goods)
  1362. {
  1363. var item = new DeliveryGoodsInfoModel()
  1364. {
  1365. DeliveryGoodsID = goods.DeliveryGoodsID,
  1366. DeliveryGoodsCode = goods.DeliveryGoodsCode,
  1367. DeliveryGoodsName = goods.DeliveryGoodsName,
  1368. AuditFlag = goods.AuditFlag,
  1369. GoodsUnit = goods.GoodsUnit,
  1370. StandardQty = goods.StandardQty,
  1371. StandardQtyRange = goods.StandardQtyRange,
  1372. DeliveryGoodsPMList = ToLocalPriceMove(goods.DeliveryGoodsPMList)
  1373. };
  1374. return item;
  1375. }
  1376. /// <summary>
  1377. /// 查询外部交易所请求
  1378. /// </summary>
  1379. /// <returns></returns>
  1380. public override byte[] ToExternalExchangeReq()
  1381. {
  1382. var externalExchangeReq = new ExternalExchangeReq()
  1383. {
  1384. Header = new MessageHead() { },
  1385. };
  1386. return ProtoBufHelper.EntitySerialize(externalExchangeReq);
  1387. }
  1388. /// <summary>
  1389. /// 查询外部交易所响应
  1390. /// </summary>
  1391. /// <param name="data"></param>
  1392. /// <returns></returns>
  1393. public override ResponeEntity<List<Muchinfo.MTPClient.Data.Model.ExternalExchangeModel>> ResponseExternalExchange(object data)
  1394. {
  1395. var byteArr = data as byte[];
  1396. if (data == null)
  1397. {
  1398. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1399. }
  1400. var itemResponeList = ProtoBufHelper.EntityDeSerialize<ExternalExchangeRsp>(byteArr);
  1401. var resultEntity = new ResponeEntity<List<ExternalExchangeModel>>()
  1402. {
  1403. RetCode = itemResponeList.RetCode,
  1404. RetMessage = itemResponeList.RetDesc,
  1405. Entity = new List<ExternalExchangeModel>() { }
  1406. };
  1407. foreach (var item in itemResponeList.ExternalExchangeList)
  1408. {
  1409. var externalExchange = BufToMarketsInfo(item);
  1410. resultEntity.Entity.Add(externalExchange);
  1411. }
  1412. return resultEntity;
  1413. }
  1414. /// <summary>
  1415. /// 外部对象转内部对象
  1416. /// </summary>
  1417. /// <param name="tasModel"></param>
  1418. /// <returns></returns>
  1419. private ExternalExchangeModel BufToMarketsInfo(ExternalExchange tasModel)
  1420. {
  1421. var localModel = new ExternalExchangeModel()
  1422. {
  1423. AutoID = tasModel.AutoID,
  1424. ExExchangeCode = tasModel.ExExchangeCode,
  1425. ExExchangeName = tasModel.ExExchangeName,
  1426. IsMarketPrice = tasModel.IsMarketPrice
  1427. };
  1428. return localModel;
  1429. }
  1430. /// <summary>
  1431. /// 查询商品组请求
  1432. /// </summary>
  1433. /// <returns></returns>
  1434. public override byte[] ToGoodsGroupReq()
  1435. {
  1436. var externalExchangeReq = new GoodsGroupReq()
  1437. {
  1438. Header = new MessageHead() { },
  1439. };
  1440. return ProtoBufHelper.EntitySerialize(externalExchangeReq);
  1441. }
  1442. /// <summary>
  1443. /// 查询商品组响应
  1444. /// </summary>
  1445. /// <param name="data"></param>
  1446. /// <returns></returns>
  1447. public override ResponeEntity<List<Data.Model.GoodsGroup>> ResponseGoodsGroup(object data)
  1448. {
  1449. var byteArr = data as byte[];
  1450. if (data == null)
  1451. {
  1452. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1453. }
  1454. var itemResponeList = ProtoBufHelper.EntityDeSerialize<GoodsGroupRsp>(byteArr);
  1455. var resultEntity = new ResponeEntity<List<Data.Model.GoodsGroup>>()
  1456. {
  1457. RetCode = itemResponeList.RetCode,
  1458. RetMessage = itemResponeList.RetDesc,
  1459. Entity = new List<Data.Model.GoodsGroup>() { }
  1460. };
  1461. foreach (var item in itemResponeList.GoodsGroupList)
  1462. {
  1463. var goodsGroup = new Data.Model.GoodsGroup()
  1464. {
  1465. GoodsGroupid = item.GoodsGroupID,
  1466. GoodsGroupName = item.GoodsGroupName,
  1467. MarketTypeID = (int)item.MarketID,
  1468. ExChangeId = item.ExExchangeID,
  1469. CanShort = item.CanShort
  1470. };
  1471. resultEntity.Entity.Add(goodsGroup);
  1472. }
  1473. return resultEntity;
  1474. }
  1475. }
  1476. }