完善大部分问题
This commit is contained in:
Binary file not shown.
@@ -10,13 +10,6 @@
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.#ctor(Microsoft.Extensions.Logging.ILogger{`0},Yi.Framework.Repository.IRepository{`0})">
|
||||
<summary>
|
||||
jb
|
||||
</summary>
|
||||
<param name="logger"></param>
|
||||
<param name="iRepository"></param>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Get(System.Object)">
|
||||
<summary>
|
||||
主键查询
|
||||
@@ -24,13 +17,13 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.GetList">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.GetList(Yi.Framework.Model.Query.QueryCondition)">
|
||||
<summary>
|
||||
列表查询
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Page(Yi.Framework.Model.Query.QueryCondition)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Page(Yi.Framework.Model.Query.QueryPageCondition)">
|
||||
<summary>
|
||||
条件分页查询
|
||||
</summary>
|
||||
@@ -51,7 +44,7 @@
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.DeleteList(System.Object[])">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.DeleteList(System.Collections.Generic.List{System.Guid})">
|
||||
<summary>
|
||||
列表删除
|
||||
</summary>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
@@ -21,9 +22,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
public class AccountController :ControllerBase
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService)
|
||||
private JwtInvoker _jwtInvoker;
|
||||
public AccountController(ILogger<UserEntity> logger, IUserService iUserService, JwtInvoker jwtInvoker)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_jwtInvoker = jwtInvoker;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@@ -32,8 +35,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
UserEntity user=new();
|
||||
if (await _iUserService.Login(loginDto.UserName, loginDto.Password,o=> user=o))
|
||||
{
|
||||
return Result.Success("登录成功!").SetData(user);
|
||||
{
|
||||
return Result.Success("登录成功!").SetData(new { user, token = _jwtInvoker.GetAccessToken(user)});
|
||||
}
|
||||
return Result.SuccessError("登录失败!用户名或者密码错误!");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
@@ -12,19 +14,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class BaseCrudController<T> : ControllerBase where T : class,new()
|
||||
public class BaseCrudController<T> : ControllerBase where T : BaseModelEntity,new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
public IRepository<T> _iRepository;
|
||||
/// <summary>
|
||||
/// jb
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="iRepository"></param>
|
||||
public BaseCrudController(ILogger<T> logger, IRepository<T> iRepository)
|
||||
public readonly ILogger<T> _logger;
|
||||
public IBaseService<T> _baseService;
|
||||
public IRepository<T> _repository;
|
||||
|
||||
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||
{
|
||||
_logger = logger;
|
||||
_iRepository = iRepository;
|
||||
_baseService = iBaseService;
|
||||
_repository = iBaseService._repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,7 +36,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpGet]
|
||||
public async Task<Result> Get(object id)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.GetByIdAsync(id));
|
||||
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,10 +44,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:list")]
|
||||
[HttpGet]
|
||||
public async Task<Result> GetList()
|
||||
[HttpPost]
|
||||
public async Task<Result> GetList(QueryCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.GetListAsync());
|
||||
return Result.Success().SetData(await _repository.GetListAsync(queryCondition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,9 +57,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:page")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Page(QueryCondition queryCondition)
|
||||
public async Task<Result> Page(QueryPageCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.CommonPage(queryCondition));
|
||||
return Result.Success().SetData(await _repository.CommonPage(queryCondition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -71,7 +71,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.InsertReturnEntityAsync(entity));
|
||||
return Result.Success().SetData(await _repository.InsertReturnEntityAsync(entity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,7 +83,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.UpdateAsync(entity));
|
||||
return Result.Success().SetStatus(await _repository.UpdateAsync(entity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,9 +93,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:delete:list")]
|
||||
[HttpDelete]
|
||||
public async Task<Result> DeleteList(object[] ids)
|
||||
public async Task<Result> DeleteList(List<Guid> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.DeleteByIdsAsync(ids));
|
||||
return Result.Success().SetStatus(await _repository.DeleteByLogic(ids));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ ServiceLocator.Instance = app.Services;
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD>ץȡ<D7A5><C8A1><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
app.UseErrorHandlingService();
|
||||
//app.UseErrorHandlingService();
|
||||
#region
|
||||
//<2F><>̬<EFBFBD>ļ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
|
||||
@@ -38,10 +38,14 @@
|
||||
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]"
|
||||
]
|
||||
},
|
||||
"JWTTokenOptions": {
|
||||
"Audience": "http://localhost:7000",
|
||||
"Issuer": "http://localhost:7000",
|
||||
"SecurityKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB"
|
||||
"JwtAuthorize": {
|
||||
"Issuer": "cc",
|
||||
"Audience": "cc",
|
||||
"PolicyName": "permission",
|
||||
"DefaultScheme": "Bearer",
|
||||
"IsHttps": false,
|
||||
"Expiration": 30,
|
||||
"ReExpiration": 3000
|
||||
},
|
||||
"RedisConnOptions": {
|
||||
"Host": "[xxxx]",
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace Yi.Framework.Common.IOCOptions
|
||||
|
||||
public string Issuer { get; set; }
|
||||
|
||||
public string SecurityKey { get; set; }
|
||||
|
||||
public string DefaultScheme { get; set; }
|
||||
public int Expiration { get; set; }
|
||||
|
||||
|
||||
@@ -23,22 +23,4 @@
|
||||
<ProjectReference Include="..\Yi.Framework.Task\Yi.Framework.Job.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces">
|
||||
<HintPath>Library\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Common">
|
||||
<HintPath>Library\ServiceStack.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Interfaces">
|
||||
<HintPath>Library\ServiceStack.Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Redis">
|
||||
<HintPath>Library\ServiceStack.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Text">
|
||||
<HintPath>Library\ServiceStack.Text.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
15
Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs
Normal file
15
Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public interface IBaseService<T> where T:BaseModelEntity,new()
|
||||
{
|
||||
public IRepository<T> _repository { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface ITenantService: IRepository<TenantEntity>
|
||||
public partial interface ITenantService:IBaseService<TenantEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IUserService: IRepository<UserEntity>
|
||||
public partial interface IUserService:IBaseService<UserEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,16 +41,6 @@ namespace Yi.Framework.Model.Models
|
||||
[SugarColumn(ColumnName = "ModifyTime")]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 删除者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "DeleteUser")]
|
||||
public Guid? DeleteUser { get; set; }
|
||||
/// <summary>
|
||||
/// 删除时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "DeleteTime")]
|
||||
public DateTime? DeleteTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "IsDeleted")]
|
||||
|
||||
@@ -8,38 +8,12 @@ namespace Yi.Framework.Model.Models
|
||||
/// 租户表
|
||||
///</summary>
|
||||
[SugarTable("Tenant")]
|
||||
public partial class TenantEntity
|
||||
public partial class TenantEntity:BaseModelEntity
|
||||
{
|
||||
public TenantEntity()
|
||||
{
|
||||
this.Id=Guid.NewGuid();
|
||||
this.IsDeleted=false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
/// 租户名
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public Guid? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
[SugarColumn(ColumnName="TenantName" )]
|
||||
public string TenantName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,6 @@ namespace Yi.Framework.Model.Models
|
||||
public partial class UserEntity:BaseModelEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// 姓名
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Name" )]
|
||||
@@ -26,31 +21,6 @@ namespace Yi.Framework.Model.Models
|
||||
[SugarColumn(ColumnName="Age" )]
|
||||
public int? Age { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public Guid? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 修改者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyUser" )]
|
||||
public Guid? ModifyUser { get; set; }
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ModifyTime" )]
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否删除
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="IsDeleted" )]
|
||||
public bool? IsDeleted { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
|
||||
@@ -6,11 +6,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Query
|
||||
{
|
||||
public class QueryCondition
|
||||
public class QueryPageCondition
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int Size { get; set; }
|
||||
public int Count { get; set; }
|
||||
|
||||
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
|
||||
public List<string> OrderBys { get; set; } = new List<string>();
|
||||
|
||||
}
|
||||
|
||||
public class QueryCondition
|
||||
{
|
||||
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
|
||||
public List<string> OrderBys { get; set; } = new List<string>();
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using SqlSugar;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Query
|
||||
{
|
||||
public class QueryParameter
|
||||
{
|
||||
public string FieldName { get; set; }
|
||||
public string FieldValue { get; set; }
|
||||
public ConditionalType ConditionalType { get; set; } = ConditionalType.Like;
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public ConditionalType Type { get; set; } = ConditionalType.Like;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Yi.Framework.Repository
|
||||
{
|
||||
public Task<T> InsertReturnEntityAsync(T entity);
|
||||
public Task<List<S>> StoreAsync<S>(string storeName, object para);
|
||||
public Task<PageModel<List<T>>> CommonPage(QueryCondition pars);
|
||||
public Task<PageModel<List<T>>> CommonPage(QueryPageCondition pars);
|
||||
public Task<List<T>> GetListAsync(QueryCondition pars);
|
||||
public Task<bool> DeleteByLogic(List<Guid> ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,18 @@ namespace Yi.Framework.Repository
|
||||
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 逻辑多删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteByLogic(List<Guid> ids)
|
||||
{
|
||||
var entitys = await Db.Queryable<T>().Where(u => ids.Contains(u.Id)).ToListAsync();
|
||||
entitys.ForEach(u=>u.IsDeleted=true);
|
||||
return await Db.Updateable(entitys).ExecuteCommandAsync()>0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 调用存储过程
|
||||
/// </summary>
|
||||
@@ -46,18 +58,41 @@ namespace Yi.Framework.Repository
|
||||
return await Db.Ado.UseStoredProcedure().SqlQueryAsync<S>(storeName, para);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 多条件查询
|
||||
/// </summary>
|
||||
/// <param name="pars"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> GetListAsync(QueryCondition pars)
|
||||
{
|
||||
return await QueryConditionHandler(pars).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仓储扩展方法:单表查询通用分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<PageModel<List<T>>> CommonPage(QueryCondition pars)
|
||||
public async Task<PageModel<List<T>>> CommonPage(QueryPageCondition pars)
|
||||
{
|
||||
RefAsync<int> tolCount = 0;
|
||||
var result = await QueryConditionHandler(new QueryCondition() {OrderBys=pars.OrderBys,Parameters=pars.Parameters } ).ToPageListAsync(pars.Index, pars.Size, tolCount);
|
||||
return new PageModel<List<T>>
|
||||
{
|
||||
Total = tolCount.Value,
|
||||
Data = result
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ISugarQueryable<T> QueryConditionHandler(QueryCondition pars)
|
||||
{
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
FieldName = it.FieldName,
|
||||
FieldValue = it.FieldValue
|
||||
ConditionalType = it.Type,
|
||||
FieldName = it.Key,
|
||||
FieldValue = it.Value
|
||||
}).ToList();
|
||||
var query = Db.Queryable<T>();
|
||||
if (pars.OrderBys != null)
|
||||
@@ -67,14 +102,9 @@ namespace Yi.Framework.Repository
|
||||
query.OrderBy(item.ToSqlFilter());
|
||||
}
|
||||
}
|
||||
var result =await query.Where(sugarParamters).ToPageListAsync(pars.Index, pars.Size, tolCount);
|
||||
|
||||
return new PageModel<List<T>>
|
||||
{
|
||||
Total = tolCount.Value,
|
||||
Data = result
|
||||
};
|
||||
return query.Where(sugarParamters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
20
Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs
Normal file
20
Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class BaseService<T>:IBaseService<T> where T:BaseModelEntity,new()
|
||||
{
|
||||
public IRepository<T> _repository { get; set; }
|
||||
public BaseService(IRepository<T> iRepository)
|
||||
{
|
||||
_repository = iRepository;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class TenantService : Repository<TenantEntity>, ITenantService
|
||||
public partial class TenantService : BaseService<TenantEntity>, ITenantService
|
||||
{
|
||||
public TenantService(ISqlSugarClient context) : base(context)
|
||||
public TenantService(IRepository<TenantEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class UserService : Repository<UserEntity>, IUserService
|
||||
public partial class UserService : BaseService<UserEntity>, IUserService
|
||||
{
|
||||
public UserService(ISqlSugarClient context) : base(context)
|
||||
public UserService(IRepository<UserEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
public async Task<bool> Exist(Guid id, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user = await GetByIdAsync(id);
|
||||
var user = await _repository.GetByIdAsync(id);
|
||||
userAction.Invoke(user);
|
||||
if (user == null)
|
||||
{
|
||||
@@ -22,7 +22,7 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
public async Task<bool> Exist(string userName, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user = await GetFirstAsync(u=>u.UserName== userName);
|
||||
var user = await _repository.GetFirstAsync(u=>u.UserName== userName);
|
||||
if (userAction != null)
|
||||
{
|
||||
userAction.Invoke(user);
|
||||
@@ -55,7 +55,7 @@ namespace Yi.Framework.Service
|
||||
user.UserName= userEntity.UserName;
|
||||
user.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
user.Password = Common.Helper.MD5Helper.SHA2Encode(userEntity.Password,user.Salt);
|
||||
userAction.Invoke(await InsertReturnEntityAsync(user));
|
||||
userAction.Invoke(await _repository.InsertReturnEntityAsync(user));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
c.Datacenter = consulClientOption.Datacenter;
|
||||
}))
|
||||
{
|
||||
|
||||
client.Agent.ServiceDeregister($"{consulRegisterOption.IP}-{consulRegisterOption.Port}-{Guid.NewGuid()}");
|
||||
client.Agent.ServiceRegister(new AgentServiceRegistration()
|
||||
{
|
||||
ID = $"{consulRegisterOption.IP}-{consulRegisterOption.Port}-{Guid.NewGuid()}",//唯一Id
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Core;
|
||||
|
||||
namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
public static IServiceCollection AddJwtService(this IServiceCollection services)
|
||||
{
|
||||
services.Configure<JWTTokenOptions>(Appsettings.appConfiguration("JwtAuthorize"));
|
||||
|
||||
services.AddTransient<JwtInvoker>();
|
||||
var jwtOptions = Appsettings.app<JWTTokenOptions>("JwtAuthorize");
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
|
||||
@@ -11,7 +11,10 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Job;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore.Utility;
|
||||
using Module = Autofac.Module;
|
||||
|
||||
@@ -38,16 +41,16 @@ namespace Yi.Framework.WebCore.Utility
|
||||
|
||||
containerBuilder.RegisterType< HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
|
||||
|
||||
|
||||
|
||||
containerBuilder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
|
||||
containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerLifetimeScope();
|
||||
///反射注入服务层及接口层
|
||||
var assemblysServices = GetDll( "Yi.Framework.Service.dll");
|
||||
containerBuilder.RegisterAssemblyTypes(assemblysServices)
|
||||
.AsImplementedInterfaces()
|
||||
.InstancePerDependency()
|
||||
.InstancePerLifetimeScope()
|
||||
.EnableInterfaceInterceptors();
|
||||
|
||||
///反射注册任务调度层
|
||||
///反射注册任务调度层
|
||||
var assemblysJob = GetDll("Yi.Framework.Job.dll");
|
||||
containerBuilder.RegisterAssemblyTypes(assemblysJob)
|
||||
.InstancePerDependency();
|
||||
|
||||
@@ -35,7 +35,10 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.DTOModel\Yi.Framework.DTOModel.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Service\Yi.Framework.Service.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user