From 53b594a36a5d72f74eaac7ce2c2f25f7f1e8a900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 15 Apr 2024 20:14:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=E5=8D=87=E7=BA=A7=E5=89=8D=E7=AB=AFel?= =?UTF-8?q?ement=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.RuoYi.Vue3/src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yi.RuoYi.Vue3/src/main.js b/Yi.RuoYi.Vue3/src/main.js index 3d609987..b9e29598 100644 --- a/Yi.RuoYi.Vue3/src/main.js +++ b/Yi.RuoYi.Vue3/src/main.js @@ -3,7 +3,7 @@ import { createApp } from 'vue' import Cookies from 'js-cookie' import ElementPlus from 'element-plus' -import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言 +import locale from "element-plus/dist/locale/zh-cn.mjs"; // 中文语言 import '@/assets/styles/index.scss' // global css From 777aa64153d4954c4e829bb60ad8003834512525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Fri, 26 Apr 2024 19:09:11 +0800 Subject: [PATCH 2/5] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit ae30d4b2cb4be329cac553c180e10dfbcbdef934 Author: 陈淳 <454313500@qq.com> Date: Fri Apr 26 19:08:18 2024 +0800 fix: 修复值对象查询导致问题,已同步sqlsugar更新 commit 4c12626b441607dc2b852fb052514de9cbad7e22 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:15:57 2024 +0800 feat: 添加值对象 commit d389dcbedf93fff9816fa776a82f18ab69bd351b Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:06:09 2024 +0800 feat: 添加值对象 commit 58ff8f45cfa3bf36feb3d4f3063e834a4f647d14 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:54:25 2024 +0800 feat: 去除新增的缓存操作 commit 826271c84d532be9ea820c295a0f033d4e22b129 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:39:41 2024 +0800 feat: 添加缓存crud --- .../YiCacheCrudAppService.cs | 119 ++++++++++++++++++ .../Services/DictionaryTypeService.cs | 3 +- .../Services/System/UserService.cs | 39 ++++-- .../Entities/UserEntity.cs | 39 +++--- .../ValueObjects/EncryPasswordValueObject.cs | 31 +++++ .../Managers/AccountManager.cs | 6 +- .../Managers/UserManager.cs | 50 ++++---- .../DataSeeds/UserDataSeed.cs | 7 +- Yi.Abp.Net8/version.props | 2 +- 9 files changed, 236 insertions(+), 60 deletions(-) create mode 100644 Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCacheCrudAppService.cs create mode 100644 Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/ValueObjects/EncryPasswordValueObject.cs diff --git a/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCacheCrudAppService.cs b/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCacheCrudAppService.cs new file mode 100644 index 00000000..d10cdd82 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCacheCrudAppService.cs @@ -0,0 +1,119 @@ +using Volo.Abp.Application.Dtos; +using Volo.Abp.Caching; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.MultiTenancy; + +namespace Yi.Framework.Ddd.Application +{ + public abstract class YiCacheCrudAppService : YiCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected YiCacheCrudAppService(IRepository repository) : base(repository) + { + } + } + + public abstract class YiCacheCrudAppService + : YiCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected YiCacheCrudAppService(IRepository repository) : base(repository) + { + } + } + + + public abstract class YiCacheCrudAppService + : YiCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected YiCacheCrudAppService(IRepository repository) : base(repository) + { + } + } + + public abstract class YiCacheCrudAppService + : YiCrudAppService + where TEntity : class, IEntity + where TEntityDto : IEntityDto + { + protected YiCacheCrudAppService(IRepository repository) : base(repository) + { + } + } + + + public abstract class YiCacheCrudAppService + : YiCrudAppService + where TEntity : class, IEntity + where TGetOutputDto : IEntityDto + where TGetListOutputDto : IEntityDto + { + protected IDistributedCache Cache => LazyServiceProvider.LazyGetRequiredService>(); + + protected string GetCacheKey(TKey id) => typeof(TEntity).Name + ":" + CurrentTenant.Id ?? Guid.Empty + ":" + id.ToString(); + protected YiCacheCrudAppService(IRepository repository) : base(repository) + { + } + + public override async Task UpdateAsync(TKey id, TUpdateInput input) + { + var output = await base.UpdateAsync(id, input); + await Cache.RemoveAsync(GetCacheKey(id)); + return output; + } + + public override async Task> GetListAsync(TGetListInput input) + { + //两种方式: + //1:全表缓存,使用缓存直接查询 + //2:非全部缓存,查询到的数据直接添加到缓存 + + //判断是否该实体为全表缓存 + throw new NotImplementedException(); + + //IDistributedCache 有局限性,条件查询无法进行缓存了 + //if (true) + //{ + // return await GetListByCacheAsync(input); + //} + //else + //{ + // return await GetListByDbAsync(input); + //} + + } + + protected virtual async Task> GetListByDbAsync(TGetListInput input) + { + //如果不是全表缓存,可以走这个啦 + throw new NotImplementedException(); + } + protected virtual async Task> GetListByCacheAsync(TGetListInput input) + { + //如果是全表缓存,可以走这个啦 + throw new NotImplementedException(); + } + + + protected override async Task GetEntityByIdAsync(TKey id) + { + var output = await Cache.GetOrAddAsync(GetCacheKey(id), async () => await base.GetEntityByIdAsync(id)); + return output!; + } + + public override async Task DeleteAsync(IEnumerable id) + { + await base.DeleteAsync(id); + foreach (var itemId in id) + { + await Cache.RemoveAsync(GetCacheKey(itemId)); + } + + } + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/DictionaryTypeService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/DictionaryTypeService.cs index ce3ca28f..441e1793 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/DictionaryTypeService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/DictionaryTypeService.cs @@ -1,5 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; using SqlSugar; using Volo.Abp.Application.Dtos; +using Volo.Abp.Caching; using Yi.Framework.Ddd.Application; using Yi.Framework.Rbac.Application.Contracts.Dtos.DictionaryType; using Yi.Framework.Rbac.Application.Contracts.IServices; @@ -36,6 +38,5 @@ namespace Yi.Framework.Rbac.Application.Services Items = await MapToGetListOutputDtosAsync(entities) }; } - } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs index ca822d31..79d2a473 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs @@ -3,6 +3,7 @@ using SqlSugar; using TencentCloud.Tcr.V20190924.Models; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.Caching; using Volo.Abp.EventBus.Local; using Volo.Abp.Users; using Yi.Framework.Ddd.Application; @@ -12,6 +13,7 @@ using Yi.Framework.Rbac.Domain.Authorization; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.Rbac.Domain.Managers; using Yi.Framework.Rbac.Domain.Repositories; +using Yi.Framework.Rbac.Domain.Shared.Caches; using Yi.Framework.Rbac.Domain.Shared.Consts; using Yi.Framework.Rbac.Domain.Shared.Etos; using Yi.Framework.Rbac.Domain.Shared.OperLog; @@ -25,10 +27,11 @@ namespace Yi.Framework.Rbac.Application.Services.System public class UserService : YiCrudAppService,IUserService //IUserService { - public UserService(ISqlSugarRepository repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus) : base(repository) + private IDistributedCache _userCache; + public UserService(ISqlSugarRepository repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus, IDistributedCache userCache) : base(repository) => - (_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus) = - (userManager, userRepository, currentUser, deptService, repository, localEventBus); + (_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus, _userCache) = + (userManager, userRepository, currentUser, deptService, repository, localEventBus, userCache); private UserManager _userManager { get; set; } private ISqlSugarRepository _repository; private IUserRepository _userRepository { get; set; } @@ -77,6 +80,14 @@ namespace Yi.Framework.Rbac.Application.Services.System return result; } + + protected override UserEntity MapToEntity(UserCreateInputVo createInput) + { + var output= base.MapToEntity(createInput); + output.EncryPassword = new Domain.Entities.ValueObjects.EncryPasswordValueObject(createInput.Password); + return output; + } + /// /// 添加用户 /// @@ -99,13 +110,13 @@ namespace Yi.Framework.Rbac.Application.Services.System { throw new UserFriendlyException(UserConst.User_Exist); } - var entities = await MapToEntityAsync(input); - - entities.BuildPassword(); + var entitiy = await MapToEntityAsync(input); + + entitiy.BuildPassword(); //using (var uow = _unitOfWorkManager.CreateContext()) //{ - var returnEntity = await _repository.InsertReturnEntityAsync(entities); + var returnEntity = await _repository.InsertReturnEntityAsync(entitiy); await _userManager.GiveUserSetRoleAsync(new List { returnEntity.Id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { returnEntity.Id }, input.PostIds); //uow.Commit(); @@ -152,17 +163,17 @@ namespace Yi.Framework.Rbac.Application.Services.System //更新密码,特殊处理 if (input.Password is not null) { - entity.Password = input.Password; + entity.EncryPassword.Password = input.Password; entity.BuildPassword(); } await MapToEntityAsync(input, entity); - //using (var uow = _unitOfWorkManager.CreateContext()) - //{ + var res1 = await _repository.UpdateAsync(entity); await _userManager.GiveUserSetRoleAsync(new List { id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { id }, input.PostIds); - // uow.Commit(); - //} + + await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId())); + return await MapToGetOutputDtoAsync(entity); } @@ -179,6 +190,7 @@ namespace Yi.Framework.Rbac.Application.Services.System await _repository.UpdateAsync(entity); var dto = await MapToGetOutputDtoAsync(entity); + await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId())); return dto; } @@ -200,13 +212,16 @@ namespace Yi.Framework.Rbac.Application.Services.System } entity.State = state; await _repository.UpdateAsync(entity); + await _userCache.RefreshAsync(new UserInfoCacheKey(id)); return await MapToGetOutputDtoAsync(entity); } [OperLog("删除用户", OperEnum.Delete)] [Permission("system:user:delete")] public override async Task DeleteAsync(Guid id) { + await base.DeleteAsync(id); + await _userCache.RefreshAsync(new UserInfoCacheKey(id)); } [Permission("system:user:export")] diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/UserEntity.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/UserEntity.cs index 4925273f..12865286 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/UserEntity.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/UserEntity.cs @@ -4,6 +4,7 @@ using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; using Yi.Framework.Core.Data; using Yi.Framework.Core.Helper; +using Yi.Framework.Rbac.Domain.Entities.ValueObjects; using Yi.Framework.Rbac.Domain.Shared.Enums; namespace Yi.Framework.Rbac.Domain.Entities @@ -22,7 +23,7 @@ namespace Yi.Framework.Rbac.Domain.Entities public UserEntity(string userName, string password, long phone, string nick = "萌新") { UserName = userName; - Password = password; + EncryPassword.Password = password; Phone = phone; Nick = nick; BuildPassword(); @@ -55,14 +56,20 @@ namespace Yi.Framework.Rbac.Domain.Entities public string UserName { get; set; } = string.Empty; /// - /// 密码 + /// 加密密码 /// - public string Password { get; set; } = string.Empty; + [SugarColumn(IsOwnsOne = true)] + public EncryPasswordValueObject EncryPassword { get; set; } = new EncryPasswordValueObject(); - /// - /// 加密盐值 - /// - public string Salt { get; set; } = string.Empty; + ///// + ///// 密码 + ///// + //public string Password { get; set; } = string.Empty; + + ///// + ///// 加密盐值 + ///// + //public string Salt { get; set; } = string.Empty; /// /// 头像 @@ -175,14 +182,14 @@ namespace Yi.Framework.Rbac.Domain.Entities //如果不传值,那就把自己的password当作传进来的password if (password == null) { - if (Password == null) + if (EncryPassword?.Password == null) { - throw new ArgumentNullException(nameof(Password)); + throw new ArgumentNullException(nameof(EncryPassword.Password)); } - password = Password; + password = EncryPassword.Password; } - Salt = MD5Helper.GenerateSalt(); - Password = MD5Helper.SHA2Encode(password, Salt); + EncryPassword.Salt = MD5Helper.GenerateSalt(); + EncryPassword.Password = MD5Helper.SHA2Encode(password, EncryPassword.Salt); return this; } @@ -193,12 +200,12 @@ namespace Yi.Framework.Rbac.Domain.Entities /// public bool JudgePassword(string password) { - if (Salt is null) + if (EncryPassword.Salt is null) { - throw new ArgumentNullException(Salt); + throw new ArgumentNullException(EncryPassword.Salt); } - var p = MD5Helper.SHA2Encode(password, Salt); - if (Password == MD5Helper.SHA2Encode(password, Salt)) + var p = MD5Helper.SHA2Encode(password, EncryPassword.Salt); + if (EncryPassword.Password == MD5Helper.SHA2Encode(password, EncryPassword.Salt)) { return true; } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/ValueObjects/EncryPasswordValueObject.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/ValueObjects/EncryPasswordValueObject.cs new file mode 100644 index 00000000..6b825434 --- /dev/null +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Entities/ValueObjects/EncryPasswordValueObject.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Values; + +namespace Yi.Framework.Rbac.Domain.Entities.ValueObjects +{ + public class EncryPasswordValueObject : ValueObject + { + public EncryPasswordValueObject() { } + public EncryPasswordValueObject(string password) { this.Password = password; } + + /// + /// 密码 + /// + public string Password { get; set; } = string.Empty; + + /// + /// 加密盐值 + /// + public string Salt { get; set; } = string.Empty; + + protected override IEnumerable GetAtomicValues() + { + yield return Password; + yield return Salt; + } + } +} diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs index 8a460e31..b326282e 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs @@ -154,7 +154,7 @@ namespace Yi.Framework.Rbac.Domain.Managers { userAction.Invoke(user); } - if (user.Password == MD5Helper.SHA2Encode(password, user.Salt)) + if (user.EncryPassword.Password == MD5Helper.SHA2Encode(password, user.EncryPassword.Salt)) { return; } @@ -247,7 +247,7 @@ namespace Yi.Framework.Rbac.Domain.Managers { throw new UserFriendlyException("无效更新!原密码错误!"); } - user.Password = newPassword; + user.EncryPassword.Password = newPassword; user.BuildPassword(); await _repository.UpdateAsync(user); } @@ -262,7 +262,7 @@ namespace Yi.Framework.Rbac.Domain.Managers { var user = await _repository.GetByIdAsync(userId); // EntityHelper.TrySetId(user, () => GuidGenerator.Create(), true); - user.Password = password; + user.EncryPassword.Password = password; user.BuildPassword(); return await _repository.UpdateAsync(user); } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/UserManager.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/UserManager.cs index 7c5edc0f..dcc906b6 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/UserManager.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/UserManager.cs @@ -95,42 +95,26 @@ namespace Yi.Framework.Rbac.Domain.Managers /// public async Task GetInfoAsync(Guid userId) { - var user = await _userRepository.GetUserAllInfoAsync(userId); - var output = await GetInfoByCacheAsync(user); + + var output = await GetInfoByCacheAsync(userId); return output; } - - /// - /// 批量查询用户信息 - /// - /// - /// - public async Task> GetInfoListAsync(List userIds) - { - List output = new List(); - var users = await _userRepository.GetListUserAllInfoAsync(userIds); - foreach (var user in users) - { - output.Add(await GetInfoByCacheAsync(user)); - } - return output; - } - - private async Task GetInfoByCacheAsync(UserEntity user) + private async Task GetInfoByCacheAsync(Guid userId) { //此处优先从缓存中获取 UserRoleMenuDto output = null; var tokenExpiresMinuteTime = LazyServiceProvider.GetRequiredService>().Value.ExpiresMinuteTime; - var cacheData = await _userCache.GetOrAddAsync(new UserInfoCacheKey(user.Id), + var cacheData = await _userCache.GetOrAddAsync(new UserInfoCacheKey(userId), async () => { + var user = await _userRepository.GetUserAllInfoAsync(userId); var data = EntityMapToDto(user); //系统用户数据被重置,老前端访问重新授权 if (data is null) { throw new AbpAuthorizationException(); } - data.Menus.Clear(); + //data.Menus.Clear(); output = data; return new UserInfoCacheItem(data); }, @@ -143,6 +127,24 @@ namespace Yi.Framework.Rbac.Domain.Managers return output!; } + + /// + /// 批量查询用户信息 + /// + /// + /// + public async Task> GetInfoListAsync(List userIds) + { + List output = new List(); + foreach (var userId in userIds) + { + output.Add(await GetInfoByCacheAsync(userId)); + } + return output; + } + + + private UserRoleMenuDto EntityMapToDto(UserEntity user) { @@ -152,8 +154,8 @@ namespace Yi.Framework.Rbac.Domain.Managers //{ // throw new UserFriendlyException($"数据错误,用户id:{nameof(userId)} 不存在,请重新登录"); //} - user.Password = string.Empty; - user.Salt = string.Empty; + user.EncryPassword.Password = string.Empty; + user.EncryPassword.Salt = string.Empty; //超级管理员特殊处理 if (UserConst.Admin.Equals(user.UserName)) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/UserDataSeed.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/UserDataSeed.cs index 2183e868..963621b0 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/UserDataSeed.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/DataSeeds/UserDataSeed.cs @@ -2,6 +2,7 @@ using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Yi.Framework.Rbac.Domain.Entities; +using Yi.Framework.Rbac.Domain.Entities.ValueObjects; using Yi.Framework.Rbac.Domain.Shared.Enums; using Yi.Framework.Rbac.Domain.Shared.Options; using Yi.Framework.SqlSugarCore.Abstractions; @@ -27,7 +28,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds Name = "大橙子", UserName = "cc", Nick = "橙子", - Password = _options.AdminPassword, + EncryPassword = new EncryPasswordValueObject(_options.AdminPassword), Email = "454313500@qq.com", Phone = 13800000000, Sex = SexEnum.Male, @@ -47,7 +48,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds Name = "大测试", UserName = "test", Nick = "测试", - Password = "123456", + EncryPassword=new EncryPasswordValueObject("123456"), Email = "454313500@qq.com", Phone = 15900000000, Sex = SexEnum.Woman, @@ -68,7 +69,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds Name = "游客", UserName = "guest", Nick = "测试", - Password = "123456", + EncryPassword = new EncryPasswordValueObject("123456"), Email = "454313500@qq.com", Phone = 15900000000, Sex = SexEnum.Woman, diff --git a/Yi.Abp.Net8/version.props b/Yi.Abp.Net8/version.props index 1cfda791..7a7a259e 100644 --- a/Yi.Abp.Net8/version.props +++ b/Yi.Abp.Net8/version.props @@ -1,6 +1,6 @@ 8.0.5 - 5.1.4.149 + 5.1.4.154-preview01 \ No newline at end of file From 1f4f98b513125cad2b73150b09dd20a4a334d918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Sun, 28 Apr 2024 11:37:51 +0800 Subject: [PATCH 3/5] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 8c343fb01fe38b4018f9f6a42333dee41ed01bac Author: 陈淳 <454313500@qq.com> Date: Sun Apr 28 11:36:48 2024 +0800 style: 修复股票api过期问题 commit ae30d4b2cb4be329cac553c180e10dfbcbdef934 Author: 陈淳 <454313500@qq.com> Date: Fri Apr 26 19:08:18 2024 +0800 fix: 修复值对象查询导致问题,已同步sqlsugar更新 commit 4c12626b441607dc2b852fb052514de9cbad7e22 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:15:57 2024 +0800 feat: 添加值对象 commit d389dcbedf93fff9816fa776a82f18ab69bd351b Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:06:09 2024 +0800 feat: 添加值对象 commit 58ff8f45cfa3bf36feb3d4f3063e834a4f647d14 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:54:25 2024 +0800 feat: 去除新增的缓存操作 commit 826271c84d532be9ea820c295a0f033d4e22b129 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:39:41 2024 +0800 feat: 添加缓存crud --- .../Managers/BankValue/BiyingBankValueProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BankValue/BiyingBankValueProvider.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BankValue/BiyingBankValueProvider.cs index f6354733..cd0b5af2 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BankValue/BiyingBankValueProvider.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BankValue/BiyingBankValueProvider.cs @@ -11,7 +11,8 @@ namespace Yi.Framework.Bbs.Domain.Managers.BankValue { public class BiyingBankValueProvider : IBankValueProvider, ITransientDependency { - private const string Url = "https://api.biyingapi.com/hsrl/ssjy/600519/006566735102404165"; + //官网地址:www.biyingapi.com + private const string Url = "https://api.biyingapi.com/hsrl/ssjy/600519/5579aa4b391945678"; public async Task GetValueAsync() { try From 643b284e270e7b1eb3e486f165107af015fd14b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Sun, 28 Apr 2024 11:45:56 +0800 Subject: [PATCH 4/5] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 368b4fcfd45c637d5d7f65f0e905c9a9220fd93f Author: 陈淳 <454313500@qq.com> Date: Sun Apr 28 11:45:13 2024 +0800 feat: 完善禁止无权限用户登录 commit 8c343fb01fe38b4018f9f6a42333dee41ed01bac Author: 陈淳 <454313500@qq.com> Date: Sun Apr 28 11:36:48 2024 +0800 style: 修复股票api过期问题 commit ae30d4b2cb4be329cac553c180e10dfbcbdef934 Author: 陈淳 <454313500@qq.com> Date: Fri Apr 26 19:08:18 2024 +0800 fix: 修复值对象查询导致问题,已同步sqlsugar更新 commit 4c12626b441607dc2b852fb052514de9cbad7e22 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:15:57 2024 +0800 feat: 添加值对象 commit d389dcbedf93fff9816fa776a82f18ab69bd351b Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 18:06:09 2024 +0800 feat: 添加值对象 commit 58ff8f45cfa3bf36feb3d4f3063e834a4f647d14 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:54:25 2024 +0800 feat: 去除新增的缓存操作 commit 826271c84d532be9ea820c295a0f033d4e22b129 Author: 陈淳 <454313500@qq.com> Date: Mon Apr 22 15:39:41 2024 +0800 feat: 添加缓存crud --- .../rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs index b326282e..0af828a7 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs @@ -79,6 +79,10 @@ namespace Yi.Framework.Rbac.Domain.Managers { throw new UserFriendlyException(UserConst.No_Role); } + if (userInfo.PermissionCodes.Count() ==0) + { + throw new UserFriendlyException(UserConst.No_Permission); + } //这里抛出一个登录的事件 if (_httpContextAccessor.HttpContext is not null) { From c21d1dd155eed45375a958e22f0378ebe26f62bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Sun, 28 Apr 2024 14:47:20 +0800 Subject: [PATCH 5/5] =?UTF-8?q?style:=20=E6=B7=BB=E5=8A=A0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/System/UserService.cs | 11 +-- Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs | 2 + .../Yi.Abp.Web/Properties/launchSettings.json | 4 +- .../src/Yi.Abp.Web/appsettings.Staging.json | 87 +++++++++++++++++++ 4 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs index 79d2a473..e640fca0 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/UserService.cs @@ -27,11 +27,10 @@ namespace Yi.Framework.Rbac.Application.Services.System public class UserService : YiCrudAppService,IUserService //IUserService { - private IDistributedCache _userCache; public UserService(ISqlSugarRepository repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus, IDistributedCache userCache) : base(repository) => - (_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus, _userCache) = - (userManager, userRepository, currentUser, deptService, repository, localEventBus, userCache); + (_userManager, _userRepository, _currentUser, _deptService, _repository, _localEventBus) = + (userManager, userRepository, currentUser, deptService, repository, localEventBus); private UserManager _userManager { get; set; } private ISqlSugarRepository _repository; private IUserRepository _userRepository { get; set; } @@ -171,9 +170,6 @@ namespace Yi.Framework.Rbac.Application.Services.System var res1 = await _repository.UpdateAsync(entity); await _userManager.GiveUserSetRoleAsync(new List { id }, input.RoleIds); await _userManager.GiveUserSetPostAsync(new List { id }, input.PostIds); - - await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId())); - return await MapToGetOutputDtoAsync(entity); } @@ -190,7 +186,6 @@ namespace Yi.Framework.Rbac.Application.Services.System await _repository.UpdateAsync(entity); var dto = await MapToGetOutputDtoAsync(entity); - await _userCache.RefreshAsync(new UserInfoCacheKey(_currentUser.GetId())); return dto; } @@ -212,7 +207,6 @@ namespace Yi.Framework.Rbac.Application.Services.System } entity.State = state; await _repository.UpdateAsync(entity); - await _userCache.RefreshAsync(new UserInfoCacheKey(id)); return await MapToGetOutputDtoAsync(entity); } [OperLog("删除用户", OperEnum.Delete)] @@ -221,7 +215,6 @@ namespace Yi.Framework.Rbac.Application.Services.System { await base.DeleteAsync(id); - await _userCache.RefreshAsync(new UserInfoCacheKey(id)); } [Permission("system:user:export")] diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs index 1f0f2e2f..2d08d6d4 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs @@ -29,6 +29,8 @@ try Log.Information("Yi框架-Abp.vNext,启动!"); var builder = WebApplication.CreateBuilder(args); + Log.Information($"当前主机启动环境-【{builder.Environment.EnvironmentName}】"); + Log.Information($"当前主机启动地址-【{builder.Configuration["App:SelfUrl"]}】"); builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]); builder.Host.UseAutofac(); builder.Host.UseSerilog(); diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Properties/launchSettings.json b/Yi.Abp.Net8/src/Yi.Abp.Web/Properties/launchSettings.json index a6df1bb6..56770734 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/Properties/launchSettings.json +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Properties/launchSettings.json @@ -5,8 +5,8 @@ "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - //,"ASPNETCORE_ENVIRONMENT": "Staging" + //"ASPNETCORE_ENVIRONMENT": "Development" + ,"ASPNETCORE_ENVIRONMENT": "Staging" }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:19001" diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json b/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json new file mode 100644 index 00000000..05bb666b --- /dev/null +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Staging.json @@ -0,0 +1,87 @@ +{ + "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" ], + + "DbConnOptions": { + "Url": "DataSource=yi-abp-dev.db", + "DbType": "Sqlite", + "EnabledReadWrite": false, + "EnabledCodeFirst": true, + "EnabledSqlLog": true, + "EnabledDbSeed": true, + //SAAS多租户 + "EnabledSaasMultiTenancy": 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 + //] + }, + + //redis使用freeesql参数在“FreeSqlOptions的ConnectionStringBuilder中” + "Redis": { + "IsEnabled": false, + "Configuration": "127.0.0.1:6379,password=123,defaultDatabase=13" + }, + + //鉴权 + "JwtOptions": { + "Issuer": "https://ccnetcore.com", + "Audience": "https://ccnetcore.com", + "SecurityKey": "zqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69520", + "ExpiresMinuteTime": 86400 + }, + //刷新token + "RefreshJwtOptions": { + "Issuer": "https://yi.ccnetcore.com", + "Audience": "https://yi.ccnetcore.com", + "SecurityKey": "67ij4o6jo4i5j6io45j6i4j74p5k6i54ojoi5t9g8ergoj34ofgkrtbmreog894jbioemgropihj48rj4io5juopjgior", + "ExpiresMinuteTime": 172800 + }, + + + //第三方登录 + "OAuth": { + //QQ + "QQ": { + "ClientId": "", + "ClientSecret": "", + "RedirectUri": "" + }, + //码云 + "Gitee": { + "ClientId": "", + "ClientSecret": "", + "RedirectUri": "" + } + }, + + //Rbac模块 + "RbacOptions": { + //超级管理员种子数据默认密码 + "AdminPassword": "123456", + + //是否开启验证码验证 + "EnableCaptcha": true, + + //是否开启注册功能 + "EnableRegister": false, + + //开启定时数据库备份 + "EnableDataBaseBackup": false + } +}