fix 增加通行记录判断
This commit is contained in:
@@ -6,6 +6,7 @@ using Kurisu.AspNetCore.Authentication.Abstractions;
|
|||||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Common.ApiLog.Services.Implements;
|
namespace Dlhis.Basic.Common.ApiLog.Services.Implements;
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ public class OperateLogService : IOperateLog
|
|||||||
Operator = x.Operator,
|
Operator = x.Operator,
|
||||||
CreateTime = x.CreateTime
|
CreateTime = x.CreateTime
|
||||||
})
|
})
|
||||||
|
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,13 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
|
|||||||
public string Image { get; set; }
|
public string Image { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 网格信息
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true, ColumnDataType = "text")]
|
||||||
|
public string WorkGridInfo { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[SugarColumn(IndexGroupNameList = new[] { "idx_DeviceUploadLog_TenantId" })]
|
[SugarColumn(IndexGroupNameList = new[] { "idx_DeviceUploadLog_TenantId" })]
|
||||||
public string TenantId { get; set; }
|
public string TenantId { get; set; }
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,28 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
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.Type }).ToListAsync();
|
||||||
var gainfos = gainfo1.Concat(gainfo2).Concat(gainfo3).DistinctBy(x => x.Code).ToList();
|
var gainfos = gainfo1.Concat(gainfo2).Concat(gainfo3).DistinctBy(x => x.Code).ToList();
|
||||||
|
|
||||||
|
var userCodes2 = gainfos.Select(x => x.Code).Distinct().ToList();
|
||||||
|
|
||||||
|
var min = DateOnly.FromDateTime(requests.Min(x => x.RaiseDateTime)).AddDays(-1);
|
||||||
|
var max = DateOnly.FromDateTime(requests.Max(x => x.RaiseDateTime));
|
||||||
|
|
||||||
|
var workGridUsers = await _dbContext.Queryable<WorkGridUserEntity>()
|
||||||
|
.Where(x => userCodes2.Contains(x.UserCode))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var workGridSchedules = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||||
|
.Where(x => x.Date >= min && x.Date <= max)
|
||||||
|
.Where(x => userCodes2.Contains(x.UserCode)).ToListAsync();
|
||||||
|
|
||||||
|
var factories = devices.Select(x => x.TenantId).Distinct().ToList();
|
||||||
|
var workGridTimePeriods = await _dbContext.Queryable<WorkGridTimePeriodEntity>()
|
||||||
|
.Where(x => factories.Contains(x.TenantId))
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
x.Type, x.Start, x.End, x.Before, x.After, x.TenantId
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
var inserts = new List<DeviceUploadLogEntity>();
|
var inserts = new List<DeviceUploadLogEntity>();
|
||||||
foreach (var request in requests.Where(x => existsDeviceUniqueNos.Contains(x.DeviceUniqueNo)))
|
foreach (var request in requests.Where(x => existsDeviceUniqueNos.Contains(x.DeviceUniqueNo)))
|
||||||
{
|
{
|
||||||
@@ -68,10 +90,70 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
var device = devices.First(x => x.UniqueNo == request.DeviceUniqueNo);
|
var device = devices.First(x => x.UniqueNo == request.DeviceUniqueNo);
|
||||||
|
|
||||||
var userType = gainfos.FirstOrDefault(x => x.Code == request.UserUniqueNo)?.Type;
|
var userType = gainfos.FirstOrDefault(x => x.Code == request.UserUniqueNo)?.Type;
|
||||||
var needUpload = userType is GainfoUserTypeEnumType.Normal or GainfoUserTypeEnumType.SecurityWhite && (device.Type == DeviceTypeEnumType.Attendance || (device.Type == DeviceTypeEnumType.Door && device.AsAttendance));
|
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
|
var dataType = device.Type == DeviceTypeEnumType.Attendance
|
||||||
? DeviceUploadLogTypeEnumType.Attendance
|
? DeviceUploadLogTypeEnumType.Attendance
|
||||||
: DeviceUploadLogTypeEnumType.Door;
|
: DeviceUploadLogTypeEnumType.Door;
|
||||||
|
|
||||||
|
var workGridInfo = new WorkGridInfo();
|
||||||
|
var currentWorkGridTimePeriods = workGridTimePeriods.Where(x => x.TenantId == device.TenantId).ToList();
|
||||||
|
var workGridUser = workGridUsers.FirstOrDefault(x => x.UserCode == request.UserUniqueNo);
|
||||||
|
if (currentWorkGridTimePeriods.Any() && workGridUser != null)
|
||||||
|
{
|
||||||
|
workGridInfo.TimeSetting = currentWorkGridTimePeriods;
|
||||||
|
workGridInfo.WorkGrid = new
|
||||||
|
{
|
||||||
|
workGridUser.WorkGridCode
|
||||||
|
};
|
||||||
|
var currentDate = request.RaiseDateTime.Date;
|
||||||
|
var currentDateOnly = DateOnly.FromDateTime(currentDate);
|
||||||
|
|
||||||
|
var currentDayWorkGridTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Day);
|
||||||
|
var currentDayWorkGridSchedule = workGridSchedules.FirstOrDefault(x => x.PeriodType == WorkGridTimePeriodEnumType.Day && x.Date == currentDateOnly);
|
||||||
|
if (currentDayWorkGridTimePeriod != null && currentDayWorkGridSchedule != null)
|
||||||
|
{
|
||||||
|
var start = currentDate.Add(currentDayWorkGridTimePeriod.Start.AddMinutes(currentDayWorkGridTimePeriod.Before).ToTimeSpan());
|
||||||
|
var end = currentDate.Add(currentDayWorkGridTimePeriod.End.AddMinutes(currentDayWorkGridTimePeriod.After).ToTimeSpan());
|
||||||
|
|
||||||
|
if (request.RaiseDateTime >= start && request.RaiseDateTime <= end)
|
||||||
|
{
|
||||||
|
workGridInfo.PeriodType = WorkGridTimePeriodEnumType.Day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentNightWorkGridTimePeriod = currentWorkGridTimePeriods.FirstOrDefault(x => x.Type == WorkGridTimePeriodEnumType.Night);
|
||||||
|
var currentNightWorkGridSchedules = workGridSchedules
|
||||||
|
.Where(x => x.PeriodType == WorkGridTimePeriodEnumType.Night && (x.Date == currentDateOnly || x.Date == currentDateOnly.AddDays(-1))).ToList();
|
||||||
|
if (currentNightWorkGridTimePeriod != null && currentNightWorkGridSchedules.Any())
|
||||||
|
{
|
||||||
|
var startTime = currentNightWorkGridTimePeriod.Start.AddMinutes(currentNightWorkGridTimePeriod.Before);
|
||||||
|
var endTime = currentNightWorkGridTimePeriod.End.AddMinutes(currentNightWorkGridTimePeriod.After);
|
||||||
|
|
||||||
|
if (currentNightWorkGridSchedules.Any(x => x.Date == currentDateOnly))
|
||||||
|
{
|
||||||
|
var start = currentDateOnly.ToDateTime(startTime);
|
||||||
|
var end = currentDateOnly.ToDateTime(new TimeOnly(23, 59, 59, 999));
|
||||||
|
|
||||||
|
if (request.RaiseDateTime >= start && request.RaiseDateTime <= end)
|
||||||
|
{
|
||||||
|
workGridInfo.PeriodType = WorkGridTimePeriodEnumType.Night;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentNightWorkGridSchedules.Any(x => x.Date == currentDateOnly.AddDays(-1)))
|
||||||
|
{
|
||||||
|
var start = currentDateOnly.AddDays(-1).ToDateTime(startTime);
|
||||||
|
var end = currentDateOnly.ToDateTime(endTime);
|
||||||
|
|
||||||
|
if (request.RaiseDateTime >= start && request.RaiseDateTime <= end)
|
||||||
|
{
|
||||||
|
workGridInfo.PeriodType = WorkGridTimePeriodEnumType.Night;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inserts.Add(new DeviceUploadLogEntity
|
inserts.Add(new DeviceUploadLogEntity
|
||||||
{
|
{
|
||||||
DeviceCode = device.Code,
|
DeviceCode = device.Code,
|
||||||
@@ -85,6 +167,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
TenantId = device.TenantId,
|
TenantId = device.TenantId,
|
||||||
Status = request.Status ?? true,
|
Status = request.Status ?? true,
|
||||||
Image = request.Image,
|
Image = request.Image,
|
||||||
|
WorkGridInfo = workGridInfo.ToJson(),
|
||||||
CreatedBy = 1,
|
CreatedBy = 1,
|
||||||
ModifiedBy = 1
|
ModifiedBy = 1
|
||||||
});
|
});
|
||||||
@@ -316,4 +399,13 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
Data = r
|
Data = r
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WorkGridInfo
|
||||||
|
{
|
||||||
|
public object WorkGrid { get; set; }
|
||||||
|
public WorkGridTimePeriodEnumType? PeriodType { get; set; }
|
||||||
|
public object TimeSetting { get; set; }
|
||||||
|
|
||||||
|
public bool NeedUpload => WorkGrid != null && PeriodType.HasValue;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user