|
@@ -29,6 +29,8 @@ using OASystem.Infrastructure.Repositories.Groups;
|
|
|
using System.Data;
|
|
using System.Data;
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
using System.Security.Claims;
|
|
using System.Security.Claims;
|
|
|
|
|
+using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
|
|
+using OASystem.Domain.Dtos.PersonnelModule;
|
|
|
|
|
|
|
|
namespace OASystem.API.OAMethodLib
|
|
namespace OASystem.API.OAMethodLib
|
|
|
{
|
|
{
|
|
@@ -6553,10 +6555,123 @@ namespace OASystem.API.OAMethodLib
|
|
|
builder.Font.Italic = false;
|
|
builder.Font.Italic = false;
|
|
|
builder.Font.Color = System.Drawing.Color.Black;
|
|
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
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|