| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619 |
- //----------------------------------------------------------------
- //Module Name: Muchinfo.MTPClient.Adapter
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/1/13 13:45:06
- //Author
- //Description Create
- //----------------------------------------------------------------
- using Muchinfo.MTPClient.Adapter.Abstract;
- using Muchinfo.MTPClient.Adapter.Utilities;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Helper;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.GoodRules;
- using Muchinfo.MTPClient.Data.Model.Message;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using tas;
- namespace Muchinfo.MTPClient.Adapter.ProtoBuf
- {
- /// <summary>
- /// Class AccountProtobufAdapter.
- /// </summary>
- public class AccountProtobufAdapter : AccountAdapter
- {
- /// <summary>
- /// 通知查询转换
- /// </summary>
- /// <param name="loginId">The login identifier.</param>
- /// <param name="lastNoticeId">The last notice identifier.</param>
- /// <returns>System.Byte[][].</returns>
- public override byte[] ToReqeustNoticeQuery(ulong loginId, long lastNoticeId)
- {
- var baseQueryReq = new NoticeQueryReq()
- {
- Header = new MessageHead() { },
- LoginID = loginId,
- LastNoticeId = (uint)lastNoticeId,
- //MsgType = 0,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 通知查询转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<NoticeMsg>> ResponeNoticeQuery(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<NoticeQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<NoticeMsg>>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new List<NoticeMsg>()
- };
- foreach (var item in itemRespone.NoticeInfoList)
- {
- var itemNoticeInfo = BufToNoticeInfo(item);
- resultEntity.Entity.Add(itemNoticeInfo);
- }
- return resultEntity;
- }
- /// <summary>
- /// 通知item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private NoticeMsg BufToNoticeInfo(NoticeInfo tasModel)
- {
- var localModel = new NoticeMsg()
- {
- MSG_ID = tasModel.NoticeId, //NoticeId id uint32
- TITLE = tasModel.NoticeTitle, //NoticeTitle 标题 string
- CONTENT = tasModel.NoticeContent, //NoticeContent 内容 string
- Sending_Time = TimeHelper.ConvertStringToDateTime(tasModel.NoticeTime.ToString()),
- NoticeType = tasModel.NoticeType, //NoticeType 类型 uint32
- };
- return localModel;
- }
- /// <summary>
- /// 风险协议书转换
- /// </summary>
- /// <param name="RiskMsgUTime">上次更新配置时间</param>
- /// <returns></returns>
- public override byte[] ToReqeustRiskTipQueryReq(ulong RiskMsgUTime)
- {
- var baseQueryReq = new RiskTipQueryReq()
- {
- Header = new MessageHead() { },
- RiskMsgUTime = RiskMsgUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 风险协议书转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<RiskTipQueryRspModel> ResponeRiskTipQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<RiskTipQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<RiskTipQueryRspModel>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new RiskTipQueryRspModel()
- {
- TipTitle = itemRespone.TipTitle,
- TipMsg = itemRespone.TipMsg
- }
- };
- return resultEntity;
- }
- /// <summary>
- /// 市场转换
- /// </summary>
- /// <param name="MarketsUTime">上次更新配置时间</param>
- /// <returns></returns>
- public override byte[] ToReqeustMarketsQueryReq(ulong MarketsUTime)
- {
- var baseQueryReq = new MarketsQueryReq()
- {
- Header = new MessageHead() { },
- MarketsUTime = MarketsUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 市场转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<MarketsInfoModel>> ResponeMarketsQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<MarketsQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<MarketsInfoModel>>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new List<MarketsInfoModel>()
- {
- }
- };
- foreach (var item in itemRespone.MarketsList)
- {
- var itemMarketsInfo = BufToMarketsInfo(item);
- resultEntity.Entity.Add(itemMarketsInfo);
- }
- return resultEntity;
- }
- /// <summary>
- /// 市场item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private MarketsInfoModel BufToMarketsInfo(MarketsInfo tasModel)
- {
- var localModel = new MarketsInfoModel()
- {
- MarketID = tasModel.MarketID,// 市场id uint32
- MarketName = tasModel.MarketName,// 市场名称 string
- TradeMode = (eTradeMode)tasModel.TradeMode,// 交易模式 uint32
- TradeProperty = (eTradeProperty)tasModel.TradeProperty,//交易属性
- };
- return localModel;
- }
- /// <summary>
- /// 枚举常量字典转换
- /// </summary>
- /// <param name="DirctionaryUTime">上次更新配置时间</param>
- /// <returns></returns>
- public override byte[] ToReqeustDictionaryQueryReq(ulong DirctionaryUTime)
- {
- var baseQueryReq = new DictionaryQueryReq()
- {
- Header = new MessageHead() { },
- DirctionaryUTime = DirctionaryUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 枚举常量字典转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<DictionaryInfoModel>> ResponeDictionaryQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<DictionaryQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<DictionaryInfoModel>>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new List<DictionaryInfoModel>()
- {
- }
- };
- foreach (var item in itemRespone.DictionaryList)
- {
- var itemDictionaryList = BufToDictionaryList(item);
- resultEntity.Entity.Add(itemDictionaryList);
- }
- return resultEntity;
- }
- /// <summary>
- /// 枚举常量字典item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private DictionaryInfoModel BufToDictionaryList(DictionaryInfo tasModel)
- {
- var localModel = new DictionaryInfoModel()
- {
- FieldCode = tasModel.FieldCode, // 枚举类型代码 string
- FieldName = tasModel.FieldName,// 枚举类型名称 string
- Key = tasModel.Key,// 枚举值 string
- Value = tasModel.Value,// 枚举名称 string
- };
- return localModel;
- }
- /// <summary>
- /// 错误码字典转换
- /// </summary>
- /// <param name="ErrorcodeUTime">上次更新配置时间</param>
- /// <returns></returns>
- public override byte[] ToReqeustErrorCodeQueryReq(ulong ErrorcodeUTime)
- {
- var baseQueryReq = new ErrorCodeQueryReq()
- {
- Header = new MessageHead() { },
- ErrorcodeUTime = ErrorcodeUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 错误码字典转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<ErrorCodeInfoModel>> ResponeErrorCodeQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<ErrorCodeQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<ErrorCodeInfoModel>>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new List<ErrorCodeInfoModel>()
- {
- }
- };
- foreach (var item in itemRespone.ErrorCodeList)
- {
- var itemErrorCodeList = BufToErrorCodeList(item);
- resultEntity.Entity.Add(itemErrorCodeList);
- }
- return resultEntity;
- }
- /// <summary>
- /// 错误码字典转换item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private ErrorCodeInfoModel BufToErrorCodeList(ErrorCodeInfo tasModel)
- {
- var localModel = new ErrorCodeInfoModel()
- {
- ErrorCode = tasModel.ErrorCode, // 错误码 string
- ErrorMsg = tasModel.ErrorMsg,// 提示信息 string
- };
- return localModel;
- }
- /// <summary>
- /// 市场运行计划转换
- /// </summary>
- /// <param name="TradeDate">交易日</param>
- /// <returns></returns>
- public override byte[] ToReqeustMarketRunQueryReq(string TradeDate)
- {
- var baseQueryReq = new MarketRunQueryReq()
- {
- Header = new MessageHead() { },
- TradeDate = TradeDate,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 市场运行计划转换-应答
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<MarketRunQueryRspModel> ResponeMarketRunQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<MarketRunQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<MarketRunQueryRspModel>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new MarketRunQueryRspModel()
- {
- TradeDate = itemRespone.TradeDate, //交易日 string
- //MarketRunList 市场及其日计划列表 MarketRun
- }
- };
- foreach (var item in itemRespone.MarketRunList)
- {
- var itemMarketRun = BufToMarketRun(item);
- resultEntity.Entity.MarketRunList.Add(itemMarketRun);
- }
- return resultEntity;
- }
- /// <summary>
- /// 市场运行计划item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private MarketRunModel BufToMarketRun(MarketRun tasModel)
- {
- var localModel = new MarketRunModel()
- {
- MarketId = tasModel.MarketId, // 市场id uint32
- //DayRunList 市场日运行计划表 DayRun
- };
- foreach (var item in tasModel.DayRunList)
- {
- var itemDayRun = BufToDayRun(item);
- localModel.DayRunList.Add(itemDayRun);
- }
- return localModel;
- }
- /// <summary>
- /// 市场日运行计划表item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private DayRunModel BufToDayRun(DayRun tasModel)
- {
- var localModel = new DayRunModel()
- {
- TradeWeekDay = tasModel.TradeWeekDay,// 交易归属日 uint32
- RunStep = tasModel.RunStep,// 运行阶段 uint32
- StartWeekDay = tasModel.StartWeekDay,// 起始周几 uint32
- StartTime = tasModel.StartTime,// 起始时间 string
- EndWeekDay = tasModel.EndWeekDay,// 结束周几 uint32
- EndTime = tasModel.EndTime,// 结束时间 string
- };
- return localModel;
- }
- /// <summary>
- /// 终端系统参数查询转换
- /// </summary>
- /// <param name="accountCode">配置时间</param>
- /// <returns></returns>
- public override byte[] ToReqeustConfigQueryReq(ulong ConfigUTime)
- {
- var baseQueryReq = new ConfigQueryReq()
- {
- Header = new MessageHead() { },
- // ConfigUTime = ConfigUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 终端系统参数查询应答转换
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<ConfigInfoModel>> ResponeConfigQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemResponeList = ProtoBufHelper.EntityDeSerialize<ConfigQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<ConfigInfoModel>>()
- {
- RetCode = itemResponeList.RetCode,
- RetMessage = itemResponeList.RetDesc,
- Entity = new List<ConfigInfoModel>() { }
- };
- foreach (var item in itemResponeList.ConfigInfoList)
- {
- var good = BufToConfigInfo(item);
- resultEntity.Entity.Add(good);
- }
- return resultEntity;
- }
- /// <summary>
- /// 终端系统参数item转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private ConfigInfoModel BufToConfigInfo(ConfigInfo tasModel)
- {
- var localModel = new ConfigInfoModel()
- {
- ParamCode = tasModel.ParamCode,//参数代码 string
- ParamName = tasModel.ParamName,// 参数名称 string
- ParamValue = tasModel.ParamValue,// 参数值 string
- ParamRemark = tasModel.ParamRemark,//说明 string
- };
- return localModel;
- }
- /// <summary>
- /// 商品查询请求转换-管理端查询
- /// </summary>
- /// <param name="accountCode">账号信息</param>
- /// <returns></returns>
- public override byte[] ToReqeustGoodsQueryReq(ulong GoodsUTime)
- {
- var baseGoodsQueryReq = new GoodsQueryReq()
- {
- Header = new MessageHead() { },
- GoodsUTime = GoodsUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseGoodsQueryReq);
- }
- /// <summary>
- /// 商品查询回应转换-管理端返回
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<List<QuoteGoods>> ResponeGoodsQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemResponeList = ProtoBufHelper.EntityDeSerialize<GoodsQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<QuoteGoods>>()
- {
- RetCode = itemResponeList.RetCode,
- RetMessage = itemResponeList.RetDesc,
- Entity = new List<QuoteGoods>() { }
- };
- foreach (var item in itemResponeList.GoodsList)
- {
- var good = BufToQuoteGoods(item);
- resultEntity.Entity.Add(good);
- }
- return resultEntity;
- }
- /// <summary>
- /// 商品转换
- /// </summary>
- /// <param name="good"></param>
- /// <returns></returns>
- private QuoteGoods BufToQuoteGoods(GoodsInfo good)
- {
- var category = QuoteCategoryType.PreciousMetal; //暂时随意定义
- var entityPara = new GoodsParameters()
- {
- AgreeUnit = Convert.ToDecimal(good.AgreeUnit),
- GoodsCode = good.GoodsCode,
- GoodsId = good.GoodsId,
- GoodsName = good.GoodsName,
- ExchAreaID = 250,
- MoneyMode = eMoneyMode.MONEYMODE_MARGIN,
- HqExchFigures = (int)good.DecimalPlace,
- // TradeMode = eTradeMode., // 交易模式
- ////todo:服务未返回,设置调试值
- ReckonRate = 1,
- };
- if (good.MarketID == 9)//全额转让市场,其他都是保证金市场
- {
- entityPara.MoneyMode = eMoneyMode.MONEYMODE_PAY;
- }
- var localGoods = new QuoteGoods("", good.GoodsCode, good.GoodsCode, category)
- {
- EndDate = good.EndDate, //EndDate 交割结束日期
- BeginDate = good.BeginDate,//BeginDate 交割起始日期
- PGoodsID1 = good.PGoodsID1,
- PGoodsID2 = good.PGoodsID2,
- MinDeliveryQty = good.MinDeliveryQty,//LimitSum 最小交割手数
- DeliveryGoodsName = good.DeliveryGoodsName, //DeliveryGoodsName 交割品种名称
- DeliveryGoodsCode = good.DeliveryGoodsCode,//DeliveryGoodsCode 交割品种代码
- DeliveryGoodsId = good.DeliveryGoodsId,//DeliveryGoodsId 交割品种代码
- GoodsUnit = good.GoodsUnit, //GoodsUnit 商品单位 uint32
- AgreeUnit = (uint)good.AgreeUnit, //AgreeUnit 合约单位 uint32
- Currency = good.Currency,//Currency 报价货币 uint32
- DecimalPlaces = (int)good.DecimalPlace,//DecimalPlace 价格小数位 uint32
- ListingDate = good.ListingDate, //ListingDate 上市时间 int32
- MarketID = good.MarketID, //MarketID 商品所属市场ID uint32
- Name = good.GoodsName,//GoodsName 商品名称 String
- GoodsCode = good.GoodsCode,//GoodsCode 商品代码 String
- GoodsId = good.GoodsId, //商品id uint32
- GoodsParameters = entityPara,
- DeliveryFlag = good.DeliveryFlag, //DeliveryFlag 是否交割 uint32 0:不交割1:要交割
- DeliveryGoodsUnit = good.DeliveryGoodsUnit, //DeliveryGoodsUnit 交割商品单位 string
- XDeliveryRatio = good.XDeliveryRatio,//XDeliveryRatio 主辅商品比的主手数 uint32 如3手主+2手辅=1份基准头寸
- PDeliveryRatio1 = good.PDeliveryRatio1, //PDeliveryRatio1 主辅商品比的辅手数 uint32
- PDeliveryRatio2 = good.PDeliveryRatio2,
- P1Type = good.P1Type,
- P2Type = good.P2Type,
- P1value = (uint)good.P1value,
- P2value = (uint)good.P2value,
- GoodsPMList = ToLocalPriceMove(good.GoodsPMList),
- ClosePriceMode = good.ClosePriceMode,
- ClosePriceParam = good.ClosePriceParam,
- Currencyid = good.Currencyid,
- DelistingMode = good.DelistingMode,
- GoodsStatus = good.GoodsStatus,
- GoodsType = good.GoodsType,
- GroupID = good.GroupID,
- InnerDealMode = good.InnerDealMode,
- IsBuyLimited = good.IsBuyLimited,
- Lotsize = good.Lotsize,
- QtyDecimalPlace = good.QtyDecimalPlace,
- QuoteMinUnit = good.QuoteMinUnit
- };
- return localGoods;
- }
- private List<PriceMoveModel> ToLocalPriceMove(List<PriceMove> priceMoveLst)
- {
- List<PriceMoveModel> retLst = new List<PriceMoveModel>();
- if (priceMoveLst != null)
- {
- foreach (var item in priceMoveLst)
- {
- PriceMoveModel pricemove = new PriceMoveModel()
- {
- PriceMoveID = item.PriceMoveID,
- PriceMoveType = item.PriceMoveType,
- PriceMoveDesc = item.PriceMoveDesc
- };
- retLst.Add(pricemove);
- }
- }
- return retLst;
- }
- /// <summary>
- /// 获取最后更新时间转换
- /// </summary>
- /// <returns></returns>
- public override byte[] ToReqeustLastUpdateTimeReq()
- {
- var baseReq = new LastUpdateTimeReq()
- {
- Header = new MessageHead() { },
- };
- return ProtoBufHelper.EntitySerialize(baseReq);
- }
- /// <summary>
- /// 获取最后更新时间回应转换
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<LastUpdateTimeModel> ResponeLastUpdateTimeReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<LastUpdateTimeRsp>(byteArr);
- var result = new ResponeEntity<LastUpdateTimeModel>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new LastUpdateTimeModel()
- {
- TradeDate = itemRespone.TradeDate,
- RiskMsgUTime = itemRespone.RiskMsgUTime,
- ConfigUTime = itemRespone.ConfigUTime,
- GoodsUTime = itemRespone.GoodsUTime,
- MarketsUTime = itemRespone.MarketsUTime,
- ErrorcodeUTime = itemRespone.ErrorcodeUTime,
- DirctionaryUTime = itemRespone.DirctionaryUTime,
- }
- };
- return result;
- }
- /// <summary>
- /// 登录查询请求转换
- /// </summary>
- /// <param name="accountCode">账号信息</param>
- /// <returns></returns>
- public override byte[] ToReqeustLoginQueryReq(ulong LoginID, string QueryItem)
- {
- QueryItem = QueryItem == "0" ? "" : QueryItem;
- var baseReq = new LoginQueryReq()
- {
- Header = new MessageHead() { },
- LoginID = LoginID,
- QueryItem = QueryItem
- };
- baseReq.Header.UserID = ProtoBufHelper.Head.UserID;
- return ProtoBufHelper.EntitySerialize(baseReq, false);
- }
- /// <summary>
- /// 登录查询回应转换
- /// </summary>
- /// <param name="data">数据内容</param>
- /// <returns></returns>
- public override ResponeEntity<AccountBaseInfoModel> ResponeLoginQueryReq(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemRespone = ProtoBufHelper.EntityDeSerialize<LoginQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<AccountBaseInfoModel>()
- {
- RetCode = itemRespone.RetCode,
- RetMessage = itemRespone.RetDesc,
- Entity = new AccountBaseInfoModel()
- {
- ServerLastNoticeId = itemRespone.ServerLastNoticeId
- },
- };
- var accountInfo = resultEntity.Entity;
- accountInfo.TAAccountList = ToLocalTAAccountList(itemRespone.TAAccountList); // 账户列表
- accountInfo.TradeAccount = ToLocalTradeAccount(itemRespone.AccountInfo); ////账号信息
- accountInfo.GoodsRuleAndFeeList = ToLocalGoodsRuleAndFeeList(itemRespone.GoodsRuleAndFeeList); ////商品交易规则和费用规则列表
- accountInfo.LastUpdateTimeList = ToLocalLastUpdateTimeList(itemRespone.ParamValues); ////最后更新时间列表
- return resultEntity;
- }
- /// <summary>
- /// 菜单转换
- /// </summary>
- /// <param name="MenuUTime"></param>
- /// <returns></returns>
- public override byte[] ToReqeustFuncMenuQueryReq(ulong MenuUTime)
- {
- var baseQueryReq = new FuncMenuReq()
- {
- Header = new MessageHead() { },
- MenuUTime = MenuUTime,
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- /// <summary>
- /// 菜单权限列表转换
- /// </summary>
- /// <param name="accountInfos"></param>
- /// <returns></returns>
- private List<SysMenuItem> ToLocalSysMenuItems(List<tas.FuncMenu> FuncMenu)
- {
- var SysMenuList = new List<SysMenuItem>();
- if (FuncMenu == null || FuncMenu.Count <= 0)
- {
- return SysMenuList;
- }
- foreach (var item in FuncMenu)
- {
- var menu = BuildFuncMenu(item);
- SysMenuList.Add(menu);
- }
- return SysMenuList;
- }
- /// <summary>
- /// 账户列表转换
- /// </summary>
- /// <param name="accountInfos"></param>
- /// <returns></returns>
- private List<TAAccountAllModel> ToLocalTAAccountList(List<tas.TAAccountAll> tAAccountAll)
- {
- var itemResultList = new List<TAAccountAllModel>();
- if (tAAccountAll == null)
- {
- return itemResultList;
- }
- foreach (var item in tAAccountAll)
- {
- var type = ConverTAAccountAllModel(item);
- itemResultList.Add(type);
- }
- return itemResultList;
- }
- private TAAccountAllModel ConverTAAccountAllModel(tas.TAAccountAll tasModel)
- {
- var model = new TAAccountAllModel();
- var goodsPositionList = new List<TradePositionModel>();
- var marketsIdList = new List<uint>();
- #region 资金信息/资金账户信息
- var fundsAccounts = new FundsAccount()
- {
- AccountId = tasModel.TaAccountInfo.AccountId,// 账户id
- TradeStatus = tasModel.TaAccountInfo.TradeStatus,
- Currency = tasModel.TaAccountInfo.Currency,
- IsMain = tasModel.TaAccountInfo.IsMain,
- ParentAccountID = tasModel.TaAccountInfo.ParentAccountID,
- TAAccountType = tasModel.TaAccountInfo.TAAccountType,
- RelatedMainAccountID = tasModel.TaAccountInfo.RelatedMainAccountID,
- Balance = (decimal)tasModel.TaAccountInfo.Balance,// 期初余额
- CurrentBalance = (decimal)tasModel.TaAccountInfo.CurrentBalance,// 期末余额
- UsedMargin = (decimal)tasModel.TaAccountInfo.UsedMargin,// 占用保证金
- FreezeMargin = (decimal)tasModel.TaAccountInfo.FreezeMargin,// 冻结保证金
- OtherFreezeMargin = (decimal)tasModel.TaAccountInfo.OtherFreezeMargin,
- FreezeCharge = (decimal)tasModel.TaAccountInfo.FreezeCharge,
- MortgageCredit = (decimal)tasModel.TaAccountInfo.MortgageCredit,
- OtherCredit = (decimal)tasModel.TaAccountInfo.OtherCredit,
- OutAmountFreeze = (decimal)tasModel.TaAccountInfo.OutAmountFreeze,
- OutAmount = (decimal)tasModel.TaAccountInfo.OutAmount,// 今日出金
- InAmount = (decimal)tasModel.TaAccountInfo.InAmount,// 今日入金
- PayCharge = (decimal)tasModel.TaAccountInfo.PayCharge,
- CreditIncrease = (decimal)tasModel.TaAccountInfo.CreditIncrease,
- CreditDecrease = (decimal)tasModel.TaAccountInfo.CreditDecrease,
- OtherCreditIncrease = (decimal)tasModel.TaAccountInfo.OtherCreditIncrease,
- OtherCreditDecrease = (decimal)tasModel.TaAccountInfo.OtherCreditDecrease,
- TransferAmount = (decimal)tasModel.TaAccountInfo.TransferAmount,
- OtherPay = (decimal)tasModel.TaAccountInfo.OtherPay,
- OtherIncome = (decimal)tasModel.TaAccountInfo.OtherIncome,
- ClosePL = (decimal)tasModel.TaAccountInfo.ClosePL,// 今日平仓盈亏
- OutThreshold = (decimal)tasModel.TaAccountInfo.OutThreshold, // 出金阀值
- CurrencyID = tasModel.TaAccountInfo.Currencyid, //todo:服务端需返回此字段
- };
- model.FundsAccounts = fundsAccounts;
- #endregion
- #region 持仓头寸列表
- foreach (var item in tasModel.TradePositionList)
- {
- var goodsPM = new TradePositionModel()
- {
- GoodsId = item.GoodsId, // 商品id
- BuyFrozenQty = item.BuyFrozenQty, // 买持仓冻结
- BuyOtherFrozenQty = item.BuyOtherFrozenQty, // 买持仓其他冻结
- SellFrozenQty = item.SellFrozenQty, // 卖持仓冻结
- SellOtherFrozenQty = item.SellOtherFrozenQty, // 卖持仓其他冻结
- BuyCurPositionQty = item.BuyCurPositionQty, //买当前持仓数量 uint32
- BuyCurHolderAmount = item.BuyCurHolderAmount, //买当前持仓金额 double
- SellCurPositionQty = item.SellCurPositionQty, //卖当前持仓数量 uint32
- SellCurHolderAmount = item.SellCurHolderAmount, //卖当前持仓金额 double
- };
- goodsPositionList.Add(goodsPM);
- }
- model.GoodsPositionList = goodsPositionList;
- #endregion
- #region 市场权限列表
- foreach (var item in tasModel.MarketsIdList)
- {
- marketsIdList.Add(item);
- }
- model.MarketsIdList = marketsIdList;
- #endregion
- return model;
- }
- /// <summary>
- /// 商品交易规则和费用规则列表转换
- /// </summary>
- /// <param name="accountInfos"></param>
- /// <returns></returns>
- private List<Data.Model.GoodRules.TradeGoodsFeeRule> ToLocalGoodsRuleAndFeeList(List<tas.GoodsRuleAndFee> goodsRuleAndFee)
- {
- var ruleAndFeeList = new List<Data.Model.GoodRules.TradeGoodsFeeRule>();
- if (goodsRuleAndFee == null || goodsRuleAndFee.Count <= 0)
- {
- return ruleAndFeeList;
- }
- foreach (var item in goodsRuleAndFee)
- {
- var feeRule = ConverFeeRuleType(item);
- ruleAndFeeList.Add(feeRule);
- }
- return ruleAndFeeList;
- }
- /// <summary>
- /// 最后更新时间列表
- /// </summary>
- /// <param name="accountInfos"></param>
- /// <returns></returns>
- private List<LastUpdateTimeKeyValueModel> ToLocalLastUpdateTimeList(List<tas.ParamValue> lastUpdateTimeKeyValue)
- {
- var lastUpdateTimeList = new List<LastUpdateTimeKeyValueModel>();
- if (lastUpdateTimeKeyValue == null || lastUpdateTimeKeyValue.Count <= 0)
- {
- return lastUpdateTimeList;
- }
- foreach (var item in lastUpdateTimeKeyValue)
- {
- if (string.IsNullOrEmpty(item.Key))
- {
- continue;
- }
- var itemKeyValue = ConverLastUpdateTime(item);
- lastUpdateTimeList.Add(itemKeyValue);
- }
- return lastUpdateTimeList;
- }
- /// <summary>
- /// 最后更新时间列表ITEM 转换
- /// </summary>
- /// <param name="goodsInce"></param>
- /// <returns></returns>
- private LastUpdateTimeKeyValueModel ConverLastUpdateTime(tas.ParamValue tasModel)
- {
- var model = new LastUpdateTimeKeyValueModel()
- {
- TimeKey = (LastUpdateTimeType)Convert.ToInt16(tasModel.Key),
- TimeValue = tasModel.Value
- };
- return model;
- }
- //============================MTP2.0 above==================================================
- public override ResponeEntity<TradeAccount> ToLocalAccountEntity(object obj)
- {
- return new ResponeEntity<TradeAccount>();
- //var protoObject = obj as ProtobufAccount;
- //if (null == protoObject) return null;
- //return new TradeAccount()
- //{
- // //初始化值
- //};
- }
- public override ResponeEntity<TradeAccount> ToLocalLoginEntity(object obj)
- {
- var byteArr = obj as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var loginRsq = ProtoBufHelper.EntityDeSerialize<LoginRsp>(byteArr);
- var result = new ResponeEntity<TradeAccount>()
- {
- RetCode = loginRsq.RetCode,
- RetMessage = loginRsq.RetDesc,
- Entity = new TradeAccount()
- {
- AccountStatus = (eAccountStatus)loginRsq.AccountStatus,
- AccountType = (eUserType)loginRsq.LoginUserType,
- LoginID = loginRsq.LoginID,
- MemberAreaId = (uint)loginRsq.MemberUserID,
- SystemTime = loginRsq.SystemTime,
- Token = loginRsq.Token,
- FundsAccountIds = loginRsq.AccountIDs,
- CustomerId = loginRsq.UserID,
- HasUpdatedPwd = loginRsq.HasUpdatedPwd,
- PwdWrongCnt = loginRsq.PwdWrongCnt,
- PwdWrongLockCnt = loginRsq.PwdWrongLockCnt,
- LoginLockHourNum = loginRsq.LoginLockHourNum,
- }
- };
- if (loginRsq.Header != null && loginRsq.RetCode == 0)
- {
- loginRsq.Header.UserID = loginRsq.UserID;
- result.Entity.FundsAccountId = loginRsq.Header.AccountID;
- ProtoBufHelper.Head = loginRsq.Header; ////保存头内容
- }
- return result;
- }
- /// <summary>
- /// To the reqeust login.
- /// </summary>
- /// <param name="loginType">Type of the login.</param>
- /// <param name="passWord">The pass word.</param>
- /// <param name="loginID">The login code.</param>
- /// <param name="guid">The unique identifier.</param>
- /// <param name="loginIP">login IP Address.</param>
- /// <param name="systemDesc">The system desc.</param>
- /// <returns>System.Byte[][].</returns>
- public override byte[] ToReqeustLogin(int loginType, string passWord, ulong loginID, string guid, string loginIP, string systemDesc, string version)
- {
- var loginReq = new LoginReq()
- {
- LoginPWD = passWord,
- ClientType = (int)eClientType.CLIENTTYPE_PC_TRADE_CLIENT,
- LoginType = (uint)loginType,
- LoginID = loginID,
- LoginIp = loginIP,
- GUID = guid,
- DeviceID = string.Empty,
- Version = version,
- EnvironmentInfo = systemDesc,
- };
- var uuid = Guid.NewGuid();
- loginReq.Header = new MessageHead() { UUID = uuid.ToString() };
- return ProtoBufHelper.EntitySerialize(loginReq, false);
- }
- /// <summary>
- /// 交易端登出
- /// </summary>
- /// <returns></returns>
- public override byte[] ToReqeustLogOut(ulong loginID)
- {
- var logOutReq = new LogoutReq() { LoginID = loginID };
- return ProtoBufHelper.EntitySerialize(logOutReq);
- }
- /// <summary>
- /// 商品组信息转换=>市场信息转换
- /// </summary>
- /// <param name="goodsGroupInfos">商品组信息=>市场信息</param>
- /// <param name="exchanges">The exchanges.</param>
- /// <returns>System.Collections.Generic.List{Muchinfo.TASClient.Data.Model.Market}.</returns>
- private List<Muchinfo.MTPClient.Data.Model.GoodsGroup> ToLocalGoodsGroupsInfo(List<MarketsInfo> goodsGroupInfos)
- {
- var goodsGroups = new List<Muchinfo.MTPClient.Data.Model.GoodsGroup>();
- if (goodsGroupInfos == null || goodsGroupInfos.Count <= 0)
- {
- return goodsGroups;
- }
- foreach (var item in goodsGroupInfos)
- {
- var goodsGroup = new Muchinfo.MTPClient.Data.Model.GoodsGroup()
- {
- MarketTypeID = (int)item.MarketID,
- GoodsGroupName = item.MarketName,
- TradeMode = (eTradeMode)item.TradeMode,
- //GoodsGroupCode = item.GoodsGroupCode,
- //GoodsGroupName = item.GoodsGroupName,
- //GoodsGroupLevelTypeID = item.GoodsGroupLevelTypeID,
- //GoodsGroupid = item.GoodsGroupid,
- //MarketTypeID = item.MarketTypeID,
- //ReckonMode = (ReckonModeType)item.ReckonMode,
- //TradeMode = (eTradeMode)item.TradeMode,
- //ExchAreaId = item.ExchAreaId,
- //ParentGoodsGroupId = item.ParentGoodsGroupId,
- };
- goodsGroups.Add(goodsGroup);
- }
- return goodsGroups;
- }
- /// <summary>
- /// 资金账户转换
- /// </summary>
- /// <param name="taAccountInfos"></param>
- /// <returns></returns>
- private FundsAccount ToLocalFundsAccounts(TaAccountInfo taAccountInfos)
- {
- return new FundsAccount();
- }
- /// <summary>
- /// 交易账号信息转换
- /// </summary>
- /// <param name="accountInfos"></param>
- /// <returns></returns>
- private TradeAccount ToLocalTradeAccount(AccountInfo accountInfos)
- {
- if (null == accountInfos)
- {
- //todo:异常信息提示
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "查询账号信息异常!");
- }
- return new TradeAccount()
- {
- CustomerId = accountInfos.UserID,
- MemberAreaId = accountInfos.ParentUserID,
- CustomerName = accountInfos.AccountName
- };
- }
- /// <summary>
- /// 商品信息参数配置
- /// </summary>
- /// <param name="goodsInfos">The goods infos.</param>
- /// <param name="goodsGroups">The goods groups.</param>
- /// <returns>List{LocalEntity.Exchange}.</returns>
- public List<QuoteGoods> ToLocalGoodsList(List<GoodsInfo> goodsInfos, List<Muchinfo.MTPClient.Data.Model.GoodsGroup> goodsGroups)
- {
- var goodsList = new List<QuoteGoods>();
- if (null == goodsInfos || goodsInfos.Count <= 0)
- {
- return goodsList;
- }
- foreach (var serviceEntity in goodsInfos)
- {
- if (serviceEntity == null)
- {
- continue;
- }
- var goodsGroup = goodsGroups.FirstOrDefault(z => z.GoodsGroupid == serviceEntity.MarketID);
- if (goodsGroup == null) continue;
- var entity = new GoodsParameters()
- {
- AgreeUnit = Convert.ToDecimal(serviceEntity.AgreeUnit),
- GoodsCode = serviceEntity.GoodsCode,
- GoodsId = serviceEntity.GoodsId,
- GoodsName = serviceEntity.GoodsName,
- ExchAreaID = goodsGroup.ExchAreaId,
- TradeMode = goodsGroup.TradeMode, // 交易模式
- ////todo:服务未返回,设置调试值
- ReckonRate = 1,
- };
- //DateTime listedtime;
- //if (DateTime.TryParse(serviceEntity.ListedTime, out listedtime))
- //{
- // entity.ListedTime = listedtime;
- //}
- var quoteGoods = ToQuoteGoods(entity);
- goodsList.Add(quoteGoods);
- }
- return goodsList;
- }
- private QuoteGoods ToQuoteGoods(GoodsParameters parameter)
- {
- if (parameter == null) return null;
- //todo:商品类别
- //var sort = dataModel.Sort.ToString();
- var category = QuoteCategoryType.PreciousMetal; //GoodsSortHelper.GetQuoteCategoryBySorts(sort);
- return new QuoteGoods(parameter.ExchHqCode, parameter.GoodsCode, parameter.GoodsHqCode, category)
- {
- ListingStatus = parameter.GoodsStatus.ToString(), // ListStatus.ToString(),
- //LotUnit = dataModel.LotSize,
- Name = parameter.GoodsName,
- GoodsId = (uint)parameter.GoodsId,
- // QuoteCurrency = parameter.QuoteCurrency, //PriceCurrency,
- // QuoteUnit = parameter.PriceUnit.ToString(),
- // Sort = QuoteCategoryType.PreciousMetal.ToString(), //sort,
- GoodsParameters = parameter,
- TradeMode = parameter.TradeMode,
- DecimalPlaces = parameter.HqExchFigures,
- //RelevanceCode = dataModel.RelevanceCode,
- //SectorCode = dataModel.Sector2,推荐
- };
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="obj"></param>ToLocalLoginEntity
- /// <returns></returns>
- public override ResponeEntity<Data.Model.AccountInfoEntity> TolocalAccountInfoEntity(object obj)
- {
- return null;
- //var byteArr = obj as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var accountRespone = ProtoBufHelper.EntityDeSerialize<QueryAccountAndGoodsRsp>(byteArr);
- //var resultEntity = new ResponeEntity<AccountInfoEntity>()
- //{
- // RetCode = accountRespone.RetCode,
- // RetMessage = accountRespone.RetDesc,
- // Entity = new AccountInfoEntity(),
- //};
- //if (accountRespone.Rsps == null || !accountRespone.Rsps.Any())
- //{
- // //todo:查询内容空
- // return resultEntity;
- //}
- //var account = resultEntity.Entity;
- //account.GoodsGroups = ToLocalGoodsGroupsInfo(accountRespone.Rsps[0].GoodsGroupInfoRsps); //市场
- //account.QuoteGoodses = ToLocalGoodsList(accountRespone.Rsps[0].GoodsInfoRsps, account.GoodsGroups); ////商品信息
- // account.FundsAccounts = ToLocalFundsAccounts(accountRespone.Rsps[0].TaAccountInfoRsps); //资金账号 单独查询资金信息
- //account.TradeAccount = ToLocalTradeAccount(accountRespone.Rsps[0].AccountInfoRsps); ////交易账号
- //if (account.FundsAccounts != null && account.FundsAccounts.Any() && account.TradeAccount!=null) ////设置会员证件
- //{
- // account.TradeAccount.MemberCardType = account.FundsAccounts[0].CardType;
- // account.TradeAccount.MemberCardNum = account.FundsAccounts[0].CardNum;
- //}
- //return resultEntity;
- }
- /// <summary>
- /// 账号基本信息查询与交易所市场商品信息
- /// </summary>
- /// <param name="accountId">The account identifier.</param>
- /// <returns>System.Byte[][].</returns>
- public override byte[] ToReqeustAccountInfo(ulong accountId)
- {
- return null;
- //var accountGoodsReq = new QueryAccountAndGoodsReq()
- //{
- // Header = new MessageHead() { },
- // AccountId = accountId,
- //};
- //return ProtoBufHelper.EntitySerialize(accountGoodsReq);
- }
- /// <summary>
- /// 请求校验Token的Protobuf对象装箱方法
- /// </summary>
- /// <param name="token"></param>
- /// <returns></returns>
- public override byte[] ToTokenCheck(ulong loginID, string token, ulong octTime)
- {
- var tokenCheckReq = new TokenCheckReq()
- {
- LoginID = loginID,
- Token = token,
- SystemTime = octTime
- };
- return ProtoBufHelper.EntitySerialize(tokenCheckReq);
- }
- /// <summary>
- /// 从检验Token返回信息中获取Token状态的方法
- /// </summary>
- /// <param name="obj">检验Token返回信息</param>
- /// <returns>Token状态值</returns>
- public override ResponeEntity<ulong> GetTokenStatus(object obj)
- {
- var byteArr = obj as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var tokenCheckRsp = ProtoBufHelper.EntityDeSerialize<TokenCheckRsp>(byteArr);
- var resultEntity = new ResponeEntity<ulong>
- {
- RetCode = tokenCheckRsp.RetCode,
- RetMessage = tokenCheckRsp.RetDesc,
- Entity = tokenCheckRsp.SystemTime //服务器时间
- };
- return resultEntity;
- }
- /// <summary>
- /// 转换修改密码
- /// </summary>
- /// <param name="accountPwds"></param>
- /// <returns></returns>
- public override byte[] ToReqeustModifyPwds(AccountPwds accountPwds)
- {
- var modifyPwdReq = new ModifyPwdReq()
- {
- ModifyPwdType = accountPwds.ModifyPwdType,
- ModifyPwdID = accountPwds.ModifyPwdID,
- NewPwd = accountPwds.NewPwd,
- OldPwd = accountPwds.OldPwd
- };
- return ProtoBufHelper.EntitySerialize(modifyPwdReq);
- }
- /// <summary>
- /// 解释修改密码返回对象
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public override ResponeEntity<int> ResponeModifyPWDEntity(object obj)
- {
- var byteArr = obj as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var modifyPwd = ProtoBufHelper.EntityDeSerialize<ModifyPwdRsp>(byteArr);
- var responeEntity = new ResponeEntity<int>()
- {
- RetCode = modifyPwd.RetCode,
- RetMessage = modifyPwd.RetDesc,
- };
- return responeEntity;
- }
- public override byte[] ToReqeustFuncMenu(string loginCode)
- {
- return null;
- //var modifyPwdReq = new QueryAccountFuncMenuReq()
- //{
- // LoginCode = loginCode,
- // RoleType = 0, ////客户端类型
- //};
- //return ProtoBufHelper.EntitySerialize(modifyPwdReq);
- }
- public override ResponeEntity<List<SysMenuItem>> ResponeLocalFuncMenu(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var menusRespone = ProtoBufHelper.EntityDeSerialize<FuncMenuRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<SysMenuItem>>()
- {
- RetCode = menusRespone.RetCode,
- RetMessage = menusRespone.RetDesc,
- Entity = new List<SysMenuItem>(),
- };
- if (menusRespone.FuncMenuList == null || !menusRespone.FuncMenuList.Any())
- {
- //todo:查询内容空
- return resultEntity;
- }
- foreach (var queryAccount in menusRespone.FuncMenuList)
- {
- var menu = BuildFuncMenu(queryAccount);
- resultEntity.Entity.Add(menu);
- }
- if (resultEntity.Entity != null) ////对子菜单进行排序
- {
- resultEntity.Entity = resultEntity.Entity.OrderBy((item) => item.SortId).ToList();
- }
- return resultEntity;
- }
- /// <summary>
- /// 生成树菜单
- /// </summary>
- /// <returns></returns>
- private SysMenuItem BuildFuncMenu(tas.FuncMenu menus)
- {
- var localMenu = new SysMenuItem(menus.FuncMenuName)
- {
- FuncMenuCode = menus.FuncMenuCode,
- ParentFuncMenuCode = menus.Parentfuncmenucode,
- Children = new List<SysMenuItem>(),
- };
- foreach (var funcMenuList in menus.SonMenus)
- {
- var childMenu = BuildFuncMenu(funcMenuList);
- if (childMenu.Children != null) ////对子菜单进行排序
- {
- childMenu.Children = childMenu.Children.OrderBy((item) => item.SortId).ToList();
- }
- localMenu.Children.Add(childMenu);
- }
- if (localMenu.Children != null) ////对子菜单进行排序
- {
- localMenu.Children = localMenu.Children.OrderBy((item) => item.SortId).ToList();
- }
- return localMenu;
- }
- /// <summary>
- /// 转换请求
- /// </summary>
- /// <param name="accountid"></param>
- /// <returns></returns>
- public override byte[] ToReqeustTradeFeeRules(uint accountid)
- {
- //var tradeRulesReq = new QueryAccountAndGoodsReq()
- //{
- // AccountId = accountid,
- //};
- //return ProtoBufHelper.EntitySerialize(tradeRulesReq);
- return null;
- }
- public override ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>> ResoneLocalGoodsFeeRules(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (data == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var goodsResult=ProtoBufHelper.EntityDeSerialize<QueryAccountGoodsTypeRsp>(byteArr);
- //var resultEntity = new ResponeEntity<List<Data.Model.GoodRules.TradeGoodsFeeRule>>()
- //{
- // RetCode = goodsResult.RetCode,
- // RetMessage = goodsResult.RetDesc,
- // Entity = new List<Data.Model.GoodRules.TradeGoodsFeeRule>(),
- //};
- //if (goodsResult.Rsps == null || !goodsResult.Rsps.Any())
- //{
- // //todo:查询内容空
- // return resultEntity;
- //}
- //foreach (var rspItem in goodsResult.Rsps)
- //{
- // var goodsFeeRules = new Dictionary<int, TradeGoodsFeeRule>();
- // foreach (var goodsRules in rspItem.GoodsRuleAndFee)
- // {
- // var feeRule = ConverFeeRuleType(goodsRules);
- // resultEntity.Entity.Add(feeRule);
- // //goodsFeeRules[feeRule.GoodsID].GoodsFees[feeRule.] = goodsFeeType;
- // }
- //}
- //return resultEntity;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="goodsInce"></param>
- /// <returns></returns>
- private Data.Model.GoodRules.TradeGoodsFeeRule ConverFeeRuleType(tas.GoodsRuleAndFee goodsInce)
- {
- var feeRule = new Data.Model.GoodRules.TradeGoodsFeeRule();
- feeRule.GoodsID = goodsInce.GoodsID;
- ////商品交易规则
- foreach (var goodsFeeType in goodsInce.GoodsRuleList)
- {
- var rule = new Data.Model.GoodRules.GoodsRuleModel()
- {
- Ruleid = goodsFeeType.Ruleid,
- RuleName = goodsFeeType.RuleName,
- ParamValue = goodsFeeType.ParamValue
- };
- feeRule.GoodsRuleList.Add(rule);
- }
- return feeRule;
- }
- public override byte[] ToReqeustRiskChecked(ulong accountid, uint isChecked)
- {
- return null;
- //var riskReq = new RiskCheckNotifyReq()
- //{
- // AccountId = (uint)accountid,
- // IsChecked = isChecked,
- //};
- //return ProtoBufHelper.EntitySerialize(riskReq);
- }
- public override ResponeEntity<uint> ResponeRiskChecked(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var riskChecked = ProtoBufHelper.EntityDeSerialize<RiskCheckNotifyRsp>(byteArr);
- //var responeEntity = new ResponeEntity<uint>()
- //{
- // RetCode = riskChecked.RetCode,
- // RetMessage = riskChecked.RetDesc,
- // Entity = riskChecked.AccountId,
- //};
- //return responeEntity;
- }
- public override byte[] ToReqeustDeliveryGoodsReq(ulong DeliveryGoodsUTime)
- {
- var baseQueryReq = new DeliveryGoodsQueryReq()
- {
- Header = new MessageHead() { },
- DeliveryGoodsUTime = DeliveryGoodsUTime
- };
- return ProtoBufHelper.EntitySerialize(baseQueryReq);
- }
- public override ResponeEntity<List<DeliveryGoodsInfoModel>> ResponeDeliveryGoodsReq(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemResponeList = ProtoBufHelper.EntityDeSerialize<DeliveryGoodsQueryRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<DeliveryGoodsInfoModel>>()
- {
- RetCode = itemResponeList.RetCode,
- RetMessage = itemResponeList.RetDesc,
- Entity = new List<DeliveryGoodsInfoModel>() { }
- };
- foreach (var item in itemResponeList.DeliveryGoodsList)
- {
- var good = ToLocalDeliveryGoodsInfo(item);
- resultEntity.Entity.Add(good);
- }
- return resultEntity;
- }
- private DeliveryGoodsInfoModel ToLocalDeliveryGoodsInfo(DeliveryGoodsInfo goods)
- {
- var item = new DeliveryGoodsInfoModel()
- {
- DeliveryGoodsID = goods.DeliveryGoodsID,
- DeliveryGoodsCode = goods.DeliveryGoodsCode,
- DeliveryGoodsName = goods.DeliveryGoodsName,
- AuditFlag = goods.AuditFlag,
- GoodsUnit = goods.GoodsUnit,
- StandardQty = goods.StandardQty,
- StandardQtyRange = goods.StandardQtyRange,
- DeliveryGoodsPMList = ToLocalPriceMove(goods.DeliveryGoodsPMList)
- };
- return item;
- }
- /// <summary>
- /// 查询外部交易所请求
- /// </summary>
- /// <returns></returns>
- public override byte[] ToExternalExchangeReq()
- {
- var externalExchangeReq = new ExternalExchangeReq()
- {
- Header = new MessageHead() { },
- };
- return ProtoBufHelper.EntitySerialize(externalExchangeReq);
- }
- /// <summary>
- /// 查询外部交易所响应
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override ResponeEntity<List<Muchinfo.MTPClient.Data.Model.ExternalExchangeModel>> ResponseExternalExchange(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemResponeList = ProtoBufHelper.EntityDeSerialize<ExternalExchangeRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<ExternalExchangeModel>>()
- {
- RetCode = itemResponeList.RetCode,
- RetMessage = itemResponeList.RetDesc,
- Entity = new List<ExternalExchangeModel>() { }
- };
- foreach (var item in itemResponeList.ExternalExchangeList)
- {
- var externalExchange = BufToMarketsInfo(item);
- resultEntity.Entity.Add(externalExchange);
- }
- return resultEntity;
- }
- /// <summary>
- /// 外部对象转内部对象
- /// </summary>
- /// <param name="tasModel"></param>
- /// <returns></returns>
- private ExternalExchangeModel BufToMarketsInfo(ExternalExchange tasModel)
- {
- var localModel = new ExternalExchangeModel()
- {
- AutoID = tasModel.AutoID,
- ExExchangeCode = tasModel.ExExchangeCode,
- ExExchangeName = tasModel.ExExchangeName,
- IsMarketPrice = tasModel.IsMarketPrice
- };
- return localModel;
- }
- /// <summary>
- /// 查询商品组请求
- /// </summary>
- /// <returns></returns>
- public override byte[] ToGoodsGroupReq()
- {
- var externalExchangeReq = new GoodsGroupReq()
- {
- Header = new MessageHead() { },
- };
- return ProtoBufHelper.EntitySerialize(externalExchangeReq);
- }
- /// <summary>
- /// 查询商品组响应
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override ResponeEntity<List<Data.Model.GoodsGroup>> ResponseGoodsGroup(object data)
- {
- var byteArr = data as byte[];
- if (data == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var itemResponeList = ProtoBufHelper.EntityDeSerialize<GoodsGroupRsp>(byteArr);
- var resultEntity = new ResponeEntity<List<Data.Model.GoodsGroup>>()
- {
- RetCode = itemResponeList.RetCode,
- RetMessage = itemResponeList.RetDesc,
- Entity = new List<Data.Model.GoodsGroup>() { }
- };
- foreach (var item in itemResponeList.GoodsGroupList)
- {
- var goodsGroup = new Data.Model.GoodsGroup()
- {
- GoodsGroupid = item.GoodsGroupID,
- GoodsGroupName = item.GoodsGroupName,
- MarketTypeID = (int)item.MarketID,
- ExChangeId = item.ExExchangeID,
- CanShort = item.CanShort
- };
- resultEntity.Entity.Add(goodsGroup);
- }
- return resultEntity;
- }
- }
- }
|