Compare commits
29 Commits
AbpUnitOfW
...
tool-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3c5d0862b | ||
|
|
e832921edf | ||
|
|
0c0ead26c0 | ||
|
|
f9a018638b | ||
|
|
d5ca8ddf1e | ||
|
|
ed5c20c612 | ||
|
|
49f1d1a8fa | ||
|
|
a87d6345c2 | ||
|
|
d83db53acb | ||
|
|
c944bd3b0e | ||
|
|
9aaa88ef51 | ||
|
|
ef2d00a254 | ||
|
|
d38159f68b | ||
|
|
dd29c9a2fa | ||
|
|
ca1b8a728d | ||
|
|
6b647cf4ea | ||
|
|
0e6f79c28e | ||
|
|
894d4eb051 | ||
|
|
8d9c5bb762 | ||
|
|
7a916fc78e | ||
|
|
73db2a202a | ||
|
|
f9890bdc7f | ||
|
|
8a0c0de8a1 | ||
|
|
8c940126b5 | ||
|
|
71b7b7cc79 | ||
|
|
f6be4ad7ac | ||
|
|
f6cbe899c6 | ||
|
|
7598c8319f | ||
|
|
a798f36529 |
1
.gitignore
vendored
@@ -269,6 +269,7 @@ dist
|
|||||||
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Production.json
|
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Production.json
|
||||||
/Yi.Abp.Net8/test/Yi.Abp.Test/appsettings.Development.json
|
/Yi.Abp.Net8/test/Yi.Abp.Test/appsettings.Development.json
|
||||||
/Yi.Abp.Net8/test/Yi.Abp.Test/appsettings.Production.json
|
/Yi.Abp.Net8/test/Yi.Abp.Test/appsettings.Production.json
|
||||||
|
/Yi.Abp.Net8/tool/Yi.Abp.Tool.Web/appsettings.Development.json
|
||||||
database_backup
|
database_backup
|
||||||
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json
|
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json
|
||||||
/Yi.Abp.Net8/src/Yi.Abp.Web/logs/
|
/Yi.Abp.Net8/src/Yi.Abp.Web/logs/
|
||||||
|
|||||||
@@ -80,20 +80,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.AuditLogging.S
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.AspNetCore.Authentication.OAuth", "framework\Yi.Framework.AspNetCore.Authentication.OAuth\Yi.Framework.AspNetCore.Authentication.OAuth.csproj", "{791AC2FA-50D3-4408-8D68-31DA72F608BE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.AspNetCore.Authentication.OAuth", "framework\Yi.Framework.AspNetCore.Authentication.OAuth\Yi.Framework.AspNetCore.Authentication.OAuth.csproj", "{791AC2FA-50D3-4408-8D68-31DA72F608BE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{01300F0F-686E-47B3-821D-12424177867B}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Web", "sample\Acme.BookStore.Web\Acme.BookStore.Web.csproj", "{576DBC97-4E5D-4444-B65C-F41649A5F8E0}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Domain.Shared", "sample\Acme.BookStore.Domain.Shared\Acme.BookStore.Domain.Shared.csproj", "{D7F8BD42-F6A2-4F0A-9212-391B5185A99D}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Domain", "sample\Acme.BookStore.Domain\Acme.BookStore.Domain.csproj", "{B615847F-8568-41D1-8B7E-63D61AE69F3D}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Application.Contracts", "sample\Acme.BookStore.Application.Contracts\Acme.BookStore.Application.Contracts.csproj", "{20827DB5-5CDE-491A-82E8-3CAB82618C1E}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Application", "sample\Acme.BookStore.Application\Acme.BookStore.Application.csproj", "{320273B6-7AE3-42DA-9675-D9AD4928A289}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.SqlSugarCore", "sample\Acme.BookStore.SqlSugarCore\Acme.BookStore.SqlSugarCore.csproj", "{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Abp.Test", "test\Yi.Abp.Test\Yi.Abp.Test.csproj", "{68627BC2-F049-4C69-AD17-81DF9478E8CE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Abp.Test", "test\Yi.Abp.Test\Yi.Abp.Test.csproj", "{68627BC2-F049-4C69-AD17-81DF9478E8CE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tenant-management", "tenant-management", "{499A8C71-7892-42D0-A77E-48756E1EFF16}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tenant-management", "tenant-management", "{499A8C71-7892-42D0-A77E-48756E1EFF16}"
|
||||||
@@ -276,30 +262,6 @@ Global
|
|||||||
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{791AC2FA-50D3-4408-8D68-31DA72F608BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{576DBC97-4E5D-4444-B65C-F41649A5F8E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{576DBC97-4E5D-4444-B65C-F41649A5F8E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{576DBC97-4E5D-4444-B65C-F41649A5F8E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{576DBC97-4E5D-4444-B65C-F41649A5F8E0}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{D7F8BD42-F6A2-4F0A-9212-391B5185A99D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{D7F8BD42-F6A2-4F0A-9212-391B5185A99D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{D7F8BD42-F6A2-4F0A-9212-391B5185A99D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{D7F8BD42-F6A2-4F0A-9212-391B5185A99D}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{B615847F-8568-41D1-8B7E-63D61AE69F3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{B615847F-8568-41D1-8B7E-63D61AE69F3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B615847F-8568-41D1-8B7E-63D61AE69F3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{B615847F-8568-41D1-8B7E-63D61AE69F3D}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{20827DB5-5CDE-491A-82E8-3CAB82618C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{20827DB5-5CDE-491A-82E8-3CAB82618C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{20827DB5-5CDE-491A-82E8-3CAB82618C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{20827DB5-5CDE-491A-82E8-3CAB82618C1E}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{320273B6-7AE3-42DA-9675-D9AD4928A289}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{320273B6-7AE3-42DA-9675-D9AD4928A289}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{320273B6-7AE3-42DA-9675-D9AD4928A289}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{320273B6-7AE3-42DA-9675-D9AD4928A289}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -461,12 +423,6 @@ Global
|
|||||||
{73CCF2C4-B9FD-44AB-8D4B-0A421805B094} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
{73CCF2C4-B9FD-44AB-8D4B-0A421805B094} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
||||||
{48806510-8E18-4E1E-9BAF-5B97E88C5FC3} = {73CCF2C4-B9FD-44AB-8D4B-0A421805B094}
|
{48806510-8E18-4E1E-9BAF-5B97E88C5FC3} = {73CCF2C4-B9FD-44AB-8D4B-0A421805B094}
|
||||||
{791AC2FA-50D3-4408-8D68-31DA72F608BE} = {77B949E9-530E-45A5-9657-20F7D5C6875C}
|
{791AC2FA-50D3-4408-8D68-31DA72F608BE} = {77B949E9-530E-45A5-9657-20F7D5C6875C}
|
||||||
{576DBC97-4E5D-4444-B65C-F41649A5F8E0} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{D7F8BD42-F6A2-4F0A-9212-391B5185A99D} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{B615847F-8568-41D1-8B7E-63D61AE69F3D} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{20827DB5-5CDE-491A-82E8-3CAB82618C1E} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{320273B6-7AE3-42DA-9675-D9AD4928A289} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7} = {01300F0F-686E-47B3-821D-12424177867B}
|
|
||||||
{68627BC2-F049-4C69-AD17-81DF9478E8CE} = {0D10EEF2-FBAE-4C72-B816-A52823FC299B}
|
{68627BC2-F049-4C69-AD17-81DF9478E8CE} = {0D10EEF2-FBAE-4C72-B816-A52823FC299B}
|
||||||
{499A8C71-7892-42D0-A77E-48756E1EFF16} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
{499A8C71-7892-42D0-A77E-48756E1EFF16} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
||||||
{FA5BBAA1-08DC-472F-BB2C-5314E59D1556} = {499A8C71-7892-42D0-A77E-48756E1EFF16}
|
{FA5BBAA1-08DC-472F-BB2C-5314E59D1556} = {499A8C71-7892-42D0-A77E-48756E1EFF16}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Core.Json;
|
||||||
|
|
||||||
|
public class DatetimeJsonConverter : JsonConverter<DateTime>
|
||||||
|
{
|
||||||
|
private string _format;
|
||||||
|
public DatetimeJsonConverter(string format="yyyy-MM-dd HH:mm:ss")
|
||||||
|
{
|
||||||
|
_format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if(reader.TokenType==JsonTokenType.String)
|
||||||
|
{
|
||||||
|
if (DateTime.TryParse(reader.GetString(), out DateTime dateTime)) return dateTime;
|
||||||
|
}
|
||||||
|
return reader.GetDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStringValue(value.ToString(_format));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ public class AuditingStore : IAuditingStore, ITransientDependency
|
|||||||
protected IUnitOfWorkManager UnitOfWorkManager { get; }
|
protected IUnitOfWorkManager UnitOfWorkManager { get; }
|
||||||
protected AbpAuditingOptions Options { get; }
|
protected AbpAuditingOptions Options { get; }
|
||||||
protected IAuditLogInfoToAuditLogConverter Converter { get; }
|
protected IAuditLogInfoToAuditLogConverter Converter { get; }
|
||||||
|
|
||||||
public AuditingStore(
|
public AuditingStore(
|
||||||
IAuditLogRepository auditLogRepository,
|
IAuditLogRepository auditLogRepository,
|
||||||
IUnitOfWorkManager unitOfWorkManager,
|
IUnitOfWorkManager unitOfWorkManager,
|
||||||
@@ -52,10 +53,10 @@ public class AuditingStore : IAuditingStore, ITransientDependency
|
|||||||
protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo)
|
protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo)
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Yi-请求追踪:" + JsonHelper.ObjToStr(auditInfo, "yyyy-MM-dd HH:mm:ss"));
|
Logger.LogDebug("Yi-请求追踪:" + JsonHelper.ObjToStr(auditInfo, "yyyy-MM-dd HH:mm:ss"));
|
||||||
using (var uow = UnitOfWorkManager.Begin(true))
|
// using (var uow = UnitOfWorkManager.Begin(true,isTransactional:false))
|
||||||
{
|
// {
|
||||||
await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo));
|
await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo));
|
||||||
await uow.CompleteAsync();
|
// await uow.CompleteAsync();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ public class AuditLogActionEntity : Entity<Guid>, IMultiTenant
|
|||||||
|
|
||||||
public virtual string? MethodName { get; protected set; }
|
public virtual string? MethodName { get; protected set; }
|
||||||
|
|
||||||
|
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
||||||
public virtual string? Parameters { get; protected set; }
|
public virtual string? Parameters { get; protected set; }
|
||||||
|
|
||||||
public virtual DateTime? ExecutionTime { get; protected set; }
|
public virtual DateTime? ExecutionTime { get; protected set; }
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ namespace Yi.Framework.AuditLogging.Domain.Entities
|
|||||||
|
|
||||||
public virtual string? CorrelationId { get; set; }
|
public virtual string? CorrelationId { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(Length = 2000)]
|
||||||
public virtual string? BrowserInfo { get; protected set; }
|
public virtual string? BrowserInfo { get; protected set; }
|
||||||
|
|
||||||
public virtual string? HttpMethod { get; protected set; }
|
public virtual string? HttpMethod { get; protected set; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
|||||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Comment
|
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Comment
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单返回,返回单条评论即可
|
/// 单返回,返回单条评论即可
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CommentGetOutputDto : EntityDto<Guid>
|
public class CommentGetOutputDto : EntityDto<Guid>
|
||||||
{
|
{
|
||||||
@@ -17,17 +17,17 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Comment
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户id联表为用户对象
|
/// 用户id联表为用户对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public BbsUserGetOutputDto User { get; set; }
|
public BbsUserGetOutputDto User { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根节点的评论id
|
/// 根节点的评论id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid RootId { get; set; }
|
public Guid RootId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 被回复的CommentId
|
/// 被回复的CommentId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid ParentId { get; set; }
|
public Guid ParentId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ namespace Yi.Framework.Bbs.Application.Contracts.IServices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Comment服务抽象
|
/// Comment服务抽象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ICommentService{
|
public interface ICommentService : IYiCrudAppService<CommentGetOutputDto, CommentGetListOutputDto, Guid, CommentGetListInputVo, CommentCreateInputVo, CommentUpdateInputVo>
|
||||||
/// <summary>
|
{
|
||||||
/// 发表评论
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="UserFriendlyException"></exception>
|
|
||||||
// [Permission("bbs:comment:add")]
|
|
||||||
// [Authorize]
|
|
||||||
Task<CommentGetOutputDto> CreateAsync(CommentCreateInputVo input);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
using Volo.Abp.Application.Services;
|
|
||||||
using Volo.Abp.Domain.Repositories;
|
|
||||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Comment;
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.Comment;
|
||||||
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
||||||
@@ -23,11 +21,19 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 评论
|
/// 评论
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CommentService : ApplicationService,
|
public class CommentService : YiCrudAppService<CommentAggregateRoot, CommentGetOutputDto, CommentGetListOutputDto, Guid, CommentGetListInputVo, CommentCreateInputVo, CommentUpdateInputVo>,
|
||||||
ICommentService
|
ICommentService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarRepository<CommentAggregateRoot, Guid> _repository;
|
private readonly ISqlSugarRepository<CommentAggregateRoot, Guid> _repository;
|
||||||
private readonly BbsUserManager _bbsUserManager;
|
private readonly BbsUserManager _bbsUserManager;
|
||||||
|
public CommentService(ForumManager forumManager, ISqlSugarRepository<DiscussAggregateRoot> discussRepository, IDiscussService discussService, ISqlSugarRepository<CommentAggregateRoot, Guid> CommentRepository, BbsUserManager bbsUserManager) : base(CommentRepository)
|
||||||
|
{
|
||||||
|
_forumManager = forumManager;
|
||||||
|
_discussRepository = discussRepository;
|
||||||
|
_discussService = discussService;
|
||||||
|
_repository = CommentRepository;
|
||||||
|
_bbsUserManager = bbsUserManager;
|
||||||
|
}
|
||||||
|
|
||||||
private ForumManager _forumManager { get; set; }
|
private ForumManager _forumManager { get; set; }
|
||||||
|
|
||||||
@@ -36,50 +42,116 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
|||||||
private ISqlSugarRepository<DiscussAggregateRoot> _discussRepository { get; set; }
|
private ISqlSugarRepository<DiscussAggregateRoot> _discussRepository { get; set; }
|
||||||
|
|
||||||
private IDiscussService _discussService { get; set; }
|
private IDiscussService _discussService { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 获取改主题下的评论,结构为二维列表,该查询无分页
|
||||||
public async Task<CommentGetOutputDto> Create2Async(CommentCreateInputVo input)
|
/// Todo: 可放入领域层
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="discussId"></param>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<PagedResultDto<CommentGetListOutputDto>> GetDiscussIdAsync([FromRoute] Guid discussId, [FromQuery] CommentGetListInputVo input)
|
||||||
{
|
{
|
||||||
var entity = new CommentAggregateRoot(Guid.Empty);
|
await _discussService.VerifyDiscussPermissionAsync(discussId);
|
||||||
return new CommentGetOutputDto();
|
|
||||||
|
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content))
|
||||||
|
.Where(x => x.DiscussId == discussId)
|
||||||
|
.Includes(x => x.CreateUser)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
//该实体需要进行转换
|
||||||
|
|
||||||
|
//同时为所有用户id进行bbs的扩展即可
|
||||||
|
List<Guid> userIds = entities.Where(x => x.CreatorId != null).Select(x => x.CreatorId ?? Guid.Empty).ToList();
|
||||||
|
var bbsUserInfoDic = (await _bbsUserManager.GetBbsUserInfoAsync(userIds)).ToDictionary(x => x.Id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//------数据查询完成------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//从根目录开始组装
|
||||||
|
//结果初始值,第一层等于全部根节点
|
||||||
|
var allOutPut = entities.OrderByDescending(x => x.CreationTime).ToList();
|
||||||
|
|
||||||
|
//获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
|
||||||
|
List<CommentGetListOutputDto> allOutoutDto = await MapToGetListOutputDtosAsync(allOutPut);
|
||||||
|
|
||||||
|
//开始映射额外用户信息字段
|
||||||
|
allOutoutDto?.ForEach(x => x.CreateUser = bbsUserInfoDic[x.CreatorId ?? Guid.Empty].Adapt<BbsUserGetOutputDto>());
|
||||||
|
|
||||||
|
//开始组装dto的层级关系
|
||||||
|
//将全部数据进行hash
|
||||||
|
var dic = allOutoutDto.ToDictionary(x => x.Id);
|
||||||
|
|
||||||
|
foreach (var comment in allOutoutDto)
|
||||||
|
{
|
||||||
|
//不是根节点,需要赋值 被评论者用户信息等
|
||||||
|
if (comment.ParentId != Guid.Empty)
|
||||||
|
{
|
||||||
|
if (dic.ContainsKey(comment.ParentId))
|
||||||
|
{
|
||||||
|
var parentComment = dic[comment.ParentId];
|
||||||
|
comment.CommentedUser = parentComment.CreateUser;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//root或者parent id,根节点都是等于0的
|
||||||
|
var id = comment.RootId;
|
||||||
|
if (id != Guid.Empty)
|
||||||
|
{
|
||||||
|
dic[id].Children.Add(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//子类需要排序
|
||||||
|
var rootOutoutDto = allOutoutDto.Where(x => x.ParentId == Guid.Empty).ToList();
|
||||||
|
rootOutoutDto?.ForEach(x =>
|
||||||
|
{
|
||||||
|
x.Children = x.Children.OrderByDescending(x => x.CreationTime).ToList();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return new PagedResultDto<CommentGetListOutputDto>(entities.Count(), rootOutoutDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Create22")]
|
|
||||||
public async Task<CommentGetOutputDto> Create22Async(CommentCreateInputVo input)
|
|
||||||
{
|
|
||||||
var entity = new CommentAggregateRoot(Guid.Empty);
|
|
||||||
return new CommentGetOutputDto();
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发表评论
|
/// 发表评论
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="UserFriendlyException"></exception>
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
// [Permission("bbs:comment:add")]
|
[Permission("bbs:comment:add")]
|
||||||
// [Authorize]
|
[Authorize]
|
||||||
public async Task<CommentGetOutputDto> CreateAsync(CommentCreateInputVo input)
|
public override async Task<CommentGetOutputDto> CreateAsync(CommentCreateInputVo input)
|
||||||
{
|
{
|
||||||
// var discuess = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId);
|
var discuess = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId);
|
||||||
// if (discuess is null)
|
if (discuess is null)
|
||||||
// {
|
{
|
||||||
// throw new UserFriendlyException(DiscussConst.No_Exist);
|
throw new UserFriendlyException(DiscussConst.No_Exist);
|
||||||
// }
|
}
|
||||||
//不是超级管理员,且主题开启禁止评论
|
//不是超级管理员,且主题开启禁止评论
|
||||||
|
|
||||||
// if (discuess.IsDisableCreateComment == true && !CurrentUser.GetPermissions().Contains(UserConst.AdminPermissionCode))
|
if (discuess.IsDisableCreateComment == true && !CurrentUser.GetPermissions().Contains(UserConst.AdminPermissionCode))
|
||||||
// {
|
{
|
||||||
// throw new UserFriendlyException("该主题已禁止评论功能");
|
throw new UserFriendlyException("该主题已禁止评论功能");
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
// var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId, input.RootId, input.Content);
|
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId, input.RootId, input.Content);
|
||||||
var entity = new CommentAggregateRoot(Guid.Empty);
|
return await MapToGetOutputDtoAsync(entity);
|
||||||
return new CommentGetOutputDto();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentService(IRepository<CommentAggregateRoot, Guid> repository)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Yi.Framework.Bbs.Application.Services.Integral
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 大转盘
|
/// 大转盘
|
||||||
/// Todo: 可放入领域层
|
/// Todo: 可放入领域层,但是太简单了,不重要
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Authorize]
|
[Authorize]
|
||||||
@@ -32,13 +32,7 @@ namespace Yi.Framework.Bbs.Application.Services.Integral
|
|||||||
int[] values = new int[10] { 0, 10, 30, 50, 60, 80, 90, 100, 200, 666 };
|
int[] values = new int[10] { 0, 10, 30, 50, 60, 80, 90, 100, 200, 666 };
|
||||||
var index = GetWheelIndex();
|
var index = GetWheelIndex();
|
||||||
var value = values[index] - 50;
|
var value = values[index] - 50;
|
||||||
|
|
||||||
////不存在负数钱钱
|
|
||||||
//if (value < 0)
|
|
||||||
//{
|
|
||||||
// value = 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//修改钱钱,如果钱钱不足,直接会丢出去,那本次抽奖将无效
|
//修改钱钱,如果钱钱不足,直接会丢出去,那本次抽奖将无效
|
||||||
await _localEventBus.PublishAsync(new MoneyChangeEventArgs { UserId = CurrentUser.Id!.Value, Number = value }, false);
|
await _localEventBus.PublishAsync(new MoneyChangeEventArgs { UserId = CurrentUser.Id!.Value, Number = value }, false);
|
||||||
|
|
||||||
@@ -47,7 +41,7 @@ namespace Yi.Framework.Bbs.Application.Services.Integral
|
|||||||
|
|
||||||
private int GetWheelIndex()
|
private int GetWheelIndex()
|
||||||
{
|
{
|
||||||
int[] probabilities = { 30, 40, 30, 15, 15, 10, 4, 3, 2, 1 };
|
int[] probabilities = {5 , 30, 40, 30, 20, 10, 4, 3, 2, 1 };
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
foreach (var prob in probabilities)
|
foreach (var prob in probabilities)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
|
||||||
|
public enum GoodsTypeEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 申请类型
|
||||||
|
/// </summary>
|
||||||
|
Apply
|
||||||
|
}
|
||||||
@@ -19,5 +19,10 @@ namespace Yi.Framework.Bbs.Domain.Shared.Enums
|
|||||||
/// 广播
|
/// 广播
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Broadcast,
|
Broadcast,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 钱钱
|
||||||
|
/// </summary>
|
||||||
|
Money
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ namespace Yi.Framework.Bbs.Domain.Shared.Etos
|
|||||||
Message = message;
|
Message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BbsNoticeEventArgs( NoticeTypeEnum noticeType, Guid acceptUserId, string message)
|
||||||
|
{
|
||||||
|
NoticeType = noticeType;
|
||||||
|
AcceptUserId = acceptUserId;
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送广播
|
/// 发送广播
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace Yi.Framework.Bbs.Domain.Entities.Forum
|
|||||||
public override Guid Id { get; protected set; }
|
public override Guid Id { get; protected set; }
|
||||||
public bool IsDeleted { get; set; }
|
public bool IsDeleted { get; set; }
|
||||||
|
|
||||||
[SugarColumn(Length = 500)]
|
[SugarColumn(Length = 2000)]
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
|
|
||||||
public Guid DiscussId { get; set; }
|
public Guid DiscussId { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Auditing;
|
||||||
|
using Volo.Abp.Domain.Entities;
|
||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.Entities.Shop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品定义表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("BbsGoods")]
|
||||||
|
public class BbsGoodsAggregateRoot: AggregateRoot<Guid>, IHasCreationTime
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 上架时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品类型
|
||||||
|
/// </summary>
|
||||||
|
public GoodsTypeEnum GoodsType{ get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下架时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每人限购数量
|
||||||
|
/// </summary>
|
||||||
|
public int LimitNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前库存数量
|
||||||
|
/// </summary>
|
||||||
|
public int StockNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品图片url
|
||||||
|
/// </summary>
|
||||||
|
public string ImageUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述
|
||||||
|
/// </summary>
|
||||||
|
public string Describe { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编号
|
||||||
|
/// </summary>
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需钱钱
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedMoney { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需价值
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所需积分
|
||||||
|
/// </summary>
|
||||||
|
public decimal NeedPoints { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Auditing;
|
||||||
|
using Volo.Abp.Domain.Entities;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.Entities.Shop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 商品申请记录表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("BbsGoodsApply")]
|
||||||
|
public class BbsGoodsApplyAggregateRoot: AggregateRoot<Guid>, IHasCreationTime
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 商品id
|
||||||
|
/// </summary>
|
||||||
|
public Guid GoodsId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 申请时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 申请人用户id
|
||||||
|
/// </summary>
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 联系方式
|
||||||
|
/// </summary>
|
||||||
|
public string ContactInformation { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Yi.Framework.Bbs.Domain.Entities.Shop.ValueObjects;
|
||||||
|
|
||||||
|
public class ShippingAddress
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,23 +25,40 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers
|
|||||||
}
|
}
|
||||||
public async Task HandleEventAsync(BbsNoticeEventArgs eventData)
|
public async Task HandleEventAsync(BbsNoticeEventArgs eventData)
|
||||||
{
|
{
|
||||||
//离线存储
|
|
||||||
var entity= await _repository.InsertReturnEntityAsync(new BbsNoticeAggregateRoot(eventData.NoticeType, eventData.Message, eventData.AcceptUserId));
|
|
||||||
switch (eventData.NoticeType)
|
//是否需要离线存储
|
||||||
|
bool isStore = true;
|
||||||
|
var now = DateTime.Now;
|
||||||
|
switch (eventData.NoticeType)
|
||||||
{
|
{
|
||||||
case Shared.Enums.NoticeTypeEnum.Personal:
|
case Shared.Enums.NoticeTypeEnum.Personal:
|
||||||
if (BbsNoticeHub.HubUserModels.TryGetValue(eventData.AcceptUserId.ToString(), out var hubUserModel))
|
if (BbsNoticeHub.HubUserModels.TryGetValue(eventData.AcceptUserId.ToString(), out var hubUserModel))
|
||||||
{
|
{
|
||||||
_hubContext.Clients.Client(hubUserModel.ConnnectionId).SendAsync(NoticeTypeEnum.Personal.ToString(), eventData.Message,entity.CreationTime);
|
_hubContext.Clients.Client(hubUserModel.ConnnectionId).SendAsync(NoticeTypeEnum.Personal.ToString(), eventData.Message,now);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Shared.Enums.NoticeTypeEnum.Broadcast:
|
case Shared.Enums.NoticeTypeEnum.Broadcast:
|
||||||
_hubContext.Clients.All.SendAsync(NoticeTypeEnum.Broadcast.ToString(), eventData.Message);
|
_hubContext.Clients.All.SendAsync(NoticeTypeEnum.Broadcast.ToString(), eventData.Message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Shared.Enums.NoticeTypeEnum.Money:
|
||||||
|
if (BbsNoticeHub.HubUserModels.TryGetValue(eventData.AcceptUserId.ToString(), out var hubUserModel2))
|
||||||
|
{
|
||||||
|
_hubContext.Clients.Client(hubUserModel2.ConnnectionId).SendAsync(NoticeTypeEnum.Money.ToString(), eventData.Message,now);
|
||||||
|
}
|
||||||
|
|
||||||
|
isStore = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isStore)
|
||||||
|
{ //离线存储
|
||||||
|
var entity= await _repository.InsertReturnEntityAsync(new BbsNoticeAggregateRoot(eventData.NoticeType, eventData.Message, eventData.AcceptUserId){CreationTime = now});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +1,73 @@
|
|||||||
// using TencentCloud.Tbm.V20180129.Models;
|
using TencentCloud.Tbm.V20180129.Models;
|
||||||
// using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
// using Volo.Abp.Domain.Entities.Events;
|
using Volo.Abp.Domain.Entities.Events;
|
||||||
// using Volo.Abp.EventBus;
|
using Volo.Abp.EventBus;
|
||||||
// using Volo.Abp.EventBus.Local;
|
using Volo.Abp.EventBus.Local;
|
||||||
// using Yi.Framework.Bbs.Domain.Entities;
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
// using Yi.Framework.Bbs.Domain.Entities.Forum;
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
// using Yi.Framework.Bbs.Domain.Shared.Consts;
|
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||||
// using Yi.Framework.Bbs.Domain.Shared.Enums;
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
// using Yi.Framework.Bbs.Domain.Shared.Etos;
|
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||||
// using Yi.Framework.Rbac.Domain.Entities;
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
// using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
//
|
|
||||||
// namespace Yi.Framework.Bbs.Domain.EventHandlers
|
namespace Yi.Framework.Bbs.Domain.EventHandlers
|
||||||
// {
|
{
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// 评论创建的领域事件
|
/// 评论创建的领域事件
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// public class CommentCreatedEventHandler : ILocalEventHandler<EntityCreatedEventData<CommentAggregateRoot>>,
|
public class CommentCreatedEventHandler : ILocalEventHandler<EntityCreatedEventData<CommentAggregateRoot>>,
|
||||||
// ITransientDependency
|
ITransientDependency
|
||||||
// {
|
{
|
||||||
// private ILocalEventBus _localEventBus;
|
private ILocalEventBus _localEventBus;
|
||||||
// private ISqlSugarRepository<DiscussAggregateRoot> _discussRepository;
|
private ISqlSugarRepository<DiscussAggregateRoot> _discussRepository;
|
||||||
// private ISqlSugarRepository<UserAggregateRoot> _userRepository;
|
private ISqlSugarRepository<UserAggregateRoot> _userRepository;
|
||||||
// public CommentCreatedEventHandler(ILocalEventBus localEventBus, ISqlSugarRepository<DiscussAggregateRoot> discussRepository, ISqlSugarRepository<UserAggregateRoot> userRepository)
|
public CommentCreatedEventHandler(ILocalEventBus localEventBus, ISqlSugarRepository<DiscussAggregateRoot> discussRepository, ISqlSugarRepository<UserAggregateRoot> userRepository)
|
||||||
// {
|
{
|
||||||
// _userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
// _localEventBus = localEventBus;
|
_localEventBus = localEventBus;
|
||||||
// _discussRepository = discussRepository;
|
_discussRepository = discussRepository;
|
||||||
// }
|
}
|
||||||
// public async Task HandleEventAsync(EntityCreatedEventData<CommentAggregateRoot> eventData)
|
public async Task HandleEventAsync(EntityCreatedEventData<CommentAggregateRoot> eventData)
|
||||||
// {
|
{
|
||||||
// var commentEntity = eventData.Entity;
|
var commentEntity = eventData.Entity;
|
||||||
//
|
|
||||||
// //给创建者发布数量+1
|
//给创建者发布数量+1
|
||||||
// await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
await _userRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
// .SetColumns(it => it.CommentNumber == it.CommentNumber + 1)
|
.SetColumns(it => it.CommentNumber == it.CommentNumber + 1)
|
||||||
// .Where(it => it.UserId == commentEntity.CreatorId)
|
.Where(it => it.UserId == commentEntity.CreatorId)
|
||||||
// .ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
// var disucssDto = await _discussRepository._DbQueryable
|
var disucssDto = await _discussRepository._DbQueryable
|
||||||
// .Where(x => x.Id == commentEntity.DiscussId)
|
.Where(x => x.Id == commentEntity.DiscussId)
|
||||||
// .LeftJoin<UserAggregateRoot>((dicuss, user) => dicuss.CreatorId == user.Id)
|
.LeftJoin<UserAggregateRoot>((dicuss, user) => dicuss.CreatorId == user.Id)
|
||||||
// .Select((dicuss, user) =>
|
.Select((dicuss, user) =>
|
||||||
// new
|
new
|
||||||
// {
|
{
|
||||||
// DiscussUserId = user.Id,
|
DiscussUserId = user.Id,
|
||||||
// DiscussTitle = dicuss.Title,
|
DiscussTitle = dicuss.Title,
|
||||||
//
|
|
||||||
// })
|
})
|
||||||
// .FirstAsync();
|
.FirstAsync();
|
||||||
//
|
|
||||||
// var commentUser = await _userRepository.GetFirstAsync(x => x.Id == commentEntity.CreatorId);
|
var commentUser = await _userRepository.GetFirstAsync(x => x.Id == commentEntity.CreatorId);
|
||||||
//
|
|
||||||
// //截取30个长度
|
//截取30个长度
|
||||||
// var content = commentEntity.Content.Length >= 30 ? commentEntity.Content.Substring(0, 30)+"..." : commentEntity.Content;
|
var content = commentEntity.Content.Length >= 30 ? commentEntity.Content.Substring(0, 30)+"..." : commentEntity.Content;
|
||||||
// //通知主题作者,有人评论
|
//通知主题作者,有人评论
|
||||||
// await _localEventBus.PublishAsync(new BbsNoticeEventArgs(disucssDto.DiscussUserId, string.Format(DiscussConst.CommentNotice, disucssDto.DiscussTitle, commentUser.UserName, content,commentEntity.DiscussId)), false);
|
await _localEventBus.PublishAsync(new BbsNoticeEventArgs(disucssDto.DiscussUserId, string.Format(DiscussConst.CommentNotice, disucssDto.DiscussTitle, commentUser.UserName, content,commentEntity.DiscussId)), false);
|
||||||
//
|
|
||||||
// //如果为空,表示根路径,没有回复者
|
//如果为空,表示根路径,没有回复者
|
||||||
// if (commentEntity.ParentId != Guid.Empty)
|
if (commentEntity.ParentId != Guid.Empty)
|
||||||
// {
|
{
|
||||||
// //通知回复者,有人评论
|
//通知回复者,有人评论
|
||||||
// await _localEventBus.PublishAsync(new BbsNoticeEventArgs(commentEntity.ParentId, string.Format(DiscussConst.CommentNoticeToReply, disucssDto.DiscussTitle, commentUser.UserName, content,commentEntity.DiscussId)), false);
|
await _localEventBus.PublishAsync(new BbsNoticeEventArgs(commentEntity.ParentId, string.Format(DiscussConst.CommentNoticeToReply, disucssDto.DiscussTitle, commentUser.UserName, content,commentEntity.DiscussId)), false);
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// //最后发布任务触发事件
|
//最后发布任务触发事件
|
||||||
// await _localEventBus.PublishAsync(
|
await _localEventBus.PublishAsync(
|
||||||
// new AssignmentEventArgs(AssignmentRequirementTypeEnum.Comment, commentUser.Id),false);
|
new AssignmentEventArgs(AssignmentRequirementTypeEnum.Comment, commentUser.Id),false);
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
using Volo.Abp.EventBus;
|
using Volo.Abp.EventBus;
|
||||||
|
using Volo.Abp.EventBus.Local;
|
||||||
using Yi.Framework.Bbs.Domain.Entities;
|
using Yi.Framework.Bbs.Domain.Entities;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||||
|
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
@@ -11,9 +13,11 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers
|
|||||||
public class MoneyChangeEventHandler : ILocalEventHandler<MoneyChangeEventArgs>, ITransientDependency
|
public class MoneyChangeEventHandler : ILocalEventHandler<MoneyChangeEventArgs>, ITransientDependency
|
||||||
{
|
{
|
||||||
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userInfoRepository;
|
private ISqlSugarRepository<BbsUserExtraInfoEntity> _userInfoRepository;
|
||||||
public MoneyChangeEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userInfoRepository)
|
private ILocalEventBus _localEventBus;
|
||||||
|
public MoneyChangeEventHandler(ISqlSugarRepository<BbsUserExtraInfoEntity> userInfoRepository, ILocalEventBus localEventBus)
|
||||||
{
|
{
|
||||||
_userInfoRepository = userInfoRepository;
|
_userInfoRepository = userInfoRepository;
|
||||||
|
_localEventBus = localEventBus;
|
||||||
}
|
}
|
||||||
public async Task HandleEventAsync(MoneyChangeEventArgs eventData)
|
public async Task HandleEventAsync(MoneyChangeEventArgs eventData)
|
||||||
{
|
{
|
||||||
@@ -28,6 +32,9 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers
|
|||||||
await _userInfoRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
await _userInfoRepository._Db.Updateable<BbsUserExtraInfoEntity>()
|
||||||
.SetColumns(it => it.Money == it.Money + eventData.Number)
|
.SetColumns(it => it.Money == it.Money + eventData.Number)
|
||||||
.Where(x => x.UserId == eventData.UserId).ExecuteCommandAsync();
|
.Where(x => x.UserId == eventData.UserId).ExecuteCommandAsync();
|
||||||
|
|
||||||
|
|
||||||
|
await _localEventBus.PublishAsync(new BbsNoticeEventArgs(NoticeTypeEnum.Money, eventData.UserId,eventData.Number.ToString()), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Volo.Abp.Domain.Services;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Bbs.Domain.Managers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// bbs商品领域
|
||||||
|
/// </summary>
|
||||||
|
public class BbsShopManager: DomainService
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -41,8 +41,7 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
|||||||
entity.Content = content;
|
entity.Content = content;
|
||||||
entity.ParentId = parentId;
|
entity.ParentId = parentId;
|
||||||
entity.RootId = rootId;
|
entity.RootId = rootId;
|
||||||
await _commentRepository.InsertAsync(entity);
|
return await _commentRepository.InsertReturnEntityAsync(entity);
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ namespace Yi.Framework.Rbac.Domain
|
|||||||
{
|
{
|
||||||
var service = context.Services;
|
var service = context.Services;
|
||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
// service.AddControllers(options =>
|
service.AddControllers(options =>
|
||||||
// {
|
{
|
||||||
// options.Filters.Add<PermissionGlobalAttribute>();
|
options.Filters.Add<PermissionGlobalAttribute>();
|
||||||
// // options.Filters.Add<OperLogGlobalAttribute>();
|
options.Filters.Add<OperLogGlobalAttribute>();
|
||||||
// });
|
});
|
||||||
|
|
||||||
//配置阿里云短信
|
//配置阿里云短信
|
||||||
Configure<AliyunOptions>(configuration.GetSection(nameof(AliyunOptions)));
|
Configure<AliyunOptions>(configuration.GetSection(nameof(AliyunOptions)));
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
|
|
||||||
public async Task SeedAsync(DataSeedContext context)
|
public async Task SeedAsync(DataSeedContext context)
|
||||||
{
|
{
|
||||||
if (!await _repository.IsAnyAsync(x => x.MenuName == "系统管理"&&x.MenuSource==MenuSourceEnum.Pure))
|
if (!await _repository.IsAnyAsync(x => x.MenuName == "系统管理" && x.MenuSource == MenuSourceEnum.Pure))
|
||||||
{
|
{
|
||||||
await _repository.InsertManyAsync(GetSeedData());
|
await _repository.InsertManyAsync(GetSeedData());
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
OrderNum = 100
|
OrderNum = 100
|
||||||
};
|
};
|
||||||
entities.Add(system);
|
entities.Add(system);
|
||||||
|
|
||||||
//系统监控
|
//系统监控
|
||||||
MenuAggregateRoot monitoring = new MenuAggregateRoot(_guidGenerator.Create())
|
MenuAggregateRoot monitoring = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
};
|
};
|
||||||
entities.Add(online);
|
entities.Add(online);
|
||||||
|
|
||||||
|
|
||||||
//Yi框架
|
//Yi框架
|
||||||
MenuAggregateRoot guide = new MenuAggregateRoot(_guidGenerator.Create())
|
MenuAggregateRoot guide = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
{
|
{
|
||||||
@@ -77,7 +77,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
Component = null
|
Component = null
|
||||||
};
|
};
|
||||||
entities.Add(guide);
|
entities.Add(guide);
|
||||||
|
|
||||||
//用户管理
|
//用户管理
|
||||||
MenuAggregateRoot user = new MenuAggregateRoot(_guidGenerator.Create())
|
MenuAggregateRoot user = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
{
|
{
|
||||||
@@ -141,7 +141,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
entities.Add(userRemove);
|
entities.Add(userRemove);
|
||||||
|
|
||||||
|
|
||||||
MenuAggregateRoot userResetPwd = new MenuAggregateRoot(_guidGenerator.Create())
|
MenuAggregateRoot userResetPwd = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
{
|
{
|
||||||
|
|
||||||
MenuName = "重置密码",
|
MenuName = "重置密码",
|
||||||
@@ -408,7 +408,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
IsDeleted = false
|
IsDeleted = false
|
||||||
};
|
};
|
||||||
entities.Add(postRemove);
|
entities.Add(postRemove);
|
||||||
|
|
||||||
|
|
||||||
//操作日志
|
//操作日志
|
||||||
MenuAggregateRoot operationLog = new MenuAggregateRoot(_guidGenerator.Create())
|
MenuAggregateRoot operationLog = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
@@ -491,10 +491,78 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
OrderNum = 100,
|
OrderNum = 100,
|
||||||
ParentId = loginLog.Id,
|
ParentId = loginLog.Id,
|
||||||
IsDeleted = false,
|
IsDeleted = false,
|
||||||
|
|
||||||
};
|
};
|
||||||
entities.Add(loginLogRemove);
|
entities.Add(loginLogRemove);
|
||||||
|
|
||||||
|
//参数设置
|
||||||
|
MenuAggregateRoot config = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "参数设置",
|
||||||
|
PermissionCode = "system:config:list",
|
||||||
|
MenuType = MenuTypeEnum.Menu,
|
||||||
|
Router = "config",
|
||||||
|
IsShow = true,
|
||||||
|
IsLink = false,
|
||||||
|
IsCache = true,
|
||||||
|
Component = "/system/config/index",
|
||||||
|
MenuIcon = "ri:edit-box-line",
|
||||||
|
OrderNum = 94,
|
||||||
|
ParentId = system.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(config);
|
||||||
|
|
||||||
|
MenuAggregateRoot configQuery = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "参数查询",
|
||||||
|
PermissionCode = "system:config:query",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = config.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(configQuery);
|
||||||
|
|
||||||
|
MenuAggregateRoot configAdd = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "参数新增",
|
||||||
|
PermissionCode = "system:config:add",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = config.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(configAdd);
|
||||||
|
|
||||||
|
MenuAggregateRoot configEdit = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "参数修改",
|
||||||
|
PermissionCode = "system:config:edit",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = config.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(configEdit);
|
||||||
|
|
||||||
|
MenuAggregateRoot configRemove = new MenuAggregateRoot(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "参数删除",
|
||||||
|
PermissionCode = "system:config:remove",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = config.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(configRemove);
|
||||||
|
|
||||||
|
|
||||||
//默认值
|
//默认值
|
||||||
entities.ForEach(m =>
|
entities.ForEach(m =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Yi.Framework.TenantManagement.Domain.Shared
|
|
||||||
{
|
|
||||||
public class TenantConst
|
|
||||||
{
|
|
||||||
public static string TenantDbDefaultName = "Master";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="8.0.0" />
|
|
||||||
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using Volo.Abp.Modularity;
|
|
||||||
using Volo.Abp.TenantManagement;
|
|
||||||
|
|
||||||
namespace YiFrameworkTenantManagementDomain.Shared
|
|
||||||
{
|
|
||||||
[DependsOn(typeof(AbpTenantManagementDomainSharedModule))]
|
|
||||||
public class YiFrameworkTenantManagementDomainSharedModule : AbpModule
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Ddd.Application.Contracts\Yi.Framework.Ddd.Application.Contracts.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Application.Contracts\Yi.Framework.Bbs.Application.Contracts.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Domain.Shared\Acme.BookStore.Domain.Shared.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Acme.BookStore.Domain.Shared.Enums;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Contracts.Dtos.Book
|
|
||||||
{
|
|
||||||
|
|
||||||
public class BookCreateUpdateDto
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[StringLength(128)]
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public BookTypeEnum Type { get; set; } = BookTypeEnum.Undefined;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Date)]
|
|
||||||
public DateTime PublishDate { get; set; } = DateTime.Now;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public float Price { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using Acme.BookStore.Domain.Shared.Enums;
|
|
||||||
using Volo.Abp.Application.Dtos;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Contracts.Dtos.Book
|
|
||||||
{
|
|
||||||
public class BookDto : AuditedEntityDto<Guid>
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public BookTypeEnum Type { get; set; }
|
|
||||||
|
|
||||||
public DateTime PublishDate { get; set; }
|
|
||||||
|
|
||||||
public float Price { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using Acme.BookStore.Application.Contracts.Dtos.Book;
|
|
||||||
using Volo.Abp.Application.Dtos;
|
|
||||||
using Yi.Framework.Ddd.Application.Contracts;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Contracts.IServices
|
|
||||||
{
|
|
||||||
public interface IBookAppService :
|
|
||||||
IYiCrudAppService< //Defines CRUD methods
|
|
||||||
BookDto, //Used to show books
|
|
||||||
Guid, //Primary key of the book entity
|
|
||||||
PagedAndSortedResultRequestDto, //Used for paging/sorting
|
|
||||||
BookCreateUpdateDto> //Used to create/update a book
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
using Volo.Abp.Modularity;
|
|
||||||
using Acme.BookStore.Domain.Shared;
|
|
||||||
using Yi.Framework.Bbs.Application.Contracts;
|
|
||||||
using Yi.Framework.Ddd.Application.Contracts;
|
|
||||||
using Yi.Framework.Rbac.Application.Contracts;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Contracts
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiAbpDomainSharedModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkRbacApplicationContractsModule),
|
|
||||||
typeof(YiFrameworkBbsApplicationContractsModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkDddApplicationContractsModule))]
|
|
||||||
public class YiAbpApplicationContractsModule:AbpModule
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Ddd.Application\Yi.Framework.Ddd.Application.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Application\Yi.Framework.Bbs.Application.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Application\Yi.Framework.Rbac.Application.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Application.Contracts\Acme.BookStore.Application.Contracts.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Domain\Acme.BookStore.Domain.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Jobs\" />
|
|
||||||
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using Quartz;
|
|
||||||
using SqlSugar;
|
|
||||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
|
||||||
using Volo.Abp.Domain.Repositories;
|
|
||||||
using Volo.Abp.Uow;
|
|
||||||
using Yi.Framework.Rbac.Domain.Entities;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Jobs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 定时任务
|
|
||||||
/// </summary>
|
|
||||||
public class TestJob : QuartzBackgroundWorkerBase
|
|
||||||
{
|
|
||||||
private ISqlSugarRepository<UserAggregateRoot> _repository;
|
|
||||||
public TestJob(ISqlSugarRepository<UserAggregateRoot> repository)
|
|
||||||
{
|
|
||||||
_repository = repository;
|
|
||||||
JobDetail = JobBuilder.Create<TestJob>().WithIdentity(nameof(TestJob)).Build();
|
|
||||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(TestJob)).StartNow()
|
|
||||||
.WithSimpleSchedule(x => x
|
|
||||||
.WithIntervalInSeconds(1000 * 60)
|
|
||||||
.RepeatForever())
|
|
||||||
.Build();
|
|
||||||
}
|
|
||||||
public override async Task Execute(IJobExecutionContext context)
|
|
||||||
{
|
|
||||||
//定时任务,非常简单
|
|
||||||
Console.WriteLine("你好,世界");
|
|
||||||
// var eneities= await _repository.GetListAsync();
|
|
||||||
//var entities= await _sqlSugarClient.Queryable<UserEntity>().ToListAsync();
|
|
||||||
//await Console.Out.WriteLineAsync(entities.Count().ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using Acme.BookStore.Application.Contracts.Dtos.Book;
|
|
||||||
using Acme.BookStore.Application.Contracts.IServices;
|
|
||||||
using Acme.BookStore.Domain.Entities;
|
|
||||||
using SqlSugar;
|
|
||||||
using Volo.Abp.Application.Dtos;
|
|
||||||
using Yi.Framework.Ddd.Application;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Services
|
|
||||||
{
|
|
||||||
public class BookAppService :
|
|
||||||
YiCrudAppService<
|
|
||||||
BookAggregateRoot, //The Book entity
|
|
||||||
BookDto, //Used to show books
|
|
||||||
Guid, //Primary key of the book entity
|
|
||||||
PagedAndSortedResultRequestDto, //Used for paging/sorting
|
|
||||||
BookCreateUpdateDto>, //Used to create/update a book
|
|
||||||
IBookAppService //implement the IBookAppService
|
|
||||||
{
|
|
||||||
private ISqlSugarRepository<BookAggregateRoot, Guid> _repository;
|
|
||||||
public BookAppService(ISqlSugarRepository<BookAggregateRoot, Guid> repository)
|
|
||||||
: base(repository)
|
|
||||||
{
|
|
||||||
_repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<PagedResultDto<BookDto>> GetListAsync(PagedAndSortedResultRequestDto input)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
RefAsync<int> total = 0;
|
|
||||||
|
|
||||||
//由于直接查询接口基本上都是有包含查询条件的,默认内置的查询接口将无法满足业务的需求,所以基本上多查询都是有进行重写的
|
|
||||||
var entities = await _repository._DbQueryable
|
|
||||||
//.WhereIF(!string.IsNullOrEmpty(input.ConfigKey), x => x.ConfigKey.Contains(input.ConfigKey!))
|
|
||||||
// .WhereIF(!string.IsNullOrEmpty(input.ConfigName), x => x.ConfigName!.Contains(input.ConfigName!))
|
|
||||||
// .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
|
||||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
|
||||||
return new PagedResultDto<BookDto>(total, await MapToGetListOutputDtosAsync(entities));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using Volo.Abp.Application.Services;
|
|
||||||
using Volo.Abp.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application.Services
|
|
||||||
{
|
|
||||||
public class TestService : ApplicationService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 你好世界
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string GetHelloWorld(string? name)
|
|
||||||
{
|
|
||||||
return name ?? "HelloWord";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using Volo.Abp.Modularity;
|
|
||||||
using Acme.BookStore.Application.Contracts;
|
|
||||||
using Acme.BookStore.Domain;
|
|
||||||
using Yi.Framework.Bbs.Application;
|
|
||||||
using Yi.Framework.Ddd.Application;
|
|
||||||
using Yi.Framework.Rbac.Application;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Application
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiAbpApplicationContractsModule),
|
|
||||||
typeof(YiAbpDomainModule),
|
|
||||||
|
|
||||||
|
|
||||||
typeof(YiFrameworkRbacApplicationModule),
|
|
||||||
typeof(YiFrameworkBbsApplicationModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkDddApplicationModule)
|
|
||||||
)]
|
|
||||||
public class YiAbpApplicationModule : AbpModule
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Volo.Abp.Ddd.Domain.Shared" Version="$(AbpVersion)" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain.Shared\Yi.Framework.Bbs.Domain.Shared.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain.Shared\Yi.Framework.Rbac.Domain.Shared.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Consts\" />
|
|
||||||
<Folder Include="Dtos\" />
|
|
||||||
<Folder Include="Etos\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Domain.Shared.Enums
|
|
||||||
{
|
|
||||||
public enum BookTypeEnum
|
|
||||||
{
|
|
||||||
Undefined,
|
|
||||||
Adventure,
|
|
||||||
Biography,
|
|
||||||
Dystopia,
|
|
||||||
Fantastic,
|
|
||||||
Horror,
|
|
||||||
Science,
|
|
||||||
ScienceFiction,
|
|
||||||
Poetry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Volo.Abp.Domain;
|
|
||||||
using Volo.Abp.Modularity;
|
|
||||||
using Yi.Framework.Bbs.Domain.Shared;
|
|
||||||
using Yi.Framework.Rbac.Domain.Shared;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Domain.Shared
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiFrameworkRbacDomainSharedModule),
|
|
||||||
typeof(YiFrameworkBbsDomainSharedModule),
|
|
||||||
|
|
||||||
typeof(AbpDddDomainSharedModule))]
|
|
||||||
public class YiAbpDomainSharedModule : AbpModule
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(AbpVersion)" />
|
|
||||||
<PackageReference Include="Volo.Abp.Caching" Version="$(AbpVersion)" />
|
|
||||||
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain\Yi.Framework.Bbs.Domain.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain\Yi.Framework.Rbac.Domain.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Domain.Shared\Acme.BookStore.Domain.Shared.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Managers\" />
|
|
||||||
<Folder Include="Repositories\" />
|
|
||||||
<Folder Include="EventHandlers\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using Acme.BookStore.Domain.Shared.Enums;
|
|
||||||
using SqlSugar;
|
|
||||||
using Volo.Abp.Data;
|
|
||||||
using Volo.Abp.Domain.Entities.Auditing;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Domain.Entities
|
|
||||||
{
|
|
||||||
[SugarTable("Book")]
|
|
||||||
public class BookAggregateRoot : AuditedAggregateRoot<Guid>
|
|
||||||
{
|
|
||||||
[SugarColumn(IsPrimaryKey = true)]
|
|
||||||
public override Guid Id { get; protected set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public BookTypeEnum Type { get; set; }
|
|
||||||
|
|
||||||
public DateTime PublishDate { get; set; }
|
|
||||||
|
|
||||||
public float Price { get; set; }
|
|
||||||
|
|
||||||
[SugarColumn(IsIgnore = true)]
|
|
||||||
public override ExtraPropertyDictionary ExtraProperties { get; protected set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using Volo.Abp.Caching;
|
|
||||||
using Volo.Abp.Domain;
|
|
||||||
using Volo.Abp.Modularity;
|
|
||||||
using Acme.BookStore.Domain.Shared;
|
|
||||||
using Yi.Framework.Bbs.Domain;
|
|
||||||
using Yi.Framework.Mapster;
|
|
||||||
using Yi.Framework.Rbac.Domain;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Domain
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiAbpDomainSharedModule),
|
|
||||||
|
|
||||||
|
|
||||||
typeof(YiFrameworkRbacDomainModule),
|
|
||||||
typeof(YiFrameworkBbsDomainModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkMapsterModule),
|
|
||||||
typeof(AbpDddDomainModule),
|
|
||||||
typeof(AbpCachingModule)
|
|
||||||
)]
|
|
||||||
public class YiAbpDomainModule : AbpModule
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore\Yi.Framework.SqlSugarCore.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.SqlSugarCore\Yi.Framework.Bbs.SqlSugarCore.csproj" />
|
|
||||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Domain\Acme.BookStore.Domain.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Repositories\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
using Acme.BookStore.Domain.Entities;
|
|
||||||
using Acme.BookStore.Domain.Shared.Enums;
|
|
||||||
using Volo.Abp.Data;
|
|
||||||
using Volo.Abp.DependencyInjection;
|
|
||||||
using Volo.Abp.Guids;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.SqlSugarCore.DataSeeds
|
|
||||||
{
|
|
||||||
public class BookStoreDataSeed : IDataSeedContributor, ITransientDependency
|
|
||||||
{
|
|
||||||
private ISqlSugarRepository<BookAggregateRoot> _bookRepository;
|
|
||||||
private IGuidGenerator _guidGenerator;
|
|
||||||
public BookStoreDataSeed(ISqlSugarRepository<BookAggregateRoot> repository, IGuidGenerator guidGenerator)
|
|
||||||
{
|
|
||||||
_bookRepository = repository;
|
|
||||||
_guidGenerator = guidGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SeedAsync(DataSeedContext context)
|
|
||||||
{
|
|
||||||
if (!await _bookRepository.IsAnyAsync(x => true))
|
|
||||||
{
|
|
||||||
await _bookRepository.InsertAsync(
|
|
||||||
new BookAggregateRoot
|
|
||||||
{
|
|
||||||
Name = "1984",
|
|
||||||
Type = BookTypeEnum.Dystopia,
|
|
||||||
PublishDate = new DateTime(1949, 6, 8),
|
|
||||||
Price = 19.84f
|
|
||||||
},
|
|
||||||
autoSave: true
|
|
||||||
);
|
|
||||||
|
|
||||||
await _bookRepository.InsertAsync(
|
|
||||||
new BookAggregateRoot
|
|
||||||
{
|
|
||||||
Name = "The Hitchhiker's Guide to the Galaxy",
|
|
||||||
Type = BookTypeEnum.ScienceFiction,
|
|
||||||
PublishDate = new DateTime(1995, 9, 27),
|
|
||||||
Price = 42.0f
|
|
||||||
},
|
|
||||||
autoSave: true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Volo.Abp.Modularity;
|
|
||||||
using Acme.BookStore.Domain;
|
|
||||||
using Acme.BookStore.SqlSugarCore;
|
|
||||||
using Yi.Framework.Bbs.SqlSugarCore;
|
|
||||||
using Yi.Framework.Mapster;
|
|
||||||
using Yi.Framework.Rbac.SqlSugarCore;
|
|
||||||
using Yi.Framework.SqlSugarCore;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.SqlsugarCore
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiAbpDomainModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkRbacSqlSugarCoreModule),
|
|
||||||
typeof(YiFrameworkBbsSqlSugarCoreModule),
|
|
||||||
|
|
||||||
typeof(YiFrameworkMapsterModule),
|
|
||||||
typeof(YiFrameworkSqlSugarCoreModule)
|
|
||||||
)]
|
|
||||||
public class YiAbpSqlSugarCoreModule : AbpModule
|
|
||||||
{
|
|
||||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
||||||
{
|
|
||||||
context.Services.AddYiDbContext<YiDbContext>();
|
|
||||||
//默认不开放,可根据项目需要是否Db直接对外开放
|
|
||||||
//context.Services.AddTransient(x => x.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using SqlSugar;
|
|
||||||
using Volo.Abp.DependencyInjection;
|
|
||||||
using Yi.Framework.Rbac.SqlSugarCore;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.SqlSugarCore
|
|
||||||
{
|
|
||||||
public class YiDbContext : YiRbacDbContext
|
|
||||||
{
|
|
||||||
public YiDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
<Import Project="..\..\common.props" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
|
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
|
||||||
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="$(AbpVersion)" />
|
|
||||||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="$(AbpVersion)" />
|
|
||||||
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="$(AbpVersion)" />
|
|
||||||
<PackageReference Include="Volo.Abp.Autofac" Version="$(AbpVersion)" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.AspNetCore.Authentication.OAuth\Yi.Framework.AspNetCore.Authentication.OAuth.csproj" />
|
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.AspNetCore\Yi.Framework.AspNetCore.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.Application\Acme.BookStore.Application.csproj" />
|
|
||||||
<ProjectReference Include="..\Acme.BookStore.SqlSugarCore\Acme.BookStore.SqlSugarCore.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Update="appsettings.json">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\icon\**">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="ip2region.db">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="database_backup\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using Serilog;
|
|
||||||
using Serilog.Events;
|
|
||||||
using Acme.BookStore.Web;
|
|
||||||
|
|
||||||
//创建日志,可使用{SourceContext}记录
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
|
||||||
.MinimumLevel.Debug()
|
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
||||||
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
|
|
||||||
.MinimumLevel.Override("Quartz", LogEventLevel.Warning)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Debug))
|
|
||||||
.WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error))
|
|
||||||
.WriteTo.Async(c => c.Console(restrictedToMinimumLevel: LogEventLevel.Information))
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Log.Information("Yi框架-Abp.vNext,启动!");
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]);
|
|
||||||
builder.Host.UseAutofac();
|
|
||||||
builder.Host.UseSerilog();
|
|
||||||
await builder.Services.AddApplicationAsync<YiAbpWebModule>();
|
|
||||||
var app = builder.Build();
|
|
||||||
await app.InitializeApplicationAsync();
|
|
||||||
await app.RunAsync();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Yi框架-Abp.vNext,爆炸!");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
||||||
"profiles": {
|
|
||||||
"Acme.BookStore.Web": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "http://localhost:19001",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
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;
|
|
||||||
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
|
|
||||||
using Volo.Abp.AspNetCore.Serilog;
|
|
||||||
using Volo.Abp.Auditing;
|
|
||||||
using Volo.Abp.Autofac;
|
|
||||||
using Volo.Abp.Modularity;
|
|
||||||
using Volo.Abp.Swashbuckle;
|
|
||||||
using Acme.BookStore.Application;
|
|
||||||
using Acme.BookStore.SqlsugarCore;
|
|
||||||
using Yi.Framework.AspNetCore;
|
|
||||||
using Yi.Framework.AspNetCore.Authentication.OAuth;
|
|
||||||
using Yi.Framework.AspNetCore.Authentication.OAuth.Gitee;
|
|
||||||
using Yi.Framework.AspNetCore.Authentication.OAuth.QQ;
|
|
||||||
using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder;
|
|
||||||
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Yi.Framework.Bbs.Application;
|
|
||||||
using Yi.Framework.Rbac.Application;
|
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Options;
|
|
||||||
|
|
||||||
namespace Acme.BookStore.Web
|
|
||||||
{
|
|
||||||
[DependsOn(
|
|
||||||
typeof(YiAbpSqlSugarCoreModule),
|
|
||||||
typeof(YiAbpApplicationModule),
|
|
||||||
|
|
||||||
|
|
||||||
typeof(AbpAspNetCoreMvcModule),
|
|
||||||
typeof(AbpAutofacModule),
|
|
||||||
typeof(AbpSwashbuckleModule),
|
|
||||||
typeof(AbpAspNetCoreSerilogModule),
|
|
||||||
typeof(AbpAuditingModule),
|
|
||||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
|
||||||
typeof(YiFrameworkAspNetCoreModule),
|
|
||||||
typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule)
|
|
||||||
|
|
||||||
)]
|
|
||||||
public class YiAbpWebModule : AbpModule
|
|
||||||
{
|
|
||||||
private const string DefaultCorsPolicyName = "Default";
|
|
||||||
public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
|
|
||||||
{
|
|
||||||
var configuration = context.Services.GetConfiguration();
|
|
||||||
var host = context.Services.GetHostingEnvironment();
|
|
||||||
var service = context.Services;
|
|
||||||
|
|
||||||
//请求日志
|
|
||||||
Configure<AbpAuditingOptions>(optios =>
|
|
||||||
{
|
|
||||||
optios.IsEnabled = true;
|
|
||||||
optios.AlwaysLogSelectors.Add(x => Task.FromResult(true));
|
|
||||||
});
|
|
||||||
|
|
||||||
//动态Api
|
|
||||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
|
||||||
{
|
|
||||||
options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly, options => options.RemoteServiceName = "default");
|
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly, options => options.RemoteServiceName = "rbac");
|
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly, options => options.RemoteServiceName = "bbs");
|
|
||||||
});
|
|
||||||
|
|
||||||
//设置api格式
|
|
||||||
service.AddControllers().AddNewtonsoftJson(options =>
|
|
||||||
{
|
|
||||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
||||||
options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
|
||||||
});
|
|
||||||
|
|
||||||
Configure<AbpAntiForgeryOptions>(options =>
|
|
||||||
{
|
|
||||||
options.AutoValidate = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
//Swagger
|
|
||||||
context.Services.AddYiSwaggerGen<YiAbpWebModule>(options =>
|
|
||||||
{
|
|
||||||
options.SwaggerDoc("default", new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" });
|
|
||||||
});
|
|
||||||
|
|
||||||
//跨域
|
|
||||||
context.Services.AddCors(options =>
|
|
||||||
{
|
|
||||||
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
||||||
{
|
|
||||||
builder
|
|
||||||
.WithOrigins(
|
|
||||||
configuration["App:CorsOrigins"]!
|
|
||||||
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
.Select(o => o.RemovePostFix("/"))
|
|
||||||
.ToArray()
|
|
||||||
)
|
|
||||||
.WithAbpExposedHeaders()
|
|
||||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
||||||
.AllowAnyHeader()
|
|
||||||
.AllowAnyMethod()
|
|
||||||
.AllowCredentials();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//jwt鉴权
|
|
||||||
var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get<JwtOptions>();
|
|
||||||
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
||||||
.AddJwtBearer(options =>
|
|
||||||
{
|
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
|
||||||
{
|
|
||||||
ClockSkew = TimeSpan.Zero,
|
|
||||||
ValidateIssuer = true,
|
|
||||||
ValidateAudience = true,
|
|
||||||
ValidateLifetime = true,
|
|
||||||
ValidateIssuerSigningKey = true,
|
|
||||||
ValidIssuer = jwtOptions.Issuer,
|
|
||||||
ValidAudience = jwtOptions.Audience,
|
|
||||||
RequireExpirationTime = true,
|
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey))
|
|
||||||
};
|
|
||||||
options.Events = new JwtBearerEvents
|
|
||||||
{
|
|
||||||
OnMessageReceived = context =>
|
|
||||||
{
|
|
||||||
var accessToken = context.Request.Query["access_token"];
|
|
||||||
if (!string.IsNullOrEmpty(accessToken))
|
|
||||||
{
|
|
||||||
context.Token = accessToken;
|
|
||||||
}
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.AddQQ(options =>
|
|
||||||
{
|
|
||||||
configuration.GetSection("OAuth:QQ").Bind(options);
|
|
||||||
})
|
|
||||||
.AddGitee(options =>
|
|
||||||
{
|
|
||||||
configuration.GetSection("OAuth:Gitee").Bind(options);
|
|
||||||
});
|
|
||||||
|
|
||||||
//授权
|
|
||||||
context.Services.AddAuthorization();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
|
||||||
{
|
|
||||||
var service = context.ServiceProvider;
|
|
||||||
|
|
||||||
var env = context.GetEnvironment();
|
|
||||||
var app = context.GetApplicationBuilder();
|
|
||||||
|
|
||||||
app.UseRouting();
|
|
||||||
|
|
||||||
//跨域
|
|
||||||
app.UseCors(DefaultCorsPolicyName);
|
|
||||||
|
|
||||||
//鉴权
|
|
||||||
app.UseAuthentication();
|
|
||||||
|
|
||||||
//swagger
|
|
||||||
app.UseYiSwagger();
|
|
||||||
|
|
||||||
//请求处理
|
|
||||||
app.UseYiApiHandlinge();
|
|
||||||
|
|
||||||
//静态资源
|
|
||||||
app.UseStaticFiles("/api/app/wwwroot");
|
|
||||||
app.UseDefaultFiles();
|
|
||||||
app.UseDirectoryBrowser("/api/app/wwwroot");
|
|
||||||
|
|
||||||
//工作单元
|
|
||||||
app.UseUnitOfWork();
|
|
||||||
|
|
||||||
//授权
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
//审计日志
|
|
||||||
app.UseAuditing();
|
|
||||||
|
|
||||||
//日志记录
|
|
||||||
app.UseAbpSerilogEnrichers();
|
|
||||||
|
|
||||||
//终节点
|
|
||||||
app.UseConfiguredEndpoints();
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
//"Default": "Information",
|
|
||||||
"Default": "Debug",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
//应用启动
|
|
||||||
"App": {
|
|
||||||
"SelfUrl": "http://*:19001",
|
|
||||||
"CorsOrigins": "http://localhost:19001;http://localhost:18000"
|
|
||||||
},
|
|
||||||
|
|
||||||
//数据库类型列表
|
|
||||||
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle", "PostgreSQL" ],
|
|
||||||
|
|
||||||
"DbConnOptions": {
|
|
||||||
"Url": "DataSource=yi-abp-dev.db",
|
|
||||||
"DbType": "Sqlite",
|
|
||||||
"EnabledReadWrite": false,
|
|
||||||
"EnabledCodeFirst": true,
|
|
||||||
"EnabledSqlLog": true,
|
|
||||||
"EnabledDbSeed": true,
|
|
||||||
"EnableUnderLine": false // 启用驼峰转下划线
|
|
||||||
//读写分离地址
|
|
||||||
//"ReadUrl": [
|
|
||||||
// "DataSource=[xxxx]", //Sqlite
|
|
||||||
// "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
|
||||||
// "Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
|
|
||||||
// "HOST=[xxxx];PORT=5432;DATABASE=[xxxx];USERID=[xxxx];PASSWORD=[xxxx]" //PostgreSQL
|
|
||||||
//]
|
|
||||||
},
|
|
||||||
|
|
||||||
//鉴权
|
|
||||||
"JwtOptions": {
|
|
||||||
"Issuer": "https://ccnetcore.com",
|
|
||||||
"Audience": "https://ccnetcore.com",
|
|
||||||
"SecurityKey": "zqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69520",
|
|
||||||
"ExpiresMinuteTime": 86400
|
|
||||||
},
|
|
||||||
|
|
||||||
//第三方登录
|
|
||||||
"OAuth": {
|
|
||||||
//QQ
|
|
||||||
"QQ": {
|
|
||||||
"ClientId": "",
|
|
||||||
"ClientSecret": "",
|
|
||||||
"RedirectUri": ""
|
|
||||||
},
|
|
||||||
//码云
|
|
||||||
"Gitee": {
|
|
||||||
"ClientId": "",
|
|
||||||
"ClientSecret": "",
|
|
||||||
"RedirectUri": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
//Rbac模块
|
|
||||||
"RbacOptions": {
|
|
||||||
//超级管理员种子数据默认密码
|
|
||||||
"AdminPassword": "123456",
|
|
||||||
|
|
||||||
//是否开启验证码验证
|
|
||||||
"EnableCaptcha": true,
|
|
||||||
|
|
||||||
//是否开启注册功能
|
|
||||||
"EnableRegister": false,
|
|
||||||
|
|
||||||
//开启定时数据库备份
|
|
||||||
"EnableDataBaseBackup": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
@@ -6,8 +6,6 @@ using Volo.Abp.Application.Services;
|
|||||||
using Volo.Abp.Settings;
|
using Volo.Abp.Settings;
|
||||||
using Volo.Abp.Uow;
|
using Volo.Abp.Uow;
|
||||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Banner;
|
using Yi.Framework.Bbs.Application.Contracts.Dtos.Banner;
|
||||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Comment;
|
|
||||||
using Yi.Framework.Bbs.Application.Contracts.IServices;
|
|
||||||
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
using Yi.Framework.Bbs.Domain.Entities.Forum;
|
||||||
using Yi.Framework.Rbac.Domain.Authorization;
|
using Yi.Framework.Rbac.Domain.Authorization;
|
||||||
using Yi.Framework.Rbac.Domain.Extensions;
|
using Yi.Framework.Rbac.Domain.Extensions;
|
||||||
@@ -21,15 +19,160 @@ namespace Yi.Abp.Application.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TestService : ApplicationService
|
public class TestService : ApplicationService
|
||||||
{
|
{
|
||||||
[HttpGet("hello-world/string")]
|
/// <summary>
|
||||||
public async Task<string> GetHelloWorld1(string? name)
|
/// 属性注入
|
||||||
|
/// 不推荐,坑太多,容易把自己玩死,简单的东西可以用一用
|
||||||
|
/// </summary>
|
||||||
|
public ISqlSugarRepository<BannerAggregateRoot> sqlSugarRepository { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 动态Api
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("hello-world")]
|
||||||
|
public string GetHelloWorld(string? name)
|
||||||
{
|
{
|
||||||
return "1";
|
//会自动添加前缀,而不是重置,更符合习惯
|
||||||
|
//如果需要重置以"/"根目录开头即可
|
||||||
|
//你好世界
|
||||||
|
return name ?? "HelloWord";
|
||||||
}
|
}
|
||||||
[HttpGet("hello-world/dto")]
|
|
||||||
public async Task<CommentGetOutputDto> GetHelloWorld2(string? name)
|
/// <summary>
|
||||||
|
/// 异常处理
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("error")]
|
||||||
|
public string GetError()
|
||||||
{
|
{
|
||||||
return new CommentGetOutputDto();
|
throw new UserFriendlyException("业务异常");
|
||||||
|
throw new Exception("系统异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SqlSugar
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<object> GetSqlSugarDbAsync()
|
||||||
|
{
|
||||||
|
//用户体验优先,可直接使用Db操作,依赖抽象
|
||||||
|
return await sqlSugarRepository._DbQueryable.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 工作单元
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task GetUowAsync()
|
||||||
|
{
|
||||||
|
//魔改
|
||||||
|
// 用户体验优先,万金油模式,支持高并发。支持单、多线程并发安全,支持多线程工作单元,支持多线程无工作单元,支持。。。
|
||||||
|
// 请注意,如果requiresNew: true只有在没有工作单元内使用,嵌套子工作单元,默认值false即可
|
||||||
|
// 自动在各个情况处理db客户端最优解之一
|
||||||
|
int i = 3;
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
await sqlSugarRepository.GetListAsync();
|
||||||
|
await sqlSugarRepository.GetListAsync();
|
||||||
|
while (i > 0)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入2" });
|
||||||
|
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
|
||||||
|
{
|
||||||
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入1" });
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入3" });
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public void GetCurrentUser()
|
||||||
|
{
|
||||||
|
//当token鉴权之后,可以直接获取
|
||||||
|
if (CurrentUser.Id is not null)
|
||||||
|
{
|
||||||
|
//权限
|
||||||
|
CurrentUser.GetPermissions();
|
||||||
|
|
||||||
|
//角色信息
|
||||||
|
CurrentUser.GetRoleInfo();
|
||||||
|
|
||||||
|
//部门id
|
||||||
|
CurrentUser.GetDeptId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据权限
|
||||||
|
/// </summary>
|
||||||
|
public void GetDataFilter()
|
||||||
|
{
|
||||||
|
//这里会数据权限过滤
|
||||||
|
using (DataFilter.DisablePermissionHandler())
|
||||||
|
{
|
||||||
|
//这里不会数据权限过滤
|
||||||
|
}
|
||||||
|
//这里会数据权限过滤
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 对象映射
|
||||||
|
/// </summary>
|
||||||
|
public void GetMapper()
|
||||||
|
{
|
||||||
|
//直接无脑Adapt,无需配置
|
||||||
|
var entity = new BannerAggregateRoot();
|
||||||
|
var dto = entity.Adapt<BannerGetListOutputDto>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int RequestNumber { get; set; } = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// 速率限制
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
// [DisableRateLimiting]
|
||||||
|
//[EnableRateLimiting("sliding")]
|
||||||
|
public int GetRateLimiting()
|
||||||
|
{
|
||||||
|
RequestNumber++;
|
||||||
|
return RequestNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ISettingProvider _settingProvider { get; set; }
|
||||||
|
|
||||||
|
public ISettingManager _settingManager { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 系统配置模块
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<string> GetSettingAsync()
|
||||||
|
{
|
||||||
|
//DDD需要提前定义
|
||||||
|
//默认来说,不提供修改操作,配置应该独立
|
||||||
|
var enableOrNull = await _settingProvider.GetOrNullAsync("DDD");
|
||||||
|
|
||||||
|
//如果要进行修改,可使用yi.framework下的ISettingManager
|
||||||
|
await _settingManager.SetGlobalAsync("DDD", "false");
|
||||||
|
|
||||||
|
var enableOrNull2 = await _settingManager.GetOrNullGlobalAsync("DDD");
|
||||||
|
|
||||||
|
//当然,他的独特地方,是支持来自多个模块,例如配置文件?
|
||||||
|
var result = await _settingManager.GetOrNullConfigurationAsync("Test");
|
||||||
|
|
||||||
|
|
||||||
|
return result ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
// Decompiled with JetBrains decompiler
|
|
||||||
// Type: Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware
|
|
||||||
// Assembly: Volo.Abp.AspNetCore, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null
|
|
||||||
// MVID: E24BDAEE-E92D-4420-84F7-3DD088C817A4
|
|
||||||
// Assembly location: C:\Users\Administrator\.nuget\packages\volo.abp.aspnetcore\8.2.0\lib\net8.0\Volo.Abp.AspNetCore.dll
|
|
||||||
// XML documentation location: C:\Users\Administrator\.nuget\packages\volo.abp.aspnetcore\8.2.0\lib\net8.0\Volo.Abp.AspNetCore.xml
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components.Endpoints;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Volo.Abp.AspNetCore.Middleware;
|
|
||||||
using Volo.Abp.DependencyInjection;
|
|
||||||
using Volo.Abp.Uow;
|
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
namespace Volo.Abp.AspNetCore.Uow
|
|
||||||
{
|
|
||||||
public class AbpUnitOfWorkMiddleware2 : AbpMiddlewareBase, ITransientDependency
|
|
||||||
{
|
|
||||||
private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
||||||
private readonly AbpAspNetCoreUnitOfWorkOptions _options;
|
|
||||||
|
|
||||||
public AbpUnitOfWorkMiddleware2(
|
|
||||||
IUnitOfWorkManager unitOfWorkManager,
|
|
||||||
IOptions<AbpAspNetCoreUnitOfWorkOptions> options)
|
|
||||||
{
|
|
||||||
this._unitOfWorkManager = unitOfWorkManager;
|
|
||||||
this._options = options.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
|
||||||
{
|
|
||||||
// await next(context);
|
|
||||||
// await next(context).ConfigureAwait(false);
|
|
||||||
if (await ShouldSkipAsync(context, next).ConfigureAwait(false) || IsIgnoredUrl(context))
|
|
||||||
{
|
|
||||||
await next(context).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
using (IUnitOfWork uow = _unitOfWorkManager.Reserve("_AbpActionUnitOfWork"))
|
|
||||||
{
|
|
||||||
await next(context).ConfigureAwait(false);
|
|
||||||
await uow.CompleteAsync(context.RequestAborted).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsIgnoredUrl(HttpContext context)
|
|
||||||
{
|
|
||||||
return context.Request.Path.Value != null && this._options.IgnoredUrls.Any<string>(
|
|
||||||
(Func<string, bool>)(x =>
|
|
||||||
context.Request.Path.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase)));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async Task<bool> ShouldSkipAsync(HttpContext context, RequestDelegate next)
|
|
||||||
{
|
|
||||||
return context.GetEndpoint()?.Metadata?.GetMetadata<RootComponentMetadata>() != null ||
|
|
||||||
await base.ShouldSkipAsync(context, next).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,30 +4,28 @@ using Yi.Abp.Web;
|
|||||||
|
|
||||||
//创建日志,可使用{SourceContext}记录
|
//创建日志,可使用{SourceContext}记录
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.MinimumLevel.Debug()
|
.MinimumLevel.Debug()
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||||
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
|
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
|
||||||
.MinimumLevel.Override("Quartz", LogEventLevel.Warning)
|
.MinimumLevel.Override("Quartz", LogEventLevel.Warning)
|
||||||
.Enrich.FromLogContext()
|
.Enrich.FromLogContext()
|
||||||
.WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day,
|
.WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Debug))
|
||||||
restrictedToMinimumLevel: LogEventLevel.Debug))
|
.WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error))
|
||||||
.WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day,
|
.WriteTo.Async(c => c.Console())
|
||||||
restrictedToMinimumLevel: LogEventLevel.Error))
|
.CreateLogger();
|
||||||
.WriteTo.Async(c => c.Console())
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log.Information("""
|
Log.Information("""
|
||||||
|
|
||||||
__ ___ ______ _
|
|
||||||
\ \ / (_) | ____| | |
|
|
||||||
\ \_/ / _ | |__ _ __ __ _ _ __ ___ _____ _____ _ __| | __
|
|
||||||
\ / | | | __| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
|
|
||||||
| | | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
|
|
||||||
|_| |_| |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\
|
|
||||||
|
|
||||||
""");
|
__ ___ ______ _
|
||||||
|
\ \ / (_) | ____| | |
|
||||||
|
\ \_/ / _ | |__ _ __ __ _ _ __ ___ _____ _____ _ __| | __
|
||||||
|
\ / | | | __| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
|
||||||
|
| | | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
|
||||||
|
|_| |_| |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\
|
||||||
|
|
||||||
|
""");
|
||||||
Log.Information("Yi框架-Abp.vNext,启动!");
|
Log.Information("Yi框架-Abp.vNext,启动!");
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -38,22 +36,6 @@ try
|
|||||||
builder.Host.UseSerilog();
|
builder.Host.UseSerilog();
|
||||||
await builder.Services.AddApplicationAsync<YiAbpWebModule>();
|
await builder.Services.AddApplicationAsync<YiAbpWebModule>();
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.Use(async (http, next) =>
|
|
||||||
{
|
|
||||||
var id = Guid.NewGuid();
|
|
||||||
Console.WriteLine("之前-----" + id);
|
|
||||||
http.Response.OnStarting(() =>
|
|
||||||
{
|
|
||||||
Console.WriteLine("之中-----" + id);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
});
|
|
||||||
await next();
|
|
||||||
if (http.Request.Path.Value.Contains("hello-world"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("之后-----" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
await app.InitializeApplicationAsync();
|
await app.InitializeApplicationAsync();
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Volo.Abp.Application.Services;
|
|
||||||
|
|
||||||
namespace Yi.Abp.Application.Services
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 常用魔改及扩展示例
|
|
||||||
/// </summary>
|
|
||||||
public class TestService : ApplicationService
|
|
||||||
{
|
|
||||||
[HttpGet("hello-world/string")]
|
|
||||||
public async Task<string> GetHelloWorld1(string? name)
|
|
||||||
{
|
|
||||||
return "1";
|
|
||||||
}
|
|
||||||
[HttpGet("hello-world/dto")]
|
|
||||||
public async Task<CommentGetOutputDto> GetHelloWorld2(string? name)
|
|
||||||
{
|
|
||||||
return new CommentGetOutputDto();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CommentGetOutputDto
|
|
||||||
{
|
|
||||||
|
|
||||||
public DateTime? CreateTime { get; set; }
|
|
||||||
public string Content { get; set; }
|
|
||||||
|
|
||||||
public Guid DiscussId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根节点的评论id
|
|
||||||
/// </summary>
|
|
||||||
public Guid RootId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 被回复的CommentId
|
|
||||||
/// </summary>
|
|
||||||
public Guid ParentId { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Text.Json.Serialization.Metadata;
|
||||||
using System.Threading.RateLimiting;
|
using System.Threading.RateLimiting;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
@@ -18,6 +22,8 @@ using Volo.Abp.AspNetCore.Serilog;
|
|||||||
using Volo.Abp.Auditing;
|
using Volo.Abp.Auditing;
|
||||||
using Volo.Abp.Autofac;
|
using Volo.Abp.Autofac;
|
||||||
using Volo.Abp.Caching;
|
using Volo.Abp.Caching;
|
||||||
|
using Volo.Abp.Json;
|
||||||
|
using Volo.Abp.Json.SystemTextJson;
|
||||||
using Volo.Abp.MultiTenancy;
|
using Volo.Abp.MultiTenancy;
|
||||||
using Volo.Abp.Swashbuckle;
|
using Volo.Abp.Swashbuckle;
|
||||||
using Yi.Abp.Application;
|
using Yi.Abp.Application;
|
||||||
@@ -33,6 +39,7 @@ using Yi.Framework.Bbs.Application;
|
|||||||
using Yi.Framework.Bbs.Application.Extensions;
|
using Yi.Framework.Bbs.Application.Extensions;
|
||||||
using Yi.Framework.ChatHub.Application;
|
using Yi.Framework.ChatHub.Application;
|
||||||
using Yi.Framework.CodeGen.Application;
|
using Yi.Framework.CodeGen.Application;
|
||||||
|
using Yi.Framework.Core.Json;
|
||||||
using Yi.Framework.Rbac.Application;
|
using Yi.Framework.Rbac.Application;
|
||||||
using Yi.Framework.Rbac.Domain.Authorization;
|
using Yi.Framework.Rbac.Domain.Authorization;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||||
@@ -42,14 +49,14 @@ using Yi.Framework.TenantManagement.Application;
|
|||||||
namespace Yi.Abp.Web
|
namespace Yi.Abp.Web
|
||||||
{
|
{
|
||||||
[DependsOn(
|
[DependsOn(
|
||||||
// typeof(YiAbpSqlSugarCoreModule),
|
typeof(YiAbpSqlSugarCoreModule),
|
||||||
// typeof(YiAbpApplicationModule),
|
typeof(YiAbpApplicationModule),
|
||||||
// typeof(AbpAspNetCoreMultiTenancyModule),
|
typeof(AbpAspNetCoreMultiTenancyModule),
|
||||||
typeof(AbpAspNetCoreMvcModule),
|
typeof(AbpAspNetCoreMvcModule),
|
||||||
typeof(AbpAutofacModule),
|
typeof(AbpAutofacModule),
|
||||||
typeof(AbpSwashbuckleModule),
|
typeof(AbpSwashbuckleModule),
|
||||||
typeof(AbpAspNetCoreSerilogModule),
|
typeof(AbpAspNetCoreSerilogModule),
|
||||||
// typeof(AbpAuditingModule),
|
typeof(AbpAuditingModule),
|
||||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
||||||
typeof(YiFrameworkAspNetCoreModule),
|
typeof(YiFrameworkAspNetCoreModule),
|
||||||
typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule)
|
typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule)
|
||||||
@@ -63,29 +70,67 @@ namespace Yi.Abp.Web
|
|||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
var host = context.Services.GetHostingEnvironment();
|
var host = context.Services.GetHostingEnvironment();
|
||||||
var service = context.Services;
|
var service = context.Services;
|
||||||
|
//请求日志
|
||||||
|
Configure<AbpAuditingOptions>(optios =>
|
||||||
|
{
|
||||||
|
//默认关闭,开启会有大量的审计日志
|
||||||
|
optios.IsEnabled = true;
|
||||||
|
//审计日志过滤器
|
||||||
|
optios.AlwaysLogSelectors.Add(x => Task.FromResult(!x.Url.StartsWith("/api/app/file/")));
|
||||||
|
});
|
||||||
|
|
||||||
|
//采用furion格式的规范化api,默认不开启,使用abp优雅的方式
|
||||||
|
//你没看错。。。
|
||||||
|
//service.AddFurionUnifyResultApi();
|
||||||
|
|
||||||
|
//配置错误处理显示详情
|
||||||
|
Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; });
|
||||||
|
|
||||||
//动态Api
|
//动态Api
|
||||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
Configure<AbpAspNetCoreMvcOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ConventionalControllers.Create(typeof(YiAbpWebModule).Assembly,
|
options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly,
|
||||||
options => options.RemoteServiceName = "default");
|
options => options.RemoteServiceName = "default");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "rbac");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "bbs");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "chat-hub");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkTenantManagementApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "tenant-management");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "code-gen");
|
||||||
|
|
||||||
//统一前缀
|
//统一前缀
|
||||||
options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app");
|
options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app");
|
||||||
});
|
});
|
||||||
|
|
||||||
//设置api格式
|
//【NewtonsoftJson严重问题!!!!!逆天】设置api格式,留给后人铭记
|
||||||
// service.AddControllers().AddNewtonsoftJson(options =>
|
// service.AddControllers().AddNewtonsoftJson(options =>
|
||||||
// {
|
// {
|
||||||
// options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
// options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
// options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
//请使用微软的,注意abp date又包了一层,采用DefaultJsonTypeInfoResolver统一覆盖
|
||||||
|
Configure<JsonOptions>(options =>
|
||||||
|
{
|
||||||
|
options.JsonSerializerOptions.TypeInfoResolver = new DefaultJsonTypeInfoResolver();
|
||||||
|
options.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
||||||
|
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||||
|
});
|
||||||
|
|
||||||
|
//设置缓存不要过期,默认滑动20分钟
|
||||||
|
Configure<AbpDistributedCacheOptions>(cacheOptions =>
|
||||||
|
{
|
||||||
|
cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null;
|
||||||
|
//缓存key前缀
|
||||||
|
cacheOptions.KeyPrefix = "Yi:";
|
||||||
|
});
|
||||||
|
|
||||||
// Configure<AbpAntiForgeryOptions>(options => { options.AutoValidate = false; });
|
|
||||||
|
Configure<AbpAntiForgeryOptions>(options => { options.AutoValidate = false; });
|
||||||
|
|
||||||
//Swagger
|
//Swagger
|
||||||
context.Services.AddYiSwaggerGen<YiAbpWebModule>(options =>
|
context.Services.AddYiSwaggerGen<YiAbpWebModule>(options =>
|
||||||
@@ -94,9 +139,143 @@ namespace Yi.Abp.Web
|
|||||||
new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" });
|
new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//跨域
|
||||||
|
context.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.WithOrigins(
|
||||||
|
configuration["App:CorsOrigins"]!
|
||||||
|
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(o => o.RemovePostFix("/"))
|
||||||
|
.ToArray()
|
||||||
|
)
|
||||||
|
.WithAbpExposedHeaders()
|
||||||
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowCredentials();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//配置多租户
|
||||||
|
Configure<AbpTenantResolveOptions>(options =>
|
||||||
|
{
|
||||||
|
//基于cookie jwt不好用,有坑
|
||||||
|
options.TenantResolvers.Clear();
|
||||||
|
options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
||||||
|
//options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
||||||
|
//options.TenantResolvers.Add(new CookieTenantResolveContributor());
|
||||||
|
|
||||||
|
//options.TenantResolvers.RemoveAll(x => x.Name == CookieTenantResolveContributor.ContributorName);
|
||||||
|
});
|
||||||
|
|
||||||
|
//速率限制
|
||||||
|
//每60秒限制100个请求,滑块添加,分6段
|
||||||
|
service.AddRateLimiter(_ =>
|
||||||
|
{
|
||||||
|
_.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
||||||
|
_.OnRejected = (context, _) =>
|
||||||
|
{
|
||||||
|
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Headers.RetryAfter =
|
||||||
|
((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||||
|
context.HttpContext.Response.WriteAsync("Too many requests. Please try again later.");
|
||||||
|
|
||||||
|
return new ValueTask();
|
||||||
|
};
|
||||||
|
|
||||||
|
//全局使用,链式表达式
|
||||||
|
_.GlobalLimiter = PartitionedRateLimiter.CreateChained(
|
||||||
|
PartitionedRateLimiter.Create<HttpContext, string>(httpContext =>
|
||||||
|
{
|
||||||
|
var userAgent = httpContext.Request.Headers.UserAgent.ToString();
|
||||||
|
|
||||||
|
return RateLimitPartition.GetSlidingWindowLimiter
|
||||||
|
(userAgent, _ =>
|
||||||
|
new SlidingWindowRateLimiterOptions
|
||||||
|
{
|
||||||
|
PermitLimit = 1000,
|
||||||
|
Window = TimeSpan.FromSeconds(60),
|
||||||
|
SegmentsPerWindow = 6,
|
||||||
|
QueueProcessingOrder = QueueProcessingOrder.OldestFirst
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//jwt鉴权
|
||||||
|
var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get<JwtOptions>();
|
||||||
|
var refreshJwtOptions = configuration.GetSection(nameof(RefreshJwtOptions)).Get<RefreshJwtOptions>();
|
||||||
|
|
||||||
|
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = jwtOptions.Issuer,
|
||||||
|
ValidAudience = jwtOptions.Audience,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey))
|
||||||
|
};
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
var accessToken = context.Request.Query["access_token"];
|
||||||
|
if (!string.IsNullOrEmpty(accessToken))
|
||||||
|
{
|
||||||
|
context.Token = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddJwtBearer(TokenTypeConst.Refresh, options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = refreshJwtOptions.Issuer,
|
||||||
|
ValidAudience = refreshJwtOptions.Audience,
|
||||||
|
IssuerSigningKey =
|
||||||
|
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey))
|
||||||
|
};
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
var refresh_token = context.Request.Headers["refresh_token"];
|
||||||
|
if (!string.IsNullOrEmpty(refresh_token))
|
||||||
|
{
|
||||||
|
context.Token = refresh_token;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
var refreshToken = context.Request.Query["refresh_token"];
|
||||||
|
if (!string.IsNullOrEmpty(refreshToken))
|
||||||
|
{
|
||||||
|
context.Token = refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddQQ(options => { configuration.GetSection("OAuth:QQ").Bind(options); })
|
||||||
|
.AddGitee(options => { configuration.GetSection("OAuth:Gitee").Bind(options); });
|
||||||
|
|
||||||
|
//授权
|
||||||
|
context.Services.AddAuthorization();
|
||||||
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +283,6 @@ namespace Yi.Abp.Web
|
|||||||
public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
{
|
{
|
||||||
var service = context.ServiceProvider;
|
var service = context.ServiceProvider;
|
||||||
|
|
||||||
var env = context.GetEnvironment();
|
var env = context.GetEnvironment();
|
||||||
var app = context.GetApplicationBuilder();
|
var app = context.GetApplicationBuilder();
|
||||||
|
|
||||||
@@ -113,17 +291,30 @@ namespace Yi.Abp.Web
|
|||||||
//跨域
|
//跨域
|
||||||
app.UseCors(DefaultCorsPolicyName);
|
app.UseCors(DefaultCorsPolicyName);
|
||||||
|
|
||||||
|
if (!env.IsDevelopment())
|
||||||
|
{
|
||||||
|
//速率限制
|
||||||
|
app.UseRateLimiter();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//无感token,先刷新再鉴权
|
||||||
|
app.UseRefreshToken();
|
||||||
|
|
||||||
|
//鉴权
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
|
||||||
|
//多租户
|
||||||
|
app.UseMultiTenancy();
|
||||||
|
|
||||||
//swagger
|
//swagger
|
||||||
app.UseYiSwagger();
|
app.UseYiSwagger();
|
||||||
|
|
||||||
|
//流量访问统计,需redis支持,否则不生效
|
||||||
|
app.UseAccessLog();
|
||||||
|
|
||||||
|
//请求处理
|
||||||
|
app.UseYiApiHandlinge();
|
||||||
|
|
||||||
//静态资源
|
//静态资源
|
||||||
app.UseStaticFiles("/api/app/wwwroot");
|
app.UseStaticFiles("/api/app/wwwroot");
|
||||||
@@ -131,12 +322,15 @@ namespace Yi.Abp.Web
|
|||||||
app.UseDirectoryBrowser("/api/app/wwwroot");
|
app.UseDirectoryBrowser("/api/app/wwwroot");
|
||||||
|
|
||||||
|
|
||||||
|
// app.Properties.Add("_AbpExceptionHandlingMiddleware_Added",false);
|
||||||
//工作单元
|
//工作单元
|
||||||
app.UseUnitOfWork();
|
app.UseUnitOfWork();
|
||||||
|
|
||||||
//授权
|
//授权
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
//审计日志
|
||||||
|
app.UseAuditing();
|
||||||
|
|
||||||
//日志记录
|
//日志记录
|
||||||
app.UseAbpSerilogEnrichers();
|
app.UseAbpSerilogEnrichers();
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ namespace Yi.Abp.Tool.Application.Contracts.Dtos
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模块类型
|
||||||
|
/// </summary>
|
||||||
|
public string ModuleSoure { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库提供者
|
/// 数据库提供者
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ namespace Yi.Abp.Tool.Application.Contracts
|
|||||||
public interface ITemplateGenService: IApplicationService
|
public interface ITemplateGenService: IApplicationService
|
||||||
{
|
{
|
||||||
Task<byte[]> CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto);
|
Task<byte[]> CreateModuleAsync(TemplateGenCreateInputDto moduleCreateInputDto);
|
||||||
Task<byte[]> CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto);
|
Task<List<string>> GetAllTemplatesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,14 @@ using Yi.Framework.Core.Helper;
|
|||||||
|
|
||||||
namespace Yi.Abp.Tool.Application
|
namespace Yi.Abp.Tool.Application
|
||||||
{
|
{
|
||||||
public class TemplateGenService : ApplicationService,ITemplateGenService
|
public class TemplateGenService : ApplicationService, ITemplateGenService
|
||||||
{
|
{
|
||||||
private readonly TemplateGenManager _templateGenManager;
|
private readonly TemplateGenManager _templateGenManager;
|
||||||
public TemplateGenService(TemplateGenManager templateGenManager) { _templateGenManager = templateGenManager; }
|
|
||||||
|
public TemplateGenService(TemplateGenManager templateGenManager)
|
||||||
|
{
|
||||||
|
_templateGenManager = templateGenManager;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载模块文件
|
/// 下载模块文件
|
||||||
@@ -29,8 +33,10 @@ namespace Yi.Abp.Tool.Application
|
|||||||
{
|
{
|
||||||
moduleCreateInputDto.SetNameReplace();
|
moduleCreateInputDto.SetNameReplace();
|
||||||
|
|
||||||
|
//模块类型,就是分支小写
|
||||||
var input = moduleCreateInputDto.Adapt<TemplateGenCreateDto>();
|
var input = moduleCreateInputDto.Adapt<TemplateGenCreateDto>();
|
||||||
input.SetTemplateFilePath(_templateGenManager._toolOptions.ModuleTemplateFilePath);
|
input.SetTemplateGiteeRef(moduleCreateInputDto.ModuleSoure);
|
||||||
|
|
||||||
var filePath = await _templateGenManager.CreateTemplateAsync(input);
|
var filePath = await _templateGenManager.CreateTemplateAsync(input);
|
||||||
|
|
||||||
////考虑从路径中获取
|
////考虑从路径中获取
|
||||||
@@ -39,22 +45,15 @@ namespace Yi.Abp.Tool.Application
|
|||||||
return await File.ReadAllBytesAsync(filePath);
|
return await File.ReadAllBytesAsync(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载模块文件
|
/// 获取全部模板列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<byte[]> CreateProjectAsync(TemplateGenCreateInputDto moduleCreateInputDto)
|
[HttpGet("template-gen/template")]
|
||||||
|
public async Task<List<string>> GetAllTemplatesAsync()
|
||||||
{
|
{
|
||||||
moduleCreateInputDto.SetNameReplace();
|
return await _templateGenManager.GetAllTemplatesAsync();
|
||||||
|
|
||||||
var input = moduleCreateInputDto.Adapt<TemplateGenCreateDto>();
|
|
||||||
input.SetTemplateFilePath(_templateGenManager._toolOptions.ProjectTemplateFilePath);
|
|
||||||
var filePath = await _templateGenManager.CreateTemplateAsync(input);
|
|
||||||
|
|
||||||
//考虑从路径中获取
|
|
||||||
// var fileContentType = MimeHelper.GetMimeMapping(Path.GetFileName(filePath));
|
|
||||||
//设置附件下载,下载名称
|
|
||||||
return await File.ReadAllBytesAsync(filePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,21 +9,19 @@ namespace Yi.Abp.Tool.Domain.Shared.Dtos
|
|||||||
{
|
{
|
||||||
public class TemplateGenCreateDto
|
public class TemplateGenCreateDto
|
||||||
{
|
{
|
||||||
public void SetTemplateFilePath(string templateFilePath)
|
public void SetTemplateGiteeRef(string moduleType)
|
||||||
{
|
{
|
||||||
this.TemplateFilePath = templateFilePath;
|
this.GiteeRef = moduleType.ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 模板文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string TemplateFilePath { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模块名称
|
/// 模块名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 模块所属gitee分支
|
||||||
|
/// </summary>
|
||||||
|
public string GiteeRef { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库提供者
|
/// 数据库提供者
|
||||||
|
|||||||
@@ -8,17 +8,6 @@ namespace Yi.Abp.Tool.Domain.Shared.Options
|
|||||||
{
|
{
|
||||||
public class ToolOptions
|
public class ToolOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 模块模板zip文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string ModuleTemplateFilePath { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 项目模板zip文件路径
|
|
||||||
/// </summary>
|
|
||||||
public string ProjectTemplateFilePath { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 临时文件目录
|
/// 临时文件目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,5 +9,8 @@
|
|||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
||||||
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Options\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
85
Yi.Abp.Net8/tool/Yi.Abp.Tool.Domain/GiteeManager.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Yi.Abp.Tool.Domain;
|
||||||
|
|
||||||
|
public class GiteeManager : ITransientDependency
|
||||||
|
{
|
||||||
|
private readonly string _accessToken;
|
||||||
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
private const string GiteeHost = "https://gitee.com/api/v5";
|
||||||
|
private const string Owner = "ccnetcore";
|
||||||
|
private const string Repo = "yi-template";
|
||||||
|
|
||||||
|
public GiteeManager(IConfiguration configuration, IHttpClientFactory httpClientFactory)
|
||||||
|
{
|
||||||
|
_httpClientFactory = httpClientFactory;
|
||||||
|
_accessToken = configuration.GetValue<string>("GiteeAccession");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否存在当前分支
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> IsExsitBranchAsync(string branch)
|
||||||
|
{
|
||||||
|
using var client = _httpClientFactory.CreateClient();
|
||||||
|
var response =
|
||||||
|
await client.GetAsync(
|
||||||
|
$"{GiteeHost}/repos/{Owner}/{Repo}/branches/{branch}?access_token={_accessToken}");
|
||||||
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有分支
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<string>> GetAllBranchAsync()
|
||||||
|
{
|
||||||
|
using var client = _httpClientFactory.CreateClient();
|
||||||
|
var response =
|
||||||
|
await client.GetAsync(
|
||||||
|
$"{GiteeHost}/repos/{Owner}/{Repo}/branches?access_token={_accessToken}&sort=name&direction=asc&page=1&per_page=100");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var result= await response.Content.ReadAsStringAsync();
|
||||||
|
JArray jsonArray= JArray.Parse(result);
|
||||||
|
// 创建一个列表来存储名字
|
||||||
|
List<string> names = new List<string>();
|
||||||
|
|
||||||
|
// 遍历每个对象,获取 name 字段
|
||||||
|
foreach (JObject obj in jsonArray)
|
||||||
|
{
|
||||||
|
// 获取 name 字段的值
|
||||||
|
string name = obj["name"]?.ToString();
|
||||||
|
if (name != null)
|
||||||
|
{
|
||||||
|
names.Add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载仓库分支代码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="branch"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<Stream> DownLoadFileAsync(string branch)
|
||||||
|
{
|
||||||
|
using var client = _httpClientFactory.CreateClient();
|
||||||
|
var response =
|
||||||
|
await client.GetAsync(
|
||||||
|
$"{GiteeHost}/repos/{Owner}/{Repo}/zipball?access_token={_accessToken}&ref={branch}");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
return await response.Content.ReadAsStreamAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,14 +13,23 @@ namespace Yi.Abp.Tool.Domain
|
|||||||
{
|
{
|
||||||
public class TemplateGenManager : ITransientDependency
|
public class TemplateGenManager : ITransientDependency
|
||||||
{
|
{
|
||||||
public readonly ToolOptions _toolOptions;
|
private readonly ToolOptions _toolOptions;
|
||||||
public TemplateGenManager(IOptionsMonitor<ToolOptions> toolOptions) { _toolOptions = toolOptions.CurrentValue; }
|
private readonly GiteeManager _giteeManager;
|
||||||
|
|
||||||
|
public TemplateGenManager(IOptionsMonitor<ToolOptions> toolOptions, GiteeManager giteeManager)
|
||||||
|
{
|
||||||
|
_giteeManager = giteeManager;
|
||||||
|
_toolOptions = toolOptions.CurrentValue;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string> CreateTemplateAsync(TemplateGenCreateDto input)
|
public async Task<string> CreateTemplateAsync(TemplateGenCreateDto input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input.TemplateFilePath))
|
//这里判断gitee上是否有这个分支
|
||||||
|
if (!await _giteeManager.IsExsitBranchAsync(input.GiteeRef))
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"模板路径无法找到,请检查,[{input.TemplateFilePath}]路径");
|
throw new UserFriendlyException($"Gitee分支未找到{input.GiteeRef},请检查,[{input.GiteeRef}]分支是否存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(_toolOptions.TempDirPath))
|
if (string.IsNullOrEmpty(_toolOptions.TempDirPath))
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"临时目录路径无法找到,请检查,[{_toolOptions.TempDirPath}]路径");
|
throw new UserFriendlyException($"临时目录路径无法找到,请检查,[{_toolOptions.TempDirPath}]路径");
|
||||||
@@ -33,25 +42,56 @@ namespace Yi.Abp.Tool.Domain
|
|||||||
Directory.CreateDirectory(tempFileDirPath);
|
Directory.CreateDirectory(tempFileDirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
//文件解压覆盖
|
|
||||||
ZipFile.ExtractToDirectory(input.TemplateFilePath, tempFileDirPath, true);
|
|
||||||
|
|
||||||
await ReplaceContentAsync(tempFileDirPath, input.ReplaceStrData);
|
//下载的模板存放文件路径
|
||||||
|
var downloadPath = Path.Combine(_toolOptions.TempDirPath, "download");
|
||||||
|
if (!Directory.Exists(downloadPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(downloadPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var downloadFilePath = Path.Combine(downloadPath, $"{id}.zip");
|
||||||
|
var gitSteam = await _giteeManager.DownLoadFileAsync(input.GiteeRef);
|
||||||
|
using (FileStream fileStream = new FileStream(downloadFilePath, FileMode.Create, FileAccess.Write))
|
||||||
|
{
|
||||||
|
await gitSteam.CopyToAsync(fileStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
//文件解压覆盖,将刚刚下载的模板,解压即可
|
||||||
|
ZipFile.ExtractToDirectory(downloadFilePath, tempFileDirPath, true);
|
||||||
|
|
||||||
|
|
||||||
|
//注意,这里下载的zip包,其实多了一层,我们进行操作的时候,要将操作目录进一步
|
||||||
|
var operPath = Directory.GetDirectories(tempFileDirPath)[0];
|
||||||
|
await ReplaceContentAsync(operPath, input.ReplaceStrData);
|
||||||
var tempFilePath = Path.Combine(_toolOptions.TempDirPath, $"{id}.zip");
|
var tempFilePath = Path.Combine(_toolOptions.TempDirPath, $"{id}.zip");
|
||||||
|
ZipFile.CreateFromDirectory(operPath, tempFilePath);
|
||||||
|
|
||||||
ZipFile.CreateFromDirectory(tempFileDirPath, tempFilePath);
|
|
||||||
//创建压缩包后删除临时目录
|
//创建压缩包后删除临时目录
|
||||||
Directory.Delete(tempFileDirPath, true);
|
Directory.Delete(tempFileDirPath, true);
|
||||||
return tempFilePath;
|
return tempFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取全部模板列表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<string>> GetAllTemplatesAsync()
|
||||||
|
{
|
||||||
|
var refs = await _giteeManager.GetAllBranchAsync();
|
||||||
|
|
||||||
|
//移除主分支
|
||||||
|
refs.Remove("master");
|
||||||
|
return refs;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 替换内容,key为要替换的内容,value为替换成的内容
|
/// 替换内容,key为要替换的内容,value为替换成的内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task ReplaceContentAsync(string rootDirectory, Dictionary<string, string> dic)
|
private async Task ReplaceContentAsync(string rootDirectory, Dictionary<string, string> dic)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (var dicEntry in dic)
|
foreach (var dicEntry in dic)
|
||||||
{
|
{
|
||||||
await ReplaceInDirectory(rootDirectory, dicEntry.Key, dicEntry.Value);
|
await ReplaceInDirectory(rootDirectory, dicEntry.Key, dicEntry.Value);
|
||||||
@@ -111,4 +151,4 @@ namespace Yi.Abp.Tool.Domain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="wwwroot\" />
|
<Folder Include="wwwroot\" />
|
||||||
|
<Folder Include="wwwroot\temp\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -33,4 +34,8 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<_ContentIncludedByDefault Remove="wwwroot\temp\download\d5bb6f4c5ca24da29ebe1b67e1e4595d.zip" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Text.Json.Serialization.Metadata;
|
||||||
using System.Threading.RateLimiting;
|
using System.Threading.RateLimiting;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
@@ -12,6 +15,7 @@ using Yi.Abp.Tool.Application;
|
|||||||
using Yi.Framework.AspNetCore;
|
using Yi.Framework.AspNetCore;
|
||||||
using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder;
|
using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder;
|
||||||
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
|
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Yi.Framework.Core.Json;
|
||||||
|
|
||||||
namespace Yi.Abp.Tool.Web
|
namespace Yi.Abp.Tool.Web
|
||||||
{
|
{
|
||||||
@@ -41,15 +45,17 @@ namespace Yi.Abp.Tool.Web
|
|||||||
});
|
});
|
||||||
|
|
||||||
//设置api格式
|
//设置api格式
|
||||||
service.AddControllers().AddNewtonsoftJson(options =>
|
Configure<JsonOptions>(options =>
|
||||||
{
|
{
|
||||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
options.JsonSerializerOptions.TypeInfoResolver = new DefaultJsonTypeInfoResolver();
|
||||||
options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
options.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
||||||
|
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Configure<AbpAntiForgeryOptions>(options =>
|
Configure<AbpAntiForgeryOptions>(options =>
|
||||||
{
|
{
|
||||||
options.AutoValidate = false;
|
options.AutoValidate = false;
|
||||||
@@ -81,7 +87,7 @@ namespace Yi.Abp.Tool.Web
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
service.AddHttpClient();
|
||||||
//速率限制
|
//速率限制
|
||||||
//每60秒限制100个请求,滑块添加,分6段
|
//每60秒限制100个请求,滑块添加,分6段
|
||||||
service.AddRateLimiter(_ =>
|
service.AddRateLimiter(_ =>
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
{
|
{
|
||||||
"Logging": {
|
"GiteeAccession": "8d9f05faec154475f121079579a0abf0"
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,6 @@
|
|||||||
"TempDirPath": "wwwroot/temp",
|
"TempDirPath": "wwwroot/temp",
|
||||||
"ModuleTemplateFilePath": "wwwroot/ModuleTemplate.zip",
|
"ModuleTemplateFilePath": "wwwroot/ModuleTemplate.zip",
|
||||||
"ProjectTemplateFilePath": "wwwroot/ProjectTemplate.zip"
|
"ProjectTemplateFilePath": "wwwroot/ProjectTemplate.zip"
|
||||||
}
|
},
|
||||||
|
"GiteeAccession": ""
|
||||||
}
|
}
|
||||||
|
|||||||
47
Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
|
namespace Yi.Abp.Tool
|
||||||
|
{
|
||||||
|
public class CommandInvoker : ISingletonDependency
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<ICommand> _commands;
|
||||||
|
private CommandLineApplication Application { get; }
|
||||||
|
|
||||||
|
public CommandInvoker(IEnumerable<ICommand> commands)
|
||||||
|
{
|
||||||
|
_commands = commands;
|
||||||
|
Application = new CommandLineApplication();
|
||||||
|
InitCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitCommand()
|
||||||
|
{
|
||||||
|
Application.HelpOption("-h|--help");
|
||||||
|
Application.VersionOption("-v|--versions", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
|
foreach (var command in _commands)
|
||||||
|
{
|
||||||
|
CommandLineApplication childrenCommandLineApplication = new CommandLineApplication(true)
|
||||||
|
{
|
||||||
|
Name = command.Command,
|
||||||
|
Parent = Application,
|
||||||
|
Description =command.Description
|
||||||
|
};
|
||||||
|
Application.Commands.Add(childrenCommandLineApplication);
|
||||||
|
command.CommandLineApplication(childrenCommandLineApplication);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InvokerAsync(string[] args)
|
||||||
|
{
|
||||||
|
Application.Execute(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Volo.Abp.DependencyInjection;
|
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace Yi.Abp.Tool
|
|
||||||
{
|
|
||||||
public class CommandSelector : ITransientDependency
|
|
||||||
{
|
|
||||||
private readonly IEnumerable<ICommand> _commands;
|
|
||||||
public CommandSelector(IEnumerable<ICommand> commands)
|
|
||||||
{
|
|
||||||
_commands = commands;
|
|
||||||
}
|
|
||||||
public async Task SelectorAsync(string[] args)
|
|
||||||
{
|
|
||||||
//不指定命令,默认给help
|
|
||||||
if (args.Length == 0)
|
|
||||||
{
|
|
||||||
await SelectorDefaultCommandAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var commandStr = args[0];
|
|
||||||
|
|
||||||
var commandOrNull = _commands.Where(x => x.CommandStrs.Select(x => x.ToUpper()).Contains(commandStr.ToUpper())).FirstOrDefault();
|
|
||||||
|
|
||||||
//没有匹配到命令,,默认给help
|
|
||||||
if (commandOrNull == null)
|
|
||||||
{
|
|
||||||
await SelectorDefaultCommandAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = new Dictionary<string, string?>();
|
|
||||||
|
|
||||||
//去除命令,剩下进行参数装载
|
|
||||||
string[] commonArgs = args.Skip(1).ToArray();
|
|
||||||
for (var i = 0; i < commonArgs.Length; i++)
|
|
||||||
{
|
|
||||||
var currentArg = commonArgs[i];
|
|
||||||
//命令参数以-或者--开头
|
|
||||||
if (IsCommandArg(currentArg))
|
|
||||||
{
|
|
||||||
string? commonValue = null;
|
|
||||||
//参数值在他的下一位
|
|
||||||
if (i + 1 < commonArgs.Length)
|
|
||||||
{
|
|
||||||
var nextArg = commonArgs[i + 1];
|
|
||||||
if (!IsCommandArg(nextArg))
|
|
||||||
{
|
|
||||||
commonValue = nextArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//删除-就是参数名
|
|
||||||
options.Add(ArgToCommandMap(currentArg), commonValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
await commandOrNull.InvokerAsync(options,args);
|
|
||||||
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 判断是否为命令参数
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private bool IsCommandArg(string arg)
|
|
||||||
{
|
|
||||||
if (arg.StartsWith("-") || arg.StartsWith("--"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 参数到命令的转换
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private string ArgToCommandMap(string arg)
|
|
||||||
{
|
|
||||||
return arg.TrimStart('-').TrimStart('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 选择默认命令
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task SelectorDefaultCommandAsync()
|
|
||||||
{
|
|
||||||
await SelectorAsync(["-h", "-error"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,54 +4,55 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
namespace Yi.Abp.Tool.Commands
|
namespace Yi.Abp.Tool.Commands
|
||||||
{
|
{
|
||||||
public class AddModuleCommand : ICommand
|
public class AddModuleCommand : ICommand
|
||||||
{
|
{
|
||||||
public List<string> CommandStrs => new List<string> { "add-module" };
|
public string Command => "add-module";
|
||||||
|
public string? Description => "将内容添加到当前解决方案` yi-abp add-module <moduleName> [-p <path>] [-s <solution>] ";
|
||||||
public async Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
//只有一个add-module
|
application.HelpOption("-h|--help");
|
||||||
if (args.Length <= 1)
|
var modulePathOption= application.Option("-p|--modulePath", "模块路径",CommandOptionType.SingleValue);
|
||||||
|
var solutionOption= application.Option("-s|--solution", "解决方案路径",CommandOptionType.SingleValue);
|
||||||
|
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
|
||||||
|
application.OnExecute(() =>
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException("命令错误,add-module命令后必须添加 模块名");
|
var moduleName = moduleNameArgument.Value;
|
||||||
}
|
|
||||||
|
//模块路径默认按小写规则,默认在模块路径下一层
|
||||||
//需要添加名称
|
var modulePath =moduleName.ToLower().Replace(".", "-");
|
||||||
var moduleName = args[1];
|
if (modulePathOption.HasValue())
|
||||||
options.TryGetValue("modulePath", out var modulePath);
|
{
|
||||||
|
modulePath = modulePathOption.Value();
|
||||||
//模块路径默认按小写规则,当前路径
|
}
|
||||||
if (string.IsNullOrEmpty(modulePath))
|
|
||||||
{
|
|
||||||
modulePath = moduleName.ToLower().Replace(".", "-");
|
//解决方案默认在模块文件夹上一级,也可以通过s进行指定
|
||||||
}
|
var slnPath = "../";
|
||||||
|
|
||||||
|
if (solutionOption.HasValue())
|
||||||
//解决方案默认在模块文件夹上一级,也可以通过s进行指定
|
{
|
||||||
var slnPath = string.Empty;
|
slnPath = solutionOption.Value();
|
||||||
options.TryGetValue("s", out var slnPath1);
|
}
|
||||||
options.TryGetValue("solution", out var slnPath2);
|
|
||||||
slnPath = string.IsNullOrEmpty(slnPath1) ? slnPath2 : slnPath1;
|
CheckFirstSlnPath(slnPath);
|
||||||
if (string.IsNullOrEmpty(slnPath))
|
var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}.";
|
||||||
{
|
var dotnetSlnCommandPart2 = new List<string>() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" };
|
||||||
slnPath = "../";
|
var paths = dotnetSlnCommandPart2.Select(x => $@"{modulePath}\{moduleName}." + x).ToArray();
|
||||||
}
|
CheckPathExist(paths);
|
||||||
|
|
||||||
CheckFirstSlnPath(slnPath);
|
var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray();
|
||||||
var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}.";
|
StartCmd(cmdCommands);
|
||||||
var dotnetSlnCommandPart2 = new List<string>() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" };
|
|
||||||
var paths = dotnetSlnCommandPart2.Select(x => $@"{modulePath}\{moduleName}." + x).ToArray();
|
Console.WriteLine("恭喜~模块添加成功!");
|
||||||
CheckPathExist(paths);
|
return 0;
|
||||||
|
});
|
||||||
var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray();
|
|
||||||
StartCmd(cmdCommands);
|
|
||||||
|
|
||||||
await Console.Out.WriteLineAsync("恭喜~模块添加成功!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取一个sln解决方案,多个将报错
|
/// 获取一个sln解决方案,多个将报错
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -117,5 +118,7 @@ namespace Yi.Abp.Tool.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,27 +3,38 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
namespace Yi.Abp.Tool.Commands
|
namespace Yi.Abp.Tool.Commands
|
||||||
{
|
{
|
||||||
public class ClearCommand : ICommand
|
public class ClearCommand : ICommand
|
||||||
{
|
{
|
||||||
public List<string> CommandStrs => ["clear"];
|
public List<string> CommandStrs => ["clear"];
|
||||||
|
|
||||||
|
|
||||||
public Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
public string Command => "clear";
|
||||||
|
public string? Description => "清除当前目录及子目录下的obj、bin文件夹` yi-abp clear `";
|
||||||
|
|
||||||
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
|
application.HelpOption("-h|--help");
|
||||||
List<string> delDirBlacklist = ["obj", "bin"];
|
List<string> delDirBlacklist = ["obj", "bin"];
|
||||||
options.TryGetValue("path", out var path);
|
var pathOption= application.Option("-path", "路径",CommandOptionType.SingleValue);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
|
application.OnExecute(() =>
|
||||||
{
|
{
|
||||||
path = "./";
|
var path = "./";
|
||||||
}
|
if (pathOption.HasValue())
|
||||||
DeleteObjBinFolders(path, delDirBlacklist);
|
{
|
||||||
return Task.CompletedTask;
|
path = pathOption.Value();
|
||||||
|
}
|
||||||
|
DeleteObjBinFolders(path, delDirBlacklist);
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void DeleteObjBinFolders(string directory, List<string> delDirBlacklist)
|
private static void DeleteObjBinFolders(string directory, List<string> delDirBlacklist)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -4,20 +4,28 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
namespace Yi.Abp.Tool.Commands
|
namespace Yi.Abp.Tool.Commands
|
||||||
{
|
{
|
||||||
public class CloneCommand : ICommand
|
public class CloneCommand : ICommand
|
||||||
{
|
{
|
||||||
public List<string> CommandStrs => new List<string> { "clone"};
|
private const string CloneAddress= "https://gitee.com/ccnetcore/Yi";
|
||||||
|
|
||||||
private const string cloneAddress= "https://gitee.com/ccnetcore/Yi";
|
|
||||||
public Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
public string Command => "clone";
|
||||||
|
public string? Description => "克隆最新YiFramework源代码,需依赖git";
|
||||||
|
|
||||||
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
StartCmd($"git clone {cloneAddress}");
|
application.OnExecute(() =>
|
||||||
return Task.CompletedTask;
|
{
|
||||||
|
StartCmd($"git clone {CloneAddress}");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行cmd命令
|
/// 执行cmd命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,40 +1,40 @@
|
|||||||
using System;
|
// using System;
|
||||||
using System.Collections.Generic;
|
// using System.Collections.Generic;
|
||||||
using System.Linq;
|
// using System.Linq;
|
||||||
using System.Reflection;
|
// using System.Reflection;
|
||||||
using System.Text;
|
// using System.Text;
|
||||||
using System.Threading.Tasks;
|
// using System.Threading.Tasks;
|
||||||
|
//
|
||||||
namespace Yi.Abp.Tool.Commands
|
// namespace Yi.Abp.Tool.Commands
|
||||||
{
|
// {
|
||||||
public class HelpCommand : ICommand
|
// public class HelpCommand : ICommand
|
||||||
{
|
// {
|
||||||
public List<string> CommandStrs => new List<string> { "h", "help", "-h", "-help" };
|
// public List<string> CommandStrs => new List<string> { "h", "help", "-h", "-help" };
|
||||||
|
//
|
||||||
public Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
// public Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
||||||
{
|
// {
|
||||||
string? errorMsg = null;
|
// string? errorMsg = null;
|
||||||
if (options.TryGetValue("error", out _))
|
// if (options.TryGetValue("error", out _))
|
||||||
{
|
// {
|
||||||
errorMsg = "您输入的命令有误,请检查,以下帮助命令提示:";
|
// errorMsg = "您输入的命令有误,请检查,以下帮助命令提示:";
|
||||||
}
|
// }
|
||||||
Console.WriteLine($"""
|
// Console.WriteLine($"""
|
||||||
{errorMsg}
|
// {errorMsg}
|
||||||
使用:
|
// 使用:
|
||||||
|
//
|
||||||
yi-abp <command> <target> [options]
|
// yi-abp <command> <target> [options]
|
||||||
|
//
|
||||||
命令列表:
|
// 命令列表:
|
||||||
|
//
|
||||||
> v: 查看yi-abp工具版本号
|
// > v: 查看yi-abp工具版本号
|
||||||
> help: 查看帮助列表,写下命令` yi-abp help <command> `
|
// > help: 查看帮助列表,写下命令` yi-abp help <command> `
|
||||||
> new: 创建模块模板` yi-abp new <name> -t module -csf `
|
// > new: 创建模块模板` yi-abp new <name> -t module -csf `
|
||||||
> new: 创建项目模板` yi-abp new <name> -csf `
|
// > new: 创建项目模板` yi-abp new <name> -csf `
|
||||||
> add-module: 将内容添加到当前解决方案` yi-abp add-module <moduleName> [-modulePath <path>] [-s <slnPath>] `
|
// > add-module: 将内容添加到当前解决方案` yi-abp add-module <moduleName> [-modulePath <path>] [-s <slnPath>] `
|
||||||
> clear: 清除当前目录及子目录下的obj、bin文件夹` yi-abp clear `
|
// > clear: 清除当前目录及子目录下的obj、bin文件夹` yi-abp clear `
|
||||||
|
//
|
||||||
""");
|
// """);
|
||||||
return Task.CompletedTask;
|
// return Task.CompletedTask;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
using Yi.Abp.Tool.Application.Contracts;
|
using Yi.Abp.Tool.Application.Contracts;
|
||||||
using Yi.Abp.Tool.Application.Contracts.Dtos;
|
using Yi.Abp.Tool.Application.Contracts.Dtos;
|
||||||
|
|
||||||
@@ -13,72 +14,126 @@ namespace Yi.Abp.Tool.Commands
|
|||||||
public class NewCommand : ICommand
|
public class NewCommand : ICommand
|
||||||
{
|
{
|
||||||
private readonly ITemplateGenService _templateGenService;
|
private readonly ITemplateGenService _templateGenService;
|
||||||
|
|
||||||
public NewCommand(ITemplateGenService templateGenService)
|
public NewCommand(ITemplateGenService templateGenService)
|
||||||
{
|
{
|
||||||
_templateGenService = templateGenService;
|
_templateGenService = templateGenService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> CommandStrs => new List<string>() { "new" };
|
|
||||||
|
|
||||||
|
public string Command => "new";
|
||||||
|
public string? Description => "创建项目模板` yi-abp new <name> -csf `";
|
||||||
|
|
||||||
public async Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
public void CommandLineApplication(CommandLineApplication application)
|
||||||
{
|
{
|
||||||
var id = Guid.NewGuid().ToString("N");
|
application.HelpOption("-h|--help");
|
||||||
//只有一个new
|
|
||||||
if (args.Length <= 1)
|
var templateTypeOption = application.Option("-t|--template", "模板类型:`module`|`porject`",
|
||||||
|
CommandOptionType.SingleValue);
|
||||||
|
var pathOption = application.Option("-p|--path", "创建路径", CommandOptionType.SingleValue);
|
||||||
|
var csfOption = application.Option("-csf", "是否创建解决方案文件夹", CommandOptionType.NoValue);
|
||||||
|
|
||||||
|
var soureOption = application.Option("-s|--soure", "模板来源,gitee模板库分支名称: 默认值`default`",
|
||||||
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
|
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
|
||||||
|
|
||||||
|
//子命令,new list
|
||||||
|
application.Command("list",(applicationlist) =>
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException("命令错误,new命令后必须添加 名称");
|
applicationlist.OnExecute(() =>
|
||||||
}
|
|
||||||
string name = args[1];
|
|
||||||
|
|
||||||
#region 处理生成类型
|
|
||||||
|
|
||||||
options.TryGetValue("t", out var templateType);
|
|
||||||
var zipPath = string.Empty;
|
|
||||||
byte[] fileByteArray;
|
|
||||||
if (templateType == "module")
|
|
||||||
{
|
|
||||||
//代表模块生成
|
|
||||||
fileByteArray = await _templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto
|
|
||||||
{
|
{
|
||||||
Name = name,
|
Console.WriteLine("正在远程搜索中...");
|
||||||
|
var list=_templateGenService.GetAllTemplatesAsync().Result;
|
||||||
|
var tip = $"""
|
||||||
|
全部模板包括:
|
||||||
|
模板名称
|
||||||
|
----------------
|
||||||
|
{list.JoinAsString("\n")}
|
||||||
|
""";
|
||||||
|
Console.WriteLine(tip);
|
||||||
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
else
|
|
||||||
|
application.OnExecute(() =>
|
||||||
{
|
{
|
||||||
//代表模块生成
|
var path = string.Empty;
|
||||||
fileByteArray = await _templateGenService.CreateProjectAsync(new TemplateGenCreateInputDto
|
if (pathOption.HasValue())
|
||||||
{
|
{
|
||||||
Name = name,
|
path = pathOption.Value();
|
||||||
});
|
if (!Directory.Exists(path))
|
||||||
}
|
{
|
||||||
zipPath = $"{id}.zip";
|
Directory.CreateDirectory(path);
|
||||||
await File.WriteAllBytesAsync(zipPath, fileByteArray);
|
return 0;
|
||||||
|
}
|
||||||
#endregion
|
|
||||||
|
}
|
||||||
#region 处理解决方案文件夹
|
|
||||||
//默认是当前目录
|
|
||||||
var unzipDirPath = "./";
|
|
||||||
//如果创建解决方案文件夹
|
#region 处理生成类型
|
||||||
if (options.TryGetValue("csf", out _))
|
|
||||||
{
|
var id = Guid.NewGuid().ToString("N");
|
||||||
var moduleName = name.ToLower().Replace(".", "-");
|
var zipPath = string.Empty;
|
||||||
|
byte[] fileByteArray;
|
||||||
if (Directory.Exists(moduleName))
|
|
||||||
{
|
var soure= soureOption.HasValue() ? soureOption.Value() : "default";
|
||||||
throw new UserFriendlyException($"文件夹[{moduleName}]已存在,请删除后重试");
|
|
||||||
|
var templateType = templateTypeOption.HasValue() ? templateTypeOption.Value() : "module";
|
||||||
|
if (templateType == "module")
|
||||||
|
{
|
||||||
|
//代表模块生成
|
||||||
|
fileByteArray = (_templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto
|
||||||
|
{
|
||||||
|
Name = moduleNameArgument.Value,
|
||||||
|
ModuleSoure = soure
|
||||||
|
}).Result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//还是代表模块生成
|
||||||
|
fileByteArray = _templateGenService.CreateModuleAsync(new TemplateGenCreateInputDto
|
||||||
|
{
|
||||||
|
Name = moduleNameArgument.Value,
|
||||||
|
}).Result;
|
||||||
}
|
}
|
||||||
Directory.CreateDirectory(moduleName);
|
|
||||||
unzipDirPath = moduleName;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
ZipFile.ExtractToDirectory(zipPath, unzipDirPath);
|
|
||||||
//创建压缩包后删除临时目录
|
|
||||||
File.Delete(zipPath);
|
|
||||||
|
|
||||||
|
|
||||||
await Console.Out.WriteLineAsync("恭喜~模块已生成!");
|
|
||||||
|
zipPath = Path.Combine(path, $"{id}.zip");
|
||||||
|
File.WriteAllBytes(zipPath, fileByteArray);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 处理解决方案文件夹
|
||||||
|
|
||||||
|
//默认是当前目录
|
||||||
|
var unzipDirPath = "./";
|
||||||
|
//如果创建解决方案文件夹
|
||||||
|
if (csfOption.HasValue())
|
||||||
|
{
|
||||||
|
var moduleName = moduleNameArgument.Value.ToLower().Replace(".", "-");
|
||||||
|
|
||||||
|
unzipDirPath = Path.Combine(path, moduleName);
|
||||||
|
if (Directory.Exists(unzipDirPath))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"文件夹[{unzipDirPath}]已存在,请删除后重试");
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.CreateDirectory(unzipDirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
ZipFile.ExtractToDirectory(zipPath, unzipDirPath);
|
||||||
|
//创建压缩包后删除临时目录
|
||||||
|
File.Delete(zipPath);
|
||||||
|
|
||||||
|
Console.WriteLine("恭喜~模块已生成!");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace Yi.Abp.Tool.Commands
|
|
||||||
{
|
|
||||||
public class VersionCommand : ICommand
|
|
||||||
{
|
|
||||||
public List<string> CommandStrs => new List<string> { "version", "v", "-version", "-v" };
|
|
||||||
|
|
||||||
public Task InvokerAsync(Dictionary<string, string> options, string[] args)
|
|
||||||
{
|
|
||||||
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
||||||
Console.WriteLine($"Yi-ABP TOOL {version}");
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,21 +3,17 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
namespace Yi.Abp.Tool
|
namespace Yi.Abp.Tool
|
||||||
{
|
{
|
||||||
public interface ICommand:ITransientDependency
|
public interface ICommand:ISingletonDependency
|
||||||
{
|
{
|
||||||
/// <summary>
|
public string Command { get; }
|
||||||
/// 命令串
|
|
||||||
/// </summary>
|
public string? Description { get; }
|
||||||
public List<string> CommandStrs { get; }
|
void CommandLineApplication(CommandLineApplication application);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public Task InvokerAsync(Dictionary<string,string> options, string[] args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,33 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using System.Reflection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Yi.Abp.Tool;
|
using Yi.Abp.Tool;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
//args = ["v"];
|
|
||||||
//args = ["-v"];
|
//帮助
|
||||||
//args = ["h"];
|
|
||||||
//args = ["-h"];
|
//args = ["-h"];
|
||||||
//args = [];
|
|
||||||
//args = ["12312"];
|
//版本
|
||||||
//args = ["new", "Acme.Book", "-t", "module", "-csf"];
|
// args = ["-v"];
|
||||||
//args = ["new", "Acme.Book", "-t", "module"];
|
|
||||||
//args = ["add-module", "Acme.Demo", "-s", "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8", "-modulePath", "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8\\module\\acme-demo"];
|
//清理
|
||||||
args = ["clear", "-path", "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8\\src"];
|
// args = ["clear"];
|
||||||
|
|
||||||
|
//创建模块
|
||||||
|
//args = ["new","oooo", "-t","module","-p","D:\\temp","-csf"];
|
||||||
|
|
||||||
|
//查看模板列表
|
||||||
|
//args = ["new","list"];
|
||||||
|
//查看子命令帮组
|
||||||
|
// args = ["new","-h"];
|
||||||
|
|
||||||
|
//添加模块
|
||||||
|
//args = ["add-module", "kkk"];
|
||||||
#endif
|
#endif
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -32,8 +42,8 @@ class Program
|
|||||||
//})
|
//})
|
||||||
.UseAutofac()
|
.UseAutofac()
|
||||||
.Build();
|
.Build();
|
||||||
var commandSelector = host.Services.GetRequiredService<CommandSelector>();
|
var commandSelector = host.Services.GetRequiredService<CommandInvoker>();
|
||||||
await commandSelector.SelectorAsync(args);
|
await commandSelector.InvokerAsync(args);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>1.1.0</Version>
|
<Version>2.0.4</Version>
|
||||||
<Authors>橙子老哥</Authors>
|
<Authors>橙子老哥</Authors>
|
||||||
<Description>yi-framework框架配套工具</Description>
|
<Description>yi-framework框架配套工具</Description>
|
||||||
<PackageProjectUrl>https://ccnetcore.com</PackageProjectUrl>
|
<PackageProjectUrl>https://ccnetcore.com</PackageProjectUrl>
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
||||||
<PackageReference Include="Volo.Abp.Autofac" Version="$(AbpVersion)" />
|
<PackageReference Include="Volo.Abp.Autofac" Version="$(AbpVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ namespace Yi.Abp.Tool
|
|||||||
Configure<AbpRemoteServiceOptions>(options =>
|
Configure<AbpRemoteServiceOptions>(options =>
|
||||||
{
|
{
|
||||||
options.RemoteServices.Default =
|
options.RemoteServices.Default =
|
||||||
new RemoteServiceConfiguration("https://ccnetcore.com:19009");
|
new RemoteServiceConfiguration("https://ccnetcore.com:19009");
|
||||||
|
// new RemoteServiceConfiguration("http://localhost:19002");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||