feat:完成内部核心模块替换改造成furion
This commit is contained in:
@@ -1,51 +1,71 @@
|
|||||||
using Furion;
|
using Furion;
|
||||||
|
using Furion.DatabaseAccessor;
|
||||||
using Furion.DependencyInjection;
|
using Furion.DependencyInjection;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||||
using Yi.Framework.Infrastructure.Uow;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Infrastructure.Sqlsugar.Uow
|
namespace Yi.Framework.Infrastructure.Sqlsugar.Uow
|
||||||
{
|
{
|
||||||
public class SqlsugarUnitOfWork : IUnitOfWork, ISingleton
|
public class SqlsugarUnitOfWork : IUnitOfWork
|
||||||
{
|
{
|
||||||
public ISqlSugarClient Db { get; set; }
|
// <summary>
|
||||||
public ITenant Tenant { get; set; }
|
/// SqlSugar 对象
|
||||||
public bool IsTran { get; set; }
|
/// </summary>
|
||||||
public bool IsCommit { get; set; }
|
private readonly ISqlSugarClient _sqlSugarClient;
|
||||||
public bool IsClose { get; set; }
|
|
||||||
|
|
||||||
public void Dispose()
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sqlSugarClient"></param>
|
||||||
|
public SqlsugarUnitOfWork(ISqlSugarClient sqlSugarClient)
|
||||||
{
|
{
|
||||||
|
_sqlSugarClient = sqlSugarClient;
|
||||||
if (IsTran && IsCommit == false)
|
|
||||||
{
|
|
||||||
Tenant.RollbackTran();
|
|
||||||
}
|
|
||||||
if (Db.Ado.Transaction == null && IsClose == false)
|
|
||||||
{
|
|
||||||
Db.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Commit()
|
/// <summary>
|
||||||
|
/// 开启工作单元处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="unitOfWork"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void BeginTransaction(FilterContext context, UnitOfWorkAttribute unitOfWork)
|
||||||
{
|
{
|
||||||
if (IsTran && IsCommit == false)
|
_sqlSugarClient.AsTenant().BeginTran();
|
||||||
{
|
|
||||||
Tenant.CommitTran();
|
|
||||||
IsCommit = true;
|
|
||||||
}
|
|
||||||
if (Db.Ado.Transaction == null && IsClose == false)
|
|
||||||
{
|
|
||||||
Db.Close();
|
|
||||||
IsClose = true;
|
|
||||||
}
|
|
||||||
return IsCommit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRepository<T> GetRepository<T>()
|
/// <summary>
|
||||||
|
/// 提交工作单元处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resultContext"></param>
|
||||||
|
/// <param name="unitOfWork"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void CommitTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
|
||||||
{
|
{
|
||||||
return App.GetRequiredService<IRepository<T>>();
|
_sqlSugarClient.AsTenant().CommitTran();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 回滚工作单元处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resultContext"></param>
|
||||||
|
/// <param name="unitOfWork"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void RollbackTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
|
||||||
|
{
|
||||||
|
_sqlSugarClient.AsTenant().RollbackTran();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行完毕(无论成功失败)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="resultContext"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void OnCompleted(FilterContext context, FilterContext resultContext)
|
||||||
|
{
|
||||||
|
_sqlSugarClient.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
using Furion.DependencyInjection;
|
|
||||||
using SqlSugar;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Yi.Framework.Infrastructure.Uow;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Infrastructure.Sqlsugar.Uow
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 此部分为sqlsugr的魔改版本
|
|
||||||
/// </summary>
|
|
||||||
internal class SqlsugarUnitOfWorkManager : IUnitOfWorkManager,ISingleton
|
|
||||||
{
|
|
||||||
public SqlsugarUnitOfWorkManager(ISqlSugarClient db)
|
|
||||||
{
|
|
||||||
Db = db;
|
|
||||||
}
|
|
||||||
public ISqlSugarClient Db { get; set; }
|
|
||||||
public IUnitOfWork CreateContext(bool isTran = true)
|
|
||||||
{
|
|
||||||
SqlsugarUnitOfWork uow = new SqlsugarUnitOfWork();
|
|
||||||
return CreateContext(isTran, uow);
|
|
||||||
}
|
|
||||||
private IUnitOfWork CreateContext(bool isTran, SqlsugarUnitOfWork sugarUnitOf)
|
|
||||||
{
|
|
||||||
sugarUnitOf.Db = Db;
|
|
||||||
sugarUnitOf.Tenant = Db.AsTenant();
|
|
||||||
sugarUnitOf.IsTran = isTran;
|
|
||||||
Db.Open();
|
|
||||||
if (isTran)
|
|
||||||
Db.AsTenant().BeginTran();
|
|
||||||
return sugarUnitOf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Yi.Framework.Infrastructure.AspNetCore;
|
using Yi.Framework.Infrastructure.AspNetCore;
|
||||||
using Yi.Framework.Infrastructure.Sqlsugar;
|
using Yi.Framework.Infrastructure.Sqlsugar;
|
||||||
|
using Yi.Framework.Infrastructure.Sqlsugar.Uow;
|
||||||
|
|
||||||
namespace Yi.Framework.Infrastructure;
|
namespace Yi.Framework.Infrastructure;
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ public class Startup : AppStartup
|
|||||||
services.Configure<DbConnOptions>(App.Configuration.GetSection("DbConnOptions"));
|
services.Configure<DbConnOptions>(App.Configuration.GetSection("DbConnOptions"));
|
||||||
|
|
||||||
services.AddDbSqlsugarContextServer();
|
services.AddDbSqlsugarContextServer();
|
||||||
|
|
||||||
|
services.AddUnitOfWork<SqlsugarUnitOfWork>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Infrastructure.Uow
|
|
||||||
{
|
|
||||||
internal class DefaultUnitOfWork : IUnitOfWork
|
|
||||||
{
|
|
||||||
public DefaultUnitOfWork() { }
|
|
||||||
public bool IsTran { get; set; }
|
|
||||||
public bool IsCommit { get; set; }
|
|
||||||
public bool IsClose { get; set; }
|
|
||||||
|
|
||||||
public bool Commit()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRepository<T> GetRepository<T>()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Yi.Framework.Infrastructure.Uow
|
|
||||||
{
|
|
||||||
internal class DefaultUnitOfWorkManager : IUnitOfWorkManager
|
|
||||||
{
|
|
||||||
public IUnitOfWork CreateContext(bool isTran = true)
|
|
||||||
{
|
|
||||||
return new DefaultUnitOfWork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
|
||||||
|
|
||||||
namespace Yi.Framework.Infrastructure.Uow
|
|
||||||
{
|
|
||||||
public interface IUnitOfWork : IDisposable
|
|
||||||
{
|
|
||||||
bool IsTran { get; set; }
|
|
||||||
bool IsCommit { get; set; }
|
|
||||||
bool IsClose { get; set; }
|
|
||||||
|
|
||||||
IRepository<T> GetRepository<T>();
|
|
||||||
bool Commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Yi.Framework.Infrastructure.Uow
|
|
||||||
{
|
|
||||||
public interface IUnitOfWorkManager
|
|
||||||
{
|
|
||||||
IUnitOfWork CreateContext(bool isTran = true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ using Yi.Framework.Infrastructure.CurrentUsers;
|
|||||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||||
using Yi.Framework.Infrastructure.Exceptions;
|
using Yi.Framework.Infrastructure.Exceptions;
|
||||||
using Yi.Framework.Infrastructure.Uow;
|
|
||||||
using Yi.Framework.Module.ImageSharp.HeiCaptcha;
|
using Yi.Framework.Module.ImageSharp.HeiCaptcha;
|
||||||
using Yi.Framework.Module.Sms.Aliyun;
|
using Yi.Framework.Module.Sms.Aliyun;
|
||||||
using Yi.Furion.Rbac.Application.System.Domain;
|
using Yi.Furion.Rbac.Application.System.Domain;
|
||||||
@@ -53,7 +52,6 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
private UserManager _userManager { get; set; }
|
private UserManager _userManager { get; set; }
|
||||||
|
|
||||||
|
|
||||||
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
private IRepository<RoleEntity> _roleRepository { get; set; }
|
private IRepository<RoleEntity> _roleRepository { get; set; }
|
||||||
@@ -222,6 +220,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
[UnitOfWork]
|
||||||
public async Task<object> PostRegisterAsync(RegisterDto input)
|
public async Task<object> PostRegisterAsync(RegisterDto input)
|
||||||
{
|
{
|
||||||
if (input.UserName == UserConst.Admin)
|
if (input.UserName == UserConst.Admin)
|
||||||
@@ -251,8 +250,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
{
|
{
|
||||||
throw new UserFriendlyException("用户已存在,注册失败");
|
throw new UserFriendlyException("用户已存在,注册失败");
|
||||||
}
|
}
|
||||||
using (var uow = _unitOfWorkManager.CreateContext())
|
|
||||||
{
|
|
||||||
var newUser = new UserEntity(input.UserName, input.Password, input.Phone);
|
var newUser = new UserEntity(input.UserName, input.Password, input.Phone);
|
||||||
|
|
||||||
var entity = await _userRepository.InsertReturnEntityAsync(newUser);
|
var entity = await _userRepository.InsertReturnEntityAsync(newUser);
|
||||||
@@ -263,9 +261,6 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
{
|
{
|
||||||
await _userManager.GiveUserSetRoleAsync(new List<long> { entity.Id }, new List<long> { role.Id });
|
await _userManager.GiveUserSetRoleAsync(new List<long> { entity.Id }, new List<long> { role.Id });
|
||||||
}
|
}
|
||||||
uow.Commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||||
using Yi.Framework.Infrastructure.Uow;
|
|
||||||
using Yi.Furion.Rbac.Application.System.Domain;
|
using Yi.Furion.Rbac.Application.System.Domain;
|
||||||
using Yi.Furion.Rbac.Application.System.Dtos.Role;
|
using Yi.Furion.Rbac.Application.System.Dtos.Role;
|
||||||
using Yi.Furion.Rbac.Core.Entities;
|
using Yi.Furion.Rbac.Core.Entities;
|
||||||
@@ -40,6 +39,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[UnitOfWork]
|
||||||
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
|
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
|
||||||
{
|
{
|
||||||
RoleGetOutputDto outputDto;
|
RoleGetOutputDto outputDto;
|
||||||
@@ -61,6 +61,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[UnitOfWork]
|
||||||
public override async Task<RoleGetOutputDto> UpdateAsync(long id, RoleUpdateInputVo input)
|
public override async Task<RoleGetOutputDto> UpdateAsync(long id, RoleUpdateInputVo input)
|
||||||
{
|
{
|
||||||
var dto = new RoleGetOutputDto();
|
var dto = new RoleGetOutputDto();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Yi.Framework.Infrastructure.CurrentUsers;
|
|||||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||||
using Yi.Framework.Infrastructure.Exceptions;
|
using Yi.Framework.Infrastructure.Exceptions;
|
||||||
using Yi.Framework.Infrastructure.Uow;
|
|
||||||
using Yi.Framework.Module.OperLogManager;
|
using Yi.Framework.Module.OperLogManager;
|
||||||
using Yi.Furion.Rbac.Application.System.Domain;
|
using Yi.Furion.Rbac.Application.System.Domain;
|
||||||
using Yi.Furion.Rbac.Application.System.Dtos.User;
|
using Yi.Furion.Rbac.Application.System.Dtos.User;
|
||||||
@@ -73,6 +72,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="UserFriendlyException"></exception>
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
[OperLog("添加用户", OperEnum.Insert)]
|
[OperLog("添加用户", OperEnum.Insert)]
|
||||||
|
[UnitOfWork]
|
||||||
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input.Password))
|
if (string.IsNullOrEmpty(input.Password))
|
||||||
@@ -118,6 +118,7 @@ namespace Yi.Furion.Rbac.Application.System.Services.Impl
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[OperLog("更新用户", OperEnum.Update)]
|
[OperLog("更新用户", OperEnum.Update)]
|
||||||
|
[UnitOfWork]
|
||||||
public async override Task<UserGetOutputDto> UpdateAsync(long id, UserUpdateInputVo input)
|
public async override Task<UserGetOutputDto> UpdateAsync(long id, UserUpdateInputVo input)
|
||||||
{
|
{
|
||||||
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
|
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
|
||||||
|
|||||||
Reference in New Issue
Block a user