forked from ddrilling/AsbCloudServer
Поправил репозитории
This commit is contained in:
parent
675da0a5d9
commit
380776c3a9
@ -1,21 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Репозиторий для работы с категориями файлов
|
||||
/// </summary>
|
||||
public interface IFileCategoryRepository : ICrudRepository<FileCategoryDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение всех записей по идентификатору типа
|
||||
/// </summary>
|
||||
/// <param name="idType"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<FileCategoryDto>> GetAllAsync(int idType, CancellationToken cancellationToken);
|
||||
}
|
37
AsbCloudApp/Repositories/IManualDirectoryRepository.cs
Normal file
37
AsbCloudApp/Repositories/IManualDirectoryRepository.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Репозиторий для работы с директориямиы хранящими инструкциями
|
||||
/// </summary>
|
||||
public interface IManualDirectoryRepository : ICrudRepository<ManualDirectoryDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение дерева директорий
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ManualDirectoryDto>> GetTreeAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Получение одной директории по параметрам
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="idParent"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ManualDirectoryDto?> GetOrDefaultAsync(string name, int? idParent, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Проверка директории на существование
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsExistsAsync(int id, CancellationToken cancellationToken);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Репозиторий для работы с папки хранящими инструкциями
|
||||
/// </summary>
|
||||
public interface IManualFolderRepository : ICrudRepository<ManualFolderDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение дерева каталога папок
|
||||
/// </summary>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ManualFolderDto>> GetTreeAsync(int idCategory, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Получение одной папки по параметрам
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="idParent"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ManualFolderDto?> GetOrDefaultAsync(string name, int? idParent, int idCategory, CancellationToken cancellationToken);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Репозиторий для инструкций
|
||||
/// </summary>
|
||||
public interface IManualRepository : ICrudRepository<ManualDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение инструкций, которые не добавлены в папку
|
||||
/// </summary>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ManualDto>> GetManualsWithoutFolderAsync(int idCategory, CancellationToken cancellationToken);
|
||||
}
|
@ -23,8 +23,10 @@ using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
||||
using AsbCloudApp.Services.Notifications;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
@ -222,10 +224,9 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IAutoGeneratedDailyReportService, AutoGeneratedDailyReportService>();
|
||||
services.AddTransient<IAutoGeneratedDailyReportMakerService, AutoGeneratedDailyReportMakerService>();
|
||||
|
||||
services.AddTransient<IManualFolderRepository, ManualFolderRepository>();
|
||||
services.AddTransient<IManualDirectoryRepository, ManualDirectoryRepository>();
|
||||
services.AddTransient<IManualCatalogService, ManualCatalogService>();
|
||||
services.AddTransient<IManualRepository, ManualRepository>();
|
||||
services.AddTransient<IFileCategoryRepository, FileCategoryRepository>();
|
||||
services.AddTransient<ICrudRepository<ManualDto>, CrudRepositoryBase<ManualDto, Manual>>();
|
||||
|
||||
services.AddTransient<IWellboreService, WellboreService>();
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class FileCategoryRepository : CrudCacheRepositoryBase<FileCategoryDto, FileCategory>, IFileCategoryRepository
|
||||
{
|
||||
public FileCategoryRepository(IAsbCloudDbContext dbContext, IMemoryCache memoryCache) : base(dbContext, memoryCache)
|
||||
{
|
||||
}
|
||||
|
||||
public FileCategoryRepository(IAsbCloudDbContext dbContext, IMemoryCache memoryCache,
|
||||
Func<DbSet<FileCategory>, IQueryable<FileCategory>> makeQuery) : base(dbContext, memoryCache, makeQuery)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FileCategoryDto>> GetAllAsync(int idType, CancellationToken cancellationToken)
|
||||
{
|
||||
return await dbContext.FileCategories.Where(f => f.IdType == idType)
|
||||
.Select(f => f.Adapt<FileCategoryDto>())
|
||||
.ToArrayAsync(cancellationToken);
|
||||
}
|
||||
}
|
@ -36,17 +36,15 @@ public class FileStorageRepository : IFileStorageRepository
|
||||
|
||||
public void DeleteDirectory(string path)
|
||||
{
|
||||
var fullPath = Path.Combine(RootPath, path);
|
||||
|
||||
if (!Directory.Exists(fullPath))
|
||||
if (!Directory.Exists(path))
|
||||
return;
|
||||
|
||||
foreach (var file in Directory.GetFiles(fullPath))
|
||||
foreach (var file in Directory.GetFiles(path))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
Directory.Delete(fullPath, true);
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
|
||||
public void DeleteFile(string fileName)
|
||||
|
@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class ManualDirectoryRepository : CrudRepositoryBase<ManualDirectoryDto, ManualDirectory>, IManualDirectoryRepository
|
||||
{
|
||||
public ManualDirectoryRepository(IAsbCloudDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ManualDirectoryDto>> GetTreeAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var directories = await dbContext.ManualDirectories
|
||||
.Include(m => m.Manuals)
|
||||
.Include(m => m.Parent)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(cancellationToken);
|
||||
|
||||
return BuildTree(directories).Select(x => x.Adapt<ManualDirectoryDto>());
|
||||
}
|
||||
|
||||
public async Task<ManualDirectoryDto?> GetOrDefaultAsync(string name, int? idParent, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await dbContext.ManualDirectories
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(m => m.Name == name &&
|
||||
m.IdParent == idParent, cancellationToken);
|
||||
|
||||
if (entity is null)
|
||||
return null;
|
||||
|
||||
return Convert(entity);
|
||||
}
|
||||
|
||||
public Task<bool> IsExistsAsync(int id, CancellationToken cancellationToken) =>
|
||||
dbContext.ManualDirectories.AnyAsync(d => d.Id == id, cancellationToken);
|
||||
|
||||
private IEnumerable<ManualDirectory> BuildTree(IEnumerable<ManualDirectory> directories)
|
||||
{
|
||||
var directoryDict = directories.ToDictionary(f => f.Id);
|
||||
|
||||
foreach (var directory in directories)
|
||||
{
|
||||
if (directory.IdParent.HasValue && directoryDict.TryGetValue(directory.IdParent.Value, out var parent))
|
||||
{
|
||||
parent.Children ??= new List<ManualDirectory>();
|
||||
parent.Children.Add(directory);
|
||||
}
|
||||
}
|
||||
|
||||
return directories.Where(f => f.IdParent == null);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class ManualFolderRepository : CrudRepositoryBase<ManualFolderDto, ManualFolder>, IManualFolderRepository
|
||||
{
|
||||
public ManualFolderRepository(IAsbCloudDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ManualFolderDto>> GetTreeAsync(int idCategory,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var folders = await dbContext.ManualFolders
|
||||
.Where(m => m.IdCategory == idCategory)
|
||||
.AsNoTracking()
|
||||
.Include(m => m.Manuals)
|
||||
.Include(m => m.Parent)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
|
||||
return BuildTree(folders).Select(x => x.Adapt<ManualFolderDto>());
|
||||
}
|
||||
|
||||
public async Task<ManualFolderDto?> GetOrDefaultAsync(string name, int? idParent, int idCategory,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await dbContext.ManualFolders
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(m => m.Name == name &&
|
||||
m.IdCategory == idCategory &&
|
||||
m.IdParent == idParent, cancellationToken);
|
||||
|
||||
if (entity is null)
|
||||
return null;
|
||||
|
||||
return Convert(entity);
|
||||
}
|
||||
|
||||
private IEnumerable<ManualFolder> BuildTree(IEnumerable<ManualFolder> folders)
|
||||
{
|
||||
var folderDict = folders.ToDictionary(f => f.Id);
|
||||
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
if (folder.IdParent.HasValue && folderDict.TryGetValue(folder.IdParent.Value, out var parent))
|
||||
{
|
||||
parent.Children ??= new List<ManualFolder>();
|
||||
parent.Children.Add(folder);
|
||||
}
|
||||
}
|
||||
|
||||
return folders.Where(f => f.IdParent == null);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.Manuals;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class ManualRepository : CrudRepositoryBase<ManualDto, Manual>, IManualRepository
|
||||
{
|
||||
public ManualRepository(IAsbCloudDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public ManualRepository(IAsbCloudDbContext context, Func<DbSet<Manual>, IQueryable<Manual>> makeQuery)
|
||||
: base(context, makeQuery)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ManualDto>> GetManualsWithoutFolderAsync(int idCategory, CancellationToken cancellationToken)
|
||||
{
|
||||
return await dbContext.Manuals.Where(m => m.IdCategory == idCategory &&
|
||||
m.IdFolder == null)
|
||||
.Select(m => m.Adapt<ManualDto>())
|
||||
.ToArrayAsync(cancellationToken);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user