//---------------------------------------------------------------- //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(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; } /// /// 头寸变化通知 /// /// /// 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(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; } /// /// 市场状态变更通知 /// /// /// 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(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(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(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(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(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; } /// /// 开休市计划通知 /// /// /// public override List 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(byteArr); //var results =remoteModels.MarketStatusChanges.ToList(); // var marketypes = new List(); // 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(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(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(byteArr); //var result = new PrepostTransferOrder() //{ // ClientSerialNo = prepostOrder.ClientSerialNo, // PrepostID = prepostOrder.PrepostID, // PrepostStatus = prepostOrder.PrepostStatus, // GoodsID = prepostOrder.GoodsID, //}; //return result; } /// /// 交收审核通知 /// /// /// 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(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; } /// /// 交割商品到期提货通知 /// /// /// 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(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; } /// /// 提货审核通知 /// /// /// 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(byteArr); //var result = new OutStoreAuditNtfModel() //{ // RetCode = model.RetCode, // auditStatus = model.auditStatus, // storeOutId = model.storeOutId, // Content = model.Content, //}; //return result; } /// /// 投资者风控通知 /// /// /// 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(byteArr); var result = new RiskControlInvestorModel() { MsgContent = model.Content, }; return result; } /// /// 会员风控通知 /// /// /// 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(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; } /// /// 通用通知 /// /// /// 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(byteArr); //var result = new CommonNotifyModel() //{ // RetCode = model.RetCode, // AccountId = model.AccountId, // Title = model.Title, // Content = model.Content, //}; //return result; } public override ResponeEntity 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(buffer); //return new ResponeEntity() //{ // 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(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(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(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(byteArr); var result = new ErrorEntity() { ReturnCode = loginRsq.RetCode, ReturnDesc = loginRsq.RetDesc, }; return result; } } }