fix 通行记录数据上报处理
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
@@ -9,9 +10,15 @@ namespace Dlhis.Entity.Device.Entities;
|
||||
[SugarTable(TableName = "DeviceUploadLog", TableDescription = "设备上传记录")]
|
||||
public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
[SugarColumn(IsNullable = true)]
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public string SerialNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备code
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public Guid DeviceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
@@ -24,6 +31,12 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string UserUniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员类型
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "人员类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public GainfoUserTypeEnumType? UserType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产生时间
|
||||
/// </summary>
|
||||
@@ -31,21 +44,27 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId
|
||||
public DateTime RaiseDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 日志类型
|
||||
/// 记录类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public DeviceUploadLogTypeEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否要上传
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit", DefaultValue = "0")]
|
||||
public bool NeedUpload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 同步数据
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit")]
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit", DefaultValue = "0")]
|
||||
public bool Sync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType = "bit")]
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "bit")]
|
||||
public bool Status { get; set; }
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync();
|
||||
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 gainfos = gainfo1.Concat(gainfo2).DistinctBy(x => x.Code).ToList();
|
||||
|
||||
var inserts = new List<DeviceUploadLogEntity>();
|
||||
foreach (var request in requests.Where(x => existsDeviceUniqueNos.Contains(x.DeviceUniqueNo)))
|
||||
{
|
||||
@@ -60,20 +65,20 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
|
||||
inserts.Add(new DeviceUploadLogEntity
|
||||
{
|
||||
DeviceCode = device.Code,
|
||||
DeviceUniqueNo = request.DeviceUniqueNo,
|
||||
UserUniqueNo = request.UserUniqueNo,
|
||||
UserType = gainfos.FirstOrDefault(x => x.Code == request.UserUniqueNo)?.Type,
|
||||
RaiseDateTime = request.RaiseDateTime,
|
||||
SerialNo = request.SerialNo,
|
||||
SerialNo = request.SerialNo ?? string.Empty,
|
||||
Type = device.Type == DeviceTypeEnumType.Attendance
|
||||
? DeviceUploadLogTypeEnumType.Attendance
|
||||
: device.Type == DeviceTypeEnumType.Door && device.AsAttendance
|
||||
? DeviceUploadLogTypeEnumType.Attendance
|
||||
: DeviceUploadLogTypeEnumType.Door,
|
||||
|
||||
: DeviceUploadLogTypeEnumType.Door,
|
||||
NeedUpload = device.Type == DeviceTypeEnumType.Attendance || (device.Type == DeviceTypeEnumType.Door && device.AsAttendance),
|
||||
TenantId = device.TenantId,
|
||||
Status = request.Status ?? true,
|
||||
CreatedBy = 1,
|
||||
ModifiedBy = 1,
|
||||
ModifiedBy = 1
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user