/// <summary> /// 创建一个今日委托记录 /// </summary> /// <param name="registerTable">登记表实体</param> /// <param name="intNum">分红过户量</param>里 /// <returns>今日委托实体</returns> private static XH_TodayEntrustTableInfo GetHistoryEntrustTable(XH_MelonCutRegisterTableInfo registerTable, int intNum) { XH_TodayEntrustTableInfo todayEntrustTable = new XH_TodayEntrustTableInfo(); todayEntrustTable.EntrustNumber = XHCommonLogic.BuildXHOrderNo(); todayEntrustTable.CurrencyTypeId = registerTable.TradeCurrencyType; todayEntrustTable.TradeUnitId = MCService.GetPriceUnit(registerTable.Code); todayEntrustTable.EntrustAmount = intNum; todayEntrustTable.EntrustPrice = 0; todayEntrustTable.EntrustTime = DateTime.Now; todayEntrustTable.OfferTime = DateTime.Now; todayEntrustTable.BuySellTypeId = (int)GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying; todayEntrustTable.OrderStatusId = (int)Types.OrderStateType.DOSDealed; todayEntrustTable.StockAccount = registerTable.UserAccountDistributeLogo;//持仓账号,在分红记录中都是持仓账号 //====通过持仓账号查询相关联的资金账号 UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); UA_UserAccountAllocationTableInfo uaUser = dal.GetUserHoldAccountByUserCapitalAccount(registerTable.UserAccountDistributeLogo); todayEntrustTable.CapitalAccount = uaUser.UserAccountDistributeLogo; //===== todayEntrustTable.PortfolioLogo = ""; todayEntrustTable.SpotCode = registerTable.Code; todayEntrustTable.TradeAmount = intNum; todayEntrustTable.TradeAveragePrice = 0; todayEntrustTable.CancelAmount = 0; todayEntrustTable.IsMarketValue = false; todayEntrustTable.OrderMessage = "股票分红生成委托记录"; todayEntrustTable.McOrderId = Guid.NewGuid().ToString(); return(todayEntrustTable); }
/// <summary> /// 根据用户ID,和用户类型,期货和现货标志 :0=期货,1=现货,从缓存数据中查询用户相关的资金账号信息 /// </summary> /// <param name="userID">交易员ID</param> /// <param name="accountType">查询的账号类型0是查询所有</param> /// <param name="futureSpotFlag">期货和现货标志 :0=期货,1=现货</param> /// <returns></returns> public List <UA_UserAccountAllocationTableInfo> GetUserCapitalAccountFormUserCache(string userID, int accountType, byte futureSpotFlag) { List <UA_UserAccountAllocationTableInfo> userAccountInfo = new List <UA_UserAccountAllocationTableInfo>(); #region 从缓存中获取账号 这里只是再封装,内部如果在内存没有查询到会先到数据库中查询后再返回再缓存 if (accountType == 0) { if (futureSpotFlag == 1) { userAccountInfo = GetAccountByUserIDAndAccountTypeClass(userID, Types.AccountAttributionType.SpotCapital); } else if (futureSpotFlag == 0) { userAccountInfo = GetAccountByUserIDAndAccountTypeClass(userID, Types.AccountAttributionType.FuturesCapital); } } else { UA_UserAccountAllocationTableInfo account = GetAccountByUserIDAndAccountType(userID, accountType); if (account != null) { userAccountInfo.Add(account); } } #endregion return(userAccountInfo); }
/// <summary>期货资金情况查询 /// 期货资金情况查询 包含盈亏相关信息在内 /// </summary> /// <param name="userId"></param> /// <param name="accountType">账号类型(注:这是账户类型不是类别,这里是有九种类型,而类别是五种)</param> /// <param name="currencyType"></param> /// <param name="userPassword"></param> /// <param name="strErrorMessage"></param> /// <returns></returns> public FuturesCapitalEntity PagingQueryFuturesCapital(string userId, int accountType, Types.CurrencyType currencyType, string userPassword, ref string strErrorMessage) { #region old code //AccountPair _AccountPair = CommonDataAgent.GeyAccountPair(userId, accountType, 0, ref userPassword); //strErrorMessage = userPassword; //if (_AccountPair == null) return null; //FuturesCapitalEntity result = null; //var aa = new CapitalAndHoldFindBLL(); //result = aa.FuturesCapitalFind(_AccountPair.CapitalAccount.UserAccountDistributeLogo, currencyType, userPassword, ref strErrorMessage); //return result; #endregion AccountManager am = AccountManager.Instance; UA_UserAccountAllocationTableInfo userAccountInfo = am.GetAccountByUserIDAndAccountType(userId, accountType); UA_UserBasicInformationTableInfo userInfo = am.GetBasicUserByUserId(userId); if (userAccountInfo == null || userInfo == null) { strErrorMessage = "交易员对应类型的帐号不存在"; return(null); } if (userInfo.Password != userPassword) { strErrorMessage = "交易员密码错误"; return(null); } FuturesCapitalEntity result = null; var aa = new CapitalAndHoldFindBLL(); result = aa.FuturesCapitalFind(userAccountInfo.UserAccountDistributeLogo, currencyType, userPassword, ref strErrorMessage); return(result); }
/// <summary> /// 开是否开启事务增加一条数据 /// <param name="model">要插入的用户账号对象</param> /// <param name="db">操作数据对象</param> /// <param name="trm">开启事务对象,如果为null不开启</param> /// </summary> public void Add(UA_UserAccountAllocationTableInfo model, Database db, DbTransaction trm) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into UA_UserAccountAllocationTable("); strSql.Append("UserAccountDistributeLogo,WhetherAvailable,UserID,AccountTypeLogo)"); strSql.Append(" values ("); strSql.Append("@UserAccountDistributeLogo,@WhetherAvailable,@UserID,@AccountTypeLogo)"); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "WhetherAvailable", DbType.Boolean, model.WhetherAvailable); db.AddInParameter(dbCommand, "UserID", DbType.AnsiString, model.UserID); db.AddInParameter(dbCommand, "AccountTypeLogo", DbType.Int32, model.AccountTypeLogo); if (trm == null) { db.ExecuteNonQuery(dbCommand); } else { db.ExecuteNonQuery(dbCommand, trm); } }
/// <summary> /// 根据交易员ID,交易账户类型来获交易账户信息UserAccountAllocationTable /// </summary> /// <param name="traderId"></param> /// <param name="accountTypeID"></param> /// <returns></returns> protected static UA_UserAccountAllocationTableInfo GetUserAccountAllocationTable(string traderId, int accountTypeID) { UA_UserAccountAllocationTableInfo val = null; try { //UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); // List<UA_UserAccountAllocationTableInfo> list = // DataRepository.UaUserAccountAllocationTableProvider.GetByUserId(traderId); //string where = string.Format("UserID = '{0}' ", traderId); //List<UA_UserAccountAllocationTableInfo> list = dal.GetListArray(where); var list = AccountManager.Instance.GetUserAllAccounts(traderId); foreach (UA_UserAccountAllocationTableInfo accountAllocationTable in list) { if (accountAllocationTable.AccountTypeLogo == accountTypeID) { if (accountAllocationTable.WhetherAvailable) { val = accountAllocationTable; break; } } } } catch (System.Exception ex) { LogHelper.WriteError(ex.Message, ex); } return(val); }
/// <summary> /// 向缓存数据添加一条用户账号信息记录 /// </summary> /// <param name="user">要添加的用户账号实体</param> public void AddUser(UA_UserAccountAllocationTableInfo user) { try { if (!accountCache.Contains(user.UserAccountDistributeLogo)) { accountCache.Add(user.UserAccountDistributeLogo, user); LogHelper.WriteDebug("添加一条账号信息记录当前用户ID:" + user.UserID + " 添加账号:" + user.UserAccountDistributeLogo + " 账号列表数:" + accountCache.GetAll().Count); } SyncList <UA_UserAccountAllocationTableInfo> accountList = null; if (userCache.Contains(user.UserID)) { accountList = userCache.Get(user.UserID); } else { accountList = new SyncList <UA_UserAccountAllocationTableInfo>(); userCache.Add(user.UserID, accountList); LogHelper.WriteDebug("【第一次】添加一条【用户拥有账号记录】ID:" + user.UserID + " 添加账号:" + user.UserAccountDistributeLogo + " 账号类型: " + user.AccountTypeLogo + " 账号列表数:" + accountList.GetAll().Count); } //如果存在不再添加 这样判断好象有问题用forearch //if (!accountList.Contains(user)) //{ bool isAdd = true; List <UA_UserAccountAllocationTableInfo> models = accountList.GetAll(); foreach (var item in accountList.GetAll()) { if (item.AccountTypeLogo == user.AccountTypeLogo && item.UserAccountDistributeLogo == user.UserAccountDistributeLogo && item.UserID == user.UserID) { isAdd = false; break; } } if (isAdd) { accountList.Add(user); LogHelper.WriteDebug("添加一条【用户拥有账号记录】ID:" + user.UserID + " 添加账号:" + user.UserAccountDistributeLogo + " 账号类型: " + user.AccountTypeLogo + " 账号列表数:" + accountList.GetAll().Count); } //} } catch (Exception ex) { LogHelper.WriteError("向缓存数据添加一条用户账号信息记录异常" + ex.Message, ex); } }
/// <summary> /// 检查交易员_港股资金交易账户表(UA_UserAccountAllocationTable)是否可用 /// </summary> /// <param name="accTypeID"></param> /// <param name="errMsg">错误信息</param> /// <returns>是否成功</returns> private bool CheckFuncTraderAvalible(int accTypeID, out string errMsg) { bool result = false; errMsg = ""; string errCode = ""; try { UA_UserAccountAllocationTableInfo val = GetUserAccountAllocationTable(request.TraderId, accTypeID); if (val != null) { if (val.WhetherAvailable) { result = true; } else { errMsg = "交易员港股资金账户不可用。"; errCode = "GT-1200"; errMsg = errCode + ":" + errMsg; LogHelper.WriteInfo(errMsg); } } else { errMsg = "交易员港股资金账户不存在。"; errCode = "GT-1201"; errMsg = errCode + ":" + errMsg; LogHelper.WriteInfo(errMsg); } } catch (Exception ex) { errMsg = "无法进行交易员港股资金账户有效性验证。"; errCode = "GT-1202"; errMsg = errCode + ":" + errMsg; LogHelper.WriteError(errMsg, ex); } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(UA_UserAccountAllocationTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update UA_UserAccountAllocationTable set "); strSql.Append("WhetherAvailable=@WhetherAvailable,"); strSql.Append("UserID=@UserID,"); strSql.Append("AccountTypeLogo=@AccountTypeLogo"); strSql.Append(" where UserAccountDistributeLogo=@UserAccountDistributeLogo "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "WhetherAvailable", DbType.Boolean, model.WhetherAvailable); db.AddInParameter(dbCommand, "UserID", DbType.AnsiString, model.UserID); db.AddInParameter(dbCommand, "AccountTypeLogo", DbType.Int32, model.AccountTypeLogo); db.ExecuteNonQuery(dbCommand); }
/// <summary> /// 对象实体绑定数据 /// </summary> public UA_UserAccountAllocationTableInfo ReaderBind(IDataReader dataReader) { UA_UserAccountAllocationTableInfo model = new UA_UserAccountAllocationTableInfo(); object ojb; model.UserAccountDistributeLogo = dataReader["UserAccountDistributeLogo"].ToString(); ojb = dataReader["WhetherAvailable"]; if (ojb != null && ojb != DBNull.Value) { model.WhetherAvailable = (bool)ojb; } model.UserID = dataReader["UserID"].ToString(); ojb = dataReader["AccountTypeLogo"]; if (ojb != null && ojb != DBNull.Value) { model.AccountTypeLogo = (int)ojb; } return(model); }
/// <summary> /// 依据交易员ID,帐户类型取帐户信息 /// </summary> /// <param name="strTraderId"></param> /// <param name="iAccountTypeId"></param> /// <returns></returns> public static UA_UserAccountAllocationTableInfo GetAccountByTraderInfo(string strTraderId, int iAccountTypeId) { //陈武民修改 2009年7月9日 UA_UserAccountAllocationTableInfo result = null; UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); string where = string.Format(" UserID = '{0}' ", strTraderId); List <UA_UserAccountAllocationTableInfo> list = dal.GetListArray(where); // DataRepository.UaUserAccountAllocationTableProvider.GetByUserId(strTraderId); foreach (UA_UserAccountAllocationTableInfo accountAllocationTable in list) { if (accountAllocationTable.AccountTypeLogo == iAccountTypeId) { result = accountAllocationTable; } } return(result); }
/// <summary> /// Create By:李健华 /// Create Date:2009-08-12 /// Title:更新缓存表中的数据用户账号状态 /// Desc.:因为用户账户信息主要有的是解冻和冻结状态的改变所以这里的更新方法主要是对 /// 解冻和冻结的更新 /// </summary> /// <param name="userID">用户ID</param> /// <param name="accountType">账号类型</param> /// <param name="state">状态</param> public void UpdateUser(string userID, int accountType, bool state) { UA_UserAccountAllocationTableInfo ua = GetAccountByUserIDAndAccountType(userID, accountType); if (ua != null) { ua.WhetherAvailable = state; accountCache.Delete(ua.UserAccountDistributeLogo); accountCache.Add(ua.UserAccountDistributeLogo, ua); } if (userCache.Contains(userID)) { var accountList = userCache.Get(userID).GetAll(); foreach (var item in accountList) { if (item.AccountTypeLogo == accountType) { item.WhetherAvailable = state; } } } }
/// <summary> /// 得到一个对象实体 /// </summary> public UA_UserAccountAllocationTableInfo GetModel(string UserAccountDistributeLogo) { StringBuilder strSql = new StringBuilder(); strSql.Append( "select UserAccountDistributeLogo,WhetherAvailable,UserID,AccountTypeLogo from UA_UserAccountAllocationTable "); strSql.Append(" where UserAccountDistributeLogo=@UserAccountDistributeLogo "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, UserAccountDistributeLogo); UA_UserAccountAllocationTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 期货持仓查询 (根据交易员、密码及查询条件来查询) 包含盈亏 /// </summary> /// <param name="userId">交易员</param> /// <param name="accountType">账号类型(注:这是账户类型不是类别,这里是有九种类型,而类别是五种)</param> /// <param name="strPassword">交易员密码</param> /// <param name="findCondition">查询条件实体对象</param> /// <param name="start">记录集页索引</param> /// <param name="pageLength">页长</param> /// <param name="count">查到的记录数</param> /// <param name="strErrorMessage"></param> /// <returns></returns> public List <FuturesHoldFindResultEntity> PagingQueryFuturesHold(string userId, int accountType, string userPassword, FuturesHoldConditionFindEntity findCondition, int start, int pageLength, out int count, ref string strErrorMessage) { #region old code //AccountPair _AccountPair = CommonDataAgent.GeyAccountPair(userId, accountType, 0, ref userPassword); //strErrorMessage = userPassword; //if (_AccountPair == null) //{ // count = 0; // return null; //} //var result = new List<FuturesHoldFindResultEntity>(); //count = 0; //var aa = new CapitalAndHoldFindBLL(); //result = aa.FuturesHoldFind(_AccountPair.CapitalAccount.UserAccountDistributeLogo, userPassword, findCondition, start, pageLength, out count, ref strErrorMessage); //return result; #endregion count = 0; AccountManager am = AccountManager.Instance; UA_UserAccountAllocationTableInfo userAccountInfo = am.GetAccountByUserIDAndAccountType(userId, accountType); UA_UserBasicInformationTableInfo userInfo = am.GetBasicUserByUserId(userId); if (userAccountInfo == null || userInfo == null) { strErrorMessage = "交易员对应类型的帐号不存在"; return(null); } if (userInfo.Password != userPassword) { strErrorMessage = "交易员密码错误"; return(null); } var result = new List <FuturesHoldFindResultEntity>(); var aa = new CapitalAndHoldFindBLL(); result = aa.FuturesHoldFind(userAccountInfo.UserAccountDistributeLogo, userPassword, findCondition, start, pageLength, out count, ref strErrorMessage); return(result); }
/// <summary> /// 写交易员帐户列表 /// </summary> /// <param name="account">账户实体对象</param> /// <param name="outMessage">输出信息</param> /// <param name="db"></param> /// <param name="tm">事务对象,如果为null不开启事务</param> public bool AddTraderAccountToUserAccountAllocation(AccountEntity account, out string outMessage, Database db, DbTransaction tm) { outMessage = string.Empty; if (account == null) { outMessage = "帐户对象为空!"; return(false); } try { //先判断该交易账号是否已经存在 //var result = DataRepository.UaUserAccountAllocationTableProvider.Find(tm, string.Format("UserAccountDistributeLogo='{0}'", account.Account)); UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); //if (result == null || result.Count > 0) if (dal.Exists(account.Account)) { outMessage = "交易账号已经存在!" + account.Account; return(false); } //var _UserAccountAllocation = new SqlUaUserAccountAllocationTableProvider(TransactionFactory.RC_ConnectionString, true, ""); UA_UserAccountAllocationTableInfo model = new UA_UserAccountAllocationTableInfo(); model.UserAccountDistributeLogo = account.Account; model.UserID = account.TraderID; model.WhetherAvailable = true; model.AccountTypeLogo = Convert.ToInt32(account.AccountType); dal.Add(model, db, tm); return(true); } catch (Exception ex) { outMessage = ex.Message.ToString(); LogHelper.WriteError(ex.ToString(), ex); return(false); } }
///// <summary> ///// 获取所有的用户基础信息对象 ///// 注意:因为这里可能是没有全部加载的所以不一定是返回与数据库同步的所有用户列表所以这里注释此方法-- 注释 --李健华 2010-06-09 ///// </summary> ///// <returns></returns> //public List<UA_UserBasicInformationTableInfo> GetAllBasicUsers() //{ // return basicUserList; //} #endregion #region 用户账号信息 /// <summary> /// 根据任意账户获取账户信息 /// </summary> /// <param name="account"></param> /// <returns></returns> public UA_UserAccountAllocationTableInfo GetUserByAccount(string account) { try { account = account.Trim(); if (accountCache.Contains(account)) { return(accountCache.Get(account)); } string format = "UserAccountDistributeLogo='{0}'"; string where = string.Format(format, account); var userList = userDal.GetModel(account); if (userList != null) { //var user = userList[0]; // AddUser(user); #region 附值返回 UA_UserAccountAllocationTableInfo model = new UA_UserAccountAllocationTableInfo(); model.AccountTypeLogo = userList.AccountTypeLogo; model.UserAccountDistributeLogo = userList.UserAccountDistributeLogo; model.UserID = userList.UserID; model.WhetherAvailable = userList.WhetherAvailable; #endregion AddUser(userList); return(model); } } catch (Exception ex) { LogHelper.WriteError("根据任意账户获取账户信息" + ex.Message, ex); } return(null); }
/// <summary> /// 根据用户的资金账户返回关联的用户持仓账户信息(也即根据相关账号查询返回相关联的账号) /// </summary> /// <param name="capitalAccount">资金账户</param> /// <returns></returns> public UA_UserAccountAllocationTableInfo GetUserHoldAccountByUserCapitalAccount(string capitalAccount) { StringBuilder sb = new StringBuilder(); sb.Append(" select u1.UserAccountDistributeLogo,u1.WhetherAvailable,u1.UserID,u1.AccountTypeLogo "); sb.Append(" from UA_UserAccountAllocationTable as u1 "); sb.Append(" inner join UA_UserAccountAllocationTable as u2 on u2.UserAccountDistributeLogo=@UserAccountDistributeLogo "); sb.Append(" inner join BD_AccountType as b on b.AccountTypeLogo=u2.AccountTypeLogo "); sb.Append(" where u1.AccountTypeLogo =b.RelationAccountId and u1.userID=u2.userID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString()); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, capitalAccount); UA_UserAccountAllocationTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public void Add(UA_UserAccountAllocationTableInfo model) { Database db = DatabaseFactory.CreateDatabase(); Add(model, db, null); }
/// <summary> /// 构造函数 /// </summary> /// <param name="capitalAccount"></param> /// <param name="holdAccount"></param> public UserAccountChecker(UA_UserAccountAllocationTableInfo capitalAccount, UA_UserAccountAllocationTableInfo holdAccount) { this.capitalAccount = capitalAccount; this.holdAccount = holdAccount; }
/// <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="tm">TransactionManager</param> /// <param name="cash">分红信息</param> /// <param name="tables">登记列表</param> private static bool UpdateCashCut(ReckoningTransaction tm, IList <XH_MelonCutRegisterTableInfo> tables) { bool issuss = true; List <XH_CapitalAccountTableInfo> capitalList = new List <XH_CapitalAccountTableInfo>(); List <UA_CapitalFlowTableInfo> flowList = new List <UA_CapitalFlowTableInfo>(); XH_CapitalAccountTableDal dal = new XH_CapitalAccountTableDal(); try { foreach (XH_MelonCutRegisterTableInfo registerTable in tables) { //分红的现金额 decimal num = registerTable.RegisterAmount; UA_UserAccountAllocationTableInfo capitalAccount = Utils.GetCapitalAccountByHoldAccount(registerTable.UserAccountDistributeLogo, registerTable.Code); XH_CapitalAccountTableInfo accountTable = dal.GetXHCapitalAccount(capitalAccount.UserAccountDistributeLogo, registerTable.TradeCurrencyType); if (accountTable == null) { continue; } accountTable.TodayOutInCapital += num; accountTable.AvailableCapital += num; capitalList.Add(accountTable); //更新资金流水表 UA_CapitalFlowTableInfo flowTable = GetFlowTable(registerTable, capitalAccount.UserAccountDistributeLogo, num); flowList.Add(flowTable); string format = "MelonCutService.UpdateCashCut进行现金分红[商品代码={0},持仓帐号={1},分红金额={2}]"; string desc = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num); LogHelper.WriteDebug(desc); } XH_CapitalAccountTableDal xh_AccountTableDal = new XH_CapitalAccountTableDal(); if (capitalList.Count > 0) { foreach (var accountTableInfo in capitalList) { xh_AccountTableDal.Update(accountTableInfo, tm.Database, tm.Transaction); } } if (flowList.Count > 0) { UA_CapitalFlowTableDal flowTableDal = new UA_CapitalFlowTableDal(); foreach (var historyTradeTableInfo in flowList) { flowTableDal.Add(historyTradeTableInfo, tm.Database, tm.Transaction); } } if (tables.Count > 0) { XH_MelonCutRegisterTableDal melonCutRegisterTableDal = new XH_MelonCutRegisterTableDal(); foreach (var registerTableInfo in tables) { melonCutRegisterTableDal.Delete(registerTableInfo, tm.Database, tm.Transaction); } } } catch (Exception ex) { issuss = false; LogHelper.WriteError("分红出现问题 ", ex); } return(issuss); }
/// <summary> /// Create by:李健华 /// Create date:2010-06-08 /// Desc.: 初始货配对资金账号与持仓账号 /// </summary> /// <param name="capitalAccountType"></param> /// <param name="userID">交易员ID</param> public static List <AccountPair> InitializeAccountPair(BD_AccountTypeInfo capitalAccountType) { List <AccountPair> AccountPairList = new List <AccountPair>(); try { List <UA_UserBasicInformationTableInfo> userBasicList = new List <UA_UserBasicInformationTableInfo>(); UA_UserBasicInformationTableDal ubDal = new UA_UserBasicInformationTableDal(); userBasicList = ubDal.GetAll(); if (userBasicList == null) { return(AccountPairList); } UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); foreach (var item in userBasicList) { string where = string.Format("UserID = '{0}' AND AccountTypeLogo= '{1}'", item.UserID, capitalAccountType.AccountTypeLogo); List <UA_UserAccountAllocationTableInfo> capitalAccountList = dal.GetListArray(where); if (Utils.IsNullOrEmpty(capitalAccountList)) { continue; } //对应资金账户类型的只能有一个资金交易账户 UA_UserAccountAllocationTableInfo capitalAccount = capitalAccountList[0]; #region 查找对应的持仓交易账户 //查找对应的持仓交易账户 int?relationID = capitalAccountType.RelationAccountId; if (!relationID.HasValue) { continue; } int holdAccountTypeID = relationID.Value; where = string.Format("UserID = '{0}' AND AccountTypeLogo= '{1}'", item.UserID, holdAccountTypeID); List <UA_UserAccountAllocationTableInfo> HoldAccountList = dal.GetListArray(where); if (Utils.IsNullOrEmpty(HoldAccountList)) { //IsInitializeSuccess = false; continue; } //对应持仓账户类型的只能有一个持仓交易账户 UA_UserAccountAllocationTableInfo holdAccount = HoldAccountList[0]; #endregion AccountPair accountPair = new AccountPair { CapitalAccount = capitalAccount, HoldAccount = holdAccount }; AccountPairList.Add(accountPair); } } catch (Exception ex) { LogHelper.WriteError("期货盘前检查初始货配对资金账号与持仓账号异常" + ex.Message, ex); AccountPairList = null; } return(AccountPairList); }
///// <summary> ///// 依据交易员ID,帐户类型取帐户信息 ///// </summary> ///// <param name="strTraderId"></param> ///// <param name="iAccountTypeId"></param> ///// <param name="AccountIsAvaliable"></param> ///// <returns></returns> //private string GetAccountByTraderInfoFromVTTraders(string strTraderId, int iAccountTypeId, out bool AccountIsAvaliable) //{ // string result = string.Empty; // AccountIsAvaliable = false; // try // { // var trader = stockTraders.GetByUserID(strTraderId); // if (trader == null) // { // trader = futureTraders.GetByUserID(strTraderId); // } // if (trader == null) // { // LogHelper.WriteInfo("CounterCache.GetAccountByTraderInfo无法获取Trader,TraderID=" + strTraderId); // return ""; // } // var list = trader.AccountPairList; // if (list != null) // { // foreach (var pair in list) // { // if (pair.CapitalAccount.AccountTypeLogo == iAccountTypeId) // { // result = pair.CapitalAccount.UserAccountDistributeLogo; // AccountIsAvaliable = pair.CapitalAccount.WhetherAvailable; // } // else if (pair.HoldAccount.AccountTypeLogo == iAccountTypeId) // { // result = pair.HoldAccount.UserAccountDistributeLogo; // AccountIsAvaliable = pair.HoldAccount.WhetherAvailable; // } // } // } // } // catch (Exception ex) // { // LogHelper.WriteError(ex.Message, ex); // } // return result; //} #endregion /// <summary> /// 依据交易员ID,帐户类型取帐户信息 /// </summary> /// <param name="strTraderId"></param> /// <param name="iAccountTypeId"></param> /// <param name="AccountIsAvaliable"></param> /// <returns></returns> private string GetAccountByTraderInfo(string strTraderId, int iAccountTypeId, out bool AccountIsAvaliable) { #region new 2010-06-08 by 李健华 string result = string.Empty; AccountIsAvaliable = false; try { UA_UserAccountAllocationTableInfo model = AccountManager.Instance.GetAccountByUserIDAndAccountType(strTraderId, iAccountTypeId); if (model != null) { result = model.UserAccountDistributeLogo; AccountIsAvaliable = model.WhetherAvailable; } } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); } return(result); #endregion #region old code 2010-06-08 update by 李健华 //string result = string.Empty; //AccountIsAvaliable = false; //try //{ // List<UA_UserAccountAllocationTableInfo> list = null; // _userAccountCacheLock.EnterReadLock(); // try // { // list = _userAccountCache.GetByKey(strTraderId); // } // finally // { // _userAccountCacheLock.ExitReadLock(); // } // if (list == null) // { // UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); // string where = string.Format("UserID = '{0}' ", strTraderId); // list = dal.GetListArray(where); // _userAccountCacheLock.EnterWriteLock(); // try // { // _userAccountCache.Add(list, strTraderId); // } // finally // { // _userAccountCacheLock.ExitWriteLock(); // } // } // if (list != null) // { // foreach (UA_UserAccountAllocationTableInfo accountAllocationTable in list) // { // if (accountAllocationTable.AccountTypeLogo == iAccountTypeId) // { // result = accountAllocationTable.UserAccountDistributeLogo; // AccountIsAvaliable = accountAllocationTable.WhetherAvailable; // } // } // } //} //catch (Exception ex) //{ // LogHelper.WriteError(ex.Message, ex); //} //return result; #endregion }