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