fix 逻辑删除增加,消息通知
This commit is contained in:
@@ -5,6 +5,8 @@ using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Jip.Api;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.Message.Api;
|
||||
using Dlhis.Message.Api.Requests;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
@@ -21,12 +23,20 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IJinkoJipApi _jinkoJipApi;
|
||||
private readonly ILogger<DeviceUploadLogService> _logger;
|
||||
private readonly IDingTalkApi _dingTalkApi;
|
||||
|
||||
public DeviceUploadLogService(IDbContext dbContext, ICurrentUser currentUser, IJinkoJipApi jinkoJipApi)
|
||||
public DeviceUploadLogService(IDbContext dbContext,
|
||||
ICurrentUser currentUser,
|
||||
IJinkoJipApi jinkoJipApi,
|
||||
ILogger<DeviceUploadLogService> logger,
|
||||
IDingTalkApi dingTalkApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_jinkoJipApi = jinkoJipApi;
|
||||
_logger = logger;
|
||||
_dingTalkApi = dingTalkApi;
|
||||
}
|
||||
|
||||
public async Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests)
|
||||
@@ -36,10 +46,10 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
var existsDeviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var userCodes = requests.Where(x => x.UserUniqueNo.IsPresent()).Select(x => x.UserUniqueNo).Distinct().ToList();
|
||||
var gainfo1 = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Type }).ToListAsync();
|
||||
var gainfo2 = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave").Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Type }).ToListAsync();
|
||||
var gainfo1 = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Name, x.Type }).ToListAsync();
|
||||
var gainfo2 = await _dbContext.Queryable<GainfoEntity>().AS("GainfoLeave").Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Name, x.Type }).ToListAsync();
|
||||
var gainfoCardNos = requests.Where(x => x.CardNo.IsPresent() && x.UserUniqueNo != x.CardNo).Select(x => x.CardNo).Distinct().ToList();
|
||||
var gainfo3 = await _dbContext.Queryable<GainfoEntity>().Where(x => gainfoCardNos.Contains(x.Code)).Select(x => new { x.Code, x.Type }).ToListAsync();
|
||||
var gainfo3 = await _dbContext.Queryable<GainfoEntity>().Where(x => gainfoCardNos.Contains(x.Code)).Select(x => new { x.Code, x.Name, x.Type }).ToListAsync();
|
||||
var gainfos = gainfo1.Concat(gainfo2).Concat(gainfo3).DistinctBy(x => x.Code).ToList();
|
||||
|
||||
var userCodes2 = gainfos.Select(x => x.Code).Distinct().ToList();
|
||||
@@ -52,7 +62,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
.Where(x => userCodes2.Contains(x.UserCode))
|
||||
.Select((x, wg) => new
|
||||
{
|
||||
x.WorkGridCode, x.UserCode, wg.LeaderUserCode, wg.Name
|
||||
x.WorkGridCode, x.UserCode, wg.LeaderUserCode, WorkGridName = wg.Name
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
@@ -94,7 +104,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
|
||||
var device = devices.First(x => x.UniqueNo == request.DeviceUniqueNo);
|
||||
|
||||
var userType = gainfos.FirstOrDefault(x => x.Code == request.UserUniqueNo)?.Type;
|
||||
var currentGainfo = gainfos.FirstOrDefault(x => x.Code == request.UserUniqueNo);
|
||||
var userType = currentGainfo?.Type;
|
||||
var needUpload = ((userType is GainfoUserTypeEnumType.Normal or GainfoUserTypeEnumType.SecurityWhite)
|
||||
&& (device.Type == DeviceTypeEnumType.Attendance || (device.Type == DeviceTypeEnumType.Door && device.AsAttendance)));
|
||||
var dataType = device.Type == DeviceTypeEnumType.Attendance
|
||||
@@ -114,7 +125,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
workGridInfo.WorkGrid = new
|
||||
{
|
||||
workGridUser.WorkGridCode,
|
||||
workGridUser.Name,
|
||||
workGridUser.WorkGridName,
|
||||
workGridUser.LeaderUserCode
|
||||
};
|
||||
var currentDate = request.RaiseDateTime.Date;
|
||||
@@ -165,6 +176,22 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
}
|
||||
|
||||
needUpload = workGridInfo.PeriodType.HasValue;
|
||||
|
||||
if (!needUpload)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
|
||||
{
|
||||
Content = $"{workGridUser.WorkGridName}的网格长,你好,检测到你网格中 {currentGainfo.Name}({currentGainfo.Code})今日未排班,但是有考勤记录,请前往系统处理!",
|
||||
WorkCodes = new List<string> { workGridUser.LeaderUserCode }
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "推送信息错误:{error}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inserts.Add(new DeviceUploadLogEntity
|
||||
|
||||
Reference in New Issue
Block a user