77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Admin.NET.Core;
|
||
public class UtilExcelExt
|
||
{
|
||
|
||
/// <summary>
|
||
/// 获取文件
|
||
/// </summary>
|
||
/// <param name="_uploadDirectory"></param>
|
||
/// <param name="fileId"></param>
|
||
/// <returns></returns>
|
||
public static async Task<IFormFile> GetFileByIdAsync(string _uploadDirectory, string fileId)
|
||
{
|
||
// 实现你的逻辑来获取文件
|
||
// 可以是从文件系统、数据库或其他存储中获取 IFormFile
|
||
// 返回 IFormFile 实例或 null(如果未找到)
|
||
|
||
// 示例:从本地文件系统获取
|
||
var filePath = Path.Combine(_uploadDirectory, fileId);
|
||
if (!System.IO.File.Exists(filePath))
|
||
{
|
||
return null; // 文件未找到
|
||
}
|
||
|
||
var fileBytes = await File.ReadAllBytesAsync(filePath);
|
||
// 传入 name 参数,例如 "file" 或其他适合的名称
|
||
return new CustomFormFile(fileBytes, fileId, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "file");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 去掉括号
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
public static string RemoveBracketContent(string input)
|
||
{
|
||
// 使用正则表达式去除括号外的部分
|
||
return Regex.Replace(input, @"\s*[(\(].*?[)\)]\s*", "").Trim();
|
||
}
|
||
|
||
public static bool AreBracketKeywordsFullyMatching(string majorNameA, string majorNameB)
|
||
{
|
||
// 提取括号内的关键词
|
||
var keywordsA = ExtractBracketKeywords(majorNameA);
|
||
var keywordsB = ExtractBracketKeywords(majorNameB);
|
||
|
||
// 如果A和B都没有括号内容,认为匹配
|
||
if (keywordsA.Count == 0 && keywordsB.Count == 0)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
// 确保A的所有关键词在B中找到,反之亦然
|
||
return keywordsA.All(keywordA => keywordsB.Any(keywordB => keywordA.Contains(keywordB) || keywordB.Contains(keywordA))) &&
|
||
keywordsB.All(keywordB => keywordsA.Any(keywordA => keywordA.Contains(keywordB) || keywordB.Contains(keywordA)));
|
||
}
|
||
|
||
private static List<string> ExtractBracketKeywords(string majorName)
|
||
{
|
||
|
||
var match = Regex.Match(majorName, @"\s*[(\(].*?[)\)]\s*");
|
||
if (match.Success)
|
||
{
|
||
// 用逗号、顿号、空格等分隔符分割关键词
|
||
return match.Groups[1].Value.Split(new[] { '、', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
}
|
||
return new List<string>();
|
||
}
|
||
|
||
|
||
}
|