From b9b96f1bfc402efaa4429a9e46ce72acd1491dc3 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 14 Jun 2024 10:17:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=94=A8=E6=88=B7=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=92=8C=E8=AE=BE=E5=A4=87ignoreTenant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DevicesConnectController.cs | 1 + .../Jobs/UpdateUserPasswordJob.cs | 98 +++++++++---------- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesConnectController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesConnectController.cs index d81ed9fa..4d83b350 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesConnectController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesConnectController.cs @@ -75,6 +75,7 @@ public class DevicesConnectController : ControllerBase /// /// [HttpGet("brand-devices")] + [IgnoreTenant] public async Task> GetDeviceUniqueInfoByBrandAsync( [Required(ErrorMessage = "请明确设备品牌")] string brand, [Required(ErrorMessage = "请明确厂区")] string factory) diff --git a/Src/Dlhis.ScheduledTask/Jobs/UpdateUserPasswordJob.cs b/Src/Dlhis.ScheduledTask/Jobs/UpdateUserPasswordJob.cs index 170e5a6e..1eead22f 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/UpdateUserPasswordJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/UpdateUserPasswordJob.cs @@ -19,71 +19,69 @@ public class UpdateUserPasswordJob : BaseJob protected override async Task RunAsync(IServiceProvider serviceProvider) { - var identityDbContext = DbContext.ChangeDb("identity"); var whitelist = new List() { "admin", "WB-0741", "WB-1091", "0123456" }; var users = await identityDbContext.Queryable() - .Where(x => !whitelist.Contains(x.UserName)) - .ToListAsync(); + .Where(x => !whitelist.Contains(x.UserName)) + .ToListAsync(); var gainfos = await DbContext.Queryable().Where(x => !whitelist.Contains(x.Code)).ToListAsync(); var hasher = new PasswordHasher(); foreach (var gainfo in gainfos) { - if (gainfo.IdNo.IsPresent()) + if (gainfo.IdNo.IsEmpty()) continue; + + try { - try - { - var password = gainfo.IdNo.TakeLast(6).Join(""); + var password = gainfo.IdNo.TakeLast(6).Join(""); - var user = users.FirstOrDefault(x => x.UserName == gainfo.Code); - if (user == null) - { - user = new UserEntity - { - UserName = gainfo.Code, - NormalizedUserName = gainfo.Code.ToUpper(), - ConcurrencyStamp = Guid.NewGuid().ToString(), - SecurityStamp = Guid.NewGuid().ToString(), - }; - password = hasher.HashPassword(user, password); - user.PasswordHash = password; + var user = users.FirstOrDefault(x => x.UserName == gainfo.Code); + if (user != null) continue; - var id = (int)await identityDbContext.InsertReturnIdentityAsync(user); - await AddUserClaim(identityDbContext, id, "jinko-code", gainfo.Code); - await AddUserClaim(identityDbContext, id, "name", gainfo.Name); - if (!string.IsNullOrEmpty(gainfo.Factory)) - { - var userTenant = await identityDbContext.Queryable().Where(x => x.UserId == user.Id).FirstAsync(); - if (userTenant == null) - { - userTenant = new UserTenantEntity - { - UserId = user.Id, - TenantCode = gainfo.Factory - }; - await identityDbContext.InsertAsync(userTenant); - } - else - { - userTenant.TenantCode = gainfo.Factory; - await identityDbContext.UpdateAsync(userTenant); - } - } - } - else - { - //password = hasher.HashPassword(user, password); - //user.PasswordHash = password; - //await identityDbContext.UpdateAsync(user); - } - } - catch (Exception) + user = new UserEntity { + UserName = gainfo.Code, + NormalizedUserName = gainfo.Code.ToUpper(), + ConcurrencyStamp = Guid.NewGuid().ToString(), + SecurityStamp = Guid.NewGuid().ToString(), + }; + password = hasher.HashPassword(user, password); + user.PasswordHash = password; + + var id = (int)await identityDbContext.InsertReturnIdentityAsync(user); + await AddUserClaim(identityDbContext, id, "jinko-code", gainfo.Code); + await AddUserClaim(identityDbContext, id, "name", gainfo.Name); + + if (string.IsNullOrEmpty(gainfo.Factory)) continue; + + var userTenant = await identityDbContext.Queryable().Where(x => x.UserId == user.Id).FirstAsync(); + if (userTenant == null) + { + userTenant = new UserTenantEntity + { + UserId = user.Id, + TenantCode = gainfo.Factory + }; + await identityDbContext.InsertAsync(userTenant); } + else + { + userTenant.TenantCode = gainfo.Factory; + await identityDbContext.UpdateAsync(userTenant); + } + // else + // { + // password = hasher.HashPassword(user, password); + // user.PasswordHash = password; + // await identityDbContext.UpdateAsync(user); + // } + } + catch (Exception) + { + //ignore } } } @@ -107,4 +105,4 @@ public class UpdateUserPasswordJob : BaseJob await dbContext.UpdateAsync(claim); } } -} +} \ No newline at end of file