fix 时段码数据处理first异常
This commit is contained in:
@@ -20,14 +20,17 @@ public class AssignmentService : IAssignmentService
|
|||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||||
|
private readonly ILogger<AssignmentService> _logger;
|
||||||
private readonly FaceUrlOptions _faceUrlOptions;
|
private readonly FaceUrlOptions _faceUrlOptions;
|
||||||
|
|
||||||
public AssignmentService(IDbContext dbContext,
|
public AssignmentService(IDbContext dbContext,
|
||||||
IDataProtectionProvider dataProtectionProvider,
|
IDataProtectionProvider dataProtectionProvider,
|
||||||
IOptions<FaceUrlOptions> options)
|
IOptions<FaceUrlOptions> options,
|
||||||
|
ILogger<AssignmentService> logger)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_dataProtectionProvider = dataProtectionProvider;
|
_dataProtectionProvider = dataProtectionProvider;
|
||||||
|
_logger = logger;
|
||||||
_faceUrlOptions = options.Value;
|
_faceUrlOptions = options.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ public class AssignmentService : IAssignmentService
|
|||||||
var data = await GetDataAsync(request);
|
var data = await GetDataAsync(request);
|
||||||
if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>();
|
if (data.IsEmpty()) return new List<DeviceTaskToDeviceByDeviceResponse>();
|
||||||
|
|
||||||
await HandlerOldDeviceGainfoAsync(data);
|
//await HandlerOldDeviceGainfoAsync(data);
|
||||||
await HandlerTimePeriodAsync(data);
|
await HandlerTimePeriodAsync(data);
|
||||||
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
|
var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data);
|
||||||
|
|
||||||
@@ -404,51 +407,64 @@ public class AssignmentService : IAssignmentService
|
|||||||
|
|
||||||
private async Task HandlerTimePeriodAsync(List<TaskDto> data)
|
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();
|
try
|
||||||
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 => new { x.TenantId, x.TemplateCode }).DistinctBy(x => new { x.TenantId, x.TemplateCode }).ToList();
|
|
||||||
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
|
|
||||||
|
|
||||||
var where = LinqExpressionExtensions.False<DeviceTimePeriodEntity>();
|
|
||||||
where = where.Or(x => x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value));
|
|
||||||
foreach (var template in templateCodes)
|
|
||||||
{
|
{
|
||||||
where = where.Or(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template && x.Value == template.TemplateCode && x.TenantId == template.TenantId);
|
var tasks = data.Where(x => x.EnableTimePeriod).Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList();
|
||||||
}
|
if (tasks.IsEmpty()) return;
|
||||||
|
var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList();
|
||||||
|
|
||||||
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync();
|
||||||
.Where(where)
|
var templateCodes = devices.Select(x => new { x.TenantId, x.TemplateCode }).DistinctBy(x => new { x.TenantId, x.TemplateCode }).ToList();
|
||||||
.Select<DeviceTimePeriodDto>()
|
var deviceCodes = devices.Select(x => x.Code).Distinct().ToList();
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var basicTypes = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "timeperiod").ToListAsync();
|
var where = LinqExpressionExtensions.False<DeviceTimePeriodEntity>();
|
||||||
settings.ForEach(x => x.CardName = basicTypes.FirstOrDefault(p => p.Code == x.CardType.ToString())?.Display);
|
where = where.Or(x => x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value));
|
||||||
|
foreach (var template in templateCodes)
|
||||||
data.ForEach(item =>
|
|
||||||
{
|
|
||||||
var device = devices.First(x => x.UniqueNo == item.DeviceUniqueNo);
|
|
||||||
var templateCode = device.TemplateCode;
|
|
||||||
var code = device.Code;
|
|
||||||
|
|
||||||
var tSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template && x.TenantId == device.TenantId)
|
|
||||||
.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);
|
where = where.Or(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template && x.Value == template.TemplateCode && x.TenantId == template.TenantId);
|
||||||
if (s != null)
|
|
||||||
{
|
|
||||||
tSettings.Remove(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
tSettings.Add(setting);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item.TimePeriods = tSettings;
|
var settings = await _dbContext.Queryable<DeviceTimePeriodEntity>()
|
||||||
});
|
.Where(where)
|
||||||
|
.Select<DeviceTimePeriodDto>()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var basicTypes = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "timeperiod").ToListAsync();
|
||||||
|
settings.ForEach(x => x.CardName = basicTypes.FirstOrDefault(p => p.Code == x.CardType.ToString())?.Display);
|
||||||
|
|
||||||
|
foreach (var item in data)
|
||||||
|
{
|
||||||
|
var device = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo);
|
||||||
|
if (device == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateCode = device.TemplateCode;
|
||||||
|
var code = device.Code;
|
||||||
|
|
||||||
|
var tSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template && x.TenantId == device.TenantId)
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "处理时段码失败:{msg}", e.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user