fix 处理已知问题

This commit is contained in:
2024-06-22 18:19:13 +08:00
parent cf04fb01ad
commit 49201f2e49
16 changed files with 219 additions and 318 deletions

View File

@@ -107,7 +107,7 @@ public class DeviceGroupService : IDeviceGroupService
await _devicePermissionService.GenerateDeviceTasksAsync(async () => await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
{ {
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); 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 var entities = request.DeviceCodes.Select(x => new DeviceGroupRelationshipEntity
{ {

View File

@@ -49,7 +49,7 @@ public class DevicePermissionService : IDevicePermissionService
.Where(x => x.TenantId == tenantId) .Where(x => x.TenantId == tenantId)
.ToListAsync(); .ToListAsync();
await _dbContext.DeleteReallyAsync(p); await _dbContext.DeleteAsync(p);
//保存配置的权限 //保存配置的权限
if (request.Codes.IsPresent()) if (request.Codes.IsPresent())
@@ -189,6 +189,7 @@ public class DevicePermissionService : IDevicePermissionService
{ {
throw new Exception("系统维护中,暂不可操作"); throw new Exception("系统维护中,暂不可操作");
} }
//获取所有人的权限 //获取所有人的权限
if (userNos.IsEmpty()) if (userNos.IsEmpty())
userNos = await GetPermissionUserNosAsync(); userNos = await GetPermissionUserNosAsync();
@@ -273,7 +274,7 @@ public class DevicePermissionService : IDevicePermissionService
_logger.LogInformation("{tenant}任务产生数量{count}", tenantId, waitTasks.Count); _logger.LogInformation("{tenant}任务产生数量{count}", tenantId, waitTasks.Count);
if (waitTasks.Any()) if (waitTasks.Any())
{ {
// await _dbContext.InsertAsync(waitTasks); // await _dbContext.InsertAsync(waitTasks);
} }
} }
@@ -423,10 +424,7 @@ public class DevicePermissionService : IDevicePermissionService
public async Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType) public async Task GenerateDeviceTasksAsync(string userNo, DeviceTaskEnumType taskType)
{ {
var deviceCodes = await GetAssignDeviceCodesAsync(userNo); var deviceCodes = await GetAssignDeviceCodesAsync(userNo);
if (!deviceCodes.Any()) if (!deviceCodes.Any()) return;
{
return;
}
var devices = await _dbContext.Queryable<DeviceEntity>() var devices = await _dbContext.Queryable<DeviceEntity>()
.Where(x => x.Enable) .Where(x => x.Enable)

View File

@@ -98,7 +98,7 @@ public class GainfoGroupService : IGainfoGroupService
await _devicePermissionService.GenerateDeviceTasksAsync(async () => await _devicePermissionService.GenerateDeviceTasksAsync(async () =>
{ {
var relations = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync(); 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)) request.UserNos = await _dbContext.Queryable<GainfoEntity>().Where(x => request.UserNos.Contains(x.No) || request.UserNos.Contains(x.Code))
.Select(x => x.No) .Select(x => x.No)

View File

@@ -1,4 +1,5 @@
using Dlhis.Basic.Api; using System.Data;
using Dlhis.Basic.Api;
using Dlhis.Canteen.Dishes.Request; using Dlhis.Canteen.Dishes.Request;
using Dlhis.Canteen.Setting.Services; using Dlhis.Canteen.Setting.Services;
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
@@ -39,7 +40,7 @@ public class OrderService : BaseOrderService, IOrderService
{ {
return await AddAsync(request); return await AddAsync(request);
} }
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request) public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
{ {
@@ -247,7 +248,6 @@ public class OrderService : BaseOrderService, IOrderService
Version = 0, Version = 0,
UserNo = order.UserNo, UserNo = order.UserNo,
UserCode = order.UserCode, UserCode = order.UserCode,
}; };
await DbContext.InsertAsync(gainfoMeal); await DbContext.InsertAsync(gainfoMeal);
@@ -269,7 +269,6 @@ public class OrderService : BaseOrderService, IOrderService
//写入记录 //写入记录
var balanceRecord = order.Adapt<BalanceRecordEntity>(); var balanceRecord = order.Adapt<BalanceRecordEntity>();
await DbContext.InsertAsync(balanceRecord); await DbContext.InsertAsync(balanceRecord);
}, 5); }, 5);
} }
@@ -592,30 +591,40 @@ public class OrderService : BaseOrderService, IOrderService
var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance); var allowNoBalance = await GetSettingAsync<bool>(order.TenantId, CanteenSettingItemEnumType.AllowNoBalance);
await CommonHelper.RetryAsync(async () => //降级到读已提交
await DbContext.Client.Ado.BeginTranAsync(IsolationLevel.ReadCommitted);
try
{ {
if (!allowNoBalance) await CommonHelper.RetryAsync(async () =>
{ {
var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync(); if (!allowNoBalance)
//金额+-
gainfoMeal.Balance += order.Amount;
if (gainfoMeal.Balance < 0)
{ {
throw new UserFriendlyException("余额不足,无法消费"); var gainfoMeal = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).SingleAsync();
//金额+-
gainfoMeal.Balance += order.Amount;
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
await DbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == gainfoMeal.Balance)
.SetColumns(x => x.Version == x.Version + 1)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
.ExecuteCommandThrowVersionAsync();
} }
await DbContext.Updateable<GainfoMealEntity>() //写入记录
.SetColumns(x => x.Balance == gainfoMeal.Balance) var balanceRecord = order.Adapt<BalanceRecordEntity>();
.SetColumns(x => x.Version == x.Version + 1) await DbContext.InsertAsync(balanceRecord);
.SetColumns(x => x.ModifiedTime == DateTime.Now) }, 5);
.Where(x => x.UserNo == order.UserNo && x.Version == gainfoMeal.Version) //必须与查询时的version一致
.ExecuteCommandThrowVersionAsync();
}
//写入记录 await DbContext.Client.Ado.CommitTranAsync();
var balanceRecord = order.Adapt<BalanceRecordEntity>(); }
await DbContext.InsertAsync(balanceRecord); catch (Exception)
}, 5); {
await DbContext.Client.Ado.RollbackTranAsync();
throw;
}
} }
public async Task ReCalcOfflineAsync(ReCalcOfflineRequest request) public async Task ReCalcOfflineAsync(ReCalcOfflineRequest request)
@@ -641,7 +650,6 @@ public class OrderService : BaseOrderService, IOrderService
Version = 0, Version = 0,
UserNo = gainfo.No, UserNo = gainfo.No,
UserCode = gainfo.Code, UserCode = gainfo.Code,
}; };
await DbContext.InsertAsync(gainfoMeal); await DbContext.InsertAsync(gainfoMeal);
@@ -668,7 +676,7 @@ public class OrderService : BaseOrderService, IOrderService
}, 5); }, 5);
} }
} }
/// <summary> /// <summary>
/// 根据二维码获取消费用户 /// 根据二维码获取消费用户
/// </summary> /// </summary>

View File

@@ -1,4 +1,5 @@
using Kurisu.AspNetCore.DataAccess.SqlSugar; using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar;
using SqlSugar; using SqlSugar;
namespace Dlhis.Entity.Basic.Entity namespace Dlhis.Entity.Basic.Entity
@@ -7,7 +8,7 @@ namespace Dlhis.Entity.Basic.Entity
/// 档案人员组关系 /// 档案人员组关系
/// </summary> /// </summary>
[SugarTable(TableName = "GainfoGroupRelationship", TableDescription = "档案人员组关系")] [SugarTable(TableName = "GainfoGroupRelationship", TableDescription = "档案人员组关系")]
public class GainfoGroupRelationshipEntity : SugarBaseEntity public class GainfoGroupRelationshipEntity : SugarBaseEntity , ISoftDeleted
{ {
/// <summary> /// <summary>
/// 分组code /// 分组code
@@ -19,5 +20,9 @@ namespace Dlhis.Entity.Basic.Entity
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "人员档案号")] [SugarColumn(ColumnDescription = "人员档案号")]
public string UserNo { get; set; } public string UserNo { get; set; }
/// <inheritdoc />
public bool IsDeleted { get; set; }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace Dlhis.Entity.Device.Entities;
/// 设备组/设备关系 /// 设备组/设备关系
/// </summary> /// </summary>
[SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")] [SugarTable(TableName = "DeviceGroupRelationship", TableDescription = "设备组/设备关系")]
public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId, ISoftDeleted
{ {
/// <summary> /// <summary>
/// 设备组code /// 设备组code
@@ -23,4 +23,7 @@ public class DeviceGroupRelationshipEntity : SugarBaseEntity, ITenantId
public Guid DeviceCode { get; set; } public Guid DeviceCode { get; set; }
public string TenantId { get; set; } public string TenantId { get; set; }
/// <inheritdoc />
public bool IsDeleted { get; set; }
} }

View File

@@ -10,7 +10,7 @@ namespace Dlhis.Entity.Sys.Entities;
/// 设备权限 /// 设备权限
/// </summary> /// </summary>
[SugarTable(TableName = "DevicePermission", TableDescription = "设备权限")] [SugarTable(TableName = "DevicePermission", TableDescription = "设备权限")]
public class DevicePermissionEntity : SugarBaseEntity, ITenantId public class DevicePermissionEntity : SugarBaseEntity, ITenantId, ISoftDeleted
{ {
/// <summary> /// <summary>
/// 分配权限类型(User,Role,Group...) /// 分配权限类型(User,Role,Group...)
@@ -38,4 +38,7 @@ public class DevicePermissionEntity : SugarBaseEntity, ITenantId
public string TenantId { get; set; } public string TenantId { get; set; }
/// <inheritdoc />
public bool IsDeleted { get; set; }
} }

View File

@@ -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; }
}

View File

@@ -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; }
}

View File

@@ -0,0 +1,6 @@
namespace Dlhis.ScheduledTask.Common.Services;
public interface IIdentityUserSyncService : IScopeDependency
{
Task SyncAccountAsync(string userName, string name, string idNo, string tenant);
}

View File

@@ -17,6 +17,7 @@ public class GainfoUpdateService : IGainfoUpdateService
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly ILogger<GainfoUpdateService> _logger; private readonly ILogger<GainfoUpdateService> _logger;
private readonly ITenantApi _tenantApi; private readonly ITenantApi _tenantApi;
private readonly IIdentityUserSyncService _identityUserSyncService;
private readonly IGainfoPermissionApi _gainfoPermissionApi; private readonly IGainfoPermissionApi _gainfoPermissionApi;
private readonly IDevicePermissionApi _devicePermissionApi; private readonly IDevicePermissionApi _devicePermissionApi;
private readonly IJinkoSapService _jinkoSapService; private readonly IJinkoSapService _jinkoSapService;
@@ -26,6 +27,7 @@ public class GainfoUpdateService : IGainfoUpdateService
public GainfoUpdateService(IDbContext dbContext, public GainfoUpdateService(IDbContext dbContext,
ILogger<GainfoUpdateService> logger, ILogger<GainfoUpdateService> logger,
ITenantApi tenantApi, ITenantApi tenantApi,
IIdentityUserSyncService identityUserSyncService,
IGainfoPermissionApi gainfoPermissionApi, IGainfoPermissionApi gainfoPermissionApi,
IDevicePermissionApi devicePermissionApi, IDevicePermissionApi devicePermissionApi,
IJinkoSapService jinkoSapService) IJinkoSapService jinkoSapService)
@@ -34,6 +36,7 @@ public class GainfoUpdateService : IGainfoUpdateService
_dbContext.Client.QueryFilter.Clear(); _dbContext.Client.QueryFilter.Clear();
_logger = logger; _logger = logger;
_tenantApi = tenantApi; _tenantApi = tenantApi;
_identityUserSyncService = identityUserSyncService;
_gainfoPermissionApi = gainfoPermissionApi; _gainfoPermissionApi = gainfoPermissionApi;
_devicePermissionApi = devicePermissionApi; _devicePermissionApi = devicePermissionApi;
_jinkoSapService = jinkoSapService; _jinkoSapService = jinkoSapService;
@@ -85,9 +88,9 @@ public class GainfoUpdateService : IGainfoUpdateService
if (modifiedPersons.Count > 0) if (modifiedPersons.Count > 0)
{ {
var d = modifiedPersons.First(); // var d = modifiedPersons.First();
_logger.LogInformation("差异信息:{json}", d.ToJson()); // _logger.LogInformation("差异信息:{json}", d.ToJson());
_logger.LogInformation("差异信息:{json}", (await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == d.ZWORKCODE).FirstAsync())?.ToJson()); // _logger.LogInformation("差异信息:{json}", (await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == d.ZWORKCODE).FirstAsync())?.ToJson());
await SavePersonAsync(modifiedPersons); await SavePersonAsync(modifiedPersons);
} }
@@ -214,26 +217,25 @@ public class GainfoUpdateService : IGainfoUpdateService
if (item.isowner == "T") if (item.isowner == "T")
{ {
await _dbContext.InsertAsync(info); await _dbContext.InsertAsync(info);
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
await _devicePermissionApi.RePermissionUsersInfoAsync(new PermissionUsersInfoDto await _devicePermissionApi.RePermissionUsersInfoAsync(new PermissionUsersInfoDto
{ {
UserNos = new List<string> { info.No }, UserNos = new List<string> { info.No },
PermissionInfos = new Dictionary<string, List<UserTenantDeviceCodeDto>> PermissionInfos = new Dictionary<string, List<UserTenantDeviceCodeDto>>
{ {
[info.No] = new List<UserTenantDeviceCodeDto>() [info.No] = new()
} }
}); });
return info.No; return info.No;
} }
else
{
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
{
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
}
return null; if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
{
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
} }
return null;
} }
private GainfoEntity GainfoSapToGainfo(GainfoSapEntity item) private GainfoEntity GainfoSapToGainfo(GainfoSapEntity item)
@@ -274,31 +276,29 @@ public class GainfoUpdateService : IGainfoUpdateService
private async Task<string> UpdatePersonAsync(GainfoSapEntity item) private async Task<string> UpdatePersonAsync(GainfoSapEntity item)
{ {
await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity
{ {
PERNR = item.PERNR, PERNR = item.PERNR,
gname = item.gname, gname = item.gname,
phone = item.phone, phone = item.phone,
appellation = item.appellation, appellation = item.appellation,
isowner = item.isowner, isowner = item.isowner,
remark = item.remark, remark = item.remark,
email = item.email, email = item.email,
WERKS = item.WERKS, WERKS = item.WERKS,
KOSTL = item.KOSTL, KOSTL = item.KOSTL,
STELL = item.STELL, STELL = item.STELL,
Z_ZJ = item.Z_ZJ, Z_ZJ = item.Z_ZJ,
ZZ_ZD = item.ZZ_ZD, ZZ_ZD = item.ZZ_ZD,
MNTXT = item.MNTXT, MNTXT = item.MNTXT,
MASSN = item.MASSN, MASSN = item.MASSN,
ZSTATUS = item.ZSTATUS, ZSTATUS = item.ZSTATUS,
ZLZRQ = item.ZLZRQ, ZLZRQ = item.ZLZRQ,
STELL_NM = item.STELL_NM, STELL_NM = item.STELL_NM,
ZZ_KLX = item.ZZ_KLX, ZZ_KLX = item.ZZ_KLX,
createdate = item.createdate, createdate = item.createdate,
ZZ_GZDJDNM = item.ZZ_GZDJDNM, ZZ_GZDJDNM = item.ZZ_GZDJDNM,
ZZ_GZDCQNM = item.ZZ_GZDCQNM, 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(); var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).FirstAsync();
@@ -309,30 +309,30 @@ public class GainfoUpdateService : IGainfoUpdateService
var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM; var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM;
var factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM; var factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM;
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
{ {
SapNo = item.PERNR, SapNo = item.PERNR,
Name = item.gname, Name = item.gname,
PositionNo = item.STELL, PositionNo = item.STELL,
Grade = item.ZZ_ZD, Grade = item.ZZ_ZD,
Title = item.Z_ZJ, Title = item.Z_ZJ,
Phone = item.phone, Phone = item.phone,
DepartmentNo = item.appellation, DepartmentNo = item.appellation,
Remark = item.remark, Remark = item.remark,
Degree = item.email, Degree = item.email,
Werks = item.WERKS, Werks = item.WERKS,
CostId = item.KOSTL, CostId = item.KOSTL,
EntryDate = item.createdate, EntryDate = item.createdate,
ResignationDate = item.ZLZRQ, ResignationDate = item.ZLZRQ,
Workplace = workplace, Workplace = workplace,
Factory = factory Factory = factory
}) }).Where(x => x.Code == item.ename).ExecuteCommandAsync();
.Where(x => x.Code == item.ename) await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
.ExecuteCommandAsync();
} }
else else
{ {
var info = GainfoSapToGainfo(item); var info = GainfoSapToGainfo(item);
await _dbContext.InsertAsync(info); await _dbContext.InsertAsync(info);
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
} }
} }
else else

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -32,6 +32,11 @@ public class DeviceTaskAssignmentRequest : PageDto, IValidatableObject
public string Factory { get; set; } public string Factory { get; set; }
/// <summary>
/// 是否离线
/// </summary>
public bool? IsOffline { get; set; }
/// <summary> /// <summary>
/// 搜索范围 /// 搜索范围
/// </summary> /// </summary>

View File

@@ -44,6 +44,10 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
|| ga.Code == request.Search || ga.Code == request.Search
|| deviceTask.DeviceUniqueNo == 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) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc)
.Select((deviceTask, device, ga, gaLeave, gaEx, deviceRegistry) => new DeviceTaskAssignmentResponse .Select((deviceTask, device, ga, gaLeave, gaEx, deviceRegistry) => new DeviceTaskAssignmentResponse
{ {