🔄refactor: 调整为SqlSugar

This commit is contained in:
yubaolee
2026-05-24 23:34:27 +08:00
parent 237fc49f2f
commit d2c8f783e1
10 changed files with 130 additions and 166 deletions

View File

@@ -7,31 +7,29 @@ using Infrastructure;
using Infrastructure.Extensions;
using Infrastructure.Helpers;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using SqlSugar;
namespace OpenAuth.App
{
/// <summary>
/// 文件管理
/// </summary>
public class FileApp : BaseStringApp<UploadFile,OpenAuthDBContext>
public class FileApp : SqlSugarBaseApp<UploadFile>
{
private ILogger<FileApp> _logger;
private string _filePath;
private string _dbFilePath; //数据库中的文件路径
private string _dbThumbnail; //数据库中的缩略图路径
public FileApp(IOptions<AppSetting> setOptions, IUnitWork<OpenAuthDBContext> unitWork, IRepository<UploadFile,OpenAuthDBContext> repository,
public FileApp(IOptions<AppSetting> setOptions, ISqlSugarClient client,
ILogger<FileApp> logger, IAuth auth)
: base(unitWork, repository, auth)
: base(client, auth)
{
_logger = logger;
_filePath = setOptions.Value.UploadPath;
@@ -47,7 +45,7 @@ namespace OpenAuth.App
public async Task<PagedDynamicDataResp> Load(QueryFileListReq request)
{
var result = new PagedDynamicDataResp();
var objs = UnitWork.Find<UploadFile>(null);
var objs = SugarClient.Queryable<UploadFile>();
if (!string.IsNullOrEmpty(request.key))
{
objs = objs.Where(u => u.FileName.Contains(request.key) || u.FilePath.Contains(request.key));
@@ -112,7 +110,7 @@ namespace OpenAuth.App
FileType = Path.GetExtension(fileName),
Extension = Path.GetExtension(fileName)
};
Repository.Add(filedb);
Repository.Insert(filedb);
return filedb;
}
}
@@ -126,9 +124,9 @@ namespace OpenAuth.App
/// 删除附件
/// </summary>
/// <param name="ids"></param>
public override void Delete(string[] ids)
public new void Delete(string[] ids)
{
var files = base.Repository.Find(u => ids.Contains(u.Id)).ToList();
var files = SugarClient.Queryable<UploadFile>().Where(u => ids.Contains(u.Id)).ToList();
for (int i = 0; i < files.Count(); i++)
{
var uploadPath = Path.Combine(_filePath, files[i].FilePath);
@@ -137,7 +135,7 @@ namespace OpenAuth.App
{
FileHelper.FileDel(Path.Combine(_filePath, files[i].Thumbnail));
}
Repository.Delete(u =>u.Id == files[i].Id);
SugarClient.Deleteable<UploadFile>().Where(u =>u.Id == files[i].Id).ExecuteCommand();
}
}