chore:修改目录

This commit is contained in:
陈淳
2023-04-15 17:33:42 +08:00
parent 0401e97ed3
commit eb8e076732
119 changed files with 1881 additions and 200 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// 常量定义
/// </summary>
public class DictionaryConst
{
}
}

View File

@@ -0,0 +1,50 @@
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Yi.Framework.Infrastructure.Ddd.Dtos;
using Yi.Framework.Infrastructure.Ddd.Services;
using Yi.Framework.Module.DictionaryManager.Dtos.Dictionary;
using Yi.Framework.Module.DictionaryManager.Entities;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// Dictionary服务实现
/// </summary>
public class DictionaryService : CrudAppService<DictionaryEntity, DictionaryGetOutputDto, DictionaryGetListOutputDto, long, DictionaryGetListInputVo, DictionaryCreateInputVo, DictionaryUpdateInputVo>,
IDictionaryService,IDynamicApiController,ITransient
{
/// <summary>
/// 查询
/// </summary>
public override async Task<PagedResultDto<DictionaryGetListOutputDto>> GetListAsync(DictionaryGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(input.DictType is not null, x => x.DictType == input.DictType)
.WhereIF(input.DictLabel is not null, x => x.DictLabel!.Contains(input.DictLabel!))
.WhereIF(input.State is not null, x => x.State == input.State)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DictionaryGetListOutputDto>
{
Total = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}
/// <summary>
/// 根据字典类型获取字典列表
/// </summary>
/// <param name="dicType"></param>
/// <returns></returns>
[Route("/api/dictionary/dic-type/{dicType}")]
public async Task<List<DictionaryGetListOutputDto>> GetDicType([FromRoute] string dicType)
{
var entities = await _repository.GetListAsync(u => u.DictType == dicType && u.State == true);
var result = await MapToGetListOutputDtosAsync(entities);
return result;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// 常量定义
/// </summary>
public class DictionaryTypeConst
{
}
}

View File

@@ -0,0 +1,37 @@
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using SqlSugar;
using Yi.Framework.Infrastructure.Ddd.Dtos;
using Yi.Framework.Infrastructure.Ddd.Services;
using Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType;
using Yi.Framework.Module.DictionaryManager.Entities;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// DictionaryType服务实现
/// </summary>
public class DictionaryTypeService : CrudAppService<DictionaryTypeEntity, DictionaryTypeGetOutputDto, DictionaryTypeGetListOutputDto, long, DictionaryTypeGetListInputVo, DictionaryTypeCreateInputVo, DictionaryTypeUpdateInputVo>,
IDictionaryTypeService, IDynamicApiController, ITransient
{
public async override Task<PagedResultDto<DictionaryTypeGetListOutputDto>> GetListAsync(DictionaryTypeGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(input.DictName is not null, x => x.DictName.Contains(input.DictName!))
.WhereIF(input.DictType is not null, x => x.DictType!.Contains(input.DictType!))
.WhereIF(input.State is not null, x => x.State == input.State)
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DictionaryTypeGetListOutputDto>
{
Total = total,
Items = await MapToGetListOutputDtosAsync(entities)
};
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Module.DictionaryManager.Dtos.Dictionary
{
/// <summary>
/// Dictionary输入创建对象
/// </summary>
public class DictionaryCreateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? Remark { get; set; }
public string? ListClass { get; set; }
public string? CssClass { get; set; }
public string DictType { get; set; } = string.Empty;
public string? DictLabel { get; set; }
public string DictValue { get; set; } = string.Empty;
public bool IsDefault { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using Yi.Framework.Infrastructure.Ddd.Dtos;
namespace Yi.Framework.Module.DictionaryManager.Dtos.Dictionary
{
public class DictionaryGetListInputVo : PagedAndSortedResultRequestDto
{
public string? DictType { get; set; }
public string? DictLabel { get; set; }
public bool? State { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
namespace Yi.Framework.Module.DictionaryManager.Dtos.Dictionary
{
public class DictionaryGetListOutputDto : IEntityDto<long>
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? Remark { get; set; }
public string? ListClass { get; set; }
public string? CssClass { get; set; }
public string DictType { get; set; } = string.Empty;
public string? DictLabel { get; set; }
public string DictValue { get; set; } = string.Empty;
public bool IsDefault { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
namespace Yi.Framework.Module.DictionaryManager.Dtos.Dictionary
{
public class DictionaryGetOutputDto : IEntityDto<long>
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? Remark { get; set; }
public string? ListClass { get; set; }
public string? CssClass { get; set; }
public string DictType { get; set; } = string.Empty;
public string? DictLabel { get; set; }
public string DictValue { get; set; } = string.Empty;
public bool IsDefault { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Module.DictionaryManager.Dtos.Dictionary
{
public class DictionaryUpdateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string? Remark { get; set; }
public string? ListClass { get; set; }
public string? CssClass { get; set; }
public string DictType { get; set; } = string.Empty;
public string? DictLabel { get; set; }
public string DictValue { get; set; } = string.Empty;
public bool IsDefault { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType
{
/// <summary>
/// DictionaryType输入创建对象
/// </summary>
public class DictionaryTypeCreateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string DictName { get; set; } = string.Empty;
public string DictType { get; set; } = string.Empty;
public string? Remark { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using Yi.Framework.Infrastructure.Ddd.Dtos;
namespace Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType
{
public class DictionaryTypeGetListInputVo : PagedAllResultRequestDto
{
public string? DictName { get; set; }
public string? DictType { get; set; }
public string? Remark { get; set; }
public bool? State { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
namespace Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType
{
public class DictionaryTypeGetListOutputDto : IEntityDto<long>
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string DictName { get; set; } = string.Empty;
public string DictType { get; set; } = string.Empty;
public string? Remark { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
namespace Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType
{
public class DictionaryTypeGetOutputDto : IEntityDto<long>
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string DictName { get; set; } = string.Empty;
public string DictType { get; set; } = string.Empty;
public string? Remark { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
namespace Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType
{
public class DictionaryTypeUpdateInputVo
{
public long Id { get; set; }
public DateTime CreationTime { get; set; } = DateTime.Now;
public long? CreatorId { get; set; }
public string DictName { get; set; } = string.Empty;
public string DictType { get; set; } = string.Empty;
public string? Remark { get; set; }
public bool State { get; set; }
}
}

View File

@@ -0,0 +1,71 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.Auditing;
using Yi.Framework.Infrastructure.Data.Entities;
using Yi.Framework.Infrastructure.Ddd.Entities;
namespace Yi.Framework.Module.DictionaryManager.Entities
{
[SugarTable("Dictionary")]
public class DictionaryEntity : AuditedObject, IEntity<long>, ISoftDelete, IOrderNum, IState
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 逻辑删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 排序
/// </summary>
public int OrderNum { get; set; } = 0;
/// <summary>
/// 状态
/// </summary>
public bool State { get; set; } = true;
/// <summary>
/// 描述
///</summary>
[SugarColumn(ColumnName = "Remark")]
public string? Remark { get; set; }
/// <summary>
/// tag类型
///</summary>
[SugarColumn(ColumnName = "ListClass")]
public string? ListClass { get; set; }
/// <summary>
/// tagClass
///</summary>
[SugarColumn(ColumnName = "CssClass")]
public string? CssClass { get; set; }
/// <summary>
/// 字典类型
///</summary>
[SugarColumn(ColumnName = "DictType")]
public string DictType { get; set; } = string.Empty;
/// <summary>
/// 字典标签
///</summary>
[SugarColumn(ColumnName = "DictLabel")]
public string? DictLabel { get; set; }
/// <summary>
/// 字典值
///</summary>
[SugarColumn(ColumnName = "DictValue")]
public string DictValue { get; set; } = string.Empty;
/// <summary>
/// 是否为该类型的默认值
///</summary>
[SugarColumn(ColumnName = "IsDefault")]
public bool IsDefault { get; set; }
}
}

View File

@@ -0,0 +1,50 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.Auditing;
using Yi.Framework.Infrastructure.Data.Entities;
using Yi.Framework.Infrastructure.Ddd.Entities;
namespace Yi.Framework.Module.DictionaryManager.Entities
{
[SugarTable("DictionaryType")]
public class DictionaryTypeEntity : AuditedObject, IEntity<long>, ISoftDelete, IOrderNum
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 逻辑删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 排序
/// </summary>
public int OrderNum { get; set; } = 0;
/// <summary>
/// 状态
/// </summary>
public bool? State { get; set; } = true;
/// <summary>
/// 字典名称
///</summary>
[SugarColumn(ColumnName = "DictName")]
public string DictName { get; set; } = string.Empty;
/// <summary>
/// 字典类型
///</summary>
[SugarColumn(ColumnName = "DictType")]
public string DictType { get; set; } = string.Empty;
/// <summary>
/// 描述
///</summary>
[SugarColumn(ColumnName = "Remark")]
public string? Remark { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
using Yi.Framework.Module.DictionaryManager.Dtos.Dictionary;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// Dictionary服务抽象
/// </summary>
public interface IDictionaryService : ICrudAppService<DictionaryGetOutputDto, DictionaryGetListOutputDto, long, DictionaryGetListInputVo, DictionaryCreateInputVo, DictionaryUpdateInputVo>
{
}
}

View File

@@ -0,0 +1,13 @@
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
using Yi.Framework.Module.DictionaryManager.Dtos.DictionaryType;
namespace Yi.Framework.Module.DictionaryManager
{
/// <summary>
/// DictionaryType服务抽象
/// </summary>
public interface IDictionaryTypeService : ICrudAppService<DictionaryTypeGetOutputDto, DictionaryTypeGetListOutputDto, long, DictionaryTypeGetListInputVo, DictionaryTypeCreateInputVo, DictionaryTypeUpdateInputVo>
{
}
}

View File

@@ -0,0 +1,43 @@
using SqlSugar;
using Yi.Framework.Infrastructure.Data.Auditing;
using Yi.Framework.Infrastructure.Ddd.Entities;
namespace Yi.Framework.Module.FileManager
{
/// <summary>
/// 文件表
///</summary>
[SugarTable("File")]
public class FileEntity : IEntity<long>, IAuditedObject
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 文件类型
///</summary>
[SugarColumn(ColumnName = "FileContentType")]
public string? FileContentType { get; set; }
/// <summary>
/// 文件大小
///</summary>
[SugarColumn(ColumnName = "FileSize")]
public decimal FileSize { get; set; }
/// <summary>
/// 文件名
///</summary>
[SugarColumn(ColumnName = "FileName")]
public string FileName { get; set; }
/// <summary>
/// 文件路径
///</summary>
[SugarColumn(ColumnName = "FilePath")]
public string FilePath { get; set; }
public DateTime CreationTime { get; set; }
public long? CreatorId { get; set; }
public long? LastModifierId { get; set; }
public DateTime? LastModificationTime { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
using Yi.Framework.Infrastructure.Ddd.Dtos.Abstract;
namespace Yi.Framework.Module.FileManager
{
public class FileGetListOutputDto : IEntityDto
{
public long Id { get; set; }
}
}

View File

@@ -0,0 +1,143 @@
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yi.Framework.Infrastructure.AspNetCore;
using Yi.Framework.Infrastructure.Const;
using Yi.Framework.Infrastructure.Ddd.Repositories;
using Yi.Framework.Infrastructure.Ddd.Services;
using Yi.Framework.Infrastructure.Enums;
using Yi.Framework.Infrastructure.Helper;
using Yi.Framework.Module.ImageSharp;
namespace Yi.Framework.Module.FileManager
{
/// <summary>
/// 文件处理
/// </summary>
public class FileService : ApplicationService, IFileService, IDynamicApiController, ITransient
{
private readonly IRepository<FileEntity> _repository;
private readonly ImageSharpManager _imageSharpManager;
private readonly HttpContext _httpContext;
public FileService(IRepository<FileEntity> repository, ImageSharpManager imageSharpManager, IHttpContextAccessor httpContextAccessor
)
{
_repository = repository;
_imageSharpManager = imageSharpManager;
if (httpContextAccessor.HttpContext is null)
{
throw new ApplicationException("HttpContext为空");
}
_httpContext = httpContextAccessor.HttpContext;
}
/// <summary>
/// 下载文件,是否缩略图
/// </summary>
/// <returns></returns>
[Route("/api/file/{code}/{isThumbnail?}")]
public async Task<IActionResult> Get([FromRoute] long code, [FromRoute] bool? isThumbnail)
{
var file = await _repository.GetByIdAsync(code);
if (file is null)
{
return new NotFoundResult();
}
var path = file.FilePath;
//如果为缩略图,需要修改路径
if (isThumbnail is true)
{
path = $"{PathConst.wwwroot}/{FileTypeEnum.Thumbnail}/{file.Id}{Path.GetExtension(file.FileName)}";
}
//路径为: 文件路径/文件id+文件扩展名
if (!File.Exists(path))
{
return new NotFoundResult();
}
var steam = await File.ReadAllBytesAsync(path);
//设置附件下载,下载名称
_httpContext.FileAttachmentHandle(file.FileName);
return new FileContentResult(steam, file.FileContentType ?? @"text/plain");
}
/// <summary>
/// 上传文件
/// </summary>
/// <returns></returns>
public async Task<List<FileGetListOutputDto>> Post([FromForm] IFormFileCollection file)
{
if (file.Count() == 0)
{
throw new ArgumentException("文件上传为空!");
}
//批量插入
List<FileEntity> entities = new();
foreach (var f in file)
{
FileEntity data = new();
data.Id = SnowflakeHelper.NextId;
data.FileSize = (decimal)f.Length / 1024;
data.FileName = f.FileName;
data.FileContentType = MimeHelper.GetMimeMapping(f.FileName);
var type = MimeHelper.GetFileType(f.FileName);
//落盘文件文件名为雪花id+自己的扩展名
string filename = data.Id.ToString() + Path.GetExtension(f.FileName);
string typePath = $"{PathConst.wwwroot}/{type}";
if (!Directory.Exists(typePath))
{
Directory.CreateDirectory(typePath);
}
var filePath = Path.Combine(typePath, filename);
data.FilePath = filePath;
//生成文件
using (var stream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite))
{
await f.CopyToAsync(stream);
//如果是图片类型,还需要生成缩略图,当然,如果图片很小,直接复制过去即可
if (FileTypeEnum.Image.Equals(type))
{
string thumbnailPath = $"{PathConst.wwwroot}/{FileTypeEnum.Thumbnail}";
if (!Directory.Exists(thumbnailPath))
{
Directory.CreateDirectory(thumbnailPath);
}
string thumbnailFilePath = Path.Combine(thumbnailPath, filename);
try
{
_imageSharpManager.ImageCompress(f.FileName, f.OpenReadStream(), thumbnailFilePath);
}
catch
{
var result = new byte[stream.Length];
await stream.ReadAsync(result, 0, result.Length);
await File.WriteAllBytesAsync(thumbnailFilePath, result);
}
}
};
entities.Add(data);
}
await _repository.InsertRangeAsync(entities);
return entities.Adapt<List<FileGetListOutputDto>>();
}
}
}

View File

@@ -0,0 +1,6 @@
namespace Yi.Framework.Module.FileManager
{
public interface IFileService
{
}
}

View File

@@ -29,5 +29,9 @@
<EmbeddedResource Include="ImageSharp\HeiCaptcha\fonts\monbaiti.ttf" />
<EmbeddedResource Include="ImageSharp\HeiCaptcha\fonts\STCAIYUN.ttf" />
</ItemGroup>
<ItemGroup>
<Folder Include="DictionaryManager\" />
</ItemGroup>
</Project>