| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630 |
- //----------------------------------------------------------------
- //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,
- ClientSystemInfo = loginRsq.ClientSystemInfo,
- ClientId = loginRsq.ClientID
- }
- };
-
- 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, byte[] clientSystemInfo, string clientAppID)
- {
- 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,
- ClientAppID = clientAppID,
- };
- // CTP
- if (clientSystemInfo != null)
- {
- loginReq.ClientSystemInfo = clientSystemInfo;
- }
- 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;
- }
- }
- }
|