AccountProtobufAdapter.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  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. }
  869. };
  870. if (loginRsq.Header != null && loginRsq.RetCode == 0)
  871. {
  872. loginRsq.Header.UserID = loginRsq.UserID;
  873. result.Entity.FundsAccountId = loginRsq.Header.AccountID;
  874. ProtoBufHelper.Head = loginRsq.Header; ////保存头内容
  875. }
  876. return result;
  877. }
  878. /// <summary>
  879. /// To the reqeust login.
  880. /// </summary>
  881. /// <param name="loginType">Type of the login.</param>
  882. /// <param name="passWord">The pass word.</param>
  883. /// <param name="loginID">The login code.</param>
  884. /// <param name="guid">The unique identifier.</param>
  885. /// <param name="loginIP">login IP Address.</param>
  886. /// <param name="systemDesc">The system desc.</param>
  887. /// <returns>System.Byte[][].</returns>
  888. public override byte[] ToReqeustLogin(int loginType, string passWord, ulong loginID, string guid, string loginIP, string systemDesc, string version)
  889. {
  890. var loginReq = new LoginReq()
  891. {
  892. LoginPWD = passWord,
  893. ClientType = (int)eClientType.CLIENTTYPE_PC_TRADE_CLIENT,
  894. LoginType = (uint)loginType,
  895. LoginID = loginID,
  896. LoginIp = loginIP,
  897. GUID = guid,
  898. DeviceID = string.Empty,
  899. Version = version,
  900. EnvironmentInfo = systemDesc,
  901. };
  902. var uuid = Guid.NewGuid();
  903. loginReq.Header = new MessageHead() { UUID = uuid.ToString() };
  904. return ProtoBufHelper.EntitySerialize(loginReq, false);
  905. }
  906. /// <summary>
  907. /// 交易端登出
  908. /// </summary>
  909. /// <returns></returns>
  910. public override byte[] ToReqeustLogOut(ulong loginID)
  911. {
  912. var logOutReq = new LogoutReq() { LoginID = loginID };
  913. return ProtoBufHelper.EntitySerialize(logOutReq);
  914. }
  915. /// <summary>
  916. /// 商品组信息转换=>市场信息转换
  917. /// </summary>
  918. /// <param name="goodsGroupInfos">商品组信息=>市场信息</param>
  919. /// <param name="exchanges">The exchanges.</param>
  920. /// <returns>System.Collections.Generic.List{Muchinfo.TASClient.Data.Model.Market}.</returns>
  921. private List<Muchinfo.MTPClient.Data.Model.GoodsGroup> ToLocalGoodsGroupsInfo(List<MarketsInfo> goodsGroupInfos)
  922. {
  923. var goodsGroups = new List<Muchinfo.MTPClient.Data.Model.GoodsGroup>();
  924. if (goodsGroupInfos == null || goodsGroupInfos.Count <= 0)
  925. {
  926. return goodsGroups;
  927. }
  928. foreach (var item in goodsGroupInfos)
  929. {
  930. var goodsGroup = new Muchinfo.MTPClient.Data.Model.GoodsGroup()
  931. {
  932. MarketTypeID = (int)item.MarketID,
  933. GoodsGroupName = item.MarketName,
  934. TradeMode = (eTradeMode)item.TradeMode,
  935. //GoodsGroupCode = item.GoodsGroupCode,
  936. //GoodsGroupName = item.GoodsGroupName,
  937. //GoodsGroupLevelTypeID = item.GoodsGroupLevelTypeID,
  938. //GoodsGroupid = item.GoodsGroupid,
  939. //MarketTypeID = item.MarketTypeID,
  940. //ReckonMode = (ReckonModeType)item.ReckonMode,
  941. //TradeMode = (eTradeMode)item.TradeMode,
  942. //ExchAreaId = item.ExchAreaId,
  943. //ParentGoodsGroupId = item.ParentGoodsGroupId,
  944. };
  945. goodsGroups.Add(goodsGroup);
  946. }
  947. return goodsGroups;
  948. }
  949. /// <summary>
  950. /// 资金账户转换
  951. /// </summary>
  952. /// <param name="taAccountInfos"></param>
  953. /// <returns></returns>
  954. private FundsAccount ToLocalFundsAccounts(TaAccountInfo taAccountInfos)
  955. {
  956. return new FundsAccount();
  957. }
  958. /// <summary>
  959. /// 交易账号信息转换
  960. /// </summary>
  961. /// <param name="accountInfos"></param>
  962. /// <returns></returns>
  963. private TradeAccount ToLocalTradeAccount(AccountInfo accountInfos)
  964. {
  965. if (null == accountInfos)
  966. {
  967. //todo:异常信息提示
  968. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "查询账号信息异常!");
  969. }
  970. return new TradeAccount()
  971. {
  972. CustomerId = accountInfos.UserID,
  973. MemberAreaId = accountInfos.ParentUserID,
  974. CustomerName = accountInfos.AccountName
  975. };
  976. }
  977. /// <summary>
  978. /// 商品信息参数配置
  979. /// </summary>
  980. /// <param name="goodsInfos">The goods infos.</param>
  981. /// <param name="goodsGroups">The goods groups.</param>
  982. /// <returns>List{LocalEntity.Exchange}.</returns>
  983. public List<QuoteGoods> ToLocalGoodsList(List<GoodsInfo> goodsInfos, List<Muchinfo.MTPClient.Data.Model.GoodsGroup> goodsGroups)
  984. {
  985. var goodsList = new List<QuoteGoods>();
  986. if (null == goodsInfos || goodsInfos.Count <= 0)
  987. {
  988. return goodsList;
  989. }
  990. foreach (var serviceEntity in goodsInfos)
  991. {
  992. if (serviceEntity == null)
  993. {
  994. continue;
  995. }
  996. var goodsGroup = goodsGroups.FirstOrDefault(z => z.GoodsGroupid == serviceEntity.MarketID);
  997. if (goodsGroup == null) continue;
  998. var entity = new GoodsParameters()
  999. {
  1000. AgreeUnit = Convert.ToDecimal(serviceEntity.AgreeUnit),
  1001. GoodsCode = serviceEntity.GoodsCode,
  1002. GoodsId = serviceEntity.GoodsId,
  1003. GoodsName = serviceEntity.GoodsName,
  1004. ExchAreaID = goodsGroup.ExchAreaId,
  1005. TradeMode = goodsGroup.TradeMode, // 交易模式
  1006. ////todo:服务未返回,设置调试值
  1007. ReckonRate = 1,
  1008. };
  1009. //DateTime listedtime;
  1010. //if (DateTime.TryParse(serviceEntity.ListedTime, out listedtime))
  1011. //{
  1012. // entity.ListedTime = listedtime;
  1013. //}
  1014. var quoteGoods = ToQuoteGoods(entity);
  1015. goodsList.Add(quoteGoods);
  1016. }
  1017. return goodsList;
  1018. }
  1019. private QuoteGoods ToQuoteGoods(GoodsParameters parameter)
  1020. {
  1021. if (parameter == null) return null;
  1022. //todo:商品类别
  1023. //var sort = dataModel.Sort.ToString();
  1024. var category = QuoteCategoryType.PreciousMetal; //GoodsSortHelper.GetQuoteCategoryBySorts(sort);
  1025. return new QuoteGoods(parameter.ExchHqCode, parameter.GoodsCode, parameter.GoodsHqCode, category)
  1026. {
  1027. ListingStatus = parameter.GoodsStatus.ToString(), // ListStatus.ToString(),
  1028. //LotUnit = dataModel.LotSize,
  1029. Name = parameter.GoodsName,
  1030. GoodsId = (uint)parameter.GoodsId,
  1031. // QuoteCurrency = parameter.QuoteCurrency, //PriceCurrency,
  1032. // QuoteUnit = parameter.PriceUnit.ToString(),
  1033. // Sort = QuoteCategoryType.PreciousMetal.ToString(), //sort,
  1034. GoodsParameters = parameter,
  1035. TradeMode = parameter.TradeMode,
  1036. DecimalPlaces = parameter.HqExchFigures,
  1037. //RelevanceCode = dataModel.RelevanceCode,
  1038. //SectorCode = dataModel.Sector2,推荐
  1039. };
  1040. }
  1041. /// <summary>
  1042. ///
  1043. /// </summary>
  1044. /// <param name="obj"></param>ToLocalLoginEntity
  1045. /// <returns></returns>
  1046. public override ResponeEntity<Data.Model.AccountInfoEntity> TolocalAccountInfoEntity(object obj)
  1047. {
  1048. return null;
  1049. //var byteArr = obj as byte[];
  1050. //if (byteArr == null)
  1051. //{
  1052. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1053. //}
  1054. //var accountRespone = ProtoBufHelper.EntityDeSerialize<QueryAccountAndGoodsRsp>(byteArr);
  1055. //var resultEntity = new ResponeEntity<AccountInfoEntity>()
  1056. //{
  1057. // RetCode = accountRespone.RetCode,
  1058. // RetMessage = accountRespone.RetDesc,
  1059. // Entity = new AccountInfoEntity(),
  1060. //};
  1061. //if (accountRespone.Rsps == null || !accountRespone.Rsps.Any())
  1062. //{
  1063. // //todo:查询内容空
  1064. // return resultEntity;
  1065. //}
  1066. //var account = resultEntity.Entity;
  1067. //account.GoodsGroups = ToLocalGoodsGroupsInfo(accountRespone.Rsps[0].GoodsGroupInfoRsps); //市场
  1068. //account.QuoteGoodses = ToLocalGoodsList(accountRespone.Rsps[0].GoodsInfoRsps, account.GoodsGroups); ////商品信息
  1069. // account.FundsAccounts = ToLocalFundsAccounts(accountRespone.Rsps[0].TaAccountInfoRsps); //资金账号 单独查询资金信息
  1070. //account.TradeAccount = ToLocalTradeAccount(accountRespone.Rsps[0].AccountInfoRsps); ////交易账号
  1071. //if (account.FundsAccounts != null && account.FundsAccounts.Any() && account.TradeAccount!=null) ////设置会员证件
  1072. //{
  1073. // account.TradeAccount.MemberCardType = account.FundsAccounts[0].CardType;
  1074. // account.TradeAccount.MemberCardNum = account.FundsAccounts[0].CardNum;
  1075. //}
  1076. //return resultEntity;
  1077. }
  1078. /// <summary>
  1079. /// 账号基本信息查询与交易所市场商品信息
  1080. /// </summary>
  1081. /// <param name="accountId">The account identifier.</param>
  1082. /// <returns>System.Byte[][].</returns>
  1083. public override byte[] ToReqeustAccountInfo(ulong accountId)
  1084. {
  1085. return null;
  1086. //var accountGoodsReq = new QueryAccountAndGoodsReq()
  1087. //{
  1088. // Header = new MessageHead() { },
  1089. // AccountId = accountId,
  1090. //};
  1091. //return ProtoBufHelper.EntitySerialize(accountGoodsReq);
  1092. }
  1093. /// <summary>
  1094. /// 请求校验Token的Protobuf对象装箱方法
  1095. /// </summary>
  1096. /// <param name="token"></param>
  1097. /// <returns></returns>
  1098. public override byte[] ToTokenCheck(ulong loginID, string token, ulong octTime)
  1099. {
  1100. var tokenCheckReq = new TokenCheckReq()
  1101. {
  1102. LoginID = loginID,
  1103. Token = token,
  1104. SystemTime = octTime
  1105. };
  1106. return ProtoBufHelper.EntitySerialize(tokenCheckReq);
  1107. }
  1108. /// <summary>
  1109. /// 从检验Token返回信息中获取Token状态的方法
  1110. /// </summary>
  1111. /// <param name="obj">检验Token返回信息</param>
  1112. /// <returns>Token状态值</returns>
  1113. public override ResponeEntity<ulong> GetTokenStatus(object obj)
  1114. {
  1115. var byteArr = obj as byte[];
  1116. if (byteArr == null)
  1117. {
  1118. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1119. }
  1120. var tokenCheckRsp = ProtoBufHelper.EntityDeSerialize<TokenCheckRsp>(byteArr);
  1121. var resultEntity = new ResponeEntity<ulong>
  1122. {
  1123. RetCode = tokenCheckRsp.RetCode,
  1124. RetMessage = tokenCheckRsp.RetDesc,
  1125. Entity = tokenCheckRsp.SystemTime //服务器时间
  1126. };
  1127. return resultEntity;
  1128. }
  1129. /// <summary>
  1130. /// 转换修改密码
  1131. /// </summary>
  1132. /// <param name="accountPwds"></param>
  1133. /// <returns></returns>
  1134. public override byte[] ToReqeustModifyPwds(AccountPwds accountPwds)
  1135. {
  1136. var modifyPwdReq = new ModifyPwdReq()
  1137. {
  1138. ModifyPwdType = accountPwds.ModifyPwdType,
  1139. ModifyPwdID = accountPwds.ModifyPwdID,
  1140. NewPwd = accountPwds.NewPwd,
  1141. OldPwd = accountPwds.OldPwd
  1142. };
  1143. return ProtoBufHelper.EntitySerialize(modifyPwdReq);
  1144. }
  1145. /// <summary>
  1146. /// 解释修改密码返回对象
  1147. /// </summary>
  1148. /// <param name="obj"></param>
  1149. /// <returns></returns>
  1150. public override ResponeEntity<int> ResponeModifyPWDEntity(object obj)
  1151. {
  1152. var byteArr = obj as byte[];
  1153. if (byteArr == null)
  1154. {
  1155. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1156. }
  1157. var modifyPwd = ProtoBufHelper.EntityDeSerialize<ModifyPwdRsp>(byteArr);
  1158. var responeEntity = new ResponeEntity<int>()
  1159. {
  1160. RetCode = modifyPwd.RetCode,
  1161. RetMessage = modifyPwd.RetDesc,
  1162. };
  1163. return responeEntity;
  1164. }
  1165. public override byte[] ToReqeustFuncMenu(string loginCode)
  1166. {
  1167. return null;
  1168. //var modifyPwdReq = new QueryAccountFuncMenuReq()
  1169. //{
  1170. // LoginCode = loginCode,
  1171. // RoleType = 0, ////客户端类型
  1172. //};
  1173. //return ProtoBufHelper.EntitySerialize(modifyPwdReq);
  1174. }
  1175. public override ResponeEntity<List<SysMenuItem>> ResponeLocalFuncMenu(object data)
  1176. {
  1177. var byteArr = data as byte[];
  1178. if (data == null)
  1179. {
  1180. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1181. }
  1182. var menusRespone = ProtoBufHelper.EntityDeSerialize<FuncMenuRsp>(byteArr);
  1183. var resultEntity = new ResponeEntity<List<SysMenuItem>>()
  1184. {
  1185. RetCode = menusRespone.RetCode,
  1186. RetMessage = menusRespone.RetDesc,
  1187. Entity = new List<SysMenuItem>(),
  1188. };
  1189. if (menusRespone.FuncMenuList == null || !menusRespone.FuncMenuList.Any())
  1190. {
  1191. //todo:查询内容空
  1192. return resultEntity;
  1193. }
  1194. foreach (var queryAccount in menusRespone.FuncMenuList)
  1195. {
  1196. var menu = BuildFuncMenu(queryAccount);
  1197. resultEntity.Entity.Add(menu);
  1198. }
  1199. if (resultEntity.Entity != null) ////对子菜单进行排序
  1200. {
  1201. resultEntity.Entity = resultEntity.Entity.OrderBy((item) => item.SortId).ToList();
  1202. }
  1203. return resultEntity;
  1204. }
  1205. /// <summary>
  1206. /// 生成树菜单
  1207. /// </summary>
  1208. /// <returns></returns>
  1209. private SysMenuItem BuildFuncMenu(tas.FuncMenu menus)
  1210. {
  1211. var localMenu = new SysMenuItem(menus.FuncMenuName)
  1212. {
  1213. FuncMenuCode = menus.FuncMenuCode,
  1214. ParentFuncMenuCode = menus.Parentfuncmenucode,
  1215. Children = new List<SysMenuItem>(),
  1216. };
  1217. foreach (var funcMenuList in menus.SonMenus)
  1218. {
  1219. var childMenu = BuildFuncMenu(funcMenuList);
  1220. if (childMenu.Children != null) ////对子菜单进行排序
  1221. {
  1222. childMenu.Children = childMenu.Children.OrderBy((item) => item.SortId).ToList();
  1223. }
  1224. localMenu.Children.Add(childMenu);
  1225. }
  1226. if (localMenu.Children != null) ////对子菜单进行排序
  1227. {
  1228. localMenu.Children = localMenu.Children.OrderBy((item) => item.SortId).ToList();
  1229. }
  1230. return localMenu;
  1231. }
  1232. /// <summary>
  1233. /// 转换请求
  1234. /// </summary>
  1235. /// <param name="accountid"></param>
  1236. /// <returns></returns>
  1237. public override byte[] ToReqeustTradeFeeRules(uint accountid)
  1238. {
  1239. //var tradeRulesReq = new QueryAccountAndGoodsReq()
  1240. //{
  1241. // AccountId = accountid,
  1242. //};
  1243. //return ProtoBufHelper.EntitySerialize(tradeRulesReq);
  1244. return null;
  1245. }
  1246. public override ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>> ResoneLocalGoodsFeeRules(object data)
  1247. {
  1248. return null;
  1249. //var byteArr = data as byte[];
  1250. //if (data == null)
  1251. //{
  1252. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1253. //}
  1254. //var goodsResult=ProtoBufHelper.EntityDeSerialize<QueryAccountGoodsTypeRsp>(byteArr);
  1255. //var resultEntity = new ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>>()
  1256. //{
  1257. // RetCode = goodsResult.RetCode,
  1258. // RetMessage = goodsResult.RetDesc,
  1259. // Entity = new List<Data.Model.GoodRules.TradeGoodsFeeRule>(),
  1260. //};
  1261. //if (goodsResult.Rsps == null || !goodsResult.Rsps.Any())
  1262. //{
  1263. // //todo:查询内容空
  1264. // return resultEntity;
  1265. //}
  1266. //foreach (var rspItem in goodsResult.Rsps)
  1267. //{
  1268. // var goodsFeeRules = new Dictionary<int, TradeGoodsFeeRule>();
  1269. // foreach (var goodsRules in rspItem.GoodsRuleAndFee)
  1270. // {
  1271. // var feeRule = ConverFeeRuleType(goodsRules);
  1272. // resultEntity.Entity.Add(feeRule);
  1273. // //goodsFeeRules[feeRule.GoodsID].GoodsFees[feeRule.] = goodsFeeType;
  1274. // }
  1275. //}
  1276. //return resultEntity;
  1277. }
  1278. /// <summary>
  1279. ///
  1280. /// </summary>
  1281. /// <param name="goodsInce"></param>
  1282. /// <returns></returns>
  1283. private Data.Model.GoodRules.TradeGoodsFeeRule ConverFeeRuleType(tas.GoodsRuleAndFee goodsInce)
  1284. {
  1285. var feeRule = new Data.Model.GoodRules.TradeGoodsFeeRule();
  1286. feeRule.GoodsID = goodsInce.GoodsID;
  1287. ////商品交易规则
  1288. foreach (var goodsFeeType in goodsInce.GoodsRuleList)
  1289. {
  1290. var rule = new Data.Model.GoodRules.GoodsRuleModel()
  1291. {
  1292. Ruleid = goodsFeeType.Ruleid,
  1293. RuleName = goodsFeeType.RuleName,
  1294. ParamValue = goodsFeeType.ParamValue
  1295. };
  1296. feeRule.GoodsRuleList.Add(rule);
  1297. }
  1298. return feeRule;
  1299. }
  1300. public override byte[] ToReqeustRiskChecked(ulong accountid, uint isChecked)
  1301. {
  1302. return null;
  1303. //var riskReq = new RiskCheckNotifyReq()
  1304. //{
  1305. // AccountId = (uint)accountid,
  1306. // IsChecked = isChecked,
  1307. //};
  1308. //return ProtoBufHelper.EntitySerialize(riskReq);
  1309. }
  1310. public override ResponeEntity<uint> ResponeRiskChecked(object data)
  1311. {
  1312. return null;
  1313. //var byteArr = data as byte[];
  1314. //if (byteArr == null)
  1315. //{
  1316. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1317. //}
  1318. //var riskChecked = ProtoBufHelper.EntityDeSerialize<RiskCheckNotifyRsp>(byteArr);
  1319. //var responeEntity = new ResponeEntity<uint>()
  1320. //{
  1321. // RetCode = riskChecked.RetCode,
  1322. // RetMessage = riskChecked.RetDesc,
  1323. // Entity = riskChecked.AccountId,
  1324. //};
  1325. //return responeEntity;
  1326. }
  1327. public override byte[] ToReqeustDeliveryGoodsReq(ulong DeliveryGoodsUTime)
  1328. {
  1329. var baseQueryReq = new DeliveryGoodsQueryReq()
  1330. {
  1331. Header = new MessageHead() { },
  1332. DeliveryGoodsUTime = DeliveryGoodsUTime
  1333. };
  1334. return ProtoBufHelper.EntitySerialize(baseQueryReq);
  1335. }
  1336. public override ResponeEntity<List<DeliveryGoodsInfoModel>> ResponeDeliveryGoodsReq(object data)
  1337. {
  1338. var byteArr = data as byte[];
  1339. if (data == null)
  1340. {
  1341. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1342. }
  1343. var itemResponeList = ProtoBufHelper.EntityDeSerialize<DeliveryGoodsQueryRsp>(byteArr);
  1344. var resultEntity = new ResponeEntity<List<DeliveryGoodsInfoModel>>()
  1345. {
  1346. RetCode = itemResponeList.RetCode,
  1347. RetMessage = itemResponeList.RetDesc,
  1348. Entity = new List<DeliveryGoodsInfoModel>() { }
  1349. };
  1350. foreach (var item in itemResponeList.DeliveryGoodsList)
  1351. {
  1352. var good = ToLocalDeliveryGoodsInfo(item);
  1353. resultEntity.Entity.Add(good);
  1354. }
  1355. return resultEntity;
  1356. }
  1357. private DeliveryGoodsInfoModel ToLocalDeliveryGoodsInfo(DeliveryGoodsInfo goods)
  1358. {
  1359. var item = new DeliveryGoodsInfoModel()
  1360. {
  1361. DeliveryGoodsID = goods.DeliveryGoodsID,
  1362. DeliveryGoodsCode = goods.DeliveryGoodsCode,
  1363. DeliveryGoodsName = goods.DeliveryGoodsName,
  1364. AuditFlag = goods.AuditFlag,
  1365. GoodsUnit = goods.GoodsUnit,
  1366. StandardQty = goods.StandardQty,
  1367. StandardQtyRange = goods.StandardQtyRange,
  1368. DeliveryGoodsPMList = ToLocalPriceMove(goods.DeliveryGoodsPMList)
  1369. };
  1370. return item;
  1371. }
  1372. /// <summary>
  1373. /// 查询外部交易所请求
  1374. /// </summary>
  1375. /// <returns></returns>
  1376. public override byte[] ToExternalExchangeReq()
  1377. {
  1378. var externalExchangeReq = new ExternalExchangeReq()
  1379. {
  1380. Header = new MessageHead() { },
  1381. };
  1382. return ProtoBufHelper.EntitySerialize(externalExchangeReq);
  1383. }
  1384. /// <summary>
  1385. /// 查询外部交易所响应
  1386. /// </summary>
  1387. /// <param name="data"></param>
  1388. /// <returns></returns>
  1389. public override ResponeEntity<List<Muchinfo.MTPClient.Data.Model.ExternalExchangeModel>> ResponseExternalExchange(object data)
  1390. {
  1391. var byteArr = data as byte[];
  1392. if (data == null)
  1393. {
  1394. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1395. }
  1396. var itemResponeList = ProtoBufHelper.EntityDeSerialize<ExternalExchangeRsp>(byteArr);
  1397. var resultEntity = new ResponeEntity<List<ExternalExchangeModel>>()
  1398. {
  1399. RetCode = itemResponeList.RetCode,
  1400. RetMessage = itemResponeList.RetDesc,
  1401. Entity = new List<ExternalExchangeModel>() { }
  1402. };
  1403. foreach (var item in itemResponeList.ExternalExchangeList)
  1404. {
  1405. var externalExchange = BufToMarketsInfo(item);
  1406. resultEntity.Entity.Add(externalExchange);
  1407. }
  1408. return resultEntity;
  1409. }
  1410. /// <summary>
  1411. /// 外部对象转内部对象
  1412. /// </summary>
  1413. /// <param name="tasModel"></param>
  1414. /// <returns></returns>
  1415. private ExternalExchangeModel BufToMarketsInfo(ExternalExchange tasModel)
  1416. {
  1417. var localModel = new ExternalExchangeModel()
  1418. {
  1419. AutoID = tasModel.AutoID,
  1420. ExExchangeCode = tasModel.ExExchangeCode,
  1421. ExExchangeName = tasModel.ExExchangeName,
  1422. IsMarketPrice = tasModel.IsMarketPrice
  1423. };
  1424. return localModel;
  1425. }
  1426. /// <summary>
  1427. /// 查询商品组请求
  1428. /// </summary>
  1429. /// <returns></returns>
  1430. public override byte[] ToGoodsGroupReq()
  1431. {
  1432. var externalExchangeReq = new GoodsGroupReq()
  1433. {
  1434. Header = new MessageHead() { },
  1435. };
  1436. return ProtoBufHelper.EntitySerialize(externalExchangeReq);
  1437. }
  1438. /// <summary>
  1439. /// 查询商品组响应
  1440. /// </summary>
  1441. /// <param name="data"></param>
  1442. /// <returns></returns>
  1443. public override ResponeEntity<List<Data.Model.GoodsGroup>> ResponseGoodsGroup(object data)
  1444. {
  1445. var byteArr = data as byte[];
  1446. if (data == null)
  1447. {
  1448. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  1449. }
  1450. var itemResponeList = ProtoBufHelper.EntityDeSerialize<GoodsGroupRsp>(byteArr);
  1451. var resultEntity = new ResponeEntity<List<Data.Model.GoodsGroup>>()
  1452. {
  1453. RetCode = itemResponeList.RetCode,
  1454. RetMessage = itemResponeList.RetDesc,
  1455. Entity = new List<Data.Model.GoodsGroup>() { }
  1456. };
  1457. foreach (var item in itemResponeList.GoodsGroupList)
  1458. {
  1459. var goodsGroup = new Data.Model.GoodsGroup()
  1460. {
  1461. GoodsGroupid = item.GoodsGroupID,
  1462. GoodsGroupName = item.GoodsGroupName,
  1463. MarketTypeID = (int)item.MarketID,
  1464. ExChangeId = item.ExExchangeID,
  1465. CanShort = item.CanShort
  1466. };
  1467. resultEntity.Entity.Add(goodsGroup);
  1468. }
  1469. return resultEntity;
  1470. }
  1471. }
  1472. }