Merge branch 'abp' of https://gitee.com/ccnetcore/Yi into abp
This commit is contained in:
@@ -7,8 +7,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public string Title { get; set; }
|
||||
public string? Types { get; set; }
|
||||
public string? Introduction { get; set; }
|
||||
public int AgreeNum { get; set; }
|
||||
public int SeeNum { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string? Color { get; set; }
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace Yi.Framework.Bbs.Domain.Entities
|
||||
public Guid? LastModifierId { get; set; }
|
||||
|
||||
public DateTime? LastModificationTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int OrderNum { get; set; } = 0;
|
||||
}
|
||||
|
||||
public static class ArticleEntityExtensions
|
||||
|
||||
@@ -3,20 +3,29 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
using Yi.Framework.Core.Data;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
public abstract class AbstractArticleImport
|
||||
{
|
||||
public virtual List<ArticleEntity> Import(Guid discussId,Guid articleParentId, List<FileObject> fileObjs)
|
||||
public void SetLogger(ILoggerFactory loggerFactory)
|
||||
{
|
||||
LoggerFactory = loggerFactory;
|
||||
}
|
||||
protected ILoggerFactory LoggerFactory { get; set; }
|
||||
public virtual List<ArticleEntity> Import(Guid discussId, Guid articleParentId, List<FileObject> fileObjs)
|
||||
{
|
||||
var articles = Convert(fileObjs);
|
||||
var orderNum = 0;
|
||||
articles.ForEach(article =>
|
||||
{
|
||||
article.DiscussId = discussId;
|
||||
article.ParentId = articleParentId;
|
||||
article.OrderNum = ++orderNum;
|
||||
});
|
||||
return articles;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
|
||||
@@ -12,6 +13,8 @@ namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
{
|
||||
public override List<ArticleEntity> Convert(List<FileObject> fileObjs)
|
||||
{
|
||||
var logger = LoggerFactory.CreateLogger<VuePressArticleImport>();
|
||||
|
||||
//排序及处理目录名称
|
||||
var fileNameHandler = fileObjs.OrderBy(x => x.FileName).Select(x =>
|
||||
{
|
||||
@@ -24,36 +27,44 @@ namespace Yi.Framework.Bbs.Domain.Managers.ArticleImport
|
||||
|
||||
|
||||
//处理内容
|
||||
var fileContentHandler= fileNameHandler.Select(x =>
|
||||
{
|
||||
var f = new FileObject { FileName = x.FileName };
|
||||
var lines = x.Content.SplitToLines();
|
||||
var fileContentHandler = fileNameHandler.Select(x =>
|
||||
{
|
||||
logger.LogError($"老的值:{x.Content}");
|
||||
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;
|
||||
var num = 0;
|
||||
var startIndex = 0;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
//编码问题
|
||||
if (lines[i] == "---")
|
||||
{
|
||||
num++;
|
||||
if (num == 2)
|
||||
{
|
||||
startIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var linesRef = lines.ToList();
|
||||
|
||||
linesRef.RemoveRange(0, startIndex+1);
|
||||
var result = string.Join(Environment.NewLine, linesRef);
|
||||
f.Content = result;
|
||||
return f;
|
||||
});
|
||||
}
|
||||
var linesRef = lines.ToList();
|
||||
|
||||
if (startIndex != 0)
|
||||
{
|
||||
linesRef.RemoveRange(0, startIndex + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
//去除头部
|
||||
linesRef.RemoveRange(0,6);
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
|
||||
default: abstractArticleImport = new DefaultArticleImport(); break;
|
||||
}
|
||||
|
||||
abstractArticleImport.SetLogger(LoggerFactory);
|
||||
var articleHandled = abstractArticleImport.Import(discussId, articleParentId, fileObjs);
|
||||
|
||||
await _articleRepository.InsertManyAsync(articleHandled);
|
||||
|
||||
@@ -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).OrderBy(x=>x.CreationTime).ToTreeAsync(x => x.Children, x => x.ParentId, Guid.Empty);
|
||||
return await _DbQueryable.Where(where).OrderBy(x=>x.OrderNum).OrderBy(x=>x.CreationTime).ToTreeAsync(x => x.Children, x => x.ParentId, Guid.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user