fix 可获取记录设备保存时候自动产生初始日志
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Basic.Packs;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@@ -5,7 +5,6 @@ using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
@@ -92,9 +91,10 @@ public class DeviceService : IDeviceService
|
||||
var template = await CheckTemplateExistsAsync(request.TemplateCode);
|
||||
await CheckTemplateFieldAsync(request.TemplateCode, request.ConnectionInfo);
|
||||
|
||||
DeviceEntity entity = null;
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<DeviceEntity>();
|
||||
entity = request.Adapt<DeviceEntity>();
|
||||
entity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(entity);
|
||||
//同时保存注册信息
|
||||
@@ -115,7 +115,7 @@ public class DeviceService : IDeviceService
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Id == request.Id).FirstAsync();
|
||||
entity.ThrowIfNull("设备不存在,无法更新");
|
||||
|
||||
//分类发生变化,检查是否存在分组
|
||||
@@ -130,15 +130,42 @@ public class DeviceService : IDeviceService
|
||||
existsG.ThrowIfTrue("存在设备分组,不可修改设备分类");
|
||||
}
|
||||
|
||||
var uniqueNo = entity.UniqueNo;
|
||||
request.Adapt(entity).UniqueNo = uniqueNo;
|
||||
|
||||
request.Adapt(entity);
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
await GenerateUploadRecordLogForBeginTimeAsync(entity);
|
||||
}
|
||||
|
||||
//******************************************************** help methods **********************************************************
|
||||
|
||||
private async Task GenerateUploadRecordLogForBeginTimeAsync(DeviceEntity entity)
|
||||
{
|
||||
if (entity.Type == DeviceTypeEnumType.Door || entity.Type == DeviceTypeEnumType.Attendance)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.Where(x => x.DeviceUniqueNo == entity.UniqueNo)
|
||||
.Where(x => x.Type == DeviceUploadLogTypeEnumType.Raise)
|
||||
.AnyAsync();
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
await _dbContext.InsertAsync(new DeviceUploadLogEntity
|
||||
{
|
||||
DeviceUniqueNo = entity.UniqueNo,
|
||||
Type = DeviceUploadLogTypeEnumType.Raise,
|
||||
UserUniqueNo = string.Empty,
|
||||
RaiseDateTime = entity.CreateTime,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifiedBy = 1,
|
||||
ModifiedTime = DateTime.Now,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查设备模板是否存在
|
||||
/// </summary>
|
||||
@@ -230,6 +257,7 @@ public class DeviceService : IDeviceService
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Enable)
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance))
|
||||
.Select(x => new DeviceResponse
|
||||
{
|
||||
FuncsStr = x.Funcs.ToString()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
@@ -21,6 +22,7 @@ public class DeviceEntity : SugarBaseEntity, ITenantId
|
||||
/// <summary>
|
||||
/// 设备唯一码,IP/MAC/SNO
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(ColumnDescription = "设备唯一码", UniqueGroupNameList = new[] { "Idx_Device_UniqueNo" })]
|
||||
public string UniqueNo { get; set; }
|
||||
|
||||
|
||||
@@ -45,4 +45,16 @@ public class DeviceUploadLogsController : ControllerBase
|
||||
{
|
||||
await _deviceUploadLogService.UploadLogsAsync(requests);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置设备获取记录开始时间
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("reset-begintime")]
|
||||
[Transactional]
|
||||
public async Task SetUploadLogsBeginDateTime(List<SetUploadLogsBeginDateTimeRequest> requests)
|
||||
{
|
||||
await _deviceUploadLogService.SetUploadLogsBeginDateTimeAsync(requests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
|
||||
public class SetUploadLogsBeginDateTimeRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备号不能为空
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "设备号不能为空")]
|
||||
public string DeviceUniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
public DateTime Begin { get; set; }
|
||||
}
|
||||
@@ -10,4 +10,5 @@ public interface IDeviceUploadLogService : IScopeDependency
|
||||
|
||||
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
||||
|
||||
Task SetUploadLogsBeginDateTimeAsync(List<SetUploadLogsBeginDateTimeRequest> requests);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Linq.Expressions;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -95,4 +96,29 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
await _dbContext.InsertAsync(records);
|
||||
}
|
||||
|
||||
public async Task SetUploadLogsBeginDateTimeAsync(List<SetUploadLogsBeginDateTimeRequest> requests)
|
||||
{
|
||||
var uniqueNos = requests.DistinctBy(x => x.DeviceUniqueNo).Select(x => x.DeviceUniqueNo).ToList();
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => uniqueNos.Contains(x.UniqueNo))
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door)
|
||||
.ToListAsync();
|
||||
|
||||
(uniqueNos.Count != devices.Count).ThrowIfTrue("存在非考勤和门禁的设备");
|
||||
|
||||
var tenantId = devices.FirstOrDefault().TenantId;
|
||||
var logs = new List<DeviceUploadLogEntity>(requests.Count);
|
||||
foreach (var request in requests)
|
||||
{
|
||||
logs.Add(new DeviceUploadLogEntity
|
||||
{
|
||||
DeviceUniqueNo = request.DeviceUniqueNo,
|
||||
Type = DeviceUploadLogTypeEnumType.Raise,
|
||||
RaiseDateTime = request.Begin,
|
||||
TenantId = tenantId
|
||||
});
|
||||
}
|
||||
|
||||
await _dbContext.InsertAsync(logs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class JobPack : BaseAppPack
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
});
|
||||
|
||||
//创建设备获取考勤的任务
|
||||
//创建设备获取的任务
|
||||
RecurringJob.AddOrUpdate<CreateGetUploadRecordJob>("CreateGetUploadRecord", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local
|
||||
|
||||
@@ -25,8 +25,7 @@ public class CreateGetUploadRecordJob
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Enable)
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)
|
||||
|| x.Type == DeviceTypeEnumType.Door)
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door)
|
||||
.ToListAsync();
|
||||
|
||||
//过滤处理中的任务
|
||||
|
||||
@@ -315,11 +315,6 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
requests = requests.Where(x => taskIds.Contains(x.TaskId)).ToList();
|
||||
|
||||
deviceTasks.ForEach(x =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
var now = DateTime.Now;
|
||||
var tasks = new List<DeviceTaskEntity>(requests.Count);
|
||||
foreach (var request in requests)
|
||||
|
||||
Reference in New Issue
Block a user