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

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