fix 优化数据分析

This commit is contained in:
2025-03-10 17:18:56 +08:00
parent 9012c45267
commit e8b1f8bd3a

View File

@@ -67,15 +67,16 @@ public class DeviceUploadLogService : IDeviceUploadLogService
var max = DateOnly.FromDateTime(requests.Max(x => x.RaiseDateTime));
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>()
.LeftJoin<WorkGridEntity>((x, wg) => x.WorkGridCode == wg.Code)
.Where(x => x.Date >= min && x.Date <= max && userCodes2.Contains(x.UserCode))
.Select((x, wg) => new
.Select(x => new
{
x.UserCode, x.WorkGridCode, x.Date, x.PeriodType, WorkGridName = wg.Name,
wg.LeaderUserCode
x.UserCode, x.WorkGridCode, x.Date, x.PeriodType
})
.ToListAsync();
var workGrids = await _dbContext.Queryable<WorkGridEntity>().ToListAsync();
var workGridUsers = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => userCodes2.Contains(x.UserCode)).ToListAsync();
var inserts = new List<DeviceUploadLogEntity>();
foreach (var request in requests.Where(x => existsDeviceUniqueNos.Contains(x.DeviceUniqueNo)))
{
@@ -112,7 +113,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
var workGridInfo = new WorkGridInfo();
var currentWorkGridTimePeriods = workGridTimePeriods.Where(x => x.TenantId == device.TenantId).ToList();
var currentWorkGridSchedules = workGridSchedules.Where(x => x.UserCode == request.UserUniqueNo).ToList();
if (needUpload && currentWorkGridTimePeriods.Any() && currentWorkGridSchedules.Any())
var currentWorkGridUser = workGridUsers.FirstOrDefault(x => x.UserCode == request.UserUniqueNo); //可能被删除,但还存在当天的排班
if (needUpload && currentWorkGridTimePeriods.Any() && (currentWorkGridUser != null || currentWorkGridSchedules.Any()))
{
workGridInfo.TimeSetting = currentWorkGridTimePeriods.Select(x => new
{
@@ -122,36 +124,48 @@ public class DeviceUploadLogService : IDeviceUploadLogService
x.TenantId
}).ToList();
var currentWorkGridSchedule = currentWorkGridSchedules.First();
workGridInfo.WorkGrid = new
if (currentWorkGridUser != null)
{
currentWorkGridSchedule.WorkGridCode,
currentWorkGridSchedule.WorkGridName,
currentWorkGridSchedule.LeaderUserCode
};
var currentWorkGrid = workGrids.First(x => x.Code == currentWorkGridUser.WorkGridCode);
workGridInfo.WorkGrid = new WorkGridInfoDetail
{
WorkGridCode = currentWorkGrid.Code,
WorkGridName = currentWorkGrid.Name,
LeaderUserCode = currentWorkGrid.LeaderUserCode
};
}
var currentDate = request.RaiseDateTime.Date;
var currentDateOnly = DateOnly.FromDateTime(currentDate);
//白班判断
var currentDayWorkGridTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Day);
if (currentDayWorkGridTimePeriod != null)
var dayTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Day);
if (dayTimePeriod != null)
{
var currentDayWorkGridSchedule = currentWorkGridSchedules.FirstOrDefault(x => x.PeriodType == WorkGridTimePeriodEnumType.Day && x.Date == currentDateOnly);
if (currentDayWorkGridSchedule != null)
{
var start = currentDate.Add(currentDayWorkGridTimePeriod.Start.AddMinutes(-currentDayWorkGridTimePeriod.Before).ToTimeSpan());
var end = currentDate.Add(currentDayWorkGridTimePeriod.End.AddMinutes(currentDayWorkGridTimePeriod.After).ToTimeSpan());
var start = currentDate.Add(dayTimePeriod.Start.AddMinutes(-dayTimePeriod.Before).ToTimeSpan());
var end = currentDate.Add(dayTimePeriod.End.AddMinutes(dayTimePeriod.After).ToTimeSpan());
if (request.RaiseDateTime >= start && request.RaiseDateTime <= end)
{
workGridInfo.PeriodType = WorkGridTimePeriodEnumType.Day;
}
var currentWorkGrid = workGrids.First(x => x.Code == currentDayWorkGridSchedule.WorkGridCode);
workGridInfo.WorkGrid = new WorkGridInfoDetail
{
WorkGridCode = currentWorkGrid.Code,
WorkGridName = currentWorkGrid.Name,
LeaderUserCode = currentWorkGrid.LeaderUserCode
};
}
}
//晚班判断
var currentNightWorkGridTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Night);
if (currentNightWorkGridTimePeriod != null)
var nightTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Night);
if (nightTimePeriod != null)
{
var currentNightWorkGridSchedules = currentWorkGridSchedules
.Where(x => x.PeriodType == WorkGridTimePeriodEnumType.Night)
@@ -160,11 +174,19 @@ public class DeviceUploadLogService : IDeviceUploadLogService
if (currentNightWorkGridSchedules.Any())
{
var startTime = currentNightWorkGridTimePeriod.Start.AddMinutes(-currentNightWorkGridTimePeriod.Before);
var endTime = currentNightWorkGridTimePeriod.End.AddMinutes(currentNightWorkGridTimePeriod.After);
var startTime = nightTimePeriod.Start.AddMinutes(-nightTimePeriod.Before);
var endTime = nightTimePeriod.End.AddMinutes(nightTimePeriod.After);
if (currentNightWorkGridSchedules.Any(x => x.Date == currentDateOnly))
{
var currentWorkGrid = workGrids.First(x => x.Code == currentNightWorkGridSchedules.First(p => p.Date == currentDateOnly).WorkGridCode);
workGridInfo.WorkGrid = new WorkGridInfoDetail
{
WorkGridCode = currentWorkGrid.Code,
WorkGridName = currentWorkGrid.Name,
LeaderUserCode = currentWorkGrid.LeaderUserCode
};
var start = currentDateOnly.ToDateTime(startTime);
var end = currentDateOnly.ToDateTime(new TimeOnly(23, 59, 59, 999));
@@ -172,10 +194,20 @@ public class DeviceUploadLogService : IDeviceUploadLogService
{
workGridInfo.PeriodType = WorkGridTimePeriodEnumType.Night;
}
}
if (currentNightWorkGridSchedules.Any(x => x.Date == currentDateOnly.AddDays(-1)))
{
var currentWorkGrid = workGrids.First(x => x.Code == currentNightWorkGridSchedules.First(p => p.Date == currentDateOnly.AddDays(-1)).WorkGridCode);
workGridInfo.WorkGrid = new WorkGridInfoDetail
{
WorkGridCode = currentWorkGrid.Code,
WorkGridName = currentWorkGrid.Name,
LeaderUserCode = currentWorkGrid.LeaderUserCode
};
var start = currentDateOnly.AddDays(-1).ToDateTime(startTime);
var end = currentDateOnly.ToDateTime(endTime);
@@ -196,8 +228,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
{
await _dingTalkApi.SendWorkMessageAsync(new JinkoSendWorkMessageRequest
{
Content = $"{currentWorkGridSchedule.WorkGridName}的网格长,你好,检测到你网格中 {currentGainfo.Name}({currentGainfo.Code})今日未排班,但是有考勤记录,请前往系统处理!",
WorkCodes = new List<string> { currentWorkGridSchedule.LeaderUserCode }
Content = $"{workGridInfo.WorkGrid.WorkGridName}的网格长,你好,检测到你网格中 {currentGainfo.Name}({currentGainfo.Code})今日未排班,但是有考勤记录,请前往系统处理!",
WorkCodes = new List<string> { workGridInfo.WorkGrid.LeaderUserCode }
});
}
catch (Exception e)
@@ -456,7 +488,14 @@ public class DeviceUploadLogService : IDeviceUploadLogService
public class WorkGridInfo
{
public bool IsError => !PeriodType.HasValue;
public object WorkGrid { get; set; }
public WorkGridInfoDetail WorkGrid { get; set; }
public WorkGridTimePeriodEnumType? PeriodType { get; set; }
public object TimeSetting { get; set; }
}
public class WorkGridInfoDetail
{
public Guid WorkGridCode { get; set; }
public string WorkGridName { get; set; }
public string LeaderUserCode { get; set; }
}