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