田爽 3 сар өмнө
parent
commit
46f174c2b1

+ 7 - 0
Hotline.sln

@@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hotline.WeChat", "src\Hotli
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TianQue.Sdk", "src\TianQue.Sdk\TianQue.Sdk.csproj", "{6CF27647-D0E0-4D17-80FB-3EE57864A2B4}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hotline.Ai.XingTang", "src\Hotline.Ai.XingTang\Hotline.Ai.XingTang.csproj", "{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -159,6 +161,10 @@ Global
 		{6CF27647-D0E0-4D17-80FB-3EE57864A2B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{6CF27647-D0E0-4D17-80FB-3EE57864A2B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{6CF27647-D0E0-4D17-80FB-3EE57864A2B4}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -190,6 +196,7 @@ Global
 		{37784861-ABC0-41F4-87B4-2E08A89A2C42} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 		{75215667-65AF-4B7B-85E7-3140239B30CC} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 		{6CF27647-D0E0-4D17-80FB-3EE57864A2B4} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
+		{8E4F64EF-314A-45BA-8BB2-46FF5B06F7D5} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {4B8EA790-BD13-4422-8D63-D6DBB77B823F}

+ 132 - 0
src/Hotline.Ai.XingTang/AiQualityService.cs

@@ -0,0 +1,132 @@
+using RestSharp;
+using Fw.Utility.UnifyResponse;
+using System.Text;
+using System.Security.Cryptography;
+using Hotline.Share.Dtos.Quality;
+using Hotline.Ai.Quality;
+
+namespace Hotline.Ai.XingTang
+{
+    public class AiQualityService : IAiQualityService
+    {
+        private readonly RestClient _client;
+        private readonly string _baseUrl;
+
+        public AiQualityService(string baseUrl)
+        {
+            _client = new RestClient();
+            _baseUrl = baseUrl;
+        }
+
+        public async Task CreateAiOrderQualityTask(
+             string id,
+             string audioFile,
+             string fromNo,
+             DateTime? callStartTime,
+             string viteRecordPrefix,
+             string ywlxString,
+			 CancellationToken cancellationToken)
+        {
+            if (string.IsNullOrEmpty(audioFile)) return;
+            var fileExtension = Path.GetExtension(audioFile);
+            if (!string.IsNullOrEmpty(fileExtension) && fileExtension.StartsWith('.'))
+                fileExtension = fileExtension.Substring(1);
+            //var ywlx = !string.IsNullOrEmpty(ywlxString) ? ywlxString : model.Source.ToString();
+            var agentChannel = "AiAnswered".Equals(ywlxString) ? "2" : "3";
+			List <AiQualityDto> datalist = new List<AiQualityDto>();
+            AiQualityDto aiQuality = new AiQualityDto
+            {
+                RecordID = id,
+                RecordPath = viteRecordPrefix + audioFile,
+                AgentID = "1001",
+                CallNumber = fromNo,
+                CallTime = callStartTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? string.Empty,
+                RecordForm = fileExtension,//recordForm,
+                ywlx = ywlxString,
+                AgentChannel = agentChannel
+			};
+            datalist.Add(aiQuality);
+            var data = Newtonsoft.Json.JsonConvert.SerializeObject(datalist);
+            var baseUrl = new Uri(_baseUrl);
+            await ExecuteAsync(baseUrl.ToString() + "routeinfo/api", Method.Post, data, cancellationToken);
+        }
+
+        public async Task<ApiResponse<TResponse>> ExecuteAsync<TRequest, TResponse>(string path, Method httpMethod,
+            TRequest request, CancellationToken cancellationToken)
+            where TRequest : class
+        {
+            var req = new RestRequest(path, httpMethod);
+            if (httpMethod is Method.Get)
+            {
+                req.AddObject(request);
+            }
+            else
+            {
+                req.AddJsonBody(request);
+            }
+
+            try
+            {
+                var response = await _client.ExecuteAsync<ApiResponse<TResponse>>(req, cancellationToken);
+                return response.Data;
+            }
+            catch (Exception e)
+            {
+                throw new HttpRequestException($"智能质检平台错误,Error: {e.Message}");
+            }
+        }
+
+        public async Task<ApiResponse> ExecuteAsync<TRequest>(string path, Method httpMethod, TRequest request,
+            CancellationToken cancellationToken)
+            where TRequest : class
+        {
+            var req = new RestRequest(path, httpMethod);
+            req.AddHeader("content-type", "application/json");
+            req.AddHeader("token", "");
+            req.AddHeader("version", "V1.0");
+            var sign = MD5Encrypt(request.ToString());
+            req.AddHeader("sign", sign);
+            req.AddHeader("signType", "md5");
+            req.AddHeader("appkey", "MTAwMDAx");
+            if (httpMethod is Method.Get)
+            {
+                req.AddObject(request);
+            }
+            else
+            {
+                req.AddJsonBody(request);
+            }
+
+            try
+            {
+                var response = await _client.ExecuteAsync<ApiResponse>(req, cancellationToken);
+                return response.Data;
+            }
+            catch (Exception e)
+            {
+                throw new HttpRequestException($"智能质检平台错误,Error: {e.Message}");
+            }
+        }
+
+        /// <summary>
+        /// MD5加密
+        /// </summary>
+        /// <param name="input">需要加密的字符串</param>
+        /// <returns></returns>
+        private static string MD5Encrypt(string? input)
+        {
+            using var md5 = MD5.Create();
+            var t = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
+            var sb = new StringBuilder(32);
+            for (var i = 0; i < t.Length; i++)
+                sb.Append(t[i].ToString("x").PadLeft(2, '0'));
+            return sb.ToString();
+        }
+
+        private static string Base64En(string? model)
+        {
+            var bytes = Encoding.UTF8.GetBytes(model);
+            return Convert.ToBase64String(bytes);
+        }
+    }
+}

+ 15 - 0
src/Hotline.Ai.XingTang/AiXingTangStartupExtensions.cs

@@ -0,0 +1,15 @@
+using Hotline.Ai.Quality;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Hotline.Ai.XingTang
+{
+	public static class AiXingTangStartupExtensions
+	{
+		public  static IServiceCollection AddAiXingTang(this IServiceCollection services, string baseUrl)
+		{
+			services.AddSingleton<IAiQualityService, AiQualityService>(_ => new AiQualityService(baseUrl));
+
+			return services;
+		}
+	}
+}

+ 20 - 0
src/Hotline.Ai.XingTang/Hotline.Ai.XingTang.csproj

@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Fw.Utility.UnifyResponse" Version="1.0.0" />
+    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
+    <PackageReference Include="RestSharp" Version="112.1.0" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\Hotline.Share\Hotline.Share.csproj" />
+    <ProjectReference Include="..\Hotline\Hotline.csproj" />
+  </ItemGroup>
+
+</Project>

+ 3 - 1
src/Hotline.Api/StartupExtensions.cs

@@ -47,6 +47,7 @@ using XF.Domain.Repository.Events;
 using Hotline.Orders.DatabaseEventHandler;
 using Hotline.Snapshot;
 using Hotline.WeChat;
+using Hotline.Ai.XingTang
 
 
 namespace Hotline.Api;
@@ -157,7 +158,8 @@ internal static class StartupExtensions
                 services.AddProxiedScoped<ISnapshotApplication, DefaultSnapshotApplication>();
                 break;
             case AppDefaults.AppScope.ZiGong:
-                services.AddProxiedScoped<ISnapshotApplication, ZiGongSnapshotApplication>();
+				services.AddAiXingTang(appConfiguration.ZiGong.AiQuality.Url);
+				services.AddProxiedScoped<ISnapshotApplication, ZiGongSnapshotApplication>();
                 break;
             case AppDefaults.AppScope.LuZhou:
                 services.AddProxiedScoped<ISnapshotApplication, DefaultSnapshotApplication>();

+ 5 - 0
src/Hotline.Api/config/appsettings.Development.json

@@ -25,6 +25,11 @@
       }
     },
     "ZiGong": {
+      //智能质检
+      "AiQuality": {
+        "Url": "http://118.122.73.80:19072/" // 正式
+        //"Url": "http://118.122.73.80:19072/", // 测试
+      },
       "AreaCode": "510300",
       "CallCenterType": "XingTang"
     },

+ 1 - 0
src/Hotline.Application/Hotline.Application.csproj

@@ -17,6 +17,7 @@
 
   <ItemGroup>
     <ProjectReference Include="..\Hotline.Ai.Jths\Hotline.Ai.Jths.csproj" />
+    <ProjectReference Include="..\Hotline.Ai.XingTang\Hotline.Ai.XingTang.csproj" />
     <ProjectReference Include="..\Hotline.Application.Contracts\Hotline.Application.Contracts.csproj" />
     <ProjectReference Include="..\Hotline.NewRock\Hotline.NewRock.csproj" />
     <ProjectReference Include="..\Hotline.Repository.SqlSugar\Hotline.Repository.SqlSugar.csproj" />

+ 2 - 1
src/Hotline/Configurations/AppConfiguration.cs

@@ -41,7 +41,8 @@ namespace Hotline.Configurations
 
     public class ZiGongConfiguration : DefaultAppScopeConfiguration
     {
-    }
+		public AiQualityConfiguration AiQuality { get; set; }
+	}
 
     public class LuZhouConfiguration : DefaultAppScopeConfiguration
     {