/// <summary> /// 构建现货成交回报 /// </summary> /// <param name="tet"></param> /// <param name="sdbe"></param> /// <param name="xhcr"></param> /// <param name="dealCapital"></param> /// <param name="tm"></param> /// <returns></returns> public static XH_TodayTradeTableInfo BuildXHDealRpt(XH_TodayEntrustTableInfo tet, StockDealBackEntity sdbe, XHCostResult xhcr, decimal dealCapital, ReckoningTransaction tm) { string result = string.Empty; //成交回报实体 var xhDealrpt = new XH_TodayTradeTableInfo(); //xhDealrpt.TradeNumber = this.BuildXHDealOrderNo(); xhDealrpt.TradeNumber = sdbe.Id; //不再自己构建id,使用成交回报的id,一一对应 //成交时间 xhDealrpt.TradeTime = sdbe.DealTime; //成交价 xhDealrpt.TradePrice = sdbe.DealPrice; //成交单位 xhDealrpt.TradeUnitId = tet.TradeUnitId; //成交量 xhDealrpt.TradeAmount = Convert.ToInt32(sdbe.DealAmount); //股东代码 xhDealrpt.StockAccount = tet.StockAccount; //资金帐户 xhDealrpt.CapitalAccount = tet.CapitalAccount; //成交回报类型 xhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTDealed; //现货名称 xhDealrpt.SpotCode = tet.SpotCode; //印花税 xhDealrpt.StampTax = xhcr.StampDuty; //佣金 xhDealrpt.Commission = xhcr.Commision; //过户费 xhDealrpt.TransferAccountFee = xhcr.TransferToll; //交易系统使用费 xhDealrpt.TradingSystemUseFee = xhcr.TradeSystemFees; //监管费 xhDealrpt.MonitoringFee = xhcr.MonitoringFee; //结算费 xhDealrpt.ClearingFee = xhcr.ClearingFees; //委托价格 xhDealrpt.EntrustPrice = tet.EntrustPrice; //成交金额 xhDealrpt.TradeCapitalAmount = dealCapital; // xhDealrpt.TradePrice*xhDealrpt.TradeAmount;//TODO:是否正确?没有算比例 //投组标识 xhDealrpt.PortfolioLogo = tet.PortfolioLogo; //货币类型 xhDealrpt.CurrencyTypeId = tet.CurrencyTypeId; //买卖方向 xhDealrpt.BuySellTypeId = tet.BuySellTypeId; xhDealrpt.EntrustNumber = tet.EntrustNumber; XH_TodayTradeTableDal xhTodayTradeTableDal = new XH_TodayTradeTableDal(); if (xhTodayTradeTableDal.Exists(xhDealrpt.TradeNumber)) { string format = "BuildXHDealRpt数据库已经存在TradeNumber={0}"; string desc = string.Format(format, xhDealrpt.TradeNumber); LogHelper.WriteDebug(desc); //xhDealrpt = xhTodayTradeTableDal.GetModel(xhDealrpt.TradeNumber); return(null); } try { xhTodayTradeTableDal.Add(xhDealrpt, tm); } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); xhDealrpt = null; } return(xhDealrpt); }
/// <summary> /// 更新过户记录 /// </summary> /// <param name="tm">TransactionManager</param> /// <param name="cash">分红信息</param> /// <param name="tables">登记列表</param> private static bool UpdateStockCut(ReckoningTransaction tm, List <XH_MelonCutRegisterTableInfo> tables) { #region old code 李健华 2010-06-11 改为因为在每天开市时处理那么生成为当日委托我成交 //List<XH_AccountHoldTableInfo> accountHoldList = new List<XH_AccountHoldTableInfo>(); //List<XH_HistoryTradeTableInfo> historyTradeList = new List<XH_HistoryTradeTableInfo>(); ////add 2010-1-15 因为数据库表有的成交记录是根据委托编号有外键关系,所以这里要生成委托记录 //List<XH_HistoryEntrustTableInfo> historyEntrustList = new List<XH_HistoryEntrustTableInfo>(); ////======== //foreach (XH_MelonCutRegisterTableInfo registerTable in tables) //{ // //更新持仓表 // List<XH_AccountHoldTableInfo> accountHoldTables = GetAccountHoldList( // registerTable.UserAccountDistributeLogo, // registerTable.TradeCurrencyType, registerTable.Code); // if (Utils.IsNullOrEmpty(accountHoldTables)) // continue; // //过户的量 // decimal num = registerTable.RegisterAmount; // //四舍五入 // num = Math.Round(num); // int intNum = decimal.ToInt32(num); // XH_AccountHoldTableInfo accountTable = accountHoldTables[0]; // SetAccountTable(accountTable, intNum); // accountHoldList.Add(accountTable); // //更新委托记录表 // XH_HistoryEntrustTableInfo historyEntrustTable = GetHistoryEntrustTable(registerTable, intNum); // historyEntrustList.Add(historyEntrustTable); // //更新历史成交表 // XH_HistoryTradeTableInfo historyTradeTable = GetHistoryTradeTable(registerTable, intNum); // historyTradeTable.EntrustNumber = historyEntrustTable.EntrustNumber; // historyTradeTable.CapitalAccount = historyEntrustTable.CapitalAccount; // historyTradeList.Add(historyTradeTable); // string format = "MelonCutService.UpdateStockCut进行股票分红[商品代码={0},持仓帐号={1},分红金额={2}]"; // string desc = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num); // LogHelper.WriteDebug(desc); //} //XH_AccountHoldTableDal xh_AccountHoldTableDal = new XH_AccountHoldTableDal(); //if (accountHoldList.Count > 0) //{ // foreach (var holdTableInfo in accountHoldList) // { // xh_AccountHoldTableDal.Update(holdTableInfo, tm.Database, tm.Transaction); // } //} ////先添加委托记录 //XH_HistoryEntrustTableDal xh_HistoryEntrustTableDal = new XH_HistoryEntrustTableDal(); //if (historyEntrustList.Count > 0) //{ // foreach (XH_HistoryEntrustTableInfo item in historyEntrustList) // { // xh_HistoryEntrustTableDal.Add(item, tm.Database, tm.Transaction); // } //} ////添加成交记录 ////DataRepository.XhAccountHoldTableProvider.Update(tm, accountHoldList); ////DataRepository.XhHistoryTradeTableProvider.BulkInsert(historyTradeList); //XH_HistoryTradeTableDal xh_HistoryTradeTableDal = new XH_HistoryTradeTableDal(); //if (historyTradeList.Count > 0) //{ // foreach (XH_HistoryTradeTableInfo historyTradeTable in historyTradeList) // { // //DataRepository.XhHistoryTradeTableProvider.Insert(tm, historyTradeTable); // xh_HistoryTradeTableDal.Add(historyTradeTable, tm.Database, tm.Transaction); // } //} ////删除对应的登记记录 ////DataRepository.XhMelonCutRegisterTableProvider.Delete(tm, tables); //XH_MelonCutRegisterTableDal xh_MelonCutRegisterTableDal = new XH_MelonCutRegisterTableDal(); //if (tables.Count > 0) //{ // foreach (var data in tables) // { // xh_MelonCutRegisterTableDal.Delete(data, tm.Database, tm.Transaction); // } //} #endregion #region new code 李健华 2010-06-11 改为因为在每天开市时处理那么生成为当日委托我成交 bool issuc = true; try { List <XH_AccountHoldTableInfo> accountHoldList = new List <XH_AccountHoldTableInfo>(); List <XH_TodayTradeTableInfo> todayTradeList = new List <XH_TodayTradeTableInfo>(); //add 2010-1-15 因为数据库表有的成交记录是根据委托编号有外键关系,所以这里要生成委托记录 List <XH_TodayEntrustTableInfo> todayEntrustList = new List <XH_TodayEntrustTableInfo>(); UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); //======== foreach (XH_MelonCutRegisterTableInfo registerTable in tables) { //更新持仓表 List <XH_AccountHoldTableInfo> accountHoldTables = GetAccountHoldList(registerTable.UserAccountDistributeLogo, registerTable.TradeCurrencyType, registerTable.Code); if (Utils.IsNullOrEmpty(accountHoldTables)) { continue; } //过户的量 decimal num = registerTable.RegisterAmount; //四舍五入 num = Math.Round(num); int intNum = decimal.ToInt32(num); XH_AccountHoldTableInfo accountTable = accountHoldTables[0]; SetAccountTable(accountTable, intNum); accountHoldList.Add(accountTable); //更新委托记录表 XH_TodayEntrustTableInfo todayEntrustTable = GetHistoryEntrustTable(registerTable, intNum); todayEntrustList.Add(todayEntrustTable); //更新历史成交表 XH_TodayTradeTableInfo todayTradeTable = GetTodayTradeTable(registerTable, intNum); todayTradeTable.EntrustNumber = todayEntrustTable.EntrustNumber; todayTradeTable.CapitalAccount = todayEntrustTable.CapitalAccount; todayTradeList.Add(todayTradeTable); UA_UserAccountAllocationTableInfo userModel = dal.GetModel(registerTable.UserAccountDistributeLogo); #region 回推相关成交记录信息 ReckonEndObject <XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo> reckonEndObject = new ReckonEndObject <XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo>(); reckonEndObject.IsSuccess = true; reckonEndObject.EntrustTable = todayEntrustTable; List <XH_TodayTradeTableInfo> tradeModels = new List <XH_TodayTradeTableInfo>(); tradeModels.Add(todayTradeTable); reckonEndObject.TradeTableList = tradeModels; if (userModel != null) { reckonEndObject.TradeID = userModel.UserID; } reckonEndObject.Message = "分红委托成交"; CounterOrderService.Instance.AcceptStockDealOrder(reckonEndObject); #endregion string format = "MelonCutService.UpdateStockCut进行股票分红[商品代码={0},持仓帐号={1},分红金额={2}]"; string desc = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num); LogHelper.WriteDebug(desc); } XH_AccountHoldTableDal xh_AccountHoldTableDal = new XH_AccountHoldTableDal(); if (accountHoldList.Count > 0) { foreach (var holdTableInfo in accountHoldList) { xh_AccountHoldTableDal.Update(holdTableInfo, tm.Database, tm.Transaction); } } //先添加委托记录 XH_TodayEntrustTableDal xh_HistoryEntrustTableDal = new XH_TodayEntrustTableDal(); if (todayEntrustList.Count > 0) { foreach (XH_TodayEntrustTableInfo item in todayEntrustList) { xh_HistoryEntrustTableDal.Add(item, tm.Database, tm.Transaction); } } //添加成交记录 //DataRepository.XhAccountHoldTableProvider.Update(tm, accountHoldList); //DataRepository.XhHistoryTradeTableProvider.BulkInsert(historyTradeList); XH_TodayTradeTableDal xh_todayTradeTableDal = new XH_TodayTradeTableDal(); if (todayTradeList.Count > 0) { foreach (XH_TodayTradeTableInfo todayTradeTable in todayTradeList) { //DataRepository.XhHistoryTradeTableProvider.Insert(tm, historyTradeTable); xh_todayTradeTableDal.Add(todayTradeTable, tm); } } //删除对应的登记记录 //DataRepository.XhMelonCutRegisterTableProvider.Delete(tm, tables); XH_MelonCutRegisterTableDal xh_MelonCutRegisterTableDal = new XH_MelonCutRegisterTableDal(); if (tables.Count > 0) { foreach (var data in tables) { xh_MelonCutRegisterTableDal.Delete(data, tm.Database, tm.Transaction); } } } catch (Exception ex) { LogHelper.WriteError("过户分红异常" + ex.Message, ex); issuc = false; } return(issuc); #endregion }
/// <summary> /// 构建现货撤单成交回报 /// </summary> /// <param name="tet"></param> /// <param name="rde"></param> /// <param name="tm"></param> /// <param name="trade"></param> /// <param name="isInternalCancel"></param> /// <returns></returns> public static string BuildXHCancelRpt(XH_TodayEntrustTableInfo tet, CancelOrderEntity rde, ReckoningTransaction tm, out XH_TodayTradeTableInfo trade, bool isInternalCancel) { string result = string.Empty; //当为价格错误的撤单时,直接作为废单,不记录到数据库中。 if (rde.OrderVolume == -1) { trade = null; return(result); } //成交回报实体 var xhDealrpt = new XH_TodayTradeTableInfo(); //xhDealrpt.TradeNumber = this.BuildXHDealOrderNo(); xhDealrpt.TradeNumber = rde.Id; //不再自己构建id,使用撤单回报的id,一一对应 //成交时间 xhDealrpt.TradeTime = DateTime.Now; //成交价 xhDealrpt.TradePrice = 0; //成交单位 xhDealrpt.TradeUnitId = tet.TradeUnitId; //成交量 xhDealrpt.TradeAmount = Convert.ToInt32(rde.OrderVolume); //股东代码 xhDealrpt.StockAccount = tet.StockAccount; //资金帐户 xhDealrpt.CapitalAccount = tet.CapitalAccount; //成交回报类型 if (isInternalCancel) { xhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTInternalCanceled; } else { xhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTCanceled; } //现货名称 xhDealrpt.SpotCode = tet.SpotCode; //印花税 xhDealrpt.StampTax = 0; //佣金 xhDealrpt.Commission = 0; //过户费 xhDealrpt.TransferAccountFee = 0; //交易系统使用费 xhDealrpt.TradingSystemUseFee = 0; //监管费 xhDealrpt.MonitoringFee = 0; xhDealrpt.ClearingFee = 0; //委托价格 xhDealrpt.EntrustPrice = tet.EntrustPrice; //成交金额 xhDealrpt.TradeCapitalAmount = xhDealrpt.TradePrice * xhDealrpt.TradeAmount; //投组标识 xhDealrpt.PortfolioLogo = tet.PortfolioLogo; //货币类型 xhDealrpt.CurrencyTypeId = tet.CurrencyTypeId; //买卖方向 xhDealrpt.BuySellTypeId = tet.BuySellTypeId; xhDealrpt.EntrustNumber = tet.EntrustNumber; XH_TodayTradeTableDal xhTodayTradeTableDal = new XH_TodayTradeTableDal(); xhTodayTradeTableDal.Add(xhDealrpt, tm); result = xhDealrpt.TradeNumber; trade = xhDealrpt; return(result); }