AccountProtobufAdapter.cs 62 KB

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