Merge branch 'abp' of https://gitee.com/ccnetcore/Yi into abp
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
@@ -75,12 +79,59 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
[scheme] = new string[0]
|
||||
});
|
||||
|
||||
|
||||
options.SchemaFilter<EnumSchemaFilter>();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Swagger文档枚举字段显示枚举属性和枚举值,以及枚举描述
|
||||
/// </summary>
|
||||
public class EnumSchemaFilter : ISchemaFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// 实现接口
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="context"></param>
|
||||
|
||||
public void Apply(OpenApiSchema model, SchemaFilterContext context)
|
||||
{
|
||||
if (context.Type.IsEnum)
|
||||
{
|
||||
model.Enum.Clear();
|
||||
model.Type = "string";
|
||||
model.Format = null;
|
||||
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Enum.GetNames(context.Type)
|
||||
.ToList()
|
||||
.ForEach(name =>
|
||||
{
|
||||
Enum e = (Enum)Enum.Parse(context.Type, name);
|
||||
var descrptionOrNull = GetEnumDescription(e);
|
||||
model.Enum.Add(new OpenApiString(name));
|
||||
stringBuilder.Append($"【枚举:{name}{(descrptionOrNull is null ? string.Empty : $"({descrptionOrNull})")}={Convert.ToInt64(Enum.Parse(context.Type, name))}】<br />");
|
||||
});
|
||||
model.Description= stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static string? GetEnumDescription(Enum value)
|
||||
{
|
||||
var fieldInfo = value.GetType().GetField(value.ToString());
|
||||
var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
return attributes.Length > 0 ? attributes[0].Description : null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Article
|
||||
@@ -16,6 +17,8 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Article
|
||||
[Required]
|
||||
public Guid DiscussId { get; set; }
|
||||
|
||||
public Guid ArticleParentId { get; set; }= Guid.Empty;
|
||||
|
||||
public ArticleImportTypeEnum ImportType { get; set; } = ArticleImportTypeEnum.Defalut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -143,7 +144,7 @@ namespace Yi.Framework.Bbs.Application.Services
|
||||
/// 导入文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task PostImportAsync(ArticleImprotDto input, [FromForm] IFormFileCollection file)
|
||||
public async Task PostImportAsync([FromQuery] ArticleImprotDto input, [FromForm][Required] IFormFileCollection file)
|
||||
{
|
||||
var fileObjs = new List<FileObject>();
|
||||
if (file.Count > 0)
|
||||
@@ -161,14 +162,18 @@ namespace Yi.Framework.Bbs.Application.Services
|
||||
|
||||
// 将字节转换成字符串
|
||||
var content = Encoding.UTF8.GetString(bytes);
|
||||
fileObjs.Add(new FileObject() { FileName=item.FileName,Content=content});
|
||||
fileObjs.Add(new FileObject() { FileName = item.FileName, Content = content });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserFriendlyException("未选择文件");
|
||||
}
|
||||
//使用简单工厂根据传入的类型进行判断
|
||||
await _forumManager.PostImportAsync(input.DiscussId, fileObjs, input.ImportType);
|
||||
await _forumManager.PostImportAsync(input.DiscussId, input.ArticleParentId, fileObjs, input.ImportType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Enums
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum ArticleImportTypeEnum
|
||||
{
|
||||
//默认导入方式
|
||||
[Description("默认导入方式")]
|
||||
Defalut,
|
||||
|
||||
//vuePresss方式
|
||||
[Description("vuePresss方式")]
|
||||
VuePress
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
public abstract class AbstractArticleImport
|
||||
{
|
||||
public virtual List<ArticleEntity> Import(Guid discussId,Guid articleParentId, List<FileObject> fileObjs)
|
||||
{
|
||||
var articles = Convert(fileObjs);
|
||||
articles.ForEach(article =>
|
||||
{
|
||||
article.DiscussId = discussId;
|
||||
article.ParentId = articleParentId;
|
||||
});
|
||||
return articles;
|
||||
}
|
||||
public abstract List<ArticleEntity> Convert(List<FileObject> fileObjs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
internal class DefaultArticleImport : AbstractArticleImport
|
||||
{
|
||||
public override List<ArticleEntity> Convert(List<FileObject> fileObjs)
|
||||
{
|
||||
return fileObjs.OrderBy(x => x.FileName).Select(x => new ArticleEntity { Name = x.FileName, Content = x.Content }).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
internal class VuePressArticleImport : AbstractArticleImport
|
||||
{
|
||||
public override List<ArticleEntity> Convert(List<FileObject> fileObjs)
|
||||
{
|
||||
//排序及处理目录名称
|
||||
var fileNameHandler = fileObjs.OrderBy(x => x.FileName).Select(x =>
|
||||
{
|
||||
var f = new FileObject { Content = x.Content };
|
||||
|
||||
//除去数字
|
||||
f.FileName = x.FileName.Split('.')[1];
|
||||
return f;
|
||||
});
|
||||
|
||||
|
||||
//处理内容
|
||||
var fileContentHandler= fileNameHandler.Select(x =>
|
||||
{
|
||||
var f = new FileObject { FileName = x.FileName };
|
||||
var lines = x.Content.SplitToLines();
|
||||
|
||||
var num = 0;
|
||||
var startIndex = 0;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (lines[i] == "---")
|
||||
{
|
||||
num++;
|
||||
if (num == 2)
|
||||
{
|
||||
startIndex = i;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var linesRef = lines.ToList();
|
||||
|
||||
linesRef.RemoveRange(0, startIndex+1);
|
||||
var result = string.Join(Environment.NewLine, linesRef);
|
||||
f.Content = result;
|
||||
return f;
|
||||
});
|
||||
|
||||
var output = fileContentHandler.Select(x => new ArticleEntity() { Content = x.Content, Name = x.FileName }).ToList();
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Managers.ArticleImport;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
@@ -16,11 +17,13 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
public readonly ISqlSugarRepository<DiscussEntity, Guid> _discussRepository;
|
||||
public readonly ISqlSugarRepository<PlateEntity, Guid> _plateEntityRepository;
|
||||
public readonly ISqlSugarRepository<CommentEntity, Guid> _commentRepository;
|
||||
public ForumManager(ISqlSugarRepository<DiscussEntity, Guid> discussRepository, ISqlSugarRepository<PlateEntity, Guid> plateEntityRepository, ISqlSugarRepository<CommentEntity, Guid> commentRepository)
|
||||
public readonly ISqlSugarRepository<ArticleEntity, Guid> _articleRepository;
|
||||
public ForumManager(ISqlSugarRepository<DiscussEntity, Guid> discussRepository, ISqlSugarRepository<PlateEntity, Guid> plateEntityRepository, ISqlSugarRepository<CommentEntity, Guid> commentRepository, ISqlSugarRepository<ArticleEntity, Guid> articleRepository)
|
||||
{
|
||||
_discussRepository = discussRepository;
|
||||
_plateEntityRepository = plateEntityRepository;
|
||||
_commentRepository = commentRepository;
|
||||
_articleRepository = articleRepository;
|
||||
}
|
||||
|
||||
//主题是不能直接创建的,需要由领域服务统一创建
|
||||
@@ -45,11 +48,30 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
/// 导入文章
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <param name="articleParentId"></param>
|
||||
/// <param name="fileObjs"></param>
|
||||
/// <param name="importType"></param>
|
||||
/// <returns></returns>
|
||||
public async Task PostImportAsync(Guid discussId, List<FileObject> fileObjs, ArticleImportTypeEnum importType)
|
||||
public async Task PostImportAsync(Guid discussId,Guid articleParentId, List<FileObject> fileObjs, ArticleImportTypeEnum importType)
|
||||
{
|
||||
AbstractArticleImport abstractArticleImport = default;
|
||||
switch (importType)
|
||||
{
|
||||
case ArticleImportTypeEnum.Defalut:
|
||||
abstractArticleImport = new DefaultArticleImport();
|
||||
|
||||
break;
|
||||
case ArticleImportTypeEnum.VuePress:
|
||||
abstractArticleImport = new VuePressArticleImport();
|
||||
break;
|
||||
|
||||
default: abstractArticleImport = new DefaultArticleImport(); break;
|
||||
}
|
||||
|
||||
var articleHandled = abstractArticleImport.Import(discussId, articleParentId, fileObjs);
|
||||
|
||||
//await _articleRepository.InsertManyAsync(articleHandled);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +248,17 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
throw new UserFriendlyException("验证码错误");
|
||||
}
|
||||
|
||||
private void ValidateUserName(RegisterDto input)
|
||||
{
|
||||
// 正则表达式,匹配只包含数字和字母的字符串
|
||||
string pattern = @"^[a-zA-Z0-9]+$";
|
||||
|
||||
bool isMatch = Regex.IsMatch(input.UserName, pattern);
|
||||
if (!isMatch)
|
||||
{
|
||||
throw new UserFriendlyException("用户名不能包含除【字母】与【数字】的其他字符");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册,需要验证码通过
|
||||
@@ -276,6 +287,10 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
{
|
||||
throw new UserFriendlyException("密码需大于等于6位!");
|
||||
}
|
||||
|
||||
//效验用户名
|
||||
ValidateUserName(input);
|
||||
|
||||
//效验验证码,根据电话号码获取 value,比对验证码已经uuid
|
||||
await ValidationPhoneCaptchaAsync(input);
|
||||
|
||||
@@ -283,7 +298,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
|
||||
//输入的用户名与电话号码都不能在数据库中存在
|
||||
UserEntity user = new();
|
||||
var isExist = await _userRepository.IsAnyAsync(x =>x.UserName == input.UserName|| x.Phone == input.Phone);
|
||||
var isExist = await _userRepository.IsAnyAsync(x => x.UserName == input.UserName || x.Phone == input.Phone);
|
||||
if (isExist)
|
||||
{
|
||||
throw new UserFriendlyException("用户已存在,注册失败");
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
@@ -65,6 +66,7 @@ namespace Yi.Abp.Web
|
||||
service.AddControllers().AddNewtonsoftJson(options =>
|
||||
{
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||
});
|
||||
|
||||
Configure<AbpAntiForgeryOptions>(options =>
|
||||
|
||||
BIN
Yi.Abp.Net8/src/Yi.Abp.Web/wwwroot/logo.png
Normal file
BIN
Yi.Abp.Net8/src/Yi.Abp.Web/wwwroot/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
Reference in New Issue
Block a user