2 Commits b9b306e85d ... 7e764a8ac9

Autore SHA1 Messaggio Data
  Lyyyi 7e764a8ac9 Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop 3 giorni fa
  Lyyyi 72bcb25f32 优化代码结构与功能增强 3 giorni fa

+ 10 - 3
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -43,10 +43,17 @@ namespace OASystem.API.Controllers
         /// <param name="messageRep"></param>
         /// <param name="deviceRep"></param>
         /// <param name="hubContext"></param>
-        public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper, MessageRepository message,
-            SystemMenuPermissionRepository sysMenuPermRep, IQiYeWeChatApiService qiYeWeChatApiService, MessageRepository messageRep,
+        public AuthController(
+            IConfiguration config, 
+            LoginRepository loginRep, 
+            IMapper mapper, 
+            MessageRepository message,
+            SystemMenuPermissionRepository sysMenuPermRep, 
+            IQiYeWeChatApiService qiYeWeChatApiService, 
+            MessageRepository messageRep,
             DeviceTokenRepository deviceRep,
-            IHubContext<ChatHub, IChatClient> hubContext)
+            IHubContext<ChatHub, 
+                IChatClient> hubContext)
         {
             _config = config;
             _loginRep = loginRep;

+ 91 - 4
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -26,6 +26,7 @@ using OASystem.Domain.Dtos.Groups;
 using OASystem.Domain.Entities.Customer;
 using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.ViewModels.CRM;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Groups;
 using OASystem.Domain.ViewModels.OCR;
@@ -39,6 +40,7 @@ using System.Data;
 using System.Diagnostics;
 using System.Globalization;
 using System.IO.Compression;
+using System.Text.Json;
 using System.Web;
 using static OASystem.API.OAMethodLib.JWTHelper;
 using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
@@ -2251,7 +2253,7 @@ FROM
                 .LeftJoin<Crm_DeleClient>((x, s, dc) => x.ClientId == dc.Id && dc.IsDel == 0)
                 .LeftJoin<Crm_CustomerCompany>((x, s, dc, cc) => dc.CrmCompanyId == cc.Id && cc.IsDel == 0)
                 .Where((x, s, dc, cc) => x.DiId == dto.GroupId && x.IsDel == 0)
-                .Select((x, s, dc, cc) => new groupClints
+                .Select((x, s, dc, cc) => new GroupClints
                 {
                     Id = x.Id,
                     Name = s.Name,
@@ -2745,18 +2747,103 @@ FROM
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> VisaFileUploadAndUpdate(FormFile file)
+        public async Task<IActionResult> VisaFileUploadAndUpdate(IFormFile file,int fileTypeId)
         {
             //文件验证
-            if (file.Length < 1)
+            if (file.Length < 1) return Ok(JsonView(false,"请选择文件!"));
+            
+            var visaFiles = new VisaUploadFileTypeView();
+            var filetypes = visaFiles.GetVisaUploadFileTypeViewItemInit();
+            if (!filetypes.Any(x => x.FileId == fileTypeId)) return Ok(JsonView(false, "请选择文件类型!"));
+
+            //服务器存储文件
+            var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Uploads";
+            if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
+            var filePath = Path.Combine(fileServerPath, file.FileName);
+            using (var stream = new FileStream(filePath, FileMode.Create))
             {
+                await file.CopyToAsync(stream);
+            }
+            //日志记录-上传文件
+            _logger.LogInformation("【签证上传文件操作信息】签证文件存储成功!路径:{fileServerPath} 文件名称:{fileName}", fileServerPath, file.FileName);
+
+            //kimi AI 识别文档返回json结果
+            int kimiAI_API_Index = 0; //KIMI-AI-API 访问计次
+            var KiMiApi = new KiMiApiClient();
+            var files = new List<IFormFile>() { file };
+            var seedConter = await KiMiApi.UploadFilesAsync(files);
+
+            if (seedConter.Count == 0) return Ok(JsonView(false, "Kimi AI 文件上传结果为空!"));
+
+            var seedMessage = filetypes.Where(x => x.FileId == fileTypeId).FirstOrDefault()?.KimiAITips;
+            var messages = new List<SeedMessages>
+            {
+                new()  { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长识别文件为Json格式的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
+                new()  { Role = KimiRole.user, Content = seedMessage }
+            };
+            messages.InsertRange(1, seedConter);
 
+            string jsonString = string.Empty;
+            bool isJson = false; // 是否是json格式 不是json格式继续访问AI
+            while (!isJson)
+            {
+                kimiAI_API_Index++;
+                var kimiApiResult = await KiMiApi.SeedMessage(messages);
+                var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
+                jsonString += kimiApiResult_JObject["content"].ToString();
+
+                string startStr = "```json", endStr = "```";
+
+                // 判断并清除开头部分
+                if (jsonString.StartsWith(startStr))
+                {
+                    jsonString = jsonString.Remove(0, startStr.Length);
+                }
+
+                // 判断并清除结尾部分
+                if (jsonString.EndsWith(endStr))
+                {
+                    jsonString = jsonString.Replace(endStr, "");
+                }
+
+                //验证json格式是否正确
+                try
+                {
+                    JsonDocument.Parse(jsonString);
+                    isJson = true; // 如果解析成功,则是json格式
+                }
+                catch (Exception)
+                {
+                    //messages = new List<SeedMessages>() { new() { Role = KimiRole.user, Content = "接着说" } };
+                    messages.Add(new() { Role = KimiRole.user, Content = "接着上一个话题继续完成未完成的内容。" });
+                }
             }
 
 
+            var clientInfo = new Crm_DeleClient();            //客户资料表
+            var clientFamily = new Crm_VisaCustomerFamily();  //客户家庭表
+            var clientCompany = new Crm_CustomerCompany();    //客户公司表
+            var clientCert = new Crm_CustomerCert();          //客户证件表
+            var clientSchool = new Crm_VisaCustomerSchool();  //客户学历表
+
+            //按照表格类型分别进行参数处理
+            switch (fileTypeId) {
+                //澳新签证个人申请表
+                case 1:
 
+                    _logger.LogInformation("【签证上传文件操作信息】【澳新签证个人申请表】【KIMI-AI-API访问计次】{count} 次", kimiAI_API_Index);
+                    VisaApplication resInfo = System.Text.Json.JsonSerializer.Deserialize<VisaApplication>(jsonString);
 
-            return Ok(JsonView(true));
+                    break;
+                default:
+
+                    break;
+            
+            }
+
+
+
+            return Ok(JsonView(true, jsonString));
         }
 
 

+ 12 - 15
OASystem/OASystem.Api/Middlewares/ExceptionHandlingMiddleware.cs

@@ -10,19 +10,16 @@ namespace OASystem.API.Middlewares
     {
         private readonly RequestDelegate _next;  // 用来处理上下文请求
         private readonly ILogger<ExceptionHandlingMiddleware> _logger;
-        private readonly SqlSugarClient _db;
 
         /// <summary>
         /// 初始化
         /// </summary>
         /// <param name="next"></param>
         /// <param name="logger"></param>
-        /// <param name="db"></param>
-        public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger, SqlSugarClient db)
+        public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger)
         {
             _next = next;
             _logger = logger;
-            _db = db;
         }
 
         /// <summary>
@@ -52,17 +49,17 @@ namespace OASystem.API.Middlewares
         /// <returns></returns>
         private async Task HandleExceptionAsync(HttpContext context, Exception exception, SqlSugarClient db)
         {
-            if (db.Ado != null && db.Ado.Transaction != null)
-            {
-                try
-                {
-                    db.Ado.RollbackTran();
-                }
-                catch (Exception ex)
-                {
-                    _logger.LogError("Error rolling back transaction: {ErrorMessage}", ex.Message);
-                }
-            }
+            //if (db.Ado != null && db.Ado.Transaction != null)
+            //{
+            //    try
+            //    {
+            //        db.Ado.RollbackTran();
+            //    }
+            //    catch (Exception ex)
+            //    {
+            //        _logger.LogError("Error rolling back transaction: {ErrorMessage}", ex.Message);
+            //    }
+            //}
 
             // 检查响应是否已开始
             if (!context.Response.HasStarted)

+ 2 - 1
OASystem/OASystem.Api/Middlewares/RecordAPIOperationMiddleware.cs

@@ -79,7 +79,8 @@ namespace OASystem.API.Middlewares
                                 if (!string.IsNullOrEmpty(number))
                                 {
                                     var info = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Number.Equals(number)).FirstAsync();
-                                    userId = info.Id;
+
+                                    userId = info?.Id ?? 0;
                                 }
                             }
                             else

+ 4 - 0
OASystem/OASystem.Api/OASystem.API.csproj

@@ -27,6 +27,10 @@
     <None Remove="Logs\**" />
   </ItemGroup>
 
+  <ItemGroup>
+    <None Remove="Controllers\GroupsController.cs~RF185e674.TMP" />
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.23" />
     <PackageReference Include="AspNetCore.HealthChecks.UI" Version="6.0.1" />

+ 9 - 1
OASystem/OASystem.Api/Program.cs

@@ -145,13 +145,19 @@ var groups = new List<Tuple<string, string>>
 #region 注入数据库
 builder.Services.AddScoped(options =>
 {
+
+    var cpuCount = Environment.ProcessorCount;
+    var poolMin = Math.Max(5, cpuCount * 2);
+    var poolMax = Math.Max(100, cpuCount * 20);
+
     return new SqlSugarClient(new List<ConnectionConfig>()
     {
         new() {
             ConfigId = DBEnum.OA2023DB,
             ConnectionString = _config.GetConnectionString("OA2023DB"),
             DbType = DbType.SqlServer,
-            IsAutoCloseConnection = true
+            IsAutoCloseConnection = true,
+            
         },
         new()
         {
@@ -198,6 +204,8 @@ builder.Services.AddScoped(options =>
 
             //获取无参数SQL对性能有影响,特别大的SQL参数多的,调试使用
             //UtilMethods.GetSqlString(DbType.SqlServer, exp.sql, exp.parameters);
+
+            
         };
         //修改SQL和参数的值
         db.Aop.OnExecutingChangeSql = (sql, pars) =>