fix 设备权限处理

This commit is contained in:
2024-04-03 21:59:47 +08:00
parent 3e2a8cc2dd
commit 174a44cf2f
2 changed files with 41 additions and 24 deletions

View File

@@ -182,11 +182,6 @@ public class DevicePermissionService : IDevicePermissionService
var userNos = beforeDto.UserNos; var userNos = beforeDto.UserNos;
var before = beforeDto.PermissionInfos.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase); var before = beforeDto.PermissionInfos.ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
//获取业务处理后所有人的权限
var nextUserNos = await GetPermissionUserNosAsync();
if (nextUserNos.Any())
userNos = userNos.Concat(nextUserNos).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var current = await GetAssignDeviceCodesInternalAsync(userNos); var current = await GetAssignDeviceCodesInternalAsync(userNos);
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync(); var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();

View File

@@ -9,6 +9,7 @@ using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.ScheduledTask.Common.Comparers; using Dlhis.ScheduledTask.Common.Comparers;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Dlhis.ScheduledTask.Common.Response; using Dlhis.ScheduledTask.Common.Response;
using Dlhis.Basic.Api.Dtos;
namespace Dlhis.ScheduledTask.Common.Services.Implements; namespace Dlhis.ScheduledTask.Common.Services.Implements;
@@ -78,7 +79,7 @@ public class GainfoUpdateService : IGainfoUpdateService
if (persons.Count > 0) if (persons.Count > 0)
{ {
var modifiedPersons = GetModifiedPerson(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
werkInfo.HandleMessage = "SAP人员差异数量" + modifiedPersons.Count; werkInfo.HandleMessage = "SAP人员差异数量" + modifiedPersons.Count;
werkInfo.DiffNumber = modifiedPersons.Count; werkInfo.DiffNumber = modifiedPersons.Count;
@@ -92,16 +93,8 @@ public class GainfoUpdateService : IGainfoUpdateService
var tenantResult = await _tenantApi.GetTenantsInternalAsync(); var tenantResult = await _tenantApi.GetTenantsInternalAsync();
_tenants = tenantResult.Data; _tenants = tenantResult.Data;
//var codes = modifiedPersons.Select(x => x.ZWORKCODE).ToList();
//var userNos = await _dbContext.Queryable<GainfoEntity>().Where(x => codes.Contains(x.Code)).Select(x => x.No).ToListAsync();
//var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(userNos);
//var dto = dtoResult.Data;
await SavePersonAsync(modifiedPersons); await SavePersonAsync(modifiedPersons);
//var rResult = await _devicePermissionApi.RePermissionUsersInfoAsync(dto);
//var r = rResult.Data;
werkInfo.PermissionChangeNumber = 0; werkInfo.PermissionChangeNumber = 0;
await _dbContext.UpdateAsync(werkInfo); await _dbContext.UpdateAsync(werkInfo);
} }
@@ -134,7 +127,7 @@ public class GainfoUpdateService : IGainfoUpdateService
_logger.LogInformation("获取SAP人员数量为:{count}", persons.Count); _logger.LogInformation("获取SAP人员数量为:{count}", persons.Count);
if (persons.Count > 0) if (persons.Count > 0)
{ {
var modifiedPersons = GetModifiedPerson(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList()); var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
_logger.LogInformation("SAP人员差异数量为:{count}", modifiedPersons.Count); _logger.LogInformation("SAP人员差异数量为:{count}", modifiedPersons.Count);
if (modifiedPersons.Count > 0) if (modifiedPersons.Count > 0)
{ {
@@ -186,8 +179,18 @@ public class GainfoUpdateService : IGainfoUpdateService
i++; i++;
try try
{ {
await InsertPersonAsync(item); var no = await InsertPersonAsync(item);
_logger.LogWarning("执行新增成功 工号:{code},姓名:{name}", item.ename, item.gname); _logger.LogWarning("执行新增成功 工号:{code},姓名:{name}", item.ename, item.gname);
var rResult = await _devicePermissionApi.RePermissionUsersInfoAsync(new PermissionUsersInfoDto
{
UserNos = new List<string> { no },
PermissionInfos = new Dictionary<string, List<UserTenantDeviceCodeDto>>
{
[no] = new List<UserTenantDeviceCodeDto>()
}
});
var r = rResult.Data;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -200,8 +203,22 @@ public class GainfoUpdateService : IGainfoUpdateService
i++; i++;
try try
{ {
await UpdatePersonAsync(item); var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).Select(x => x.No).SingleAsync();
_logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname); if (no.IsPresent())
{
var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { no });
var dto = dtoResult.Data;
await UpdatePersonAsync(item);
_logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname);
await _devicePermissionApi.RePermissionUsersInfoAsync(dto);
}
else
{
await UpdatePersonAsync(item);
_logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -211,7 +228,7 @@ public class GainfoUpdateService : IGainfoUpdateService
} }
} }
private async Task InsertPersonAsync(GainfoSapEntity item) private async Task<string> InsertPersonAsync(GainfoSapEntity item)
{ {
await _dbContext.InsertAsync(item); await _dbContext.InsertAsync(item);
@@ -220,10 +237,12 @@ public class GainfoUpdateService : IGainfoUpdateService
if (item.isowner == "T") if (item.isowner == "T")
{ {
await _dbContext.InsertAsync(info); await _dbContext.InsertAsync(info);
return info.No;
} }
else else
{ {
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync(); await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
return null;
} }
} }
@@ -260,7 +279,7 @@ public class GainfoUpdateService : IGainfoUpdateService
return info; return info;
} }
private async Task UpdatePersonAsync(GainfoSapEntity item) private async Task<string> UpdatePersonAsync(GainfoSapEntity item)
{ {
var gainfoSap = await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == item.ename).FirstAsync(); var gainfoSap = await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == item.ename).FirstAsync();
await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity
@@ -331,11 +350,14 @@ public class GainfoUpdateService : IGainfoUpdateService
await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync(); await _dbContext.Client.Insertable(gainfo).AS("GainfoLeave").ExecuteCommandAsync();
} }
} }
return gainfo?.No;
} }
private List<SapPersonItem> GetModifiedPerson(List<SapPersonItem> sapList) private async Task<List<SapPersonItem>> GetModifiedPersonAsync(List<SapPersonItem> sapList)
{ {
var last = LoadData(); var last = await LoadDataAsync();
if (last.Count <= 0) if (last.Count <= 0)
{ {
return sapList; return sapList;
@@ -373,11 +395,11 @@ public class GainfoUpdateService : IGainfoUpdateService
} }
private List<SapPersonItem> LoadData() private async Task<List<SapPersonItem>> LoadDataAsync()
{ {
//var pJson = "{\"id\":0,\"ano\":null,\"class\":\"C\",\"passwd\":null,\"question\":null,\"answer\":null,\"gname\":\"岳文超\",\"ename\":\"098250\",\"country\":null,\"idcls\":\"ID\",\"idno\":\"\\\"140105200112051318\n\",\"native\":\"14010\",\"sex\":\"M\",\"birthday\":\"2001-12-05T00:00:00\",\"address\":\"\",\"postcode\":null,\"occupation\":\"99\",\"appellation\":\"00210591\",\"nation\":\"01\",\"phone\":\"13773151205\",\"fax\":null,\"mobile\":null,\"email\":\"高中/中专【失效】\",\"web\":\"\",\"vip\":null,\"sec\":null,\"cropsno\":null,\"cropname\":null,\"fancy\":null,\"remark\":\"入职时间:2023-05-05 离职时间:2023-10-30 变更原因:自离【失效】\",\"amount\":0,\"days\":0,\"consume01\":0.0000,\"consume02\":0.0000,\"consume03\":0.0000,\"consume04\":0.0000,\"log_id\":\"XX\",\"log_shift\":\"1\",\"log_date\":null,\"log_ip\":\"127.0.0.1\",\"times\":0,\"logmark\":0,\"rmcode\":null,\"mkt\":null,\"src\":null,\"isowner\":\"F\",\"createdate\":\"2023-05-05T00:00:00\",\"PERNR\":\"00281800\",\"WERKS\":\"1560\",\"ZSTATUS\":\"5\",\"KOSTL\":\"156020336\",\"ZZ_ZD\":\"3\",\"Z_ZJ\":\"T0\",\"STELL\":null,\"STELL_NM\":null,\"ZLZRQ\":\"2023-10-30T00:00:00\",\"MASSN\":\"ZD\",\"MNTXT\":\"离职\",\"MASSG\":null,\"MGTXT\":null,\"logdate\":\"2024-03-14T00:02:34\",\"updatelogdate\":null,\"guestno\":null,\"ZZ_KLX\":\"3\",\"DAT01\":null,\"ZZ_COUNNM\":null,\"ZZ_GZDJDNM\":\"海宁基地\",\"ZZ_GZDCQNM\":\"海宁尖山\"}"; //var pJson = "{\"id\":0,\"ano\":null,\"class\":\"C\",\"passwd\":null,\"question\":null,\"answer\":null,\"gname\":\"岳文超\",\"ename\":\"098250\",\"country\":null,\"idcls\":\"ID\",\"idno\":\"\\\"140105200112051318\n\",\"native\":\"14010\",\"sex\":\"M\",\"birthday\":\"2001-12-05T00:00:00\",\"address\":\"\",\"postcode\":null,\"occupation\":\"99\",\"appellation\":\"00210591\",\"nation\":\"01\",\"phone\":\"13773151205\",\"fax\":null,\"mobile\":null,\"email\":\"高中/中专【失效】\",\"web\":\"\",\"vip\":null,\"sec\":null,\"cropsno\":null,\"cropname\":null,\"fancy\":null,\"remark\":\"入职时间:2023-05-05 离职时间:2023-10-30 变更原因:自离【失效】\",\"amount\":0,\"days\":0,\"consume01\":0.0000,\"consume02\":0.0000,\"consume03\":0.0000,\"consume04\":0.0000,\"log_id\":\"XX\",\"log_shift\":\"1\",\"log_date\":null,\"log_ip\":\"127.0.0.1\",\"times\":0,\"logmark\":0,\"rmcode\":null,\"mkt\":null,\"src\":null,\"isowner\":\"F\",\"createdate\":\"2023-05-05T00:00:00\",\"PERNR\":\"00281800\",\"WERKS\":\"1560\",\"ZSTATUS\":\"5\",\"KOSTL\":\"156020336\",\"ZZ_ZD\":\"3\",\"Z_ZJ\":\"T0\",\"STELL\":null,\"STELL_NM\":null,\"ZLZRQ\":\"2023-10-30T00:00:00\",\"MASSN\":\"ZD\",\"MNTXT\":\"离职\",\"MASSG\":null,\"MGTXT\":null,\"logdate\":\"2024-03-14T00:02:34\",\"updatelogdate\":null,\"guestno\":null,\"ZZ_KLX\":\"3\",\"DAT01\":null,\"ZZ_COUNNM\":null,\"ZZ_GZDJDNM\":\"海宁基地\",\"ZZ_GZDCQNM\":\"海宁尖山\"}";
//var gainfos = new List<GainfoSapEntity>() { pJson.ToObject<GainfoSapEntity>() }; //var gainfos = new List<GainfoSapEntity>() { pJson.ToObject<GainfoSapEntity>() };
var gainfos = _dbContext.Queryable<GainfoSapEntity>().ToList(); var gainfos = await _dbContext.Queryable<GainfoSapEntity>().ToListAsync();
return gainfos.Select(x => new SapPersonItem return gainfos.Select(x => new SapPersonItem
{ {