fix 调整时段码结构
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -8,12 +9,12 @@ using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Kurisu.AspNetCore;
|
||||
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;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||
|
||||
@@ -37,6 +38,8 @@ public class AssignmentService : IAssignmentService
|
||||
var data = await GetDataAsync(request);
|
||||
if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>();
|
||||
|
||||
await HandlerOldDeviceGainfoAsync(data);
|
||||
await HandlerTimePeriodAsync(data);
|
||||
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
|
||||
|
||||
var timeLimitedDataProtector = _dataProtectionProvider
|
||||
@@ -90,14 +93,14 @@ public class AssignmentService : IAssignmentService
|
||||
UserName = item.UserName,
|
||||
DepartmentNo = item.DepartmentNo,
|
||||
DepartmentName = item.DepartmentName,
|
||||
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo,
|
||||
CardNo = item.CardNo,
|
||||
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token, //下发才附带照片信息
|
||||
ValidDatePeriod = new DatePeriod
|
||||
{
|
||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||
},
|
||||
TimePeriods = new List<int> { 1 },
|
||||
TimePeriods = new List<int> { item.CardType },
|
||||
Doors = new List<int> { 1 },
|
||||
Schedule = 1
|
||||
};
|
||||
@@ -106,27 +109,22 @@ public class AssignmentService : IAssignmentService
|
||||
case DeviceTaskEnumType.TimePeriodAdd:
|
||||
case DeviceTaskEnumType.TimePeriodDelete:
|
||||
{
|
||||
dto.Info = new TimePeriodToDeviceResponse
|
||||
dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse
|
||||
{
|
||||
Id = 1,
|
||||
Name = "小白领",
|
||||
Id = t.CardType,
|
||||
Name = t.CardType == 2 ? "行政卡" : "车间卡",
|
||||
Enable = true,
|
||||
Sections = new List<TimePeriodWeekDaySection>
|
||||
Sections = t.Sections.Select(s => new TimePeriodWeekDaySection
|
||||
{
|
||||
new()
|
||||
DayOfWeek = s.DayOfWeek,
|
||||
TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod
|
||||
{
|
||||
DayOfWeek = DayOfWeek.Monday,
|
||||
TimePeriods = new List<TimePeriod>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Start = TimeOnly.Parse("08:00:00"),
|
||||
End = TimeOnly.Parse("17:30:00")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Enable = p.Enable,
|
||||
Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00),
|
||||
End = p.Enable ? p.End : new TimeOnly(00, 00, 00),
|
||||
}).ToList()
|
||||
}).ToList()
|
||||
});
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.ScheduleAdd:
|
||||
@@ -173,33 +171,6 @@ public class AssignmentService : IAssignmentService
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取新token
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<string> RenewFaceUrlAsync(long taskId)
|
||||
{
|
||||
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
|
||||
task.ThrowIfNull("该任务不存在");
|
||||
(task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}");
|
||||
|
||||
var faceUrlOptions = App.GetServiceProvider(true).GetService<IOptions<FaceUrlOptions>>().Value;
|
||||
var dataProtectionProvider = App.GetServiceProvider(true).GetService<IDataProtectionProvider>();
|
||||
|
||||
var timeLimitedDataProtector = dataProtectionProvider
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
|
||||
var userCode = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == task.UserNo).Select(x => x.Code).SingleAsync();
|
||||
|
||||
var key = $"face:{userCode}";
|
||||
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
|
||||
|
||||
return faceUrlOptions.Url + token;
|
||||
}
|
||||
|
||||
|
||||
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
||||
{
|
||||
@@ -290,8 +261,12 @@ public class AssignmentService : IAssignmentService
|
||||
.WhereIF(factories.Any(), (deviceTask, device) => factories.Contains(deviceTask.TenantId))
|
||||
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
|
||||
.WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand)
|
||||
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) =>
|
||||
|
||||
#if !DEBUG
|
||||
.Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) =>
|
||||
device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now)
|
||||
#endif
|
||||
|
||||
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
|
||||
.Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto
|
||||
{
|
||||
@@ -313,7 +288,13 @@ public class AssignmentService : IAssignmentService
|
||||
DepartmentName = department.Name,
|
||||
CardNo = ga.CardNo,
|
||||
Version = deviceTask.Version,
|
||||
Status = deviceTask.Status
|
||||
Status = deviceTask.Status,
|
||||
EnableTimePeriod = device.EnableTimePeriod,
|
||||
CardType = device.EnableTimePeriod
|
||||
? SqlFunc.IsNullOrEmpty(ga.CardType)
|
||||
? 1
|
||||
: SqlFunc.ToInt32(ga.CardType)
|
||||
: 1
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
@@ -338,28 +319,17 @@ public class AssignmentService : IAssignmentService
|
||||
throw new VersionExceptions("version exceptions");
|
||||
}
|
||||
|
||||
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
|
||||
{
|
||||
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
|
||||
page.Data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); });
|
||||
var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error)
|
||||
.Where(oldDeviceGainfoWhere)
|
||||
.ToListAsync();
|
||||
|
||||
page.Data.ForEach(item =>
|
||||
{
|
||||
var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo);
|
||||
if (o != null)
|
||||
item.OldUserNo = o.No;
|
||||
});
|
||||
}
|
||||
|
||||
return page.Data;
|
||||
}, 5);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理获取上传记录的任务
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<string, DateTime?>> GetDeviceUploadRecordInfosAsync(List<TaskDto> data)
|
||||
{
|
||||
if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord))
|
||||
@@ -383,4 +353,65 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理老档案数据
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
private async Task HandlerOldDeviceGainfoAsync(List<TaskDto> data)
|
||||
{
|
||||
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
|
||||
{
|
||||
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
|
||||
data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); });
|
||||
var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error)
|
||||
.Where(oldDeviceGainfoWhere)
|
||||
.ToListAsync();
|
||||
|
||||
data.ForEach(item =>
|
||||
{
|
||||
var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo);
|
||||
if (o != null)
|
||||
item.OldUserNo = o.No;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task HandlerTimePeriodAsync(List<TaskDto> data)
|
||||
{
|
||||
var tasks = data.Where(x => x.EnableTimePeriod).Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList();
|
||||
var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList();
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync();
|
||||
var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList();
|
||||
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
|
||||
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
||||
.Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value))
|
||||
|| (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value)))
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
data.ForEach(item =>
|
||||
{
|
||||
var templateCode = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.TemplateCode;
|
||||
var code = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.Code;
|
||||
|
||||
var tSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template).Where(x => x.Value == templateCode).ToList();
|
||||
var dSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Device).Where(x => x.Value == code).ToList();
|
||||
|
||||
foreach (var setting in dSettings)
|
||||
{
|
||||
var s = tSettings.FirstOrDefault(x => x.CardType == setting.CardType);
|
||||
if (s != null)
|
||||
{
|
||||
tSettings.Remove(s);
|
||||
}
|
||||
|
||||
tSettings.Add(setting);
|
||||
}
|
||||
|
||||
item.TimePeriods = tSettings;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user