Merge branch 'abp' of https://gitee.com/ccnetcore/Yi into abp

# Conflicts:
#	.gitignore
#	Yi.Abp.Net8/src/Yi.Abp.Web/Logs/log-20231214.txt
This commit is contained in:
陈淳
2023-12-15 18:28:01 +08:00
29 changed files with 2673 additions and 1864 deletions

View File

@@ -12,7 +12,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
public string Content { get; set; }
public string? Color { get; set; }
public List<Guid> PermissionUserIds { get; set; }
public List<Guid>? PermissionUserIds { get; set; }
public DiscussPermissionTypeEnum PermissionType { get; set; }

View File

@@ -55,7 +55,7 @@ namespace Yi.Framework.Bbs.Application.Services
/// <summary>
/// 获取文章全部平铺信息
/// 获取文章全部树级信息
/// </summary>
/// <param name="discussId"></param>
/// <returns></returns>

View File

@@ -0,0 +1,214 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Bbs.SqlSugarCore.DataSeeds
{
public class BbsDictionaryDataSeed : IDataSeedContributor, ITransientDependency
{
private ISqlSugarRepository<DictionaryEntity> _repository;
private ISqlSugarRepository<DictionaryTypeEntity> _typeRepository;
public BbsDictionaryDataSeed(ISqlSugarRepository<DictionaryEntity> repository, ISqlSugarRepository<DictionaryTypeEntity> typeRepository) {
_repository=repository;
_typeRepository=typeRepository;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _typeRepository.IsAnyAsync(x => x.DictType== "bbs_type_lable"))
{
await _typeRepository.InsertManyAsync(GetSeedDictionaryTypeData());
await _repository.InsertManyAsync(GetSeedDictionaryData());
}
}
public List<DictionaryEntity> GetSeedDictionaryData()
{
List<DictionaryEntity> entities = new List<DictionaryEntity>();
DictionaryEntity dictInfo1 = new DictionaryEntity()
{
DictLabel = "前端",
DictValue = "0",
DictType = "bbs_type_lable",
OrderNum = 100,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo1);
DictionaryEntity dictInfo2 = new DictionaryEntity()
{
DictLabel = "后端",
DictValue = "1",
DictType = "bbs_type_lable",
OrderNum = 99,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo2);
DictionaryEntity dictInfo3 = new DictionaryEntity()
{
DictLabel = "运维",
DictValue = "2",
DictType = "bbs_type_lable",
OrderNum = 98,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo3);
DictionaryEntity dictInfo4 = new DictionaryEntity()
{
DictLabel = "测试",
DictValue = "3",
DictType = "bbs_type_lable",
OrderNum = 97,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo4);
DictionaryEntity dictInfo5 = new DictionaryEntity()
{
DictLabel = "UI",
DictValue = "4",
DictType = "bbs_type_lable",
OrderNum = 96,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo5);
DictionaryEntity dictInfo6 = new DictionaryEntity()
{
DictLabel = "产品",
DictValue = "5",
DictType = "bbs_type_lable",
OrderNum = 95,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo6);
DictionaryEntity dictInfo7 = new DictionaryEntity()
{
DictLabel = "项目",
DictValue = "6",
DictType = "bbs_type_lable",
OrderNum = 94,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo7);
DictionaryEntity dictInfo8 = new DictionaryEntity()
{
DictLabel = "C#",
DictValue = "7",
DictType = "bbs_type_lable",
OrderNum = 93,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo8);
DictionaryEntity dictInfo9 = new DictionaryEntity()
{
DictLabel = ".Net",
DictValue = "8",
DictType = "bbs_type_lable",
OrderNum = 92,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo9);
DictionaryEntity dictInfo10 = new DictionaryEntity()
{
DictLabel = ".NetCore",
DictValue = "9",
DictType = "bbs_type_lable",
OrderNum = 91,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo10);
DictionaryEntity dictInfo11 = new DictionaryEntity()
{
DictLabel = "Asp.NetCore",
DictValue = "10",
DictType = "bbs_type_lable",
OrderNum = 90,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo11);
DictionaryEntity dictInfo12 = new DictionaryEntity()
{
DictLabel = "Abp.vNext",
DictValue = "11",
DictType = "bbs_type_lable",
OrderNum = 89,
Remark = "",
IsDeleted = false,
State = true
};
entities.Add(dictInfo12);
return entities;
}
public List<DictionaryTypeEntity> GetSeedDictionaryTypeData()
{
List<DictionaryTypeEntity> entities = new List<DictionaryTypeEntity>();
DictionaryTypeEntity dict1 = new DictionaryTypeEntity()
{
DictName = "BBS类型标签",
DictType = "bbs_type_lable",
OrderNum = 200,
Remark = "BBS类型标签",
IsDeleted = false,
State = true
};
entities.Add(dict1);
return entities;
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar.DistributedSystem.Snowflake;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Enums;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Bbs.SqlSugarCore.DataSeeds
{
public class BbsMenuDataSeed : IDataSeedContributor, ITransientDependency
{
private IGuidGenerator _guidGenerator;
private ISqlSugarRepository<MenuEntity, Guid> _repository;
public BbsMenuDataSeed(ISqlSugarRepository<MenuEntity,Guid> repository, IGuidGenerator guidGenerator)
{
_repository=repository;
_guidGenerator=guidGenerator;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _repository.IsAnyAsync(x => x.MenuName == "BBS"))
{
await _repository.InsertManyAsync(GetSeedData());
}
}
public List<MenuEntity> GetSeedData()
{
List<MenuEntity> entities = new List<MenuEntity>();
//BBS
MenuEntity bbs = new MenuEntity(_guidGenerator.Create())
{
MenuName = "BBS",
MenuType = MenuTypeEnum.Catalogue,
Router = "/bbs",
IsShow = true,
IsLink = false,
MenuIcon = "monitor",
OrderNum = 91,
IsDeleted = false
};
entities.Add(bbs);
//板块管理
MenuEntity plate = new MenuEntity(_guidGenerator.Create())
{
MenuName = "板块管理",
PermissionCode = "bbs:plate:list",
MenuType = MenuTypeEnum.Menu,
Router = "plate",
IsShow = true,
IsLink = false,
IsCache = true,
Component = "bbs/plate/index",
MenuIcon = "component",
OrderNum = 100,
ParentId = bbs.Id,
IsDeleted = false
};
entities.Add(plate);
//文章管理
MenuEntity article = new MenuEntity(_guidGenerator.Create())
{
MenuName = "文章管理",
PermissionCode = "bbs:article:list",
MenuType = MenuTypeEnum.Menu,
Router = "article",
IsShow = true,
IsLink = false,
IsCache = true,
Component = "bbs/article/index",
MenuIcon = "documentation",
OrderNum = 99,
ParentId = bbs.Id,
IsDeleted = false
};
entities.Add(article);
return entities;
}
}
}

View File

@@ -15,7 +15,7 @@ namespace Yi.Framework.Bbs.SqlSugarCore.Repositories
public async Task<List<ArticleEntity>> GetTreeAsync(Expression<Func<ArticleEntity, bool>> where)
{
return await _DbQueryable.Where(where).ToTreeAsync(x => x.Children, x => x.ParentId, 0);
return await _DbQueryable.Where(where).ToTreeAsync(x => x.Children, x => x.ParentId, Guid.Empty);
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.Rbac.Application.FileManger
{
public class FileGetListOutputDto:EntityDto<Guid>
{
}
}

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Http;
using Volo.Abp.Application.Services;
using Yi.Framework.Rbac.Application.FileManger;
namespace Yi.Framework.Rbac.Application.Contracts.IServices
{
public interface IFileService : IApplicationService
{
Task<string> GetReturnPathAsync(Guid code, bool? isThumbnail);
Task<List<FileGetListOutputDto>> Post(IFormFileCollection file);
}
}

View File

@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
using Yi.Framework.Core.Enums;
using Yi.Framework.Core.Helper;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Application.FileManger;
using Yi.Framework.Rbac.Domain.Entities;
namespace Yi.Framework.Rbac.Application.Services
{
public class FileService : ApplicationService, IFileService
{
private readonly IRepository<FileAggregateRoot> _repository;
private readonly HttpContext _httpContext;
private IGuidGenerator _guidGenerator;
public FileService(IRepository<FileAggregateRoot> repository, IHttpContextAccessor httpContextAccessor, IGuidGenerator guidGenerator)
{
_guidGenerator = guidGenerator;
_repository = repository;
_httpContext = httpContextAccessor.HttpContext;
}
/// <summary>
/// 下载文件,是否缩略图
/// </summary>
/// <returns></returns>
[Route("file/{code}/{isThumbnail?}")]
public async Task<IActionResult> Get([FromRoute] Guid code, [FromRoute] bool? isThumbnail)
{
var path = await GetReturnPathAsync(code, isThumbnail);
var steam = await File.ReadAllBytesAsync(path);
//考虑从路径中获取
var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(path));
//设置附件下载,下载名称
//_httpContext.FileAttachmentHandle(file.FileName);
return new FileContentResult(steam, fileContentType ?? @"text/plain");
}
public async Task<string> GetReturnPathAsync(Guid code, bool? isThumbnail)
{
var file = await _repository.GetAsync(x => x.Id == code);
if (file is null)
{
throw new UserFriendlyException("文件编号未匹配", "404");
}
var path = file.FilePath;
//如果为缩略图,需要修改路径
if (isThumbnail is true)
{
path = $"wwwroot/{FileTypeEnum.Thumbnail}/{file.Id}{Path.GetExtension(file.FileName)}";
}
//路径为: 文件路径/文件id+文件扩展名
if (!File.Exists(path))
{
throw new UserFriendlyException("本地文件不存在", "404");
}
return path;
}
/// <summary>
/// 上传文件
/// </summary>
/// <returns></returns>
public async Task<List<FileGetListOutputDto>> Post([FromForm] IFormFileCollection file)
{
if (file.Count() == 0)
{
throw new ArgumentException("文件上传为空!");
}
//批量插入
List<FileAggregateRoot> entities = new();
foreach (var f in file)
{
FileAggregateRoot data = new(_guidGenerator.Create());
data.FileSize = (decimal)f.Length / 1024;
data.FileName = f.FileName;
var type = MimeHelper.GetFileType(f.FileName);
//落盘文件文件名为雪花id+自己的扩展名
string filename = data.Id.ToString() + Path.GetExtension(f.FileName);
string typePath = $"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 = $"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.InsertManyAsync(entities);
return entities.Adapt<List<FileGetListOutputDto>>();
}
}
}

View File

@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<ItemGroup>
<Compile Remove="Events\**" />
<EmbeddedResource Remove="Events\**" />
<None Remove="Events\**" />
</ItemGroup>
<ItemGroup>
@@ -15,8 +20,4 @@
<ProjectReference Include="..\Yi.Framework.Rbac.Domain\Yi.Framework.Rbac.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Events\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
namespace Yi.Framework.Rbac.Domain.Entities
{
public class FileAggregateRoot : AggregateRoot<Guid>, IAuditedObject
{
public FileAggregateRoot()
{
}
public FileAggregateRoot(Guid fileId)
{
this.Id = fileId;
}
[SugarColumn(IsPrimaryKey = true)]
public override Guid Id { get; protected 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 Guid? CreatorId { get; set; }
public Guid? LastModifierId { get; set; }
public DateTime? LastModificationTime { get; set; }
}
}

View File

@@ -652,7 +652,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/role/index",
MenuIcon = "peoples",
OrderNum = 100,
OrderNum = 99,
ParentId = system.Id,
IsDeleted = false
};
@@ -720,7 +720,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/menu/index",
MenuIcon = "tree-table",
OrderNum = 100,
OrderNum = 98,
ParentId = system.Id,
IsDeleted = false
};
@@ -787,7 +787,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/dept/index",
MenuIcon = "tree",
OrderNum = 100,
OrderNum = 97,
ParentId = system.Id,
IsDeleted = false
};
@@ -856,7 +856,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/post/index",
MenuIcon = "post",
OrderNum = 100,
OrderNum = 96,
ParentId = system.Id,
IsDeleted = false
};
@@ -923,7 +923,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/dict/index",
MenuIcon = "dict",
OrderNum = 100,
OrderNum = 95,
ParentId = system.Id,
IsDeleted = false
};
@@ -991,7 +991,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsCache = true,
Component = "system/config/index",
MenuIcon = "edit",
OrderNum = 100,
OrderNum = 94,
ParentId = system.Id,
IsDeleted = false
};
@@ -1058,7 +1058,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
IsShow = true,
IsLink = false,
MenuIcon = "log",
OrderNum = 100,
OrderNum = 93,
ParentId = system.Id,
IsDeleted = false
};

View File

@@ -73,7 +73,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.Repositories
user.Roles = new List<RoleEntity>();
userRoleMenu.User = user.Adapt<UserDto>();
userRoleMenu.Menus = userRoleMenu.Menus.OrderByDescending(x => x.OrderNum).ToHashSet();
return userRoleMenu;
}
}