浏览代码

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

yuanrf 16 小时之前
父节点
当前提交
e2f37761e3

+ 67 - 0
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -13,6 +13,7 @@ using System.Dynamic;
 using System.Linq;
 using static OASystem.API.OAMethodLib.GeneralMethod;
 using static OASystem.API.OAMethodLib.JWTHelper;
+using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 
 namespace OASystem.API.Controllers
 {
@@ -3241,6 +3242,72 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
             return Ok(JsonView(false));
         }
 
+
+        /// <summary>
+        /// 数据测试
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> TransactionExTest1()
+        {
+            
+            var groupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                .Where(x => x.IsDel == 0)
+                .Where(x => x.VisitDate >= Convert.ToDateTime("2025-01-01 00:00:00") && x.VisitDate <= Convert.ToDateTime("2025-12-31 23:59:59"))
+                .Select(x => x.Id)
+                .ToListAsync();
+
+            var datas = new List<View1>();
+            foreach (var id in groupIds)
+            {
+                var sql = @"
+SELECT 
+    dac.DiId,
+    CASE ntf.City
+        WHEN '全部城市' THEN ntf.Country + ' -> 全部城市'
+        WHEN '其他城市' THEN ntf.Country + ' -> 其他城市'
+        ELSE ntf.Country + ' -> ' + ntf.City
+    END as City
+FROM Grp_DayAndCost dac
+LEFT JOIN grp_NationalTravelFee ntf ON dac.NationalTravelFeeId = ntf.Id
+WHERE dac.IsDel = 0 
+    AND dac.DiId = @DiId
+GROUP BY 
+    dac.DiId,
+    CASE ntf.City
+        WHEN '全部城市' THEN ntf.Country + ' -> 全部城市'
+        WHEN '其他城市' THEN ntf.Country + ' -> 其他城市'
+        ELSE ntf.Country + ' -> ' + ntf.City
+    END";
+
+                var data = await _sqlSugar.Ado.SqlQueryAsync<View1>(sql, new { DiId = id });
+
+                datas.AddRange(data);
+            }
+
+            var view = datas.GroupBy(x => x.City)
+                .Select(x => new
+                {
+                    x.Key,
+                    Count = x.Count()
+                })
+                .OrderByDescending(x => x.Count)
+                .Skip(1)
+                .Take(20)
+                .ToList();
+            return Ok(JsonView(view));
+        }
+
+        private class View1 {
+
+            public int DiId { get; set; }
+
+            public string City { get; set; }
+        }
+
+
+
         #endregion
 
         #region 审批模板

+ 58 - 0
OASystem/OASystem.Api/OAMethodLib/DeepSeekAPI/DeepSeekService.cs

@@ -319,6 +319,64 @@ namespace OASystem.API.OAMethodLib.DeepSeekAPI
             }
         }
 
+        /// <summary>
+        /// 使用进行聊天
+        /// </summary>
+        public async Task<ApiResponse> ChatAsync(string question, string model = "deepseek-chat", float temperature = 0.7f, int maxTokens = 4000)
+        {
+            try
+            {
+                // 构建消息内容
+                var messageContent = new List<object>
+                {
+                    new { type = "text", text = question }
+                };
+
+                var request = new DeepSeekChatWithFilesRequest
+                {
+                    Model = model,
+                    Messages = new List<FileMessage>
+                    {
+                        new FileMessage
+                        {
+                            Role = "user",
+                            Content = messageContent
+                        }
+                    },
+                    Temperature = temperature,
+                    MaxTokens = maxTokens
+                };
+
+                var jsonContent = JsonSerializer.Serialize(request, new JsonSerializerOptions
+                {
+                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+                });
+
+                var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");
+                var response = await _httpClient.PostAsync("chat/completions", httpContent);
+                response.EnsureSuccessStatusCode();
+
+                var responseContent = await response.Content.ReadAsStringAsync();
+                var chatResponse = JsonSerializer.Deserialize<DeepSeekResponse>(responseContent, new JsonSerializerOptions
+                {
+                    PropertyNameCaseInsensitive = true
+                });
+
+                return new ApiResponse
+                {
+                    Success = true,
+                    Message = "聊天成功",
+                    Answer = chatResponse.Choices[0].Message.Content,
+                    TokensUsed = chatResponse.Usage.TotalTokens
+                };
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex, "使用文件聊天失败");
+                throw;
+            }
+        }
+
         /// <summary>
         /// 等待文件处理完成
         /// </summary>

+ 10 - 0
OASystem/OASystem.Api/OAMethodLib/DeepSeekAPI/IDeepSeekService.cs

@@ -64,6 +64,16 @@
         /// <returns>聊天响应</returns>
         Task<ApiResponse> ChatWithFilesAsync(List<string> fileIds, string question, string model = "deepseek-chat", float temperature = 0.7f, int maxTokens = 4000);
 
+        /// <summary>
+        /// 使用已上传的文件进行聊天
+        /// </summary>
+        /// <param name="question">问题</param>
+        /// <param name="model">模型名称</param>
+        /// <param name="temperature">温度参数</param>
+        /// <param name="maxTokens">最大token数</param>
+        /// <returns>聊天响应</returns>
+        Task<ApiResponse> ChatAsync(string question, string model = "deepseek-chat", float temperature = 0.7f, int maxTokens = 4000);
+
         /// <summary>
         /// 等待文件处理完成
         /// </summary>