第三方接口请求记录

This commit is contained in:
2024-07-11 15:20:45 +08:00
parent 614681284d
commit 22f255f85e
5 changed files with 235 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Core.Manager;
@@ -432,6 +433,62 @@ namespace Tnb.ProductionMgr
await _prdMoTaskService.PrdReport(input);
return "true";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> SendThirdApi(string thirdNmaes)
{
string[] thirdNameArr = thirdNmaes.Split("-");
List<ThirdWebapiRecord> records = await _db.Queryable<ThirdWebapiRecord>().Where(x => thirdNameArr.Contains(x.third_name) && x.status == 0 && x.is_send == 1).ToListAsync();
DateTime now = DateTime.Now;
Stopwatch stopwatch = null;
string response = "";
var elapsedMilliseconds = 0l;
ThirdResult thirdResult = null;
foreach (var record in records)
{
now = DateTime.Now;
stopwatch = Stopwatch.StartNew();
switch (record.method.ToUpper())
{
case "GET":
response = HttpUtils.RequestGet(record.url);
break;
case "POST":
response = HttpUtils.RequestPost(record.url, record.request_data);
break;
}
stopwatch.Stop();
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
thirdResult = JsonConvert.DeserializeObject<ThirdResult>(response);
if (thirdResult.Code == 200)
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.SetColumns(x => x.send_type == "自动")
.SetColumns(x => x.status == 1)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
else
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
}
return "true";
}
}
}