/// <summary> /// 拉去redis内容 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_checkAllAsset_Click(object sender, EventArgs e) { try { int redisNumber = Convert.ToInt32(this.txb_RedisNumber.Text.Trim()); string redisKeyname = this.txb_RedisKey.Text.Trim(); if (string.IsNullOrEmpty(redisKeyname)) { MessageBox.Show("请输入redisKeyName......."); return; } //生成redisHelper RedisHelperSpecial redisHelperSpecial = new RedisHelperSpecial(redisNumber); //获取redisContent string content = await redisHelperSpecial.GetRedisContentAsync(redisKeyname); //存入到文本文件中 Logger.LoadData(@"RedisContent/content_" + redisKeyname + ".txt", content); MessageBox.Show("获取rediscontent成功,请到bin目录下RedisContent文件夹中查看"); } catch (Exception exception) { MessageBox.Show("获取失败,失败错误信息为" + exception.Message); } }
public UpdateDataFromBank(LoadAppSettings loadAppSettings, CloudTableClient tableClient) { this.redisHelperSpecial = new RedisHelperSpecial(10); this.loadAppSettings = loadAppSettings; this.tableClient = tableClient; this.httpClient = new HttpClient(); CheckForIllegalCrossThreadCalls = false; this.InitializeComponent(); }
public UpdateUserAssetRatioInfoForm(LoadAppSettings loadAppSettings, CloudTableClient tableClient) { this.redisHelperSpecial = new RedisHelperSpecial(11); this.loadAppSettings = loadAppSettings; this.tableClient = tableClient; this.httpClient = new HttpClient(); this.httpClient.Timeout = TimeSpan.FromSeconds(180); CheckForIllegalCrossThreadCalls = false; this.InitializeComponent(); }
public UpdateAssetUserRatioForms(LoadAppSettings loadAppSettings, CloudTableClient tableClient) { this.threadNums = Convert.ToInt32(ConfigurationManager.AppSettings["ThreadNumsByUpdate"]); this.redisHelperSpecial = new RedisHelperSpecial(11); this.startTime = Convert.ToDateTime(ConfigurationManager.AppSettings["startTime"]).ToChinaStandardTime(); this.endTime = Convert.ToDateTime(ConfigurationManager.AppSettings["endTime"]).ToChinaStandardTime(); this.loadAppSettings = loadAppSettings; this.tableClient = tableClient; this.httpClient = new HttpClient(); this.httpClient.Timeout = TimeSpan.FromSeconds(180); CheckForIllegalCrossThreadCalls = false; this.InitializeComponent(); }
/// <summary> /// 根据资产id查询一个资产是否正确 /// </summary> /// <param name="asseId"></param> /// <param name="reidsHelperSpecial"></param> /// <param name="dbNumber"></param> /// <returns></returns> private bool CheckAssetInfo(string asseId, int dbNumber, RedisHelperSpecial reidsHelperSpecial) { try { //获取Asset对象 CloudTable assertIdsTable = this.tableClient.GetTableReference(this.loadAppSettings.SearchAssetAzureTable); TableQuery <OnSellAssetDto> queryOnSellAsset = new TableQuery <OnSellAssetDto>() .Where($"RowKey eq '{asseId}' and IsLock eq false"); // //queryPurchaseOrder = new TableQuery<YemUserProductDto>() // .Where($"PartitionKey eq '{yemUserPurchase}' and RemainingAmount gt 0 and IsLock eq false"); OnSellAssetDto onSellAssetDto = assertIdsTable.ExecuteQuery(queryOnSellAsset).FirstOrDefault(); //获取融资金额以及剩余金额 if (onSellAssetDto == null) { //记录下来 Logger.LoadData(@"CheckOneRedisUserAssetInfo\ErrorInfo.txt", $"{asseId}:根据assetid拉取AzureTable数据异常" + DateTime.UtcNow.ToChinaStandardTime()); return(false); } long calculatedAmount = onSellAssetDto.PresentValue; long remainAmount = onSellAssetDto.RemainderTotal; //再从redis中拉出所有的资产的下对应 List <UserAssetRatio> listAssetUserInfos = new RedisHelperSpecial(dbNumber).GetRedisAssetUserRatiosAsync(asseId).ToList(); long sumSellAmount = 0; if (listAssetUserInfos.Count > 0) { sumSellAmount += listAssetUserInfos.Sum(info => info.Capital); } //从收尾那边拉出所有的资产比例 List <UserAssetRatio> listEndAssetUserInfos = reidsHelperSpecial.GetRedisAssetUserRatiosAsync(asseId).ToList(); if (listEndAssetUserInfos.Count > 0) { sumSellAmount += listEndAssetUserInfos.Sum(info => info.Capital); } //List<UserAssetRatio> if (calculatedAmount - sumSellAmount != remainAmount) { //记录下来 Logger.LoadData(@"CheckOneRedisUserAssetInfo\ErrorInfo.txt", $"{asseId}:该资产剩余金额不等于该资产总融资金额减去该资产下用户购买金额之和" + DateTime.UtcNow.ToChinaStandardTime()); return(false); } return(true); } catch (Exception e) { Logger.LoadData(@"CheckOneRedisUserAssetInfo\Error.txt", $"{asseId}:该资产发生异常{e.Message}"); return(false); } }
/// <summary> /// 根据用户id查看用户购买订单是否正确 /// </summary> /// <param name="userId"></param> /// <param name="dbNumber"></param> /// <param name="redisHelperSpecial"></param> /// <returns></returns> private bool CheckPurchaseOrderInfo(string userId, int dbNumber, List <YemUserProductDto> yemUserProductDtos, RedisHelperSpecial redisHelperSpecial) { try { //获取Asset对象 //string oldPurchaseOrder = "OldPurchaseOrder"; //CloudTable assertIdsTable = this.tableClient.GetTableReference(this.loadAppSettings.SearchUserInfoAzureTable); //TableQuery<YemUserProductDto> queryYemProduct = new TableQuery<YemUserProductDto>() // .Where($"PartitionKey eq '{oldPurchaseOrder}' and IsLock eq false and UserId eq '{userId}'"); //YemUserProductDto yemUserProductDto = assertIdsTable.ExecuteQuery(queryYemProduct).FirstOrDefault(); YemUserProductDto yemUserProductDto = yemUserProductDtos.FirstOrDefault(p => p.UserId == userId); //获取融资金额以及剩余金额 if (yemUserProductDto == null) { //记录下来 Logger.LoadData(@"CheckOneRedisUserAssetInfo\ErrorInfoUserInfo.txt", $"{userId}:根据userId拉取AzureTable数据异常---" + DateTime.UtcNow.ToChinaStandardTime()); return(false); } long purchaseAmount = yemUserProductDto.PurchaseMoney; long remainingAmount = yemUserProductDto.RemainingAmount; //再从reedis中拉出所有的资产的下对应 List <UserAssetRatio> listUserAssetInfos = new RedisHelperSpecial(dbNumber).GetRedisUserAssetRatiosAsync(userId).ToList(); long sumPurchaseAmount = 0; if (listUserAssetInfos.Count > 0) { sumPurchaseAmount += listUserAssetInfos.Sum(info => info.Capital); } //最后的节点 List <UserAssetRatio> listEndUserAssetinfos = redisHelperSpecial.GetRedisUserAssetRatiosAsync(userId).ToList(); if (listEndUserAssetinfos.Count > 0) { sumPurchaseAmount += listEndUserAssetinfos.Sum(info => info.Capital); } if (purchaseAmount - sumPurchaseAmount != remainingAmount) { //记录下来 Logger.LoadData(@"CheckOneRedisUserAssetInfo\ErrorInfoUserInfo.txt", $"{userId}:该用户购买订单总购买金额减去所有本金不等于剩余金额" + DateTime.UtcNow.ToChinaStandardTime()); return(false); } return(true); } catch (Exception e) { Logger.LoadData(@"CheckOneRedisUserAssetInfo\Error.txt", $"{userId}:该资产发生异常{e.Message}"); return(false); } }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void button1_Click(object sender, EventArgs e) { List <int> numbers = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8 }; long totalNums = 0; for (int i = 0; i < numbers.Count; i++) { int number = numbers[i]; RedisHelperSpecial redisHelperSpecial = new RedisHelperSpecial(number); //啦list List <string> userids = redisHelperSpecial.GetRedisUserInfos().Select(u => u.UserId).ToList(); for (int j = 0; j < userids.Count; j++) { //获取list totalNums += redisHelperSpecial.GetRedisUserAssetRatiosAsync(userids[j]).Count; } } // MessageBox.Show(totalNums.ToString()); }
private void btn_CheckAllUserInfo_Click(object sender, EventArgs e) { //验证所有的用户和资产信息 try { //获取所有的asset信息 string[] redisNumbers = ConfigurationManager.AppSettings["AllDbNumberNotExitEnd"].Split(','); Dictionary <string, int> dicUserInfo = new Dictionary <string, int>(); List <string> userIds = new List <string>(); for (int i = 0; i < redisNumbers.Length; i++) { int number = Convert.ToInt32(redisNumbers[i]); RedisHelperSpecial redisHelperSpecial = new RedisHelperSpecial(number); List <string> oneRedisUserIds = redisHelperSpecial.GetRedisUserInfos().Select(a => a.UserId).ToList(); foreach (string t in oneRedisUserIds) { if (!dicUserInfo.ContainsKey(t)) { userIds.Add(t); dicUserInfo.Add(t, number); } } } //循环跑 if (dicUserInfo.Count == 0) { MessageBox.Show("redis不存在用户购买数据"); } string oldPurchaseOrder = "OldPurchaseOrder"; CloudTable assertIdsTable = this.tableClient.GetTableReference(this.loadAppSettings.SearchUserInfoAzureTable); TableQuery <YemUserProductDto> queryYemProduct = new TableQuery <YemUserProductDto>() .Where($"PartitionKey eq '{oldPurchaseOrder}' and IsLock eq false"); List <YemUserProductDto> yemUserProductDtos = assertIdsTable.ExecuteQuery(queryYemProduct).Where(p => userIds.Contains(p.UserId)).ToList(); this.lbl_ShowAllUserInfo.Text = "正在开始验证所有的用户数据,请稍等....."; this.btn_CheckAllUserInfo.Enabled = false; this.txb_allUserFail.Text = "0"; this.txb_allUserSuccess.Text = "0"; //跑数据 for (int i = 0; i < 6; i++) { Thread th = new Thread(() => { while (dicUserInfo.Count > 0) { string userid = string.Empty; int dbNumber = 0; lock (this.objLock) { if (dicUserInfo.Count > 0) { userid = dicUserInfo.Keys.First(); dbNumber = dicUserInfo[userid]; dicUserInfo.Remove(userid); } } if (!string.IsNullOrEmpty(userid)) { //执行 bool result = this.CheckPurchaseOrderInfo(userid, dbNumber, yemUserProductDtos, new RedisHelperSpecial(this.loadAppSettings.EndDbNumber)); lock (this.objLock) { this.UpdateTxbText(result ? this.txb_allUserSuccess : this.txb_allUserFail); } } } }); th.IsBackground = true; th.Start(); } Thread thShow = new Thread(() => { while (true) { if (dicUserInfo.Count > 0) { Thread.Sleep(1500); continue; } break; } Thread.Sleep(2000); this.btn_CheckAllUserInfo.Enabled = true; this.lbl_ShowAllUserInfo.Text = "验证完所有用户数据"; //提示 }); thShow.IsBackground = true; thShow.Start(); } catch (Exception ex) { this.btn_CheckAllUserInfo.Enabled = true; Logger.LoadData(@"CheckOneRedisUserAssetInfo\Error.txt", $"验证所有用户数据发生异常{ex.Message}"); } }
/// <summary> /// 验证所有的用户 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_checkAllUser_Click(object sender, EventArgs e) { try { //获取所有的AssetId List <string> userIds = RedisHelper.GetRedisUserInfos().Select(x => x.UserId).ToList(); if (userIds.Count == 0) { MessageBox.Show("该redis不存在用户数据"); return; } this.txb_checkUserFailed.Text = "0"; this.txb_checkUserSuccess.Text = "0"; this.btn_checkAllUser.Enabled = false; this.lbl_showMsg_User.Text = "正在开始验证所有的用户数据,请稍等....."; RedisHelperSpecial redisHelperSpecial = new RedisHelperSpecial(this.loadAppSettings.EndDbNumber); int i = 0; string oldPurchaseOrder = "OldPurchaseOrder"; CloudTable assertIdsTable = this.tableClient.GetTableReference(this.loadAppSettings.SearchUserInfoAzureTable); TableQuery <YemUserProductDto> queryYemProduct = new TableQuery <YemUserProductDto>() .Where($"PartitionKey eq '{oldPurchaseOrder}' and IsLock eq false"); List <YemUserProductDto> yemUserProductDtos = assertIdsTable.ExecuteQuery(queryYemProduct).Where(p => userIds.Contains(p.UserId)).ToList(); Parallel.ForEach(userIds, userId => { bool result = this.CheckPurchaseOrderInfo(userId, this.loadAppSettings.DbNumber, yemUserProductDtos, redisHelperSpecial); lock (this.objLock) { this.UpdateTxbText(result ? this.txb_checkUserSuccess : this.txb_checkUserFailed); i = i + 1; } }); //for (int i = 0; i < 6; i++) //{ // Thread thread = new Thread(() => // { // while (userIds.Count > 0) // { // string userId = string.Empty; // lock (this.objLock) // { // if (userIds.Count > 0) // { // userId = userIds[0]; // userIds.Remove(userId); // } // } // if (!string.IsNullOrEmpty(userId)) // { // //执行 // bool result = this.CheckPurchaseOrderInfo(userId, this.loadAppSettings.DbNumber, redisHelperSpecial); // lock (this.objLock) // { // this.UpdateTxbText(result ? this.txb_checkUserSuccess : this.txb_checkUserFailed); // } // } // } // }); // thread.IsBackground = true; // thread.Start(); //} Thread thShow = new Thread(() => { while (true) { if (i == userIds.Count) { break; } Thread.Sleep(2000); } Thread.Sleep(2000); this.btn_checkAllUser.Enabled = true; this.lbl_showMsg_User.Text = "验证完所有用户数据"; //提示 }); thShow.IsBackground = true; thShow.Start(); } catch (Exception exception) { this.btn_checkAllUser.Enabled = true; this.lbl_showMsg_User.Text = "验证所有用户购买订单数据异常," + exception.Message; Logger.LoadData(@"CheckOneRedisUserAssetInfo\Error.txt", $"验证所有用户数据发生异常{exception.Message}"); } }
/// <summary> /// 验证所有的用户和资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_CheckAllInfo_Click(object sender, EventArgs e) { //验证所有的用户和资产信息 try { //获取所有的asset信息 string[] redisNumbers = ConfigurationManager.AppSettings["AllDbNumberNotExitEnd"].Split(','); Dictionary <string, int> dicAssetInfo = new Dictionary <string, int>(); for (int i = 0; i < redisNumbers.Length; i++) { int number = Convert.ToInt32(redisNumbers[i]); RedisHelperSpecial redisHelperSpecial = new RedisHelperSpecial(number); List <string> oneRedisAssetIds = redisHelperSpecial.GetRedisAssetInfos().Select(a => a.OnSellAssetId).ToList(); foreach (string t in oneRedisAssetIds) { if (!dicAssetInfo.ContainsKey(t)) { dicAssetInfo.Add(t, number); } } } //循环跑 if (dicAssetInfo.Count == 0) { MessageBox.Show("redis不存在资产数据"); } this.lbl_ShowAllAssetInfo.Text = "正在开始验证所有的资产数据,请稍等....."; this.btn_CheckAllAssetInfo.Enabled = false; this.txb_allAssetFail.Text = "0"; this.txb_allAssetSuccess.Text = "0"; //跑数据 for (int i = 0; i < 6; i++) { Thread th = new Thread(() => { while (dicAssetInfo.Count > 0) { string assetId = string.Empty; int dbNumber = 0; lock (this.objLock) { if (dicAssetInfo.Count > 0) { assetId = dicAssetInfo.Keys.First(); dbNumber = dicAssetInfo[assetId]; dicAssetInfo.Remove(assetId); } } if (!string.IsNullOrEmpty(assetId)) { //执行 bool result = this.CheckAssetInfo(assetId, dbNumber, new RedisHelperSpecial(this.loadAppSettings.EndDbNumber)); lock (this.objLock) { this.UpdateTxbText(result ? this.txb_allAssetSuccess : this.txb_allAssetFail); } } } }); th.IsBackground = true; th.Start(); } Thread thShow = new Thread(() => { while (true) { if (dicAssetInfo.Count > 0) { Thread.Sleep(1500); continue; } break; } Thread.Sleep(2000); this.btn_CheckAllAssetInfo.Enabled = true; this.lbl_ShowAllAssetInfo.Text = "验证完所有资产数据"; //提示 }); thShow.IsBackground = true; thShow.Start(); } catch (Exception ex) { this.btn_CheckAllAssetInfo.Enabled = true; Logger.LoadData(@"CheckOneRedisUserAssetInfo\Error.txt", $"验证所有资产数据发生异常{ex.Message}"); } }