增加HttpClient日志处理器并更新Dockerfile时区设置
This commit is contained in:
parent
dfbc7fffb3
commit
3f21f5432a
22
AutoDispathingWork/DefaultHttpLoggingInterceptor.cs
Normal file
22
AutoDispathingWork/DefaultHttpLoggingInterceptor.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace AutoDispathingWork;
|
||||
|
||||
public class HttpClientLogHandler(ILogger<HttpClientLogHandler> logger) : DelegatingHandler
|
||||
{
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Content != null)
|
||||
{
|
||||
var content = await request.Content.ReadAsStringAsync(cancellationToken);
|
||||
logger.LogInformation("Request: {}",
|
||||
"RequestUri:" + request.RequestUri + content
|
||||
!);
|
||||
}
|
||||
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
logger.LogInformation(request.RequestUri + ":Response{Response}",
|
||||
await response.Content.ReadAsStringAsync(cancellationToken));
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@ -3,5 +3,6 @@ FROM 192.168.100.10:5000/dotnet/aspnet:8.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
ENV TZ=Asia/Shanghai
|
||||
COPY ./release .
|
||||
ENTRYPOINT ["dotnet", "AutoDispathingWork.dll"]
|
||||
@ -9,6 +9,11 @@ public class QueryReq
|
||||
[JsonPropertyName("pageSize")] public int PageSize { get; set; }
|
||||
|
||||
[JsonPropertyName("sortType")] public int[]? SortType { get; set; }
|
||||
[JsonPropertyName("createStartTime")] public long CreateStartTime { get; set; }
|
||||
[JsonPropertyName("createEndTime")] public long CreateEndTime { get; set; }
|
||||
[JsonPropertyName("createStartTime")] public long? CreateStartTime { get; set; }
|
||||
[JsonPropertyName("createEndTime")] public long? CreateEndTime { get; set; }
|
||||
|
||||
|
||||
|
||||
[JsonPropertyName("handleStartTime")] public long? HandleStartTime { get; set; }
|
||||
[JsonPropertyName("handleEndTime")] public long? HandleEndTime { get; set; }
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
using AutoDispathingWork;
|
||||
using AutoDispathingWork.Utils;
|
||||
using LiteDB;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Http.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Npgsql;
|
||||
using WorkerService1;
|
||||
@ -47,7 +49,9 @@ builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSingleton<LiteDatabase>(x => new LiteDatabase(builder.Configuration["Database:ConnectionString"]));
|
||||
builder.Services.AddSingleton<IConfiguration>(config);
|
||||
builder.Services.Configure<ClientOptions>(config.GetSection("ClientOptions"));
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddSingleton<HttpClientLogHandler>();
|
||||
builder.Services.AddHttpClient("Default")
|
||||
.AddHttpMessageHandler<HttpClientLogHandler>();
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddLogging();
|
||||
// builder.Services.AddMvcCore();
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using AutoDispathingWork.Utils;
|
||||
using LiteDB;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -43,7 +45,7 @@ public class SpiderServices
|
||||
public async Task<SpiderResponse<LoginResultData>> Login()
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
using var client = _httpClientFactory.CreateClient();
|
||||
using var client = _httpClientFactory.CreateClient("Default");
|
||||
var getClientOptions = await scope.ServiceProvider.GetService<SettingServices>()?
|
||||
.GetClientOptions();
|
||||
var loginApi = getClientOptions.LoginUrl;
|
||||
@ -114,7 +116,7 @@ public class SpiderServices
|
||||
// "referrer": "http://33.10.72.100/megcity/",
|
||||
// "referrerPolicy": "strict-origin-when-cross-origin",
|
||||
var token = await GetToken();
|
||||
using var client = _httpClientFactory.CreateClient();
|
||||
using var client = _httpClientFactory.CreateClient("Default");
|
||||
client.DefaultRequestHeaders.Add("authorization", $"{token}");
|
||||
client.DefaultRequestHeaders.Add("accept-language", "zh-CN,zh;q=0.9");
|
||||
client.DefaultRequestHeaders.Add("client-app-id", "megcity-web");
|
||||
@ -126,13 +128,25 @@ public class SpiderServices
|
||||
var endTs = (long)(DateTime.Now - startTime).TotalMilliseconds;
|
||||
var body = new QueryReq
|
||||
{
|
||||
State = new int[] { state },
|
||||
State = [state],
|
||||
PageNo = 1,
|
||||
PageSize = 50,
|
||||
SortType = new int[] { 20, 10 },
|
||||
CreateStartTime = (long)beginTs,
|
||||
CreateEndTime = (long)endTs
|
||||
};
|
||||
switch (state)
|
||||
{
|
||||
case 1:
|
||||
body.SortType = [20, 10];
|
||||
body.CreateStartTime = beginTs;
|
||||
body.CreateEndTime = endTs;
|
||||
break;
|
||||
case 3:
|
||||
body.SortType = [20, 10];
|
||||
body.HandleStartTime = beginTs;
|
||||
body.HandleEndTime = endTs;
|
||||
break;
|
||||
}
|
||||
|
||||
// {"state":[3],"pageNo":1,"pageSize":50,"sortType":[40,10],"handleStartTime":1762099200000,"handleEndTime":1762340979629}
|
||||
// {"state":[3],"pageNo":1,"pageSize":50,"sortType":[40,10],"handleStartTime":1697293650750,"handleEndTime":1699885650750}
|
||||
// {"state":[1],"pageNo":1,"pageSize":50,"sortType":[20,10],"createStartTime":1697290618034,"createEndTime":1699882618034}
|
||||
// {\"state\":[1],\"pageNo\":1,\"pageSize\":50,\"sortType\":[20,10],\"createStartTime\":1697204639551,\"createEndTime\":1697204639551}
|
||||
@ -140,8 +154,13 @@ public class SpiderServices
|
||||
var getClientOptions = await scope.ServiceProvider.GetService<SettingServices>()?
|
||||
.GetClientOptions();
|
||||
var taskPath = getClientOptions.GetTaskUrl;
|
||||
|
||||
var response = await client.PostAsync(taskPath,
|
||||
new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"));
|
||||
new StringContent(JsonSerializer.Serialize(body, new JsonSerializerOptions()
|
||||
{
|
||||
DefaultIgnoreCondition
|
||||
= JsonIgnoreCondition.WhenWritingNull
|
||||
}), Encoding.UTF8, "application/json"));
|
||||
var respJsonStr = await response.Content.ReadAsStringAsync();
|
||||
_logger.LogInformation("获得列表返回json: {respJsonStr}", respJsonStr);
|
||||
var spiderRes = JsonSerializer.Deserialize<QueryResp>(respJsonStr);
|
||||
@ -322,7 +341,7 @@ public class SpiderServices
|
||||
.SendText(
|
||||
$"案件{caseNumber}已经结案,所在位置{address},处理意见{(string.IsNullOrWhiteSpace(suggestion) ? "无" : suggestion)}",
|
||||
false);
|
||||
|
||||
|
||||
return new SpiderResponse<object>()
|
||||
{
|
||||
IsSuccess = true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user