fix 修复部门变更不下发新部门权限
This commit is contained in:
@@ -263,26 +263,26 @@ public class GainfoUpdateService : IGainfoUpdateService
|
|||||||
{
|
{
|
||||||
var change = string.Empty;
|
var change = string.Empty;
|
||||||
|
|
||||||
if (gainfo.Factory != factory || gainfo.Workplace != workplace || gainfo.DepartmentNo != item.appellation)
|
var hasFactoryChange = gainfo.Factory != factory || gainfo.Workplace != workplace;
|
||||||
|
var hasDepartmentChange = gainfo.DepartmentNo != item.appellation;
|
||||||
|
|
||||||
|
|
||||||
|
if (hasFactoryChange)
|
||||||
{
|
{
|
||||||
if (gainfo.Factory != factory)
|
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||||
{
|
change = $"{gainfo.Factory}->{factory}";
|
||||||
change = $"{gainfo.Factory}->{factory}";
|
}
|
||||||
}
|
|
||||||
|
if (hasDepartmentChange)
|
||||||
if (gainfo.DepartmentNo != item.appellation)
|
{
|
||||||
{
|
change += $"{gainfo.DepartmentNo}->{item.appellation}";
|
||||||
change += $"{gainfo.DepartmentNo}->{item.appellation}";
|
}
|
||||||
}
|
|
||||||
|
if (change.IsPresent())
|
||||||
if (change.IsPresent())
|
{
|
||||||
{
|
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})");
|
||||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
|
||||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasAllChange = gainfo.Factory != factory || gainfo.Workplace != workplace;
|
|
||||||
|
|
||||||
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||||
{
|
{
|
||||||
@@ -304,43 +304,48 @@ public class GainfoUpdateService : IGainfoUpdateService
|
|||||||
ModifiedTime = DateTime.Now
|
ModifiedTime = DateTime.Now
|
||||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||||
|
|
||||||
if (hasAllChange)
|
//有变更就重新下发
|
||||||
|
if (change.IsPresent())
|
||||||
{
|
{
|
||||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null, $"异动生成({change})");
|
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null, $"异动生成({change})");
|
||||||
|
|
||||||
var workGridUser = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
//只有厂区变更才需要处理工作网格
|
||||||
if (workGridUser != null)
|
if (hasFactoryChange)
|
||||||
{
|
{
|
||||||
try
|
var workGridUser = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
||||||
|
if (workGridUser != null)
|
||||||
{
|
{
|
||||||
var resignationDate = DateOnly.FromDateTime(gainfo.ModifiedTime);
|
try
|
||||||
|
|
||||||
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>().Where(x => x.UserCode == gainfo.Code)
|
|
||||||
.Where(x => x.Date >= resignationDate)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
if (workGridSchedules.Any())
|
|
||||||
{
|
{
|
||||||
var dates = workGridSchedules.Select(x => $"{x.Date.ToString("yyyy年-MM月-dd日")}的{x.PeriodType.GetDescription()}").Join(",");
|
var resignationDate = DateOnly.FromDateTime(gainfo.ModifiedTime);
|
||||||
var workGrid = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.Code == workGridUser.WorkGridCode).Select(x => new
|
|
||||||
{
|
|
||||||
x.LeaderUserCode, x.Name
|
|
||||||
}).SingleAsync();
|
|
||||||
var content = $"{workGrid.Name}的网格长,你好,检测到你网格中 {gainfo.Name}({gainfo.Code}),因发生离职或者异动,现已经删除该员工{dates}的排班信息,请前往系统处理!";
|
|
||||||
|
|
||||||
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
|
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>().Where(x => x.UserCode == gainfo.Code)
|
||||||
|
.Where(x => x.Date >= resignationDate)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (workGridSchedules.Any())
|
||||||
{
|
{
|
||||||
Content = content,
|
var dates = workGridSchedules.Select(x => $"{x.Date.ToString("yyyy年-MM月-dd日")}的{x.PeriodType.GetDescription()}").Join(",");
|
||||||
WorkCodes = new List<string> { workGrid.LeaderUserCode }
|
var workGrid = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.Code == workGridUser.WorkGridCode).Select(x => new
|
||||||
});
|
{
|
||||||
|
x.LeaderUserCode, x.Name
|
||||||
|
}).SingleAsync();
|
||||||
|
var content = $"{workGrid.Name}的网格长,你好,检测到你网格中 {gainfo.Name}({gainfo.Code}),因发生离职或者异动,现已经删除该员工{dates}的排班信息,请前往系统处理!";
|
||||||
|
|
||||||
|
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
|
||||||
|
{
|
||||||
|
Content = content,
|
||||||
|
WorkCodes = new List<string> { workGrid.LeaderUserCode }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await _dbContext.DeleteAsync(workGridUser);
|
||||||
|
await _dbContext.DeleteAsync(workGridSchedules);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "网格异动处理异常:{error}", e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _dbContext.DeleteAsync(workGridUser);
|
|
||||||
await _dbContext.DeleteAsync(workGridSchedules);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError(e, "网格异动处理异常:{error}", e.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user