| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/1/27 20:38:55
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Linq;
- using Muchinfo.MTPClient.Adapter.Abstract;
- using Muchinfo.MTPClient.Adapter.Utilities;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.Listing;
- using Muchinfo.MTPClient.Data.Model.Message;
- using Muchinfo.MTPClient.Data.Quote;
- using tas;
- using Muchinfo.MTPClient.Data.Model.Delivery;
- namespace Muchinfo.MTPClient.Adapter.ProtoBuf
- {
- public class MassageProbufAdapter : MessageAdapter
- {
- public override Data.Model.OrderCompleteArg ComplateNotice(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var orderDealed = ProtoBufHelper.EntityDeSerialize<OrderDealedNtf>(byteArr);
- var result = new OrderCompleteArg()
- {
- OrderId = (long)orderDealed.OrderID,
- AccountId = orderDealed.AccountID,
- ActiveQty = orderDealed.ActiveQty,
- Direction = (Direction)orderDealed.BuyOrSell,
- EntrustQty = Convert.ToDecimal(orderDealed.OrderQty),
- Amount = Convert.ToDecimal(orderDealed.Amount),
- TradeQuantity = Convert.ToDecimal(orderDealed.TradeQty),
- OrderType = (eOrderType)orderDealed.OrderType,
- TradeTime = orderDealed.TradeTime,
- TradeCharge = Convert.ToDecimal(orderDealed.TradeCharge),
- TradePrice = Convert.ToDecimal(orderDealed.TradePrice),
- // OperatorCode = orderDealed.OperatorID,
- // GoodsCode = orderDealed.GoodsID
- };
- return result;
- }
- /// <summary>
- /// 头寸变化通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override Data.Model.PosChangedNtfModel PosChangedReturnMessage(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var model = ProtoBufHelper.EntityDeSerialize<PosChangedNtf>(byteArr);
- var result = new PosChangedNtfModel()
- {
- AccountID = model.AccountID,
- //BuyOrSell = model.BuyOrSell,
- //FreezeQty = model.FreezeQty,
- GoodsID = model.GoodsID,
- //HolderAmount = model.HolderAmount,
- //HoldQty = model.HoldQty,
- //ReckonPL = model.ReckonPL,
- //RetCode = model.RetCode,
- //TradeAmount = model.TradeAmount,
- //UsedMargin = model.UsedMargin
-
- };
- return result;
- }
- /// <summary>
- /// 市场状态变更通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override Data.Model.MarketStatusChangeNtfModel MarketStatusChangeNtf(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var model = ProtoBufHelper.EntityDeSerialize<MarketStatusChangeNtf>(byteArr);
- var result = new MarketStatusChangeNtfModel()
- {
- MarketId = model.MarketID,
- Status = model.Status,
- TradeDay = model.TradeDay,
- NotifyTime = model.NotifyTime
- };
- return result;
- }
- public override string ConvertAmountNotice(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var notice = ProtoBufHelper.EntityDeSerialize<MoneyChangedNtf>(byteArr);
- //var result = new AmountArg()
- //{
- // AvailMarginLimit=(decimal)notice.AvailMarginLimit,
- // Currency=notice.Currency,
- // CurrentNetWorth=(decimal)notice.CurrentNetWorth,
- // FreezeMargin=(decimal)notice.FreezeMargin,
- // MaxUsedMargin=(decimal)notice.MaxUsedMargin,
- // UsedMargin=(decimal)notice.UsedMargin,
- //};
- string result = notice.AccountID.ToString();
- return result;
- }
- public override RiskControl RiskCtrlBltNotice(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var riskCtrlBltNotice = ProtoBufHelper.EntityDeSerialize<RiskCtrlBltRsp>(byteArr);
- //var result = new RiskControl()
- //{
- // //SendType = false,
- // //Content = Encoding.UTF8.GetString(notifyBulletin.Content),
- // //MsgID = notifyBulletin.MsgID,
- // //PublishDate = ToDateTime(notifyBulletin.PublishDate),
- // //Title = Encoding.UTF8.GetString(notifyBulletin.Title),
- // //ValidDate = ToDateTime(notifyBulletin.ValidDate),
- // //MsgType =(Muchinfo.MTPClient.Data.Enums.MsgTypeEnum)notifyBulletin.MsgType,
- // //RiskLevel = notifyBulletin.RiskLevel,
- // //PubExchName = notifyBulletin.PubExchName,
- // //PubAccountCode = notifyBulletin.PubAccountCode,
- // //AccountStatus = (Muchinfo.MTPClient.Data.Enums.AccountStatus)riskCtrlBltNotice.AccountStatus, -- 风控不改状态,不用赋值
- // Date = riskCtrlBltNotice.Idate,
- // LoginCode = riskCtrlBltNotice.LoginCode,
- // MemberCode = riskCtrlBltNotice.MemberId.ToString(),
- // MsgRate = riskCtrlBltNotice.MsgRate,
- // RealRate = riskCtrlBltNotice.RealRate,
- // RiskLevel = riskCtrlBltNotice.RiskLevel,
- //};
- //return result;
- }
- public static DateTime ToDateTime(string dateTime)
- {
- DateTime date = DateTime.MinValue;
- DateTime.TryParse(dateTime, out date);
- return date;
- }
- public static T ToEnum<T>(int value)
- {
- object eValue = value;
- object defaultEnum = 0;
- var type = typeof(T);
- if (System.Enum.IsDefined(type, eValue))
- {
- return (T)eValue;
- }
- else
- {
- var v = System.Enum.GetValues(type);
- return (T)v.GetValue(0);
- }
- }
- public override NoticeMsg NotifyBulletin(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var bltMsgNtf = ProtoBufHelper.EntityDeSerialize<BltMsgNtf>(byteArr);
- var result = new NoticeMsg()
- {
- //CONTENT = Encoding.UTF8.GetString(bltMsgNtf.Content),
- //MSG_ID= bltMsgNtf.MsgID,
- //TITLE = Encoding.UTF8.GetString(bltMsgNtf.Title),
- //PubAccountCode = bltMsgNtf.PubAccountId.ToString(),
- //MsgType = (Muchinfo.MTPClient.Data.Enums.MsgTypeEnum)bltMsgNtf.MsgType,
- SCHEDULE_TIME = ToDateTime(bltMsgNtf.PublishDate),
- //todo:对比字段
- Sending_Time = ToDateTime(bltMsgNtf.PublishDate),
- //MemberIds = ToEntityIds(bltMsgNtf.MemberIds),
- //ExchID=ToEntityIds(bltMsgNtf.ExchID),
- //ValidDateBegin=bltMsgNtf.ValidDateBegin,
- //ValidDateEnd=bltMsgNtf.ValidDateEnd,
-
- };
- return result;
- }
-
- /// <summary>
- /// 开休市计划通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override List<MarketTypeStatus> MarketStatusChangeNotifyAd(object data)
- {
- return null;
- // var byteArr = data as byte[];
- // if (byteArr == null)
- // {
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- // }
- // var remoteModels = ProtoBufHelper.EntityDeSerialize<MarketStatusChangeNotify>(byteArr);
- //var results =remoteModels.MarketStatusChanges.ToList();
- // var marketypes = new List<MarketTypeStatus>();
- // foreach (var marketStatus in results)
- // {
- // var tem = new MarketTypeStatus()
- // {
- // Id =(int) marketStatus.MarketTypeId,
- // TradeDay = marketStatus.TradeDate,
- // Type =marketStatus.SignalType
- // };
- // marketypes.Add(tem);
- // }
- // //SignalType = (SignalTypeEnum)remoteModel.SignalType,
- // //ControlTime = remoteModel.ControlTime,
- // //MarketTypeId = remoteModel.MarketTypeId,
- // //GoodsId = ToEntityUintIds(remoteModel.GoodsId),
- // //RunStatus = (eRunStatus)remoteModel.RunStatus,
- // //RunStep = (eRunStep)remoteModel.RunStep,
- // //NextTradeDate = remoteModel.NextTradeDate,
- // //TradeDate = remoteModel.TradeDate,
- // //OpenMarketDate = remoteModel.OpenMarketDate,
- // //LastTradeDateOfWeek = remoteModel.LastTradeDateOfWeek,
- // return marketypes;
- }
- public override RiskControl RiskCtrlMemberNotice(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var riskCtrlBltNotice = ProtoBufHelper.EntityDeSerialize<RiskControlMsg>(byteArr);
- //var result = new RiskControl()
- //{
-
- // Date = riskCtrlBltNotice.Date,
- // LoginCode = riskCtrlBltNotice.LoginCode,
- // MemberCode = riskCtrlBltNotice.MemberId.ToString(),
- // MsgRate = riskCtrlBltNotice.MsgRate,
- // RealRate = riskCtrlBltNotice.RealRate,
- // RiskLevel = riskCtrlBltNotice.RiskLevel,
- //};
- //return result;
- }
- public override RiskControl RiskCtrlMemberBreak(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var riskCtrlBltNotice = ProtoBufHelper.EntityDeSerialize<RiskCtrlMemRsp>(byteArr);
- //var result = new RiskControl()
- //{
- // Date = riskCtrlBltNotice.Idate,
- // LoginCode = riskCtrlBltNotice.LoginCode,
- // MemberCode = riskCtrlBltNotice.MemberId.ToString(),
- // MsgRate = riskCtrlBltNotice.MsgRate,
- // RealRate = riskCtrlBltNotice.RealRate,
- // AccountStatus = (eAccountStatus)riskCtrlBltNotice.AccountStatus,
- //};
- //return result;
- }
- public override PrepostTransferOrder PrepostTransferOrderNtf(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var prepostOrder = ProtoBufHelper.EntityDeSerialize<PrepostTransferOrderNtf>(byteArr);
- //var result = new PrepostTransferOrder()
- //{
- // ClientSerialNo = prepostOrder.ClientSerialNo,
- // PrepostID = prepostOrder.PrepostID,
- // PrepostStatus = prepostOrder.PrepostStatus,
- // GoodsID = prepostOrder.GoodsID,
- //};
- //return result;
- }
- /// <summary>
- /// 交收审核通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override DeliveryAuditNtfModel DeliveryReturnMessage(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var model = ProtoBufHelper.EntityDeSerialize<DeliveryAuditNtf>(byteArr);
- var result = new DeliveryAuditNtfModel()
- {
- //RetCode = model.RetCode,
- //OrderID = model.OrderID,
- //GoodsID = model.GoodsID,
- //AccountID = model.AccountID,
- //BuyOrSell = model.BuyOrSell,
- //OrderQty = model.OrderQty,
- //Result = model.Result,
- OperatorID = model.OperatorID,
- };
- return result;
- }
-
- /// <summary>
- /// 交割商品到期提货通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override GoodsCloseDateNtfModel GoodsCloseDateReturnMessage(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var model = ProtoBufHelper.EntityDeSerialize<GoodsCloseDateNtf>(byteArr);
- //var result = new GoodsCloseDateNtfModel()
- //{
- // RetCode = model.RetCode,
- // LoginCode = model.LoginCode,
- // AccountId = model.AccountId,
- // RiskLevel = model.RiskLevel,
- // ReceiverTypes = model.ReceiverTypes,
- // MsgContent = model.MsgContent,
- // Idate = model.Idate,
- //};
- //return result;
- }
- /// <summary>
- /// 提货审核通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override OutStoreAuditNtfModel OutStoreAuditReturnMessage(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var model = ProtoBufHelper.EntityDeSerialize<OutStoreAuditNtf>(byteArr);
- //var result = new OutStoreAuditNtfModel()
- //{
- // RetCode = model.RetCode,
- // auditStatus = model.auditStatus,
- // storeOutId = model.storeOutId,
- // Content = model.Content,
- //};
- //return result;
- }
- /// <summary>
- /// 投资者风控通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override RiskControlInvestorModel RiskControlInvestorReturnMessage(object data)
- {
- //return null;
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- RiskToWebNtf model = ProtoBufHelper.EntityDeSerialize<RiskToWebNtf>(byteArr);
- var result = new RiskControlInvestorModel()
- {
- MsgContent = model.Content,
- };
- return result;
- }
- /// <summary>
- /// 会员风控通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override RiskControlMemberModel RiskControlMemberReturnMessage(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var model = ProtoBufHelper.EntityDeSerialize<RiskControlMember>(byteArr);
- //var result = new RiskControlMemberModel()
- //{
- // RetCode = model.RetCode,
- // AccountId = model.AccountId,
- // Idate = model.Idate,
- // AccountStatus=model.AccountStatus,
- // AccountType=model.AccountType,
- // LoginCode=model.LoginCode,
- // MemberCode=model.MemberCode,
- // MemberName=model.MemberName,
- // ReceiverTypes=model.ReceiverTypes,
- // RiskLevel=model.RiskLevel,
- // MsgContent = model.MsgContent,
- //};
- //return result;
- }
- /// <summary>
- /// 通用通知
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public override CommonNotifyModel CommonNotifyReturnMessage(object data)
- {
- return null;
- //var byteArr = data as byte[];
- //if (byteArr == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var model = ProtoBufHelper.EntityDeSerialize<CommonNotify>(byteArr);
- //var result = new CommonNotifyModel()
- //{
- // RetCode = model.RetCode,
- // AccountId = model.AccountId,
- // Title = model.Title,
- // Content = model.Content,
- //};
- //return result;
- }
- public override ResponeEntity<Data.Model.Listing.ListingNoticeModel> ToListingNoticeModel(object responeData)
- {
- return null;
- //var buffer = responeData as byte[];
- //if (buffer == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var lintingNtf = ProtoBufHelper.EntityDeSerialize<ListingNtf>(buffer);
- //return new ResponeEntity<ListingNoticeModel>()
- //{
- // RetCode = lintingNtf.RetCode,
- // Entity = new ListingNoticeModel()
- // {
- // OrderID = lintingNtf.OrderID,
- // AccountID = lintingNtf.AccountID,
- // Direction = (Direction)lintingNtf.BuyOrSell,
- // GoodsID = lintingNtf.GoodsID,
- // MsgType = (ListingMsgType)lintingNtf.MsgType,
- // Price = Convert.ToDecimal(lintingNtf.Price),
- // OperatorID = lintingNtf.OperatorID,
- // RemainQty = (long)lintingNtf.RemainQty,
- // },
- //};
- }
- public override uint ToMessageHeadFunCode(object responeData)
- {
- var buffer = responeData as byte[];
- if (buffer == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var messageHead = ProtoBufHelper.EntityDeSerialize<CommonPackage>(buffer);
- if (messageHead != null&& messageHead.Header!=null)
- {
- return messageHead.Header.FunCode;
- }
- return 0;
- }
- public override MarketStatusComplete ToMarketStatusRsp(object responeData)
- {
- return null;
- //var buffer = responeData as byte[];
- //if (buffer == null)
- //{
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- //}
- //var marketComplete = new MarketStatusComplete(){RetCode = -1};
- //var mStatus = ProtoBufHelper.EntityDeSerialize<MarketStatusRsp>(buffer);
- //if (mStatus != null )
- //{
- // marketComplete.RetCode = mStatus.RetCode;
- // marketComplete.SignalType = mStatus.SignalType;
- // marketComplete.ObjectIds = mStatus.ObjectId;
- // marketComplete.ControlTime = mStatus.ControlTime;
- //}
- //return marketComplete;
- }
- public override string AccountChangeNotifyRspNotifyAd(object data)
- {
- return null;
-
- // var buffer = data as byte[];
- // if (buffer == null)
- // {
- // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- // }
- // var mStatus = ProtoBufHelper.EntityDeSerialize<AccountChangeNotifyRsp>(buffer);
- // if (mStatus != null )
- // {
- // //marketComplete.RetCode = mStatus.RetCode;
- // //marketComplete.SignalType = mStatus.SignalType;
- // //marketComplete.ObjectIds = mStatus.ObjectId;
- // //marketComplete.ControlTime = mStatus.ControlTime;
- // }
- //// return marketComplete;
- // return mStatus.FunName;
- }
- public override ErrorEntity LogoutRspConvert(object data)
- {
- var byteArr = data as byte[];
- if (byteArr == null)
- {
- throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
- }
- var loginRsq = ProtoBufHelper.EntityDeSerialize<LoginRsp>(byteArr);
- var result = new ErrorEntity()
- {
- ReturnCode = loginRsq.RetCode,
- ReturnDesc = loginRsq.RetDesc,
- };
- return result;
- }
- }
- }
|