fix 逻辑删除增加,消息通知

This commit is contained in:
2025-03-06 16:49:02 +08:00
parent 7e71884b32
commit bf392a7c46
16 changed files with 170 additions and 28 deletions

View File

@@ -5,6 +5,8 @@ using Dlhis.Entity.Device.Enums;
using Dlhis.Entity.Sys.Entities;
using Dlhis.Entity.Sys.Enums;
using Dlhis.Jip.Api.Dto;
using Dlhis.Message.Api;
using Dlhis.Message.Api.Requests;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
@@ -16,12 +18,14 @@ public class GainfoUpdateService : IGainfoUpdateService
private readonly ILogger<GainfoUpdateService> _logger;
private readonly IJinkoSapService _jinkoSapService;
private readonly IGainfoPermissionService _gainfoPermissionService;
private readonly IDingTalkApi _dingTalkApi;
private readonly IIdentityUserSyncService _identityUserSyncService;
public GainfoUpdateService(IDbContext dbContext,
ILogger<GainfoUpdateService> logger,
IJinkoSapService jinkoSapService,
IGainfoPermissionService gainfoPermissionService,
IDingTalkApi dingTalkApi,
IIdentityUserSyncService identityUserSyncService)
{
_dbContext = dbContext;
@@ -29,6 +33,7 @@ public class GainfoUpdateService : IGainfoUpdateService
_logger = logger;
_jinkoSapService = jinkoSapService;
_gainfoPermissionService = gainfoPermissionService;
_dingTalkApi = dingTalkApi;
_identityUserSyncService = identityUserSyncService;
}
@@ -276,7 +281,7 @@ public class GainfoUpdateService : IGainfoUpdateService
if (change.IsPresent())
{
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})");
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})");
}
}
@@ -303,6 +308,43 @@ public class GainfoUpdateService : IGainfoUpdateService
if (change.IsPresent())
{
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)
{
try
{
var resignationDate = DateOnly.FromDateTime(gainfo.ResignationDate!.Value);
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 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);
}
}
}
}
else
@@ -322,6 +364,42 @@ public class GainfoUpdateService : IGainfoUpdateService
await _dbContext.Deleteable<GainfoGroupRelationshipEntity>().Where(x => x.UserNo == gainfo.No).ExecuteCommandAsync();
await _dbContext.Deleteable<DevicePermissionEntity>().Where(x => x.AssignType == AssignTypeEnumType.User && x.AssignValue == gainfo.No).ExecuteCommandAsync();
var workGridUser = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
if (workGridUser != null)
{
try
{
var resignationDate = DateOnly.FromDateTime(gainfo.ResignationDate!.Value);
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 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);
}
}
gainfo.Id = gainfo.IdentityUserId;
await _dbContext.DeleteReallyAsync(gainfo);
await _identityUserSyncService.LockAccountAsync(gainfo.Code);