Kaynağa Gözat

AI绩效分析市场完善

yuanrf 1 gün önce
ebeveyn
işleme
79edecf75e

Dosya farkı çok büyük olduğundan ihmal edildi
+ 63 - 5
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs


+ 117 - 2
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -29,6 +29,8 @@ using OASystem.Infrastructure.Repositories.Groups;
 using System.Data;
 using System.IdentityModel.Tokens.Jwt;
 using System.Security.Claims;
+using OASystem.Domain.ViewModels.PersonnelModule;
+using OASystem.Domain.Dtos.PersonnelModule;
 
 namespace OASystem.API.OAMethodLib
 {
@@ -6553,10 +6555,123 @@ namespace OASystem.API.OAMethodLib
             builder.Font.Italic = false;
             builder.Font.Color = System.Drawing.Color.Black;
         }
+        #endregion
 
-    }
-    #endregion
 
+        #region 动态参数字符串格式化
+
+        /// <summary>
+        /// 动态参数字符串格式化
+        /// </summary>
+        /// <param name="dto">字符串格式化参数DTO</param>
+        /// <returns>格式化结果View</returns>
+        public static Task<StringFormatView> StringFormatAsync(StringFormatDto dto)
+        {
+            // 参数验证
+            if (string.IsNullOrWhiteSpace(dto?.FormatTemplate))
+            {
+                return Task.FromResult(new StringFormatView
+                {
+                    Success = false,
+                    Message = "格式化模板不能为空!"
+                });
+            }
+
+            if (dto.Parameters == null)
+            {
+                dto.Parameters = new List<string>();
+            }
+
+            try
+            {
+                // 计算需要的占位符数量
+                var placeholderCount = CountPlaceholders(dto.FormatTemplate);
+
+                // 验证参数数量是否匹配
+                if (dto.Parameters.Count != placeholderCount)
+                {
+                    return Task.FromResult(new StringFormatView
+                    {
+                        Success = false,
+                        Message = $"参数数量不匹配!模板需要 {placeholderCount} 个参数,但提供了 {dto.Parameters.Count} 个参数。"
+                    });
+                }
+
+                // 格式化字符串
+                string formattedResult = string.Format(dto.FormatTemplate, dto.Parameters.Cast<object>().ToArray());
+
+                var result = new StringFormatView
+                {
+                    Success = true,
+                    Message = "操作成功!",
+                    OriginalTemplate = dto.FormatTemplate,
+                    FormattedResult = formattedResult,
+                    Parameters = dto.Parameters,
+                    ParameterCount = dto.Parameters.Count
+                };
+
+                return Task.FromResult(result);
+            }
+            catch (FormatException ex)
+            {
+                return Task.FromResult(new StringFormatView
+                {
+                    Success = false,
+                    Message = $"格式化错误:{ex.Message}"
+                });
+            }
+            catch (Exception ex)
+            {
+                return Task.FromResult(new StringFormatView
+                {
+                    Success = false,
+                    Message = $"处理失败:{ex.Message}"
+                });
+            }
+        }
+
+        /// <summary>
+        /// 计算模板字符串中的占位符数量
+        /// </summary>
+        private static int CountPlaceholders(string template)
+        {
+            if (string.IsNullOrWhiteSpace(template))
+                return 0;
+
+            int maxIndex = -1;
+            int index = 0;
+
+            while (index < template.Length)
+            {
+                if (template[index] == '{')
+                {
+                    int endIndex = template.IndexOf('}', index);
+                    if (endIndex > index)
+                    {
+                        string placeholder = template.Substring(index + 1, endIndex - index - 1);
+                        if (int.TryParse(placeholder, out int placeholderIndex))
+                        {
+                            maxIndex = Math.Max(maxIndex, placeholderIndex);
+                        }
+                        index = endIndex + 1;
+                    }
+                    else
+                    {
+                        index++;
+                    }
+                }
+                else
+                {
+                    index++;
+                }
+            }
+
+            return maxIndex + 1; // 返回最大索引+1(因为索引从0开始)
+        }
+
+
+        #endregion
+    }
 }
 
 

+ 18 - 1
OASystem/OASystem.Domain/Dtos/PersonnelModule/AiPerformanceAnalysisDtos.cs

@@ -10,11 +10,28 @@ namespace OASystem.Domain.Dtos.PersonnelModule
     {
     }
 
-    public class AiPerformanceAnalysis_UserListDto: DtoBase
+    public class AiPerformanceAnalysis_UserListDto : DtoBase
     {
         /// <summary>
         /// 筛选条件 公司/部门/岗位/用户
         /// </summary>
         public string ScreeningCriteria { get; set; }
     }
+
+    /// <summary>
+    /// 字符串格式化DTO - 支持动态参数字符串格式化
+    /// </summary>
+    public class StringFormatDto
+    {
+        /// <summary>
+        /// 格式化模板字符串,使用 {0}, {1}, {2} 等占位符
+        /// 示例: "名称:{0} -- 编号:{1}"
+        /// </summary>
+        public string FormatTemplate { get; set; }
+
+        /// <summary>
+        /// 格式化参数列表,按顺序对应模板中的占位符 {0}, {1}, {2} 等
+        /// </summary>
+        public List<string> Parameters { get; set; } = new List<string>();
+    }
 }

+ 41 - 0
OASystem/OASystem.Domain/ViewModels/PersonnelModule/AiPerformanceAnalysisView.cs

@@ -0,0 +1,41 @@
+using System.Collections.Generic;
+
+namespace OASystem.Domain.ViewModels.PersonnelModule
+{
+    /// <summary>
+    /// 字符串格式化结果View
+    /// </summary>
+    public class StringFormatView
+    {
+        /// <summary>
+        /// 原始模板
+        /// </summary>
+        public string OriginalTemplate { get; set; }
+
+        /// <summary>
+        /// 格式化后的结果
+        /// </summary>
+        public string FormattedResult { get; set; }
+
+        /// <summary>
+        /// 参数列表
+        /// </summary>
+        public List<string> Parameters { get; set; }
+
+        /// <summary>
+        /// 参数数量
+        /// </summary>
+        public int ParameterCount { get; set; }
+
+        /// <summary>
+        /// 操作是否成功
+        /// </summary>
+        public bool Success { get; set; }
+
+        /// <summary>
+        /// 操作消息
+        /// </summary>
+        public string Message { get; set; }
+    }
+}
+