From feb73174ebdae238269d12aeac9f8b3defe8fdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Fri, 8 Apr 2022 23:44:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=A7=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebFirst/database/sqlite.db | Bin 135168 -> 135168 bytes .../Config/SwaggerDoc.xml | 13 +---- .../Controllers/AccountController.cs | 9 ++- .../BaseController/BaseCrudController.cs | 40 +++++++------- .../Yi.Framework.ApiMicroservice/Program.cs | 2 +- .../appsettings.json | 12 ++-- .../IOCOptions/JWTTokenOptions.cs | 2 - .../Yi.Framework.Core.csproj | 18 ------ .../Yi.Framework.Interface/IBaseService.cs | 15 +++++ .../IServiceTemplate/ITenantService.cs | 2 +- .../IServiceTemplate/IUserService.cs | 2 +- .../Models/BaseModel/BaseModelEntity.cs | 10 ---- .../Yi.Framework.Model/Models/TenantEntity.cs | 34 ++---------- .../Yi.Framework.Model/Models/UserEntity.cs | 30 ---------- .../Query/QueryCondition.cs | 11 +++- .../Query/QueryParameter.cs | 11 ++-- .../Yi.Framework.Repository/IRepository.cs | 4 +- .../Yi.Framework.Repository/Repository.cs | 52 ++++++++++++++---- .../Yi.Framework.Service/BaseService.cs | 20 +++++++ .../ServiceTemplate/TenantService.cs | 4 +- .../ServiceTemplate/UserService.cs | 4 +- .../Yi.Framework.Service/UserService.cs | 6 +- .../MiddlewareExtend/ConsulRegiterExtend.cs | 2 + .../MiddlewareExtend/JwtExtension.cs | 3 +- .../Utility/CustomAutofacModule.cs | 11 ++-- .../Yi.Framework.WebCore.csproj | 3 + 26 files changed, 160 insertions(+), 160 deletions(-) create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index ee5ce8b1b3f0011ac8e5d7095dde24a605857d8c..6d4d8bbfa82a5a068ce4b148d88c313b6a75e382 100644 GIT binary patch delta 524 zcmZozz|pXPV}i8c7X}6fMIeTOu!%axj9)e;nCLT3-aJ)5$AB9s!^Eo2z^cxtwb@aC zlV!7LiV!2`BnC!qhCt3mm6KYfH>;<)GYVKaB^Iap=BK3QxaO5)mQ-%$@rq~CRZ#HB zEH1GrE-A{)OSe&H`%O}S6(6n5i_+iveYv)Fg7qZHkthKnOgJBN84{c pV$_yp_F$Sbm7S@diD?cn{#clp4O@k$-)3bpV6@tPfr-h07XS!wi%9?g delta 511 zcmZozz|pXPV}i8cYX$}eMIeTOpou!hjITE)nCLT3+B{W1$AFtpl!1wjnSqU&PiwQI z04K|4(G(%Z$-4RSlN0Kt>Up`UdASsT2nh7`pYEOfw6pj5#@$c1Z+gDF|M~9a&pP)% z+0~{HlvAG1@c6LHcg(%Pks;}kcs(rF!*3+(qMg~Skx(3F&MurN8CRPT9 zRwkBuMh2!6_!+qw0y*c4Z#GCxVw}uauQfTKo~>R(6Ji<2>D5p#fY=~Vl95@g=b2*b zUYePr=a*UzqBS(F5gHJRid|B3QcF@(Y||2Ric_&EaV| - - - jb - - - - 主键查询 @@ -24,13 +17,13 @@ - + 列表查询 - + 条件分页查询 @@ -51,7 +44,7 @@ - + 列表删除 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index e05677f1..365c5339 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -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 logger, IUserService iUserService) + private JwtInvoker _jwtInvoker; + public AccountController(ILogger 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("登录失败!用户名或者密码错误!"); } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs index 1fcfb87c..d48ebbdf 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs @@ -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 /// [ApiController] [Route("api/[controller]/[action]")] - public class BaseCrudController : ControllerBase where T : class,new() + public class BaseCrudController : ControllerBase where T : BaseModelEntity,new() { - private readonly ILogger _logger; - public IRepository _iRepository; - /// - /// jb - /// - /// - /// - public BaseCrudController(ILogger logger, IRepository iRepository) + public readonly ILogger _logger; + public IBaseService _baseService; + public IRepository _repository; + + public BaseCrudController(ILogger logger, IBaseService iBaseService) { _logger = logger; - _iRepository = iRepository; + _baseService = iBaseService; + _repository = iBaseService._repository; } /// @@ -36,7 +36,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpGet] public async Task Get(object id) { - return Result.Success().SetData(await _iRepository.GetByIdAsync(id)); + return Result.Success().SetData(await _repository.GetByIdAsync(id)); } /// @@ -44,10 +44,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [Permission($"{nameof(T)}:get:list")] - [HttpGet] - public async Task GetList() + [HttpPost] + public async Task GetList(QueryCondition queryCondition) { - return Result.Success().SetData(await _iRepository.GetListAsync()); + return Result.Success().SetData(await _repository.GetListAsync(queryCondition)); } /// @@ -57,9 +57,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [Permission($"{nameof(T)}:get:page")] [HttpPost] - public async Task Page(QueryCondition queryCondition) + public async Task Page(QueryPageCondition queryCondition) { - return Result.Success().SetData(await _iRepository.CommonPage(queryCondition)); + return Result.Success().SetData(await _repository.CommonPage(queryCondition)); } /// @@ -71,7 +71,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task Add(T entity) { - return Result.Success().SetData(await _iRepository.InsertReturnEntityAsync(entity)); + return Result.Success().SetData(await _repository.InsertReturnEntityAsync(entity)); } /// @@ -83,7 +83,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPut] public async Task Update(T entity) { - return Result.Success().SetStatus(await _iRepository.UpdateAsync(entity)); + return Result.Success().SetStatus(await _repository.UpdateAsync(entity)); } /// @@ -93,9 +93,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// [Permission($"{nameof(T)}:delete:list")] [HttpDelete] - public async Task DeleteList(object[] ids) + public async Task DeleteList(List ids) { - return Result.Success().SetStatus(await _iRepository.DeleteByIdsAsync(ids)); + return Result.Success().SetStatus(await _repository.DeleteByLogic(ids)); } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs index e84864cb..3a2c3c7f 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs @@ -127,7 +127,7 @@ ServiceLocator.Instance = app.Services; #region //ץȡע #endregion -app.UseErrorHandlingService(); +//app.UseErrorHandlingService(); #region //̬ļע #endregion diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json index c7ae2d34..24a90649 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json @@ -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]", diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs index 8c4601c4..5f4388b8 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs @@ -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; } diff --git a/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj index c8f401f9..fc9dce43 100644 --- a/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework.Net6/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -23,22 +23,4 @@ - - - Library\Microsoft.Bcl.AsyncInterfaces.dll - - - Library\ServiceStack.Common.dll - - - Library\ServiceStack.Interfaces.dll - - - Library\ServiceStack.Redis.dll - - - Library\ServiceStack.Text.dll - - - diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs new file mode 100644 index 00000000..3f26d296 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IBaseService.cs @@ -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 where T:BaseModelEntity,new() + { + public IRepository _repository { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs index d0e94463..31f8a4a9 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs @@ -3,7 +3,7 @@ using Yi.Framework.Repository; namespace Yi.Framework.Interface { - public partial interface ITenantService: IRepository + public partial interface ITenantService:IBaseService { } } diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserService.cs index 2d1b9210..9d12e09a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/IUserService.cs @@ -3,7 +3,7 @@ using Yi.Framework.Repository; namespace Yi.Framework.Interface { - public partial interface IUserService: IRepository + public partial interface IUserService:IBaseService { } } diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs index f2eb7432..eb7b55db 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs @@ -41,16 +41,6 @@ namespace Yi.Framework.Model.Models [SugarColumn(ColumnName = "ModifyTime")] public DateTime? ModifyTime { get; set; } /// - /// 删除者 - /// - [SugarColumn(ColumnName = "DeleteUser")] - public Guid? DeleteUser { get; set; } - /// - /// 删除时间 - /// - [SugarColumn(ColumnName = "DeleteTime")] - public DateTime? DeleteTime { get; set; } - /// /// 是否删除 /// [SugarColumn(ColumnName = "IsDeleted")] diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs index 820d901d..8da9ff39 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs @@ -8,38 +8,12 @@ namespace Yi.Framework.Model.Models /// 租户表 /// [SugarTable("Tenant")] - public partial class TenantEntity + public partial class TenantEntity:BaseModelEntity { - public TenantEntity() - { - this.Id=Guid.NewGuid(); - this.IsDeleted=false; - this.CreateTime = DateTime.Now; - } /// - /// 1 + /// 租户名 /// - [SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )] - public Guid Id { get; set; } - /// - /// 创建者 - /// - [SugarColumn(ColumnName="CreateUser" )] - public Guid? CreateUser { get; set; } - /// - /// 创建时间 - /// - [SugarColumn(ColumnName="CreateTime" )] - public DateTime? CreateTime { get; set; } - /// - /// 修改时间 - /// - [SugarColumn(ColumnName="ModifyTime" )] - public DateTime? ModifyTime { get; set; } - /// - /// 是否删除 - /// - [SugarColumn(ColumnName="IsDeleted" )] - public bool? IsDeleted { get; set; } + [SugarColumn(ColumnName="TenantName" )] + public string TenantName { get; set; } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs index 80b3bd81..f79d8aea 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs @@ -11,11 +11,6 @@ namespace Yi.Framework.Model.Models public partial class UserEntity:BaseModelEntity { /// - /// 1 - /// - [SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )] - public Guid Id { get; set; } - /// /// 姓名 /// [SugarColumn(ColumnName="Name" )] @@ -26,31 +21,6 @@ namespace Yi.Framework.Model.Models [SugarColumn(ColumnName="Age" )] public int? Age { get; set; } /// - /// 创建者 - /// - [SugarColumn(ColumnName="CreateUser" )] - public Guid? CreateUser { get; set; } - /// - /// 创建时间 - /// - [SugarColumn(ColumnName="CreateTime" )] - public DateTime? CreateTime { get; set; } - /// - /// 修改者 - /// - [SugarColumn(ColumnName="ModifyUser" )] - public Guid? ModifyUser { get; set; } - /// - /// 修改时间 - /// - [SugarColumn(ColumnName="ModifyTime" )] - public DateTime? ModifyTime { get; set; } - /// - /// 是否删除 - /// - [SugarColumn(ColumnName="IsDeleted" )] - public bool? IsDeleted { get; set; } - /// /// 租户Id /// [SugarColumn(ColumnName="TenantId" )] diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryCondition.cs b/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryCondition.cs index e3875eac..08c6a33d 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryCondition.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryCondition.cs @@ -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 Parameters { get; set; } = new List(); + public List OrderBys { get; set; } = new List(); + + } + + public class QueryCondition + { public List Parameters { get; set; } = new List(); public List OrderBys { get; set; } = new List(); diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryParameter.cs b/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryParameter.cs index e46520c1..330902c4 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryParameter.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/Query/QueryParameter.cs @@ -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; } } diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs index c7eeabac..273954e9 100644 --- a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs +++ b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs @@ -15,6 +15,8 @@ namespace Yi.Framework.Repository { public Task InsertReturnEntityAsync(T entity); public Task> StoreAsync(string storeName, object para); - public Task>> CommonPage(QueryCondition pars); + public Task>> CommonPage(QueryPageCondition pars); + public Task> GetListAsync(QueryCondition pars); + public Task DeleteByLogic(List ids); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs index 93c4da66..b9846506 100644 --- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs +++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs @@ -34,6 +34,18 @@ namespace Yi.Framework.Repository return await Db.Insertable(entity).ExecuteReturnEntityAsync(); } + /// + /// 逻辑多删除 + /// + /// + public async Task DeleteByLogic(List ids) + { + var entitys = await Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync(); + entitys.ForEach(u=>u.IsDeleted=true); + return await Db.Updateable(entitys).ExecuteCommandAsync()>0; + } + + /// /// 调用存储过程 /// @@ -46,18 +58,41 @@ namespace Yi.Framework.Repository return await Db.Ado.UseStoredProcedure().SqlQueryAsync(storeName, para); } + + /// + /// 多条件查询 + /// + /// + /// + public async Task> GetListAsync(QueryCondition pars) + { + return await QueryConditionHandler(pars).ToListAsync(); + } + /// /// 仓储扩展方法:单表查询通用分页 /// /// - public async Task>> CommonPage(QueryCondition pars) + public async Task>> CommonPage(QueryPageCondition pars) { RefAsync tolCount = 0; + var result = await QueryConditionHandler(new QueryCondition() {OrderBys=pars.OrderBys,Parameters=pars.Parameters } ).ToPageListAsync(pars.Index, pars.Size, tolCount); + return new PageModel> + { + Total = tolCount.Value, + Data = result + }; + } + + + + private ISugarQueryable 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(); 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> - { - Total = tolCount.Value, - Data = result - }; + return query.Where(sugarParamters); } + } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs b/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs new file mode 100644 index 00000000..43fff21c --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/BaseService.cs @@ -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:IBaseService where T:BaseModelEntity,new() + { + public IRepository _repository { get; set; } + public BaseService(IRepository iRepository) + { + _repository = iRepository; + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs index b401891e..6093f532 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs @@ -5,9 +5,9 @@ using Yi.Framework.Repository; namespace Yi.Framework.Service { - public partial class TenantService : Repository, ITenantService + public partial class TenantService : BaseService, ITenantService { - public TenantService(ISqlSugarClient context) : base(context) + public TenantService(IRepository repository) : base(repository) { } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserService.cs index a44353d3..964a76dd 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/UserService.cs @@ -5,9 +5,9 @@ using Yi.Framework.Repository; namespace Yi.Framework.Service { - public partial class UserService : Repository, IUserService + public partial class UserService : BaseService, IUserService { - public UserService(ISqlSugarClient context) : base(context) + public UserService(IRepository repository) : base(repository) { } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs index 54bd1352..35a22f68 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs @@ -12,7 +12,7 @@ namespace Yi.Framework.Service { public async Task Exist(Guid id, Action 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 Exist(string userName, Action 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; diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/ConsulRegiterExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/ConsulRegiterExtend.cs index 7c8ab310..9eeca35e 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/ConsulRegiterExtend.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/ConsulRegiterExtend.cs @@ -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 diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs index 08e2fb92..a09163d1 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs @@ -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(Appsettings.appConfiguration("JwtAuthorize")); - + services.AddTransient(); var jwtOptions = Appsettings.app("JwtAuthorize"); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs index 26777668..e83a0a99 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs @@ -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().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(); diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj b/Yi.Framework.Net6/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj index bc373a9f..27308c25 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj @@ -35,7 +35,10 @@ + + +