feat 手动上传,手动设置时间范围

This commit is contained in:
2024-12-19 15:21:45 +08:00
parent e8632b0d49
commit 0f69c56a93
39 changed files with 458 additions and 304 deletions

View File

@@ -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);
}
}

View File

@@ -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("开始时间不可大于等于结束时间");
}
}
}

View File

@@ -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; }
}

View File

@@ -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);
}

View File

@@ -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,64 @@ 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 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 +184,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
TenantId = device.TenantId,
Status = true,
CreatedBy = 1,
ModifiedBy = 1,
ModifiedBy = 1
});
}