/// <summary> /// 批量债转通知银行队列消耗 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btn_consumebatchCreditBank_Click(object sender, EventArgs e) { try { this.lbl_showMsg.Text = "正在消耗......"; this.btn_consumebatchCreditBank.Enabled = false; BrokeredMessage brokeredMessage; this.txb_batchCreditBankSNums.Text = "0"; this.txb_batchCreditBankFNums.Text = "0"; do { brokeredMessage = await this.messageReceiverBatchbookcredit.ReceiveAsync(TimeSpan.FromMinutes(1)); if (brokeredMessage != null) { string batchBookCreditInfos = brokeredMessage.GetBody <string>(); JObject jObject = JObject.Parse(batchBookCreditInfos); if (jObject == null) { continue; } //转json SendDebtForBankModel sendDebtForBankModel = jObject["MessageData"].ToString().FromJson <SendDebtForBankModel>(); //重试5次执行数据 for (int i = 0; i < 5; i++) { bool result = await YemApiService.SendDebtForBank(this.loadAppSettings.AssetApiUrl, sendDebtForBankModel, "SendDebtForBankLogs"); if (result) { this.UpdateTxtInfos(this.txb_batchCreditBankSNums); break; } else { if (i == 4) { this.UpdateTxtInfos(this.txb_batchCreditBankFNums); //记录下来数据 Logger.LoadData(@"SendDebtForBankInfos\ErrorDeadLineInfos.txt", sendDebtForBankModel.ToJson()); Logger.LoadData(@"SendDebtForBankInfos\ErrorDeadLineInfos.txt", "\r\n"); } } } } } while (brokeredMessage != null); this.btn_consumebatchCreditBank.Enabled = true; MessageBox.Show("本轮次执行完毕"); } catch (Exception exception) { this.lbl_showMsg.Text = "发生一个错误" + exception.Message; this.btn_consumebatchCreditBank.Enabled = true; Logger.LoadData(@"SendDebtForBankInfos\Errors.txt", exception.Message); } }
public static async Task <bool> SendDebtForBank(string url, SendDebtForBankModel request, string logFolderName) { HttpResponseMessage httpResponseMesage = new HttpResponseMessage(); try { //DebtForBank/SendAdvanceDebt httpResponseMesage = await InitialHttpClient().PostAsJsonAsync($"{url}DebtForBank/SendDebtForBank", request); CommonResult <bool> response = await httpResponseMesage.Content.ReadAsAsync <CommonResult <bool> >(); if (response.Result) { return(true); } return(false); } catch (Exception ex) { //log记录日志 Logger.LoadData(Path.Combine(logFolderName, "Error.txt"), ex.Message + "---------" + await httpResponseMesage.Content.ReadAsStringAsync() + "----" + request.ToJson()); return(false); } }
/// <summary> /// 设置每个rowkey的SendDebtForBankModel /// </summary> /// <param name="sendDebtForBankModel"></param> /// <param name="rowKey"></param> /// <returns></returns> public async Task SetRedisSendDebtForBankModelAsync(SendDebtForBankModel sendDebtForBankModel, string rowKey) { await this.database.HashSetToCacheAsync("SendDebtForBankModel", "List", rowKey, sendDebtForBankModel, TimeSpan.MaxValue); }