fix 处理已知问题
This commit is contained in:
@@ -107,7 +107,7 @@ public class DeviceGroupService : IDeviceGroupService
|
||||
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
|
||||
{
|
||||
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
|
||||
await _dbContext.DeleteReallyAsync(relationships);
|
||||
await _dbContext.DeleteAsync(relationships);
|
||||
|
||||
var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
.Where(x => x.TenantId == tenantId)
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.DeleteReallyAsync(p);
|
||||
await _dbContext.DeleteAsync(p);
|
||||
|
||||
//保存配置的权限
|
||||
if (request.Codes.IsPresent())
|
||||
@@ -189,6 +189,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
{
|
||||
throw new Exception("系统维护中,暂不可操作");
|
||||
}
|
||||
|
||||
//获取所有人的权限
|
||||
if (userNos.IsEmpty())
|
||||
userNos = await GetPermissionUserNosAsync();
|
||||
@@ -423,10 +424,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
public async Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType)
|
||||
{
|
||||
var deviceCodes = await GetAssignDeviceCodesAsync(userNo);
|
||||
if (!deviceCodes.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!deviceCodes.Any()) return;
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Enable)
|
||||
|
||||
@@ -98,7 +98,7 @@ public class GainfoGroupService : IGainfoGroupService
|
||||
await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
|
||||
{
|
||||
var relations = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
|
||||
await _dbContext.DeleteReallyAsync(relations);
|
||||
await _dbContext.DeleteAsync(relations);
|
||||
|
||||
request.UserNos = await _dbContext.Queryable<GainfoEntity>().Where(x => request.UserNos.Contains(x.No) || request.UserNos.Contains(x.Code))
|
||||
.Select(x => x.No)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Api;
|
||||
using System.Data;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Canteen.Dishes.Request;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
@@ -247,7 +248,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
Version = 0,
|
||||
UserNo = order.UserNo,
|
||||
UserCode = order.UserCode,
|
||||
|
||||
};
|
||||
|
||||
await DbContext.InsertAsync(gainfoMeal);
|
||||
@@ -269,7 +269,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@@ -592,17 +591,19 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
|
||||
|
||||
//降级到读已提交
|
||||
await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
|
||||
try
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
if (!allowNoBalance)
|
||||
{
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
|
||||
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += order.Amount;
|
||||
if (gainfoMeal.Balance < 0)
|
||||
{
|
||||
throw new UserFriendlyException("余额不足,无法消费");
|
||||
}
|
||||
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == gainfoMeal.Balance)
|
||||
@@ -616,6 +617,14 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
}, 5);
|
||||
|
||||
await DbContext.Client.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await DbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReCalcOfflineAsync(ReCalcOfflineRequest request)
|
||||
@@ -641,7 +650,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
Version = 0,
|
||||
UserNo = gainfo.No,
|
||||
UserCode = gainfo.Code,
|
||||
|
||||
};
|
||||
|
||||
await DbContext.InsertAsync(gainfoMeal);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity
|
||||
@@ -7,7 +8,7 @@ namespace Dlhis.Entity.Basic.Entity
|
||||
/// 档案人员组关系
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "GainfoGroupRelationship", TableDescription = "档案人员组关系")]
|
||||
public class GainfoGroupRelationshipEntity : SugarBaseEntity
|
||||
public class GainfoGroupRelationshipEntity : SugarBaseEntity , ISoftDeleted
|
||||
{
|
||||
/// <summary>
|
||||
/// 分组code
|
||||
@@ -19,5 +20,9 @@ namespace Dlhis.Entity.Basic.Entity
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "人员档案号")]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Dlhis.Entity.Device.Entities;
|
||||
/// 设备组/设备关系
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
|
||||
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
|
||||
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备组code
|
||||
@@ -23,4 +23,7 @@ public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
|
||||
public Guid DeviceCode { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Dlhis.Entity.Sys.Entities;
|
||||
/// 设备权限
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "DevicePermission", TableDescription = "设备权限")]
|
||||
public class DevicePermissionEntity : SugarBaseEntity, ITenantId
|
||||
public class DevicePermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
||||
{
|
||||
/// <summary>
|
||||
/// 分配权限类型(User,Role,Group...)
|
||||
@@ -38,4 +38,7 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId
|
||||
|
||||
|
||||
public string TenantId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Dto;
|
||||
|
||||
public class DepartmentOpenResponse
|
||||
{
|
||||
public string No { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上级部门号
|
||||
/// </summary>
|
||||
public string PNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Dto;
|
||||
|
||||
public class GainfoOpenResponse
|
||||
{
|
||||
public string Code { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public GenderEnumType Gender { get; set; }
|
||||
|
||||
public string DepartmentNo { get; set; }
|
||||
|
||||
public string DepartmentName { get; set; }
|
||||
|
||||
public GainfoStatusEnumType Status { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Dlhis.ScheduledTask.Common.Services;
|
||||
|
||||
public interface IIdentityUserSyncService : IScopeDependency
|
||||
{
|
||||
Task SyncAccountAsync(string userName, string name, string idNo, string tenant);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<GainfoUpdateService> _logger;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly IIdentityUserSyncService _identityUserSyncService;
|
||||
private readonly IGainfoPermissionApi _gainfoPermissionApi;
|
||||
private readonly IDevicePermissionApi _devicePermissionApi;
|
||||
private readonly IJinkoSapService _jinkoSapService;
|
||||
@@ -26,6 +27,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
public GainfoUpdateService(IDbContext dbContext,
|
||||
ILogger<GainfoUpdateService> logger,
|
||||
ITenantApi tenantApi,
|
||||
IIdentityUserSyncService identityUserSyncService,
|
||||
IGainfoPermissionApi gainfoPermissionApi,
|
||||
IDevicePermissionApi devicePermissionApi,
|
||||
IJinkoSapService jinkoSapService)
|
||||
@@ -34,6 +36,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
_dbContext.Client.QueryFilter.Clear();
|
||||
_logger = logger;
|
||||
_tenantApi = tenantApi;
|
||||
_identityUserSyncService = identityUserSyncService;
|
||||
_gainfoPermissionApi = gainfoPermissionApi;
|
||||
_devicePermissionApi = devicePermissionApi;
|
||||
_jinkoSapService = jinkoSapService;
|
||||
@@ -85,9 +88,9 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
if (modifiedPersons.Count > 0)
|
||||
{
|
||||
var d = modifiedPersons.First();
|
||||
_logger.LogInformation("差异信息:{json}", d.ToJson());
|
||||
_logger.LogInformation("差异信息:{json}", (await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == d.ZWORKCODE).FirstAsync())?.ToJson());
|
||||
// var d = modifiedPersons.First();
|
||||
// _logger.LogInformation("差异信息:{json}", d.ToJson());
|
||||
// _logger.LogInformation("差异信息:{json}", (await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == d.ZWORKCODE).FirstAsync())?.ToJson());
|
||||
|
||||
await SavePersonAsync(modifiedPersons);
|
||||
}
|
||||
@@ -214,19 +217,19 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
if (item.isowner == "T")
|
||||
{
|
||||
await _dbContext.InsertAsync(info);
|
||||
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
|
||||
await _devicePermissionApi.RePermissionUsersInfoAsync(new PermissionUsersInfoDto
|
||||
{
|
||||
UserNos = new List<string> { info.No },
|
||||
PermissionInfos = new Dictionary<string, List<UserTenantDeviceCodeDto>>
|
||||
{
|
||||
[info.No] = new List<UserTenantDeviceCodeDto>()
|
||||
[info.No] = new()
|
||||
}
|
||||
});
|
||||
|
||||
return info.No;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
|
||||
{
|
||||
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
|
||||
@@ -234,7 +237,6 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private GainfoEntity GainfoSapToGainfo(GainfoSapEntity item)
|
||||
{
|
||||
@@ -296,9 +298,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
createdate = item.createdate,
|
||||
ZZ_GZDJDNM = item.ZZ_GZDJDNM,
|
||||
ZZ_GZDCQNM = item.ZZ_GZDCQNM,
|
||||
})
|
||||
.Where(x => x.ename == item.ename)
|
||||
.ExecuteCommandAsync();
|
||||
}).Where(x => x.ename == item.ename).ExecuteCommandAsync();
|
||||
|
||||
//获取当前在职人员
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).FirstAsync();
|
||||
@@ -325,14 +325,14 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
ResignationDate = item.ZLZRQ,
|
||||
Workplace = workplace,
|
||||
Factory = factory
|
||||
})
|
||||
.Where(x => x.Code == item.ename)
|
||||
.ExecuteCommandAsync();
|
||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = GainfoSapToGainfo(item);
|
||||
await _dbContext.InsertAsync(info);
|
||||
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Common.Services.Implements;
|
||||
|
||||
public class IdentityUserSyncService : IIdentityUserSyncService
|
||||
{
|
||||
private readonly IDbContext _identityDbContext;
|
||||
|
||||
public IdentityUserSyncService(IDbContext dbContext)
|
||||
{
|
||||
_identityDbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SyncAccountAsync(string userName, string name, string idNo, string tenant)
|
||||
{
|
||||
if (tenant.IsEmpty()) return;
|
||||
|
||||
try
|
||||
{
|
||||
var password = idNo.TakeLast(6).Join("");
|
||||
|
||||
var user = await _identityDbContext.Queryable<UserEntity>().SingleAsync(x => x.UserName == userName);
|
||||
if (user == null)
|
||||
{
|
||||
var hasher = new PasswordHasher<UserEntity>();
|
||||
|
||||
user = new UserEntity
|
||||
{
|
||||
UserName = userName,
|
||||
NormalizedUserName = userName.ToUpper(),
|
||||
ConcurrencyStamp = Guid.NewGuid().ToString(),
|
||||
SecurityStamp = Guid.NewGuid().ToString(),
|
||||
};
|
||||
password = hasher.HashPassword(user, password);
|
||||
user.PasswordHash = password;
|
||||
|
||||
var id = (int)await _identityDbContext.InsertReturnIdentityAsync(user);
|
||||
user.Id = id;
|
||||
await AddUserClaim(_identityDbContext, id, "jinko-code", userName);
|
||||
await AddUserClaim(_identityDbContext, id, "name", name);
|
||||
}
|
||||
|
||||
|
||||
//todo 考虑角色?
|
||||
var userTenants = await _identityDbContext.Queryable<UserTenantEntity>().Where(x => x.UserId == user.Id).ToListAsync();
|
||||
if (userTenants.Count is 0 or 1)
|
||||
{
|
||||
var userTenant = userTenants.FirstOrDefault();
|
||||
if (userTenant == null)
|
||||
{
|
||||
userTenant = new UserTenantEntity
|
||||
{
|
||||
UserId = user.Id,
|
||||
TenantCode = tenant
|
||||
};
|
||||
await _identityDbContext.InsertAsync(userTenant);
|
||||
}
|
||||
else
|
||||
{
|
||||
userTenant.TenantCode = tenant;
|
||||
await _identityDbContext.UpdateAsync(userTenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
//************************************************************************** help method **************************************************************************************
|
||||
|
||||
private async Task AddUserClaim(IDbContext dbContext, int userId, string type, string value)
|
||||
{
|
||||
var claim = await _identityDbContext.Queryable<UserClaimEntity>().Where(x => x.UserId == userId).FirstAsync(x => x.ClaimType == type);
|
||||
if (claim == null)
|
||||
{
|
||||
claim = new UserClaimEntity()
|
||||
{
|
||||
UserId = userId,
|
||||
ClaimType = type,
|
||||
ClaimValue = value
|
||||
};
|
||||
await dbContext.InsertAsync(claim);
|
||||
}
|
||||
else
|
||||
{
|
||||
claim.ClaimValue = value;
|
||||
await dbContext.UpdateAsync(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Dlhis.ScheduledTask.Common.Dto;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存山西档案数据
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(SyncShanxiGainfoJob), "0 0 3 * * ?", Name = "缓存山西档案数据")]
|
||||
public class SyncShanxiGainfoJob : BaseJob
|
||||
{
|
||||
private readonly RedisCache _redisCache;
|
||||
|
||||
public SyncShanxiGainfoJob(IServiceProvider serviceProvider, RedisCache redisCache) : base(serviceProvider)
|
||||
{
|
||||
_redisCache = redisCache;
|
||||
}
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var key = "gainfo:shanxi";
|
||||
await _redisCache.KeyDeleteAsync(key);
|
||||
|
||||
var gainfos = await DbContext.Queryable<GainfoEntity>()
|
||||
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
||||
.Where(x => x.Factory == "2401")
|
||||
.Select((x, d) => new GainfoOpenResponse
|
||||
{
|
||||
Code = x.Code,
|
||||
DepartmentNo = x.DepartmentNo,
|
||||
DepartmentName = d.Name,
|
||||
Name = x.Name,
|
||||
Gender = x.Gender,
|
||||
Status = GainfoStatusEnumType.Working,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in gainfos)
|
||||
{
|
||||
await _redisCache.ListLeftPushAsync(key, item);
|
||||
}
|
||||
|
||||
var gainfoLeaves = await DbContext.Queryable<GainfoEntity>().AS("GainfoLeave")
|
||||
.LeftJoin<DepartmentEntity>((x, d) => x.DepartmentNo == d.No)
|
||||
.Where(x => x.Factory == "2401")
|
||||
.Select((x, d) => new GainfoOpenResponse
|
||||
{
|
||||
Code = x.Code,
|
||||
DepartmentNo = x.DepartmentNo,
|
||||
DepartmentName = d.Name,
|
||||
Name = x.Name,
|
||||
Gender = x.Gender,
|
||||
Status = GainfoStatusEnumType.Leave,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in gainfoLeaves)
|
||||
{
|
||||
await _redisCache.ListLeftPushAsync(key, item);
|
||||
}
|
||||
|
||||
|
||||
var departmentKey = "department:all";
|
||||
await _redisCache.KeyDeleteAsync(departmentKey);
|
||||
|
||||
var departments = await DbContext.Queryable<DepartmentEntity>()
|
||||
.Select((x) => new DepartmentOpenResponse
|
||||
{
|
||||
Name = x.Name,
|
||||
No = x.No,
|
||||
PNo = x.PNo,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in departments)
|
||||
{
|
||||
await _redisCache.ListLeftPushAsync(departmentKey, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 用户创建
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(UpdateUserPasswordJob), "0 0 6 * * ?", Name = "用户创建")]
|
||||
public class UpdateUserPasswordJob : BaseJob
|
||||
{
|
||||
public UpdateUserPasswordJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var identityDbContext = DbContext.ChangeDb("identity");
|
||||
|
||||
var whitelist = new List<string>() { "admin", "WB-0741", "WB-1091", "0123456" };
|
||||
|
||||
var users = await identityDbContext.Queryable<UserEntity>()
|
||||
.Where(x => !whitelist.Contains(x.UserName))
|
||||
.ToListAsync();
|
||||
|
||||
var gainfos = await DbContext.Queryable<GainfoEntity>().Where(x => !whitelist.Contains(x.Code)).ToListAsync();
|
||||
|
||||
var hasher = new PasswordHasher<UserEntity>();
|
||||
foreach (var gainfo in gainfos)
|
||||
{
|
||||
if (gainfo.IdNo.IsEmpty()) continue;
|
||||
|
||||
try
|
||||
{
|
||||
var password = gainfo.IdNo.TakeLast(6).Join("");
|
||||
|
||||
var user = users.FirstOrDefault(x => x.UserName == gainfo.Code);
|
||||
if (user != null) continue;
|
||||
|
||||
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<UserTenantEntity>().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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddUserClaim(IDbContext dbContext, int userId, string type, string value)
|
||||
{
|
||||
var claim = await dbContext.Queryable<UserClaimEntity>().Where(x => x.UserId == userId).FirstAsync(x => x.ClaimType == type);
|
||||
if (claim == null)
|
||||
{
|
||||
claim = new UserClaimEntity()
|
||||
{
|
||||
UserId = userId,
|
||||
ClaimType = type,
|
||||
ClaimValue = value
|
||||
};
|
||||
await dbContext.InsertAsync(claim);
|
||||
}
|
||||
else
|
||||
{
|
||||
claim.ClaimValue = value;
|
||||
await dbContext.UpdateAsync(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,11 @@ public class DeviceTaskAssignmentRequest : PageDto, IValidatableObject
|
||||
public string Factory { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否离线
|
||||
/// </summary>
|
||||
public bool? IsOffline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 搜索范围
|
||||
/// </summary>
|
||||
|
||||
@@ -44,6 +44,10 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
|
||||
|| ga.Code == request.Search
|
||||
|| deviceTask.DeviceUniqueNo == request.Search
|
||||
)
|
||||
.WhereIF(request.IsOffline.HasValue && request.IsOffline.Value, (deviceTask, device, ga, gaLeave, gaEx, deviceRegistry) =>
|
||||
SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) < DateTime.Now)
|
||||
.WhereIF(request.IsOffline.HasValue && !request.IsOffline.Value, (deviceTask, device, ga, gaLeave, gaEx, deviceRegistry) =>
|
||||
SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) >= DateTime.Now)
|
||||
.OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc)
|
||||
.Select((deviceTask, device, ga, gaLeave, gaEx, deviceRegistry) => new DeviceTaskAssignmentResponse
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user