Merge branch 'development'
This commit is contained in:
@@ -79,4 +79,24 @@ public class DeviceUploadLogsController : ControllerBase
|
||||
{
|
||||
return await _deviceUploadLogService.GetDeviceUploadRecordSettingAsync(deviceNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动上传考勤记录
|
||||
/// </summary>
|
||||
/// <param name="logIds"></param>
|
||||
[HttpPost("manuallyUpload")]
|
||||
public async Task ManuallyUploadAsync(List<long> logIds)
|
||||
{
|
||||
await _deviceUploadLogService.ManuallyUploadAsync(logIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动设置上传考勤时间范围
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[HttpPost("manuallySetTimeInfo")]
|
||||
public async Task ManuallySetTimeInfoAsync(DeviceUploadLogManuallySetTimeInfoRequest request)
|
||||
{
|
||||
await _deviceUploadLogService.ManuallySetTimeInfoAsync(request.DeviceNo, request.Start, request.End);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
|
||||
public class DeviceUploadLogManuallySetTimeInfoRequest : IValidatableObject
|
||||
{
|
||||
[Required(ErrorMessage = "设备号不能为空")]
|
||||
public string DeviceNo { get; set; }
|
||||
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
public DateTime End { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Start >= End)
|
||||
{
|
||||
yield return new ValidationResult("开始时间不可大于等于结束时间");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public interface IDeviceUploadLogService : IScopeDependency
|
||||
/// <param name="requests"></param>
|
||||
/// <returns></returns>
|
||||
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询通行记录分页
|
||||
/// </summary>
|
||||
@@ -28,13 +28,30 @@ public interface IDeviceUploadLogService : IScopeDependency
|
||||
/// <returns></returns>
|
||||
Task<List<DeviceUploadLogResponse>> GetMyRecordsAsync(DeviceUploadLogMyRecordRequest request);
|
||||
|
||||
|
||||
Task QiaoqiaoGaoshiqingAsync(DeviceUploadLogSecretAddRequest request);
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取设备记录获取的开始-结束时间
|
||||
/// </summary>
|
||||
/// <param name="deviceNo"></param>
|
||||
/// <returns></returns>
|
||||
Task<DateTimePeriod> GetDeviceUploadRecordSettingAsync(string deviceNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动上传考勤记录
|
||||
/// </summary>
|
||||
/// <param name="requestIds"></param>
|
||||
/// <returns></returns>
|
||||
Task ManuallyUploadAsync(List<long> requestIds);
|
||||
|
||||
/// <summary>
|
||||
/// 手动设置获取记录时间范围
|
||||
/// </summary>
|
||||
/// <param name="deviceNo"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
Task ManuallySetTimeInfoAsync(string deviceNo, DateTime start, DateTime end);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Jip.Api;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
@@ -16,11 +18,13 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IJinkoJipApi _jinkoJipApi;
|
||||
|
||||
public DeviceUploadLogService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public DeviceUploadLogService(IDbContext dbContext, ICurrentUser currentUser, IJinkoJipApi jinkoJipApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_jinkoJipApi = jinkoJipApi;
|
||||
}
|
||||
|
||||
public async Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests)
|
||||
@@ -103,6 +107,66 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ManuallyUploadAsync(List<long> requestIds)
|
||||
{
|
||||
var existsOther = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.Where(x => requestIds.Contains(x.Id))
|
||||
.Where(x => x.Type != DeviceUploadLogTypeEnumType.Attendance)
|
||||
.AnyAsync();
|
||||
|
||||
existsOther.ThrowIfTrue("存在非考勤通行记录,无法上传");
|
||||
|
||||
var requests = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, device) => x.DeviceUniqueNo == device.UniqueNo)
|
||||
.Where(x => x.Sync == false)
|
||||
.Where(x => !string.IsNullOrEmpty(x.UserUniqueNo))
|
||||
.Where(x => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == x.UserUniqueNo).NotAny())
|
||||
.Where(x => requestIds.Contains(x.Id))
|
||||
.Select((x, device) => new UploadAttendanceRequestItem
|
||||
{
|
||||
Id = x.Id,
|
||||
RaiseDateTime = x.RaiseDateTime,
|
||||
ZNOTE = device.DeployPlace,
|
||||
ZWORKCODE = x.UserUniqueNo
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
if (requests.Any())
|
||||
{
|
||||
foreach (var items in requests.Chunk(500))
|
||||
{
|
||||
var ids = items.Select(x => x.Id).ToList();
|
||||
var r = await _jinkoJipApi.UploadAttendancesAsync(new UploadAttendanceRequest { Data = items.ToList() });
|
||||
if (r.OLX == "0")
|
||||
{
|
||||
await _dbContext.Updateable<DeviceUploadLogEntity>()
|
||||
.SetColumns(x => x.Sync == true)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ManuallySetTimeInfoAsync(string deviceNo, DateTime start, DateTime end)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == deviceNo).SingleAsync();
|
||||
(device.Type != DeviceTypeEnumType.Attendance && device.Type != DeviceTypeEnumType.Door).ThrowIfTrue("不支持该设备类型");
|
||||
var exists = await _dbContext.Queryable<DeviceUploadLogManuallyEntity>().Where(x => x.DeviceNo == deviceNo).Where(x => x.IsFinished == false).AnyAsync();
|
||||
exists.ThrowIfTrue("已存在配置尚未完成");
|
||||
|
||||
await _dbContext.InsertAsync(new DeviceUploadLogManuallyEntity
|
||||
{
|
||||
DeviceNo = deviceNo,
|
||||
Start = start,
|
||||
End = end,
|
||||
IsFinished = false
|
||||
});
|
||||
}
|
||||
|
||||
public async Task QiaoqiaoGaoshiqingAsync(DeviceUploadLogSecretAddRequest request)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == request.DeviceUniqueNo).SingleAsync();
|
||||
@@ -122,7 +186,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
TenantId = device.TenantId,
|
||||
Status = true,
|
||||
CreatedBy = 1,
|
||||
ModifiedBy = 1,
|
||||
ModifiedBy = 1
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ public class CreateGetUploadRecordJob : BaseJob
|
||||
TenantId = x.TenantId,
|
||||
Version = 0,
|
||||
Type = DeviceTaskEnumType.UploadRecord,
|
||||
CancellationId = 0,
|
||||
Priority = 50,
|
||||
Source = "定时任务创建设备获取通行记录任务"
|
||||
}).ToList();
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
"profiles": {
|
||||
"Dlhis.ScheduledTask": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger/index.html",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://*:5010"
|
||||
"applicationUrl": "http://localhost:5010;http://*:5010;"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ using Newtonsoft.Json.Linq;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Dto;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||
@@ -153,12 +152,13 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
case DeviceTaskEnumType.UploadRecord:
|
||||
{
|
||||
var timeInfo = deviceUploadInfos[d];
|
||||
dto.Info = new UploadRecordToDeviceResponse
|
||||
{
|
||||
DateTimePeriod = new DateTimePeriod
|
||||
{
|
||||
Start = deviceUploadInfos.TryGetValue(d, out var dt) ? (dt ?? DateTime.Now) : DateTime.Now,
|
||||
End = DateTime.Now.AddDays(1)
|
||||
Start = timeInfo.Item1,
|
||||
End = timeInfo.Item2
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -262,8 +262,6 @@ public class AssignmentService : IAssignmentService
|
||||
.WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand)
|
||||
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, deviceRegistry) =>
|
||||
device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now)
|
||||
#if !DEBUG
|
||||
#endif
|
||||
.OrderBy(deviceTask => new { deviceTask.CreateTime, Priority = SqlFunc.Desc(deviceTask.Priority) })
|
||||
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department) => new TaskDto
|
||||
{
|
||||
@@ -328,15 +326,21 @@ public class AssignmentService : IAssignmentService
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<string, DateTime?>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data)
|
||||
private async Task<Dictionary<string, (DateTime, DateTime)>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data)
|
||||
{
|
||||
if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord))
|
||||
{
|
||||
return new Dictionary<string, DateTime?>();
|
||||
return new Dictionary<string, (DateTime, DateTime)>();
|
||||
}
|
||||
|
||||
var deviceNos = data.Select(x => x.DeviceUniqueNo).Distinct().ToList();
|
||||
var result = new Dictionary<string, DateTime?>(deviceNos.Count);
|
||||
var result = new Dictionary<string, (DateTime, DateTime)>(deviceNos.Count);
|
||||
|
||||
var manualSettings = await _dbContext.Queryable<DeviceUploadLogManuallyEntity>().Where(x => deviceNos.Contains(x.DeviceNo))
|
||||
.Where(x => x.IsFinished == false)
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.Select(x => new { x.Id, x.DeviceNo, x.Start, x.End })
|
||||
.ToListAsync();
|
||||
|
||||
var logInfos = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.GroupBy(x => x.DeviceUniqueNo)
|
||||
@@ -347,12 +351,27 @@ public class AssignmentService : IAssignmentService
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var commonEnd = DateTime.Now.AddDays(1);
|
||||
foreach (var item in deviceNos)
|
||||
{
|
||||
var logInfo = logInfos.FirstOrDefault(x => x.DeviceUniqueNo == item);
|
||||
result.Add(item, logInfo?.RaiseDateTime);
|
||||
var setting = manualSettings.FirstOrDefault(x => x.DeviceNo == item);
|
||||
if (setting != null)
|
||||
{
|
||||
result.Add(item, (setting.Start, setting.End));
|
||||
}
|
||||
else
|
||||
{
|
||||
var logInfo = logInfos.FirstOrDefault(x => x.DeviceUniqueNo == item);
|
||||
result.Add(item, logInfo == null ? (DateTime.Now.AddMinutes(-10), commonEnd) : (logInfo.RaiseDateTime, commonEnd));
|
||||
}
|
||||
}
|
||||
|
||||
//更新为已处理
|
||||
await _dbContext.Updateable<DeviceUploadLogManuallyEntity>()
|
||||
.SetColumns(x => x.IsFinished == true)
|
||||
.Where(x => manualSettings.Select(p => p.Id).Contains(x.Id))
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user